Skip to content

Instantly share code, notes, and snippets.

View kisai's full-sized avatar

Sergio Diaz kisai

  • UNOSQUARE
  • Mexico
View GitHub Profile
#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
# 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
@kisai
kisai / git_diff_sta.sh
Created August 26, 2014 15:40
git diff stash
git stash show -p stash@{0}
@kisai
kisai / emacs_multi_instance.sh
Created August 24, 2014 02:33
Different emacs inits
$ emacs -q -l initfile1.el &
$ emacs -q -l initfile2.el
@kisai
kisai / method_missing.rb
Created August 23, 2014 05:47
Method missing
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]
@kisai
kisai / my_attr_accessor.rb
Created August 23, 2014 05:44
My attr_accesor.rb
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
@kisai
kisai / add_method_to_object.rb
Last active August 29, 2015 14:05
Meat: Add method to an instanced object
obj = SomeObject.new
obj.define_singleton_method(:new_method) do
"do some things"
end
# Using a mixin
module AdditionalMethods
def new_method
rails g migration add_public_and_private_to_document public:string private:string
bin/rails generate migration AddSomeRefAndSomeColumnToSomeTable some:references some_column:boolean
@kisai
kisai / find_duplicate_array.rb
Created August 20, 2014 16:10
Find duplicates in a array
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
@kisai
kisai / precedence_nightmare.rb
Last active August 29, 2015 14:05
precedence rule nightmare.... damn i love lisp (pun made on a comment "damn i love ruby" when he was using zippers an FP algorithm)
true || true and false #=> false
true || true && false #=> true