Skip to content

Instantly share code, notes, and snippets.

View capitalist's full-sized avatar
🎯
Focusing

Joe Martinez capitalist

🎯
Focusing
View GitHub Profile
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@ahoward
ahoward / render.rb
Created August 20, 2012 17:19
rendering outside a controller
av = ActionView::Base.new(Rails.application.config.paths['app/views'].first)
### av.controller = Current.mock_controller # gem install rails_current
av.render( :locals => {:model => Model.first}, :partial => "shared/model" ) #=> string
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@ahoward
ahoward / backup.rake
Created July 17, 2012 20:04
lib/tasks/backup.rake
## file : RAILS_ROOT/lib/tasks/backup.rake
namespace('backup') do
namespace('dump') do
##
desc 'backup:dump:all'
task('all' => %w( dump:schema dump:tables dump:assets ))
##
desc 'backup:dump:schema'
@ahoward
ahoward / Capfile.rb
Created July 16, 2012 17:19
lib/tasks/jobs.rake, config/schedule.rb, Capfile
## maybe we have background tasks running...
#
namespace :jobs do
task :restart do
run("cd #{ deploy_to }/current && ./script/jobs restart; true")
end
task :start do
run("cd #{ deploy_to }/current && ./script/jobs start; true")
end
@ahoward
ahoward / job.rb
Created July 16, 2012 17:13
app/models/job.rb
#
# this module encapsulate the interface expected by DelayedJob, and Resque -
# if you use it your app will not need to change if you change background
# processing systems. it also centralizes and makes easy to test all
# potential background jobs independently of your preferred system.
#
# all jobs are stored in the db, but a queueing system, like resque, is used
# to run them in the background. this way the job class can support a rich
# query interface and persistence regardless of the background processing
# system used.
@mrmemes-eth
mrmemes-eth / decent_decorator.rb
Created June 1, 2012 19:17
Simple monkey patch for decent_exposure's nu_nu branch to add automatic decoration of singular resources. Throw this in config/initializers and monkey patch your way to victory! Assumes a module like the one included.
class DecentExposure::ActiveRecord::Finder
def decorated_singular_resource
singular_resource.extend("#{singular_resource.class.name}Decorator".constantize)
rescue NameError
singular_resource
end
def resource
if plural?
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@nixme
nixme / acr122u.rb
Created May 17, 2012 08:00
Read NFC tag IDs from a Tagstand ACR122U USB reader
# Quick and dirty script to read unique IDs from NFC tags using the ACR122U USB
# reader.
#
# PC/SC-based API details for the ACR122U available at
# http://acs.com.hk/drivers/eng/API_ACR122U_v2.01.pdf
#
# Assumes ruby >= 1.9.2
# `gem install smartcard` first
#
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"