Skip to content

Instantly share code, notes, and snippets.

@anithri
anithri / clause.rb
Created March 7, 2012 23:33
operations dispatch?
def clause(op, field, data)
out = []
out << ops_table[op][:field_proc].call(field)
out << ops_table[op][:data_proc].call(data)
out
end
#later
model.where(*clause(op, field, data))
@anithri
anithri / exception.rb
Created February 16, 2012 05:04
Toying with an idea for exception handling.
module MyModule
class MyModuleError < StandardError
@@ignore = :warn
def ok_to_ignore?
@@ignore
end
def self.ok_to_ignore
@@ignore
@anithri
anithri / gist:1208809
Created September 10, 2011 21:24
rmu color formatter example
class ColorFormatter < Log4r::Formatter
attr_accessor :color, :label, :colors, :format_string
def colors
@level_colors || [:cyan, :green, :yellow, :light_red, :red]
end
def initialize(opts={})
@depth = (opts[:depth] || 7 ).to_i
@color = opts[:color] || true
@anithri
anithri / Gemfile
Created September 5, 2011 20:25
guard examples
#Gemfile
group :development do
gem 'guard'
gem 'guard-bundler'
gem 'guard-rspec'
gem 'guard-annotate'
gem 'guard-spork'
#For linux
#gem 'rb-inotify'
#gem 'libnotify'
@anithri
anithri / mk_rvmrc.zsh
Created August 7, 2011 09:54
zsh function to create .rvmrc files
function mk_rvmrc() {
my_ruby=${argv[1]:=$ruby19} #I set ruby19=ruby-1.9.2@p290 elsewhere.
my_gemset=${argv[2]:=`basename $PWD`} #uses the name of the current directory if no 2nd arg is given
rvm --create --rvmrc ${my_ruby}@${my_gemset}
}
@anithri
anithri / gist:987622
Created May 23, 2011 21:11
Guardfile
guard 'bundler' do
watch('Gemfile')
end
guard 'passenger' do
watch(%r{lib/.*\.rb})
watch(%r{config/.*\.rb})
end
guard 'livereload' do
@anithri
anithri / Execute once
Created April 19, 2011 19:11
script and commands to open txmt links in RubyMine on Ubuntu
gconftool-2 -s /desktop/gnome/url-handlers/txmt/command '/usr/local/bin/openInMine "%s"' --type String
gconftool-2 -s /desktop/gnome/url-handlers/txmt/enabled --type Boolean true
@anithri
anithri / gist:853303
Created March 3, 2011 19:05
Callback is run twice.
require 'paper_trail'
class EventLog < ActiveRecord::Base
#snipped stuff
before_create :on_creation
before_save :on_save
after_save :after_save
#snipped stuff
def after_save
#do stuff
#Anithri preinstall gems
#gem install rails -v 3.0.0.beta4
#gem install bundler -v 1.0.0.beta.4
# When ready run as
# rails new ArtificalCasting -d mysql -J -m http://gist.github.com/471391.txt
puts "=" * 80
puts "Step 1. Remove some unused files and directories"
puts "=" * 80
#----------------------------------------------------------------------------
# Remove unnecessary Rails files
#----------------------------------------------------------------------------
run 'rm README'
run 'rm config/database.yml.example'
run 'rm config/database.yml'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/images/rails.png'
run 'touch README'