Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# vault
#
# Usage:
#
# vault file_name [vault_name]
#
# requires mvln from http://gist.github.com/54392 to be in the same directory as this file.
#
#!/usr/bin/env ruby
# unmvln
#
# Usage:
#
# unmvln symlink
#
# "undoes" a symlink
# removes the symlink and moves its target to the symlink's original path
# haml + liquid example
#
# James MacAulay 2009
require 'rubygems'
require 'liquid'
require 'haml'
template = <<EOF
if ((typeof Shopify) == 'undefined') {
var Shopify = {};
}
// ---------------------------------------------------------------------------
// Shopify generic helper methods
// ---------------------------------------------------------------------------
Shopify.each = function(ary, callback) {
for (var i = 0; i < ary.length; i++) {
# Enumerable#mash (MAp_to_haSH)
#
# %w{a baz buzz}.mash {|word| [word, word.length]}
# # => {"a"=>1, "baz"=>3, "buzz"=>4}
module Enumerable
def mash
self.inject(Hash.new) do |hash,e|
key, value = yield(e)
hash[key] = value
hash
#!/bin/sh
#
# .git/hooks/pre-commit
# make sure to make executable:
# chmod u+x .git/hooks/pre-commit
git diff HEAD | grep ^+.*debugger
if [ $? -ne 0 ]
then
(\{\{([^\}]*\n[^\}]*)\}\}|\{%([^\}]*\n[^\}]*)%\})
#!/usr/bin/env ruby
# put in .git/hooks/pre-commit and make executable
require 'rubygems'
require 'bundler'
begin
Bundler.definition
rescue Bundler::GemfileError => e
puts "Nothing was committed: #{e.message}"
Loading development environment (Rails 3.0.0.beta2)
irb(main):001:0> foo = Thing.first
=> #<Thing id: 1, name: "foo">
irb(main):002:0> Thing.include_root_in_json = true
=> true
irb(main):003:0> puts foo.to_json
{"thing":{"name":"foo","id":1}}
=> nil
irb(main):004:0> Hash.from_xml(foo.to_xml)
=> {"thing"=>{"name"=>"foo", "id"=>1}}
class Object
# [1, 2.0, 'a', 'b'].select(&Numeric)
# => [1, 2.0]
#
# duplicates Enumerable#grep, but:
# %w{purple monkey dishwasher}.select(&/r/)
# => ["purple", "dishwasher"]
def to_proc
Proc.new { |*args| self === args.first }
end