Skip to content

Instantly share code, notes, and snippets.

View betawaffle's full-sized avatar

Andrew Hodges betawaffle

View GitHub Profile
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@eliaslevy
eliaslevy / gist:3042381
Created July 3, 2012 19:43
High level AMQP blocking publish method
# Helper method that publishes a message to an exchange and waits for a
# broker acknowledgement using RabbitMQ's publisher confirmation extension.
#
# Confirm mode must already be enabled in the channel. You can turn
# confirm mode on using channel.confirm_select. You must only do this
# once.
#
# It also raises an error if you use the mandatory and/or immediate
# options, and these constrains cannot be meet by the broker.
#
@jboner
jboner / latency.txt
Last active July 15, 2025 00:14
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
require 'minitest/autorun'
###
# Test to demonstrate TCO in Ruby. Tested in 1.9.2+
class TestTCO < MiniTest::Unit::TestCase
code = <<-eocode
class Facts
def fact_helper(n, res)
if n == 1
res
@robinsmidsrod
robinsmidsrod / _INSTALL.md
Last active July 14, 2025 23:28
Bootstrapping full iPXE native menu with customizable default option with timeout (also includes working Ubuntu 12.04 preseed install)

Add the following chunk to your existing ISC dhcpd.conf file.

if exists user-class and ( option user-class = "iPXE" ) {
    filename "http://boot.smidsrod.lan/boot.ipxe";
}
else {
    filename "undionly.kpxe";
}

(or see https://gist.github.com/4008017 for a more elaborate setup

@betawaffle
betawaffle / y.rb
Created March 25, 2012 21:00
Ruby Y Combinator
def Y f = nil, &b
f ||= b; -> g { g[g] }.call -> g { f[-> *a { g[g][*a] }] }
end
# Hash Autovivification
Y { |d| -> { Hash.new do |h, k| h[k] = d[] end }[]
# Factorial
Y -> fac { -> n { n <= 2 ? n : n * fac[n - 1] } }
class FormattedString < String
PATTERN = /:(\w+)/
DEFER = lambda { |match| match }
def initialize str = '', pattern = nil
super str
pattern ||= PATTERN
@compiler = DEFER
# in config/initializers
ActiveRecord::Relation.class_eval do
include EachRow
end
module Enumerable
def lazy_map mapper = nil, &block
return to_enum(:lazy_map, block) unless mapper
return to_enum(:lazy_map, mapper) unless block
each do |*args|
yield mapper.call(*args)
end
end
end