Skip to content

Instantly share code, notes, and snippets.

# http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/
module DoAsYouPlease
Object.send :include, self
def method_missing(name, *args, &block)
self.class.const_get(name).call(*args, &block)
end
end
Foo = proc { 42 }
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@nicholasjhenry
nicholasjhenry / your_application.rb
Created October 22, 2011 04:56
PayRoll application, embedded in Rails, borrowing from Use Case Driven Architecture and DCI
## PayRoll gem
# lib/pay_roll.rb
module PayRoll
class << self
attr_accessor :employee_directory
def config
yield self
end
end
@tomstuart
tomstuart / gist:1466504
Created December 12, 2011 10:40
FizzBuzz in the lambda calculus in Ruby
>> IF = -> b { b }
=> #<Proc:0x007fb4e4049cc8 (lambda)>
>> LEFT = -> p { p[-> x { -> y { x } } ] }
=> #<Proc:0x007fb4e403d680 (lambda)>
>> RIGHT = -> p { p[-> x { -> y { y } } ] }
=> #<Proc:0x007fb4e4028ff0 (lambda)>
>> IS_EMPTY = LEFT
@christophermanning
christophermanning / README.md
Last active March 30, 2023 04:24
Voronoi Diagram with Force Directed Nodes and Delaunay Links

Created by Christopher Manning

Summary

Nodes are linked to nodes in neighboring cells. The cell's color is a function of its area.

The white lines are the Delaunay triangulation and the purple cells are the Voronoi diagram.

Controls

@krisleech
krisleech / README.md
Created February 23, 2012 15:50
A Micro Gem for commenting out lines of Ruby/Erb
hide do          
          _     _     _            
    /\  /(_) __| | __| | ___ _ __  
   / /_/ / |/ _` |/ _` |/ _ \ '_ \ 
  / __  /| | (_| | (_| |  __/ | | |
  \/ /_/ |_|\__,_|\__,_|\___|_| |_|
end
@JanKoszewski
JanKoszewski / H&P:[01-15].md
Created March 12, 2012 01:38
Hackers and Painters Reading Group [Chapters 1-15]

Chapter 1:

Summary

  • nerds are unpopular in high school, not because they don't want to be, but because they care more about being smart and pursuing higher intellectual goals than being popular.

What Stood Out

  • school is equivalently a prison, or at the tamest, a holding center for young kids
  • teenagers/children are cruel by nature
@mshafrir
mshafrir / states_hash.json
Created May 9, 2012 17:05
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@kellyredding
kellyredding / run.rb
Created May 16, 2012 17:54
Pull Gmail labels via IMAP using Gmail IMAP extensions
require 'net/imap'
# Net::IMAP raises a parse error exception when fetching attributes it doesn't
# recognize. Here I patch an instance of Net::IMAP's `msg_att` method to
# recognize the Gmail IMAP extended attributes
# Refer to:
# * https://developers.google.com/google-apps/gmail/imap_extensions#access_to_gmail_labels_x-gm-labels
# * http://blog.wojt.eu/post/13496746332/retrieving-gmail-thread-ids-with-ruby
@jboner
jboner / latency.txt
Last active April 19, 2024 23:08
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD