This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via: http://julianbonilla.com/2008/03/16/finding-python-site-packages/ | |
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openssl rand 9 -base64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SEThreadInvocation.h | |
// | |
#import <Foundation/Foundation.h> | |
@interface SEThreadInvocation : NSObject | |
{ | |
NSThread * _thread; | |
NSInvocation * _invocation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer