Skip to content

Instantly share code, notes, and snippets.

View simon-engledew's full-sized avatar
🙈

Simon Engledew simon-engledew

🙈
View GitHub Profile
def curry(function, *curried_args):
def curried_method(*args):
return function(*(curried_args + args))
return curried_method
def hello(firstname, lastname):
print "hello %s %s" % (firstname, lastname)
hello_mickey = curry(hello, 'Mickey')
import weakref
def generate_key(o):
if hasattr(o, 'items'):
return generate_key(sorted(o.items(), lambda a, b: cmp(a[0], b[0])))
if hasattr(o, '__iter__'):
return tuple(generate_key(v) for v in o)
return o
# via: http://julianbonilla.com/2008/03/16/finding-python-site-packages/
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
openssl rand 9 -base64
@simon-engledew
simon-engledew / run script for resque w. monit
Created February 16, 2010 12:59
A script to run Resque as a daemon.
#!/usr/bin/env ruby
if GC.respond_to?(:copy_on_write_friendly=); GC.copy_on_write_friendly = true; end
def pidfile
@pidfile ||= File.expand_path(File.join('..', '..', 'tmp', 'pids', 'consumer.pid'), __FILE__)
end
case ARGV.first
when 'start' then
@simon-engledew
simon-engledew / SEThreadInvocation.h
Created June 24, 2010 08:49
Thread invocation with varargs in Objective C
//
// SEThreadInvocation.h
//
#import <Foundation/Foundation.h>
@interface SEThreadInvocation : NSObject
{
NSThread * _thread;
NSInvocation * _invocation;
@simon-engledew
simon-engledew / post-commit
Created August 5, 2010 12:45
Post commit hook to play Hallelujah
#!/bin/sh
# post commit hook to play "Hallelujah" after a commit
FILENAME=~/.git/post-commit.mp3
DIRECTORY=`dirname $FILENAME`
if [ ! -d "$DIRECTORY" ]
then
mkdir "$DIRECTORY"
fi
@simon-engledew
simon-engledew / application_controller.rb
Created August 11, 2010 10:09
ruby lambda in a different scope
class ApplicationController < ActionController::Base
def self.before_filter_in_instance(&block)
before_filter do |controller|
controller.instance_eval(&block)
end
end
# fails!
# params is not available
<html>
<head>
<style>
input[type="button"]::-moz-focus-inner
{
border: 0;
}
.button, input[type="button"], input[type="submit"]
{
@simon-engledew
simon-engledew / cache.rb
Created December 10, 2010 16:09
Helper/Wrapper for the Rails caching mechanism.
class Cache
class << self
def read(key, &block)
if (value = self[key]).nil? and block_given?
value = block.call
self[key] = value
end
return value
end