Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / before_enqueue.rb
Created April 27, 2010 15:09
How to hook into Resque's `enqueue` method from a plugin.
# How to hook into Resque's `enqueue` method from a plugin.
module EnqueuePlugin
# Only enqueues subclasses of GitHub::Job
def enqueue(klass, *args)
looks_okay?(klass) ? super : false
end
def looks_okay?(klass)
klass < GitHub::Job
@defunkt
defunkt / ports.sh
Created April 21, 2010 17:24
List what ports are in use on OS X
# List what ports are in use on OS X
sudo lsof -iTCP -sTCP:LISTEN -P
@defunkt
defunkt / clients.md
Created April 18, 2010 14:09
A list of Gist clients.

Gist Clients

Want to create a Gist from your editor, the command line, or the Services menu? Here's how.

Editor Support

@defunkt
defunkt / memrate.rb
Created April 8, 2010 08:09 — forked from rtomayko/memrate.rb
Awesome option parsing.
#!/usr/bin/env ruby
## Usage: memrate.rb [-l <lib>] [-i <num>] [-t <threshold>] [-k <size>] [<host>]
## Measure memcached server read time.
##
## Options
## -l, --library=<lib> Memcached client library to use. memcache-client by
## default. memcached also supported.
## -i, --iterations=<num> Number of times to read the value. If not set, read
## until interrupted.
## -t, --threshold=<time> Report iterations that take longer than <time>
@defunkt
defunkt / jobs_per_fork.rb
Created March 30, 2010 18:11
Resque hook to run N jobs per fork
Resque.after_fork do |job|
# How many jobs should we process in each fork?
jobs_per_fork = [ ENV['JOBS_PER_FORK'].to_i, 1 ].max
# Set hook to nil to prevent running this hook over
# and over while processing more jobs in this fork.
Resque.after_fork = nil
# Make sure we process jobs in the right order.
job.worker.process(job)
@defunkt
defunkt / beatles.mustache
Created March 30, 2010 03:35
Pragma-less implicit iterators in mustache.rb
The Beatles were:
{{#names}}
* {{to_s}}
{{/names}}
<html>
<title>{{title}}</title>
</html>
@defunkt
defunkt / _README.md
Created March 26, 2010 22:37
Upgrading to Sinatra 1.0 and Mustache 0.9

Previously you'd do this:

set :namespace, Haystack
set :views, 'templates/'
set :mustaches, views/'

Now you do this:

set :mustache, {

:namespace => Haystack,

@defunkt
defunkt / rip-dependency-tree
Created March 13, 2010 18:41
Cuz why not?
$ rip-dependency-tree test/fixtures/complex.rip
test/fixtures/complex.rip
|-- git://github.com/ezmobius/redis-rb.git
|-- git://github.com/brianmario/yajl-ruby.git (0.6.3)
|-- sinatra (0.9.4)
| |-- rack (1.0)
| | `-- url_escape
| | |-- cgi_escape
| | `-- url_parser (0.4.3)
| `-- haml (1.0.0)
@defunkt
defunkt / gist:331174
Created March 13, 2010 07:02
Dumbed down `cat` in Ruby.
#!/usr/bin/env ruby
# Usage: rcat [file ...]
#
# Reads files sequentially, writing them to the standard output. The
# file operands are processed in command-line order. If file is a
# single dash (`-') or absent, rcat reads from the standard input.
#
# Like cat(1), but dumber.
puts ARGF.read