This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#source http://stackoverflow.com/questions/12265421/sidekiq-authentication | |
require 'sidekiq' | |
require 'sidekiq/web' | |
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password| | |
[user, password] == ["sidekiqadmin", "yourpassword"] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://robots.thoughtbot.com/how-to-share-a-session-between-sinatra-and-rails | |
# wanna do this | |
get '/dashboard' do | |
if session[:user_id].present? | |
redirect to('/') | |
else | |
# set up and render dashboard | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git stash show -p stash@{0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ emacs -q -l initfile1.el & | |
$ emacs -q -l initfile2.el |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method_missing(mid, *args) # :nodoc: | |
mname = mid.id2name | |
len = args.length | |
if mname.chomp!('=') && mid != :[]= | |
if len != 1 | |
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1) | |
end | |
modifiable[new_ostruct_member(mname)] = args[0] | |
elsif len == 0 && mid != :[] | |
@table[mid] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Class | |
#firstly, the * decoration on the parameter variable | |
#indicates that the parameters should come in as an array | |
#of whatever was sent | |
def my_attr_accessor(*args) | |
#We simply iterate through each passed in argument... | |
args.each do |arg| | |
#Here's the getter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
obj = SomeObject.new | |
obj.define_singleton_method(:new_method) do | |
"do some things" | |
end | |
# Using a mixin | |
module AdditionalMethods | |
def new_method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails g migration add_public_and_private_to_document public:string private:string | |
bin/rails generate migration AddSomeRefAndSomeColumnToSomeTable some:references some_column:boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ary = ["A", "B", "C", "B", "A"] | |
ary.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first) | |
ary.sort.chunk { |e| e }.select { |e, count| count.size > 1 }.map(&:first) | |
ary.select { |e| ary.count(e) > 1 }.uniq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
true || true and false #=> false | |
true || true && false #=> true |