Skip to content

Instantly share code, notes, and snippets.

View davidlee's full-sized avatar

David Lee davidlee

  • Melbourne, Australia
View GitHub Profile
module MetaLoader
def load_all_controllers
@controller_files = []
Find.find( File.join( RAILS_ROOT, 'app/controllers' )) do |fn|
next unless fn =~ /_controller.rb$/
# begin
@controller_files << fn
require( fn )
# rescue Exception => e
require 'stringio'
module NoStdout
module InstanceMethods
def no_stdout ( to = StringIO.new('','r+'), &block )
# supply an IO of your own to capture STDOUT, otherwise it's put in a StringIO
orig_stdout = $stdout
$stdout = @alt_stdout = to
result = yield
#!/usr/bin/env ruby
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
file '.gitignore', <<-END
.swo
def donation_uk_giftaid
unless request.post?
redirect_to :action=>"donate"
return
end
@heroPage = HeroPage.search_url(params[:url], DateTime.now)
hero_page_variables("preview", true)
if session[:mydonation_id]
@donation = Donation.find_by_id(session[:mydonation_id])
@donation.update_attributes(params[:donation])
module PageHelper
def hero?
!!params[:event_url]
end
def event?
!hero? && !!params[:url]
end
module OrderedHash
def []( index )
begin
super( index )
rescue TypeError
x = self.detect do |i|
i.first == index
end # if index.class ...
x && x[1]
end
class Foo
end
class Flibby
def make_method( _method_name )
puts _method_name
Foo.class_eval do
puts _method_name
class << self
define_method _method_name do
@davidlee
davidlee / gist:81790
Created March 19, 2009 12:32
eventmachine policy file server for flash
equire 'rubygems'
require 'eventmachine'
module Socky
module Policy
DEBUG = true
HOST = 'localhost'
PORT = 843
EOF = "\r\000"
REQUEST = "<policy-file-request/>\000"
def new
x = Builder::XmlMarkup.new
x.instruct!
x.comment! "User Authentication Successful"
x.user {
x.id @user.id
x.login @user.login
x.name @user.name
}
render :xml => x
#!/usr/bin/env ruby
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
run "for i in tmp/*; do touch tmp/$i; done"
file '.gitignore', <<-END