Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / mustache_i18n.rb
Created March 19, 2011 19:16
Mustache & i18n
class Stache18n
@@tags = {
'comment-and-close' => 'Comment and close',
'github' => 'GitHub',
'social-coding' => 'Social Coding'
}
def self.t
@@tags
end
@defunkt
defunkt / gist:877708
Created March 19, 2011 19:00
Handing Mustache normal Ruby objects
class Highlighter
def ruby(text)
"<pre class='ruby'>#{text}</pre>"
end
def python(text)
"<pre class='python'>#{text}</pre>"
end
end
@defunkt
defunkt / gist:877705
Created March 19, 2011 18:52 — forked from aumgn/gist:864853
Mustache Object Implementation
class HighlighterHelper
def respond_to?(language)
Highlighter.highlight?(language)
end
def method_missing(language)
lambda { |text|
Highlighter.send(language, text)
}
end
@defunkt
defunkt / jsize.sh
Created February 28, 2011 00:08
Print the size of a minified & gzip'd js file.
#!/bin/sh -e
#
# Usage: jsize file.js
# Print the size of a minified & gzip'd js file.
# e.g.
# $ jsize src/facebox.js
# 1.4K
#
# Requires uglify-js
@defunkt
defunkt / gh-get.sh
Created February 4, 2011 08:04
Easily grab a single file from GitHub.
# $ gh-get https://github.com/defunkt/facebox/blob/master/src/facebox.js
function gh-get () {
curl -#O $(echo $1 | sed 's|blob|raw|')
}
@defunkt
defunkt / zombies.md
Created December 29, 2010 22:57
—All You Zombies— by Robert A. Heinlein

All You Zombies

2217 Time Zone V (EST) 7 Nov. 1970--NTC-- "Pop's Place": I was polishing a brandy snifter when the Unmarried Mother came in. I noted the time---10:17 P. M. zone five, or eastern time, November 7th, 1970. Temporal agents always notice time and date; we must.

The Unmarried Mother was a man twenty--five years old, no taller than I am, childish features and a touchy temper. I didn't like his looks---I never had---but he was a lad I was here to recruit, he was my boy. I gave him my best barkeep's smile.

Maybe I'm too critical. He wasn't swish; his nickname came from what he always said when some nosy type asked him his line: "I'm an unmarried mother." If he felt less than murderous he would add: "at four cents a word. I write confession stories."

If he felt nasty, he would wait for somebody to make something of it. He had a lethal style of infighting, like a female cop---reason I wanted him. Not the only one.

$ CACHED=1 ruby -rubygems -I lib benchmarks/speed.rb
Rehearsal ---------------------------------------------------
ERB w/ caching 0.190000 0.000000 0.190000 ( 0.200326)
HAML w/ caching 0.810000 0.010000 0.820000 ( 0.846492)
{{ w/ caching 0.840000 0.000000 0.840000 ( 0.842275)
------------------------------------------ total: 1.850000sec
user system total real
ERB w/ caching 0.190000 0.010000 0.200000 ( 0.194241)
HAML w/ caching 0.810000 0.010000 0.820000 ( 0.823237)
@defunkt
defunkt / murder.sh
Created July 22, 2010 19:20
murder processes matching a pattern
# sh function to murder all running processes matching a pattern
# thanks 3n: http://twitter.com/3n/status/19113206105
murder () {
ps | grep $1 | grep -v grep | awk '{print $1}' | xargs kill -9
}
@defunkt
defunkt / gist:449668
Created June 23, 2010 08:55 — forked from dustin/gist:397971
Emacs Lisp to automatically add, commit, and push when files change
;; Automatically add, commit, and push when files change.
(defvar autocommit-dir-set '()
"Set of directories for which there is a pending timer job")
(defun autocommit-schedule-commit (dn)
"Schedule an autocommit (and push) if one is not already scheduled for the given dir."
(if (null (member dn autocommit-dir-set))
(progn
(run-with-idle-timer