Skip to content

Instantly share code, notes, and snippets.

View jqr's full-sized avatar

Elijah Miller jqr

View GitHub Profile
@jqr
jqr / gist:57524
Created February 3, 2009 13:30 — forked from anonymous/gist:57476
module ApplicationHelper
def self_url(options = {})
url_for(request.path_parameters.merge(options))
end
end
describe ApplicationHelper do
describe '#self_url' do
before(:each) do
# using params we can easily detect a reverse merge with
require 'rubygems'
require 'httparty'
require 'time'
require 'active_support'
File.read("#{ENV['HOME']}/.gitconfig").match(/token = (\w+)/)
TOKEN = $1
class Github
include HTTParty
class FilterableEnumerable
def initialize(original)
@original = original
end
def ==(value)
@original.select { |v| v == value }
end
def method_missing(sym, *args, &block)
# Spawned from this thread: http://rubyflow.com/items/1990
module Enumerable
# Wraps an enumerable in an easy interface for selecting subsets. Comparison
# and method calls are supported.
#
# [0, 1, 2, 3].filter > 1 # => [2, 3]
# [0, 1, 2, 3].filter.zero? # => [0]
#
# Warning: Do not use this with the != operator, use filter_not instead.
irb(main):001:0> thing
NameError: undefined local variable or method `thing' for main:Object
from (irb):1
irb(main):002:0> defined? thing
=> nil
irb(main):003:0> thing = thing
=> nil
irb(main):004:0> thing
=> nil
irb(main):005:0> defined? thing
module Breadcrumb
def breadcrumbs
if parent
parent.breadcrumbs << self
else
[self]
end
end
end
require 'activesupport'
{:one => 1, :two => 2}.slice(:one) #=> {:one=>1}
# In ruby 1.9
{:one => 1, :two => 2}.select {|k,v| k == :one} #=> {:one=>1}
{:one => 1, :two => 2}.reject {|k,v| k == :one} #=> {:two=>2}
#!/usr/bin/env ruby
home = File.expand_path('~')
Dir["#{home}/Library/Application Support/TextMate{,/Pristine Copy}/Bundles/*/.git"].each do |bundle|
dir = bundle.gsub(/\.git/, '')
puts "Updating #{File.basename(dir)}"
Dir.chdir(dir) { `git pull` }
end
`osascript -e 'tell app "TextMate" to reload bundles'`
@jqr
jqr / bertmark.rb
Created October 23, 2009 12:40 — forked from brianmario/bertmark.rb
require 'rubygems'
require 'bert'
require 'json'
require 'yajl'
require 'benchmark'
ITER = 1_000
tiny = t[:ok, :awesome]
small = t[:ok, :answers, [42] * 42]