Skip to content

Instantly share code, notes, and snippets.

@dustin
dustin / cat.rb
Created July 30, 2008 23:38
Object concatenation class. Combine two objects to get the union of their properties and behaviors.
require 'core_ext'
module Metahackery
# Object concatentation, singleton multiple inheritence, singleton mixin, etc...
# This object allows you to smash two objects together into one object that
# appears to be any of the sub-objects depending on how you look at it.
class Cat
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
@dustin
dustin / sitemap-walk.py
Created October 26, 2008 08:05
A sitemap spider tool.
#!/usr/bin/env python
"""
Walk a sitemap and report timings and stuff.
Copyright (c) 2008 Dustin Sallings <dustin@spy.net>
"""
import sys
import time
import getopt
#!/usr/bin/env python
"""
A script to tell you who actually wrote your current codebase.
Usage:
git ls-files | xargs -n 1 git annotate | ./who-wrote-this.py
Copyright (c) 2008 Dustin Sallings <dustin@spy.net>
"""
@dustin
dustin / post-receive-email.sh
Created December 4, 2008 20:33
Old post-receive email script I used at caring.com
#!/bin/sh
#
# Copyright (c) 2007 Andy Parkins
#
# An example hook script to mail out commit update information. This hook
# sends emails listing new revisions to the repository introduced by the
# change being reported. The rule is that (for branch updates) each commit
# will appear on one email and one email only.
#
# This hook is stored in the contrib/hooks directory. Your distribution
@dustin
dustin / no-reserved-words.rb
Created December 17, 2008 21:28
Playing around with reserved words. Ruby doesn't seem to care.
#!/usr/bin/env ruby -w
class O
def yield
puts "Yielded."
end
def do
puts "Doing."
end
def def
@dustin
dustin / autolinks.html
Created December 24, 2008 08:00
HTML to generate an HTML list of related links for you.
#!/usr/bin/env python
import random
if __name__ == '__main__':
colors=('red', 'green', 'yellow', 'blue')
limbs=('left foot', 'right foot', 'left hand', 'right hand')
print random.choice(limbs), random.choice(colors)
# moved to http://gist.github.com/41462
def whack(objects)
Hash[ *objects.map{|o| [o.send('table_name'), o.send('delete_all')]}.flatten]
end
@dustin
dustin / gist:41462
Created December 30, 2008 00:48 — forked from damon/gist:41453
def whack(objects)
Hash[*objects.map{|o| [o.send('table_name'), o.send('delete_all')]}.flatten]
end
# or (depending on what "send" means there)
def whack(objects)
Hash[*objects.map{|o| [o.table_name, o.delete_all]}.flatten]
end
@dustin
dustin / sample-eventd-script-for-twisted
Created January 6, 2009 05:44
Sample upstart script for a twisted project.
# This is a sample script for upstart to keep a twisted project running.
# Place it in /etc/event.d/[projectname]
description "useful description"
author "Dustin Sallings <dustin@spy.net>"
start on runlevel 2
start on runlevel 3
stop on runlevel 0