This file contains hidden or 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/ruby | |
require 'rubygems' | |
require 'xmlsimple' | |
require 'date' | |
def print_array(array, prefix="") | |
puts "#{prefix}[" | |
array.each do |v| | |
if v.is_a? Hash | |
print_hash(v, "#{prefix}\t") |
This file contains hidden or 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
#Method to slowly delete items from a db giving sleep time between deletions to prevent longer term locking | |
def slow_delete(num1, num2=nil, options={}) | |
step = options[:step] || 5000 | |
sleeptime = options[:sleep] || 2 | |
klazz = options[:class] || Log | |
if num2.nil? | |
num2 = num1 | |
num1 = 0 | |
end |
This file contains hidden or 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 'date' | |
year = 2009 | |
chapters = [ | |
["MATTHEW" , 28], | |
["MARK" , 16], | |
["LUKE" , 24], | |
["JOHN" , 21], | |
["ACTS" , 28], |
This file contains hidden or 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 'rubygems' | |
require 'webster' | |
lines = ARGV[0].to_i | |
cols = ARGV[1].to_i | |
@webster = Webster.new | |
(1..lines).each do |m| | |
line = [] | |
(1..cols).each do |n| |
This file contains hidden or 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
EDGES = [ | |
[ 'A', 'B', 50], | |
[ 'A', 'D', 150], | |
[ 'B', 'C', 250], | |
[ 'B', 'E', 250], | |
[ 'C', 'E', 350], | |
[ 'C', 'D', 50], | |
[ 'C', 'F', 100], | |
[ 'D', 'F', 400], | |
[ 'E', 'G', 200], |
This file contains hidden or 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 ApplicationController < ActionController::Base | |
def load_resource | |
parent = nil | |
request.path.split("/").select{|p| !p.blank?}.to_pairs.each do |obj| | |
parent = set_instance_variable(obj.first.singularize, obj.last, parent) | |
end | |
model_name = params[:controller].split('/').last.singularize | |
begin |
This file contains hidden or 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 | |
require 'pathname' | |
# memcached requires an absolute path for the -P switch | |
root = (Pathname.new(__FILE__).dirname + '..').realpath | |
pidfile = root + 'tmp' + 'memcached.pid' | |
if not pidfile.exist? | |
puts "memcached not running: starting" | |
system 'memcached', '-d', '-P', pidfile, '-l', '127.0.0.1' |
This file contains hidden or 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
set :stage, nil unless defined? stage | |
namespace :growl do | |
task :notify do | |
growl_send(ENV["GROWL_MESSAGE"] || "wants your attention") | |
end | |
task :alert do | |
growl_send(ENV["GROWL_MESSAGE"] || "needs your attention", 2) | |
end |
This file contains hidden or 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
My::Application.routes.draw do | |
resources :contacts | |
resources :requests do | |
get 'pending', :on => :collection | |
put 'approve', :on => :member | |
put 'deny', :on => :member | |
end | |
resource :profile, :only => [:show, :update] |
This file contains hidden or 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
SpaceTruckin.play("John", "Paul", "George") do |game| | |
until game.finished? | |
game.reset_stages | |
game.players.each do |player| | |
stage_name = game.available_stage_names[rand(game.available_stage_names.length)] | |
case stage_name | |
when "Demand" |
OlderNewer