Skip to content

Instantly share code, notes, and snippets.

View captainpete's full-sized avatar

Peter Hollows captainpete

View GitHub Profile
# At first glance, this doesn't seem so useful.
def a
def b
'you called b'
end
'b is now defined'
end
# > b
# NameError: undefined local variable or method `b'...
// Needs to be run from a separate host that
// does not consider itself the server it's proxying to.
// So ghost the host to a VM running this (as root, for port 80).
var sys = require('sys'),
http = require('http'),
url = require('url');
var port = 80;
# NVM
if [[ -s $HOME/.nvm ]] ; then
setopt nullglob
NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh
nvm use
fi
@captainpete
captainpete / gist:782528
Created January 17, 2011 05:32
Example DRYish database.yml from 2010
common: &common
adapter: mysql
encoding: utf8
username: root
password:
development:
<<: *common
database: app_name
@captainpete
captainpete / Makefile
Created May 15, 2011 22:18 — forked from wezm/Makefile
Text processor for some strangely formatted geo data
CFLAGS = -O2 -Wall $(OPTFLAGS)
CC = clang
SOURCES = $(wildcard *.c)
OBJECTS := $(patsubst %.c, %.o, $(SOURCES))
all : main
main : $(OBJECTS)
$(CC) -o main $(CFLAGS) $(OBJECTS)
@captainpete
captainpete / gist:990168
Created May 25, 2011 01:51
Sample Hash unwrapper for Jon
def unwrap_hash(hash, scope = [])
hash.each do |key, value|
scope.push key
if value.is_a? Hash
unwrap_hash value, scope
else
puts "#{scope.join(':')} = #{value.inspect}"
end
scope.pop
end
@captainpete
captainpete / gist:992631
Created May 26, 2011 06:06
The Wesley Date Challenge
# Uses 1.9.2
# Makes use of existing day names in Date class
# Demeter is happy
# Support full and abbreviated names
# Doesn't use seconds (avoids error scenarios when crossing DST & leap-seconds)
class DDate < Date
def self.next(target_dayname)
target_wday = ABBR_DAYNAMES.index { |dayname| target_dayname =~ Regexp.new(dayname) }
diff = target_wday - today.wday
@captainpete
captainpete / library.rb
Created June 3, 2011 02:22
Tom's coding challenge. MiniTest suite
class Library
def self.leaf_paths_of(paths)
PathTree.new(paths).reduce
end
end
class PathTree < Hash
def initialize(paths = [])
paths.each { |path| self << path }
end
@captainpete
captainpete / First build
Created December 8, 2011 22:37
Pyrit benchmark: Custom rig, 2.7GHz AMD X2 235e, 850MHz Gigabyte HD 6770 Silent Cell
Pyrit 0.4.0 (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Running benchmark (22176.6 PMKs/s)... \
Computed 22176.60 PMKs/s total.
#1: 'OpenCL-Device 'Juniper'': 23084.8 PMKs/s (RTT 2.8)
#2: 'CPU-Core (SSE2)': 628.6 PMKs/s (RTT 3.0)
@captainpete
captainpete / gist:1449044
Created December 8, 2011 22:44
Pyrit benchmark: MacBook Pro 6,2 (15" mid-2010), 2.4GHz Intel Core i5, NVIDIA GeForce GT 330M 256MB
Pyrit 0.4.0 (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Running benchmark (2747.2 PMKs/s)... \
Computed 2747.16 PMKs/s total.
#1: 'OpenCL-Device 'GeForce GT 330M'': 1630.3 PMKs/s (RTT 2.6)
#2: 'CPU-Core (SSE2)': 458.1 PMKs/s (RTT 3.1)
#3: 'CPU-Core (SSE2)': 477.6 PMKs/s (RTT 3.1)
#4: 'CPU-Core (SSE2)': 471.0 PMKs/s (RTT 3.1)