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
# /* [ <!-- */ include <stdio.h> /* \ | |
#{\ | |
`""""true \\#{"\n#"}; \ | |
\ | |
if [ -n "$ZSH_VERSION" ]; then \ | |
\ | |
echo exec echo I\'m a zsh script.; \ | |
\ | |
elif [ -n "$BASH_VERSION" ]; 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
controller: | |
def task_summary | |
# Find all the tasks | |
tasks = Task.find(:all) | |
# Create an IO buffer for the generated excel data | |
target_string = StringIO.new |
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 | |
# for usage: ruby timecard.rb --help | |
require 'rubygems' | |
require 'optparse' | |
# This requires the 'cyberfox-gchart' gem (0.5.4), as the standard | |
# gchart gem is woefully broken for this kind of graph. Broken to the |
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
in application.rb | |
config.active_record.observers = :foo_observer | |
foo_observer.rb: | |
class FooObserver < ActiveRecord::Observer | |
def before_update(foo) |
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
module SQLGrowler | |
class Subscriber < ActiveRecord::Railties::Subscriber | |
def sql(event) | |
super | |
g('%s (%.1fms) %s' % [event.payload[:name], event.duration, event.payload[:sql].squeeze(' ')]) | |
end | |
end | |
def self.enable | |
if Kernel.respond_to?(:g) |
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
require 'enumerator' | |
class Always42 | |
include Enumerable | |
def each | |
while true | |
yield 42 | |
end | |
end |
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
require 'test/unit' | |
class Thingy | |
def method_missing(method_name,*args) | |
@attrs ||= {} | |
case method_name.to_s | |
when /^set_(.+)/ then | |
@attrs[$1] = args.first | |
when /^get_(.+)/ 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
# Create a method on a class that will duplicate an instance, | |
# remove a method given as an argument and return the new methodless object | |
require 'test/unit' | |
module MetaClassFetcher | |
def metaclass | |
class <<self | |
self | |
end |
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
require 'test/unit' | |
module GetterSetter | |
def getter_setter(attribute) | |
instance_variable = "@#{instance_variable}" | |
define_method("#{attribute}=") do |value| | |
instance_variable_set(instance_variable,value) | |
end |
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 ImplicitReceiverTest | |
def method_missing(method,*args,&block) | |
if method.to_s == "bar=" | |
puts 'method missing for bar=' | |
else | |
super | |
end | |
end | |
def bar=(barvalue) |
OlderNewer