Skip to content

Instantly share code, notes, and snippets.

#!/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")
#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
require 'date'
year = 2009
chapters = [
["MATTHEW" , 28],
["MARK" , 16],
["LUKE" , 24],
["JOHN" , 21],
["ACTS" , 28],
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|
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],
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
#!/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'
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
@marksim
marksim / gist:996202
Created May 27, 2011 21:20
Example restful Routes file in Rails 3
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]
@marksim
marksim / basic.rb
Created July 28, 2011 13:03
Basic mechanics of the game
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"