Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am emrekutlu on github.
  • I am emrekutlu (https://keybase.io/emrekutlu) on keybase.
  • I have a public key whose fingerprint is 9D27 1C00 B12A DFB0 F5F7 925D 6D65 A5BA 3506 4F07

To claim this, I am signing this object:

View .vimrc
set nocompatible
syntax on
set ts=2
set shiftwidth=2
set expandtab
retab
set autoindent
set ruler
set incsearch
set background=dark
@emrekutlu
emrekutlu / dj_custom_job.rb
Created Aug 29, 2011
Check existence of DelayedJob records
View dj_custom_job.rb
#A Custom job is a class with a method called perform
class User
def perform
#long running process
end
end
#check existence of DelayedJob record
Delayed::Job.exists?(:handler => Delayed::Job.new(:payload_object => User.new).handler, :locked_at => nil)
@emrekutlu
emrekutlu / add_instance_methods.rb
Created Jun 5, 2011
dynamically adding methods to instances
View add_instance_methods.rb
class Message
[:hello, :goodbye].each do |method_name|
define_method method_name do |arg|
"#{method_name} #{arg}"
end
end
end
#irb
Message.instance_methods false #=> [:hello, :goodbye]
View deep_merge.rb
def deep_merge!(other_hash, &block)
other_hash.each_pair do |k,v|
tv = self[k]
self[k] = (tv.is_a?(Hash) && v.is_a?(Hash)) ? tv.deep_merge(v, &block) : (block_given? and (!tv.nil? and !v.nil?)) ? yield(k, tv, v) : v
end
self
end
View ordered_hash_merge_with_block.rb
module ActiveSupport
class OrderedHash
def merge!(other_hash)
other_hash.each do |k, v|
self[k] = block_given? ? yield(k, self[k], v) : v
end
self
end