Skip to content

Instantly share code, notes, and snippets.

end_char = ARGV.first
characters = ('A'..end_char).to_a + ('A'...end_char).to_a.reverse
max_level = end_char.ord - 'A'.ord
diamond = characters.map do |char|
current_level = char.ord - 'A'.ord
before_spaces = max_level - current_level
if char == 'A'
end_char = ARGV.first
characters = ('A'..end_char).to_a + ('A'...end_char).to_a.reverse
max_level = end_char.ord - 'A'.ord
diamond = characters.map do |char|
current_level = char.ord - 'A'.ord
before_spaces = max_level - current_level
if char == 'A'
AllCops:
Exclude:
- 'vendor/**/*'
- 'db/schema.rb'
Metrics/LineLength:
Enabled: false
Style/Documentation:
Enabled: false
Style/StringLiterals:
Enabled: false
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
  1. don't use self.method name, just put it in class << self
  2. don't use get_property, use the property name directly get_ and set_ is considered noise in ruby
  3. always add () in function definition with parameters
  4. you should always specify your rescued excpetion class
  5. there are a lot of cryptic lines with implicit logic like flatten[1]
  6. be consistent with methods names "_by(id)"
= AAccttiivveeRReeccoorrdd::::BBaassee  <<  OObbjjeecctt
------------------------------------------------------------------------------
= IInncclluuddeess::
(from gem activerecord-4.2.5.1)
Core
Persistence
ReadonlyAttributes
ModelSchema
Inheritance
@emad-elsaid
emad-elsaid / clone-bitbucket.sh
Last active February 19, 2016 12:26
Clone all bitbucket repositories to directory
#!/bin/bash
#Script to get all repositories under a user from bitbucket
#Usage: getAllRepos.sh [username]
#source: http://haroldsoh.com/2011/10/07/clone-all-repos-from-a-bitbucket-source/
curl -u ${1} https://api.bitbucket.org/1.0/users/${1} > repoinfo
# curl -u adomingues https://api.bitbucket.org/1.0/users/adomingues
# cat repoinfo
for repo_name in `cat repoinfo | sed -r 's/("name": )/\n\1/g' | sed -r 's/"name": "(.*)"/\1/' | sed -e 's/{//' | cut -f1 -d\" | tr '\n' ' '`
@emad-elsaid
emad-elsaid / gist:7f683d6c80b6034ca796
Created January 2, 2016 20:47
disable submit button and enable it after 3 seconds
$(function(){
$('button[type="submit"]').click(function(){
var _this = $(this);
_this.attr('disabled', 'disabled');
setTimeout(function(){
_this.removeAttr('disabled');
}, 3000);
});
});
@emad-elsaid
emad-elsaid / yamls.rb
Created October 20, 2015 10:21
# this initializer will load all yaml files in config/yamls then assign each # file content to a constant that is equal to the file name capitalized. # if you added a file named `config/yamls/foo.yml` you can access its # content through `FOO` constant
# this initializer will load all yaml files in config/yamls then assign each
# file content to a constant that is equal to the file name capitalized.
# if you added a file named `config/yamls/foo.yml` you can access its
# content through `FOO` constant
@emad-elsaid
emad-elsaid / string_indices.rb
Created September 17, 2015 10:52
works like index for string but return all indices occurrences for a substring
class String
def indices(part)
ids = []
begin
ids << index(part, (ids[-1]||-1)+1)
end while !ids[-1].nil?
ids.pop
ids
end
end