Skip to content

Instantly share code, notes, and snippets.

View gstark's full-sized avatar

Gavin Stark gstark

View GitHub Profile
# /* [ <!-- */ include <stdio.h> /* \
#{\
`""""true \\#{"\n#"}; \
\
if [ -n "$ZSH_VERSION" ]; then \
\
echo exec echo I\'m a zsh script.; \
\
elif [ -n "$BASH_VERSION" ]; then \
\
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
@gstark
gstark / timecard.rb
Created December 2, 2009 04:08 — forked from gilesbowkett/personal git punch card grapher
Personal git punch chard grapher
#!/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
in application.rb
config.active_record.observers = :foo_observer
foo_observer.rb:
class FooObserver < ActiveRecord::Observer
def before_update(foo)
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)
require 'enumerator'
class Always42
include Enumerable
def each
while true
yield 42
end
end
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
# 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
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
@gstark
gstark / gist:284673
Created January 23, 2010 16:33
ImplicitReceiverTest
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)