Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / pbcopy.rb
Created June 22, 2010 17:44
Copy a string to the pasteboard in MacRuby
def pbcopy(string)
pasteBoard = NSPasteboard.generalPasteboard
pasteBoard.declareTypes([NSStringPboardType], owner: nil)
pasteBoard.setString(string, forType: NSStringPboardType)
end
var Timezone = {
set : function() {
var date = new Date();
date.setTime(date.getTime() + (1000*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = "timezone=" + (-date.getTimezoneOffset() * 60) + expires + "; path=/";
}
}
@defunkt
defunkt / gem-publish.sh
Created June 4, 2010 09:15
Builds and publishes a RubyGem.
#!/bin/sh -e
# Usage: gem-publish resque.gemspec
# Builds and publishes a RubyGem.
GEM=`gem build $1 2> /dev/null | grep File: | sed -e 's/File://'`
gem push $GEM
rm $GEM
@defunkt
defunkt / config.ru
Created June 3, 2010 19:36
Rails < 2.3 on Rack
# Because Unicorn is such a brilliant piece of software, it wraps older,
# non-Rack versions of Rails in a Rack handler. That way Unicorn
# itself can target Rack and not have to worry about monkey patching
# Rails' dispatcher.
#
# This means we can do the same, and even more.
#
# Starting Rackhub locally:
#
# Thin:
@defunkt
defunkt / ipad.js
Created May 31, 2010 00:53
Show or hide a sidebar in JS on iPad orientation change
window.onorientationchange = function() {
if (window.orientation == 0) {
$('#sidebar').fadeOut()
} else {
$('#sidebar').fadeIn()
}
}
@defunkt
defunkt / layout.rb
Created May 27, 2010 01:41
Dirt cheap layouts with Mustache.
require 'mustache'
class Layout < Mustache
self.template = "Header
{{{yield}}}
Footer"
end
class Index < Mustache
self.template = "The Index."
@defunkt
defunkt / gist:415205
Created May 26, 2010 23:15
redis-rb 2.0.0 compatibility patches
$ curl -s http://github.com/soveran/resque/commit/437b7736b9436c57c8d47a52f714daf849c40189.patch | wc -c
35046
$ curl -s http://github.com/defunkt/redis-namespace/commit/45811085eef9db6711ba73a8d575196e0ef8e962.patch | wc -c
1245
@defunkt
defunkt / ii.rb
Created May 24, 2010 23:33
{{.}} in mustache.rb
require 'mustache'
Mustache::Parser::ALLOWED_CONTENT = /(\w|[?!\/.-])*/
class ImplicitIterator < Mustache
define_method "." do
self[:to_s]
end
def names
@defunkt
defunkt / mustache_test.rb
Created May 24, 2010 18:06 — forked from rafaelss/mustache_test.rb
Ruby 1.9 Failing Mustache case
# Fails on 1.9.1p376
require 'test/unit'
require 'mustache'
class MTest < Test::Unit::TestCase
def test_array_of_arrays
template = <<template
{{#items}}
start
@defunkt
defunkt / gist:412166
Created May 24, 2010 17:35
ripenv in your sh prompt
ripenv_prompt () {
_OLDPS1="$PS1"
PS1="{\$(rip-env)}$PS1"
}
ripenv_no_prompt () {
PS1="$_OLDPS1"
}