Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
class Utils
def self.staged_files(*dirs)
@staged_files ||= `git diff --cached --name-only #{dirs.join(' ')} | xargs`.chomp
end
end
@jish
jish / chef.rb
Created January 3, 2011 23:02
Monkey patching a library with custom functionality
class Chef
def some_method
puts 'This method does something'
end
end
~% irb
ree-1.8.7-2010.02 > 2.megabytes
NoMethodError: undefined method `megabytes' for 2:Fixnum
from (irb):1
ree-1.8.7-2010.02 > require 'rubygems'
=> true
ree-1.8.7-2010.02 > require 'active_support'
=> true
ree-1.8.7-2010.02 > 2.megabytes
=> 2097152
@jish
jish / foo.rb
Created January 22, 2011 18:20
the description
class Foo
def bar
puts 'baz'
end
end
change_iterm_colors() {
osascript -e "tell application \"iTerm\"\
to tell the current terminal\
to tell the current session\
to set the background color to \"$1\""
osascript -e "tell application \"iTerm\"\
to tell the current terminal\
to tell the current session\
to set the foreground color to \"$2\""
}

Command clicking a link in a "clickable" table row.

Expanding on the ideas presented here: [https://gist.github.com/898696] [1]

I thought of another idea. No better or worse than any presented thus far, just another idea.

New idea

Treat the cell with the link in it normally, and add click handlers to all cells in that row that do not contain a link.

@jish
jish / multi_include.rb
Created June 9, 2011 23:24
Multi include
module One
def method
"one"
end
end
module Two
def method
"two"
end
end
@jish
jish / change_events.js
Created June 30, 2011 16:24
Backbone change events
// The source of Underscore and Backbone are included at the top of this file
// They are omitted here for brevity.
var foo = new Backbone.Model();
foo.set({a: "old a", b: "old b"});
foo.bind("change:a", function(foo) {
print("in change:a");
print(foo.get("a"));
print(foo.get("b"));
@jish
jish / foo.rb
Created August 10, 2011 15:03
$LOADED_FEATURES
puts ' - required foo.'
class Foo
end
@jish
jish / ranges.rb
Created August 23, 2011 02:43
Ranges
input = [1, 2, 3, 8, 9, 10, 21, 22, 23, 24]
def scan(input)
min, max = input[0], input[1]
output = []
input.each_with_index do |current, index|
next if index == 0