Skip to content

Instantly share code, notes, and snippets.

View corntrace's full-sized avatar

Kevin corntrace

  • Shanghai, China
View GitHub Profile
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
@corntrace
corntrace / rvm_set_default_error
Created October 20, 2010 16:49
My system: snow leopard 10.6.4; zsh 4.3.9; rvm 1.0.15; ruby 1.8.7-p174(system); ruby 1.9.2-p0(installed by rvm). The following are outputs of `rvm --trace --default system`
+__rvm_parse_args:414> [[ -z 4.3.9 ]]
+__rvm_parse_args:570> [[ -z '' && -n '' ]]
+__rvm_parse_args:572> [[ 0 -eq 1 || -n '' ]]
+__rvm_parse_args:15> [[ -n --default ]]
+__rvm_parse_args:17> rvm_token=--default
+__rvm_parse_args:19> [[ 1 -gt 0 ]]
+__rvm_parse_args:19> next_token=system
+__rvm_parse_args:19> shift
+__rvm_parse_args:21> case --default (fetch|version|srcdir|reset|debug|reload|update|monitor|notes|implode|seppuku|question|answer|env)
+__rvm_parse_args:21> case --default (package)
var mozmill = {}; Components.utils.import('resource://mozmill/modules/mozmill.js', mozmill);
var elementslib = {}; Components.utils.import('resource://mozmill/modules/elementslib.js', elementslib);
var testFoo = function(){
var controller = mozmill.getMail3PaneController();
var e =
new elementslib.XPath(controller.window.frames[0].document, "/*[name()='page' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul']/*[name()='grid' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'][1]/*[name()='rows' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'][1]/*[name()='row' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'][16]/*[name()='hbox' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'][1]/*[name()='label' and namespace-uri()='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'][1]");
controller.click(e);
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@corntrace
corntrace / ruby-1.9-tips.rb
Created May 15, 2011 04:12 — forked from lporras/ruby-1.9-tips.rb
Ruby 1.9 Tips
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@corntrace
corntrace / README
Created July 9, 2011 14:44 — forked from andersonsp/README
Rails 3 custom form builder implementing a simple color picker based on JQuery and CaryonBox plugin
INSTALLATION
the rails application must have support for JQuery
get JQuery.Crayonbox.js at http://gelform.com/crayonbox-jquery-plugin/
add the plugin JQuery.Crayonbox.js to /public/javascript folder
add the crayonbox css to /public/stylesheets folder
add color_picker_form_builder.rb to the /lib folder
add to the view or layout file:
@corntrace
corntrace / setup_load_path.rb
Created July 19, 2011 13:16
The solution about setting project specified gemset for passenger
# Setup rvm to load ruby and gemset from ./.rvmrc
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
@corntrace
corntrace / inheritance_klasses.rb
Created August 11, 2011 16:44
Class variable overwrite in inheritance
class BaseKlass
cattr_accessor :map
end
class KlassA < BaseKlass
self.map = {:a => 1, :b => 2}
end
class KlassB < BaseKlass
self.map = {:c => 3, :d => 4}
@corntrace
corntrace / Evolution_of_a_Python_programmer.py
Created August 12, 2011 05:32
Evolution of a Python programmer
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal