Skip to content

Instantly share code, notes, and snippets.

@rtomayko
rtomayko / latency.txt
Created June 1, 2012 00:43 — forked from jhclark/latency.txt
Latency numbers every programmer should know
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
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
Read 1 MB sequentially from SSD 1,000,000 ns 1 ms 4X memory
@rtomayko
rtomayko / gist:942910
Created April 26, 2011 19:21 — forked from schacon/gist:942899
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v -e '>' -e master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
.__ ___. .__ __ .__ .___
| |__ _____ ______ ______ ___.__. \_ |__ |__|_______ _/ |_ | |__ __| _/_____ ___.__.
| | \ \__ \ \____ \ \____ \< | | | __ \ | |\_ __ \\ __\| | \ / __ | \__ \ < | |
| Y \ / __ \_| |_> >| |_> >\___ | | \_\ \| | | | \/ | | | Y \/ /_/ | / __ \_\___ |
|___| /(____ /| __/ | __/ / ____| |___ /|__| |__| |__| |___| /\____ | (____ // ____|
\/ \/ |__| |__| \/ \/ \/ \/ \/ \/
_____ ___ ___ ___ ___ ___
/ /::\ / /\ / /\ /__/\ /__/\ /__/| ___
/ /:/\:\ / /:/_ / /:/_ \ \:\ \ \:\ | |:| / /\
/ /:/ \:\ / /:/ /\ / /:/ /\ \ \:\ \ \:\ | |:| / /:/
# GC on Template finalize
class Template
module CompiledTemplates; end
def self.garbage_collect_compiled_method(object_id)
CompiledTemplates.module_eval do
remove_method Template.compiled_method(object_id)
end
end
@rtomayko
rtomayko / license
Created January 27, 2010 12:04 — forked from ap/license
#!/bin/sh
# Usage: license
# Prints an MIT license appropriate for totin' around.
#
# $ license > COPYING
exec sh -c "tail -n +$(expr $LINENO + 1) < $0 | sed s/DATE/$(date +%Y)/"
Copyright (c) DATE Ryan Tomayko
Permission is hereby granted, free of charge, to any person ob-
taining a copy of this software and associated documentation
#!/bin/sh -e
# Usage: git-amend <commit>
# Amend changes staged in the index to <commit>, or edit commit message if
# no changes are currently staged. Modifications not staged are stashed and
# then reapplied once the amend and rebase operations are complete.
#
# This command rewrites history. Do not run it after <commit> or its
# decendants have been published to the world.
#
# This version in POSIX sh by Ryan Tomayko <tomayko.com/about>
##
# test/spec/mini 2
# http://gist.github.com/25455
# chris@ozmm.org
# file:lib/test/spec/mini.rb
#
def context(*args, &block)
return super unless (name = args.first) && block
require 'test/unit'
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
require "sinatra/base"
class WhatTheFuck < Sinatra::Base
set :raise_errors, false
set :dump_errors, true
use_in_file_templates!
get "/" do
erb :wtf
end
# The code in lib/foobar.rb
require 'sinatra/base'
class Foobar < Sinatra::Base
VERSION = '1.0.0'
configure do
set :foobar, environment
end
end
# The tests in test/test_foobar.rb
The "registered" module method was added to help ensure that extensions can
initialize options in a way that guarantees they can be accessed using
"options.option_name" at the request-level or "self.option_name" at the class
level. I've rewritten the examples to illustrate the new usage.