This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# unmvln | |
# | |
# Usage: | |
# | |
# unmvln symlink | |
# | |
# "undoes" a symlink | |
# removes the symlink and moves its target to the symlink's original path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# haml + liquid example | |
# | |
# James MacAulay 2009 | |
require 'rubygems' | |
require 'liquid' | |
require 'haml' | |
template = <<EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((typeof Shopify) == 'undefined') { | |
var Shopify = {}; | |
} | |
// --------------------------------------------------------------------------- | |
// Shopify generic helper methods | |
// --------------------------------------------------------------------------- | |
Shopify.each = function(ary, callback) { | |
for (var i = 0; i < ary.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(\{\{([^\}]*\n[^\}]*)\}\}|\{%([^\}]*\n[^\}]*)%\}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |