Skip to content

Instantly share code, notes, and snippets.

View mustache_i18n.rb
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 Mar 19, 2011
Handing Mustache normal Ruby objects
View gist:877708
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 Mar 19, 2011 — forked from aumgn/gist:864853
Mustache Object Implementation
View gist:877705
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 Feb 28, 2011
Print the size of a minified & gzip'd js file.
View jsize.sh
#!/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 Feb 4, 2011
Easily grab a single file from GitHub.
View gh-get.sh
# $ 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 Dec 29, 2010
—All You Zombies— by Robert A. Heinlein
View zombies.md

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.

View after-spec-merge
$ 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 Jul 22, 2010
murder processes matching a pattern
View murder.sh
# 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 Jun 23, 2010 — forked from dustin/gist:397971
Emacs Lisp to automatically add, commit, and push when files change
View gist:449668
;; 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
@defunkt
defunkt / pbcopy.rb
Created Jun 22, 2010
Copy a string to the pasteboard in MacRuby
View pbcopy.rb
def pbcopy(string)
pasteBoard = NSPasteboard.generalPasteboard
pasteBoard.declareTypes([NSStringPboardType], owner: nil)
pasteBoard.setString(string, forType: NSStringPboardType)
end