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
#Newbie programmer | |
def factorial(x): | |
if x == 0: | |
return 1 | |
else: | |
return x * factorial(x - 1) | |
print factorial(6) | |
#First year programmer, studied Pascal |
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 BaseKlass | |
cattr_accessor :map | |
end | |
class KlassA < BaseKlass | |
self.map = {:a => 1, :b => 2} | |
end | |
class KlassB < BaseKlass | |
self.map = {:c => 3, :d => 4} |
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
# 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 |
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
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: |
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
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!" |
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
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!" |
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
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); |
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
+__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) |
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
# 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' |
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
module Embedding | |
def embeds_many(association_id, options = {}) | |
has_many association_id, options.merge(:dependent => :destroy) | |
accepts_nested_attributes_for association_id, :allow_destroy => true | |
end | |
def embeds_one(association_id, options = {}) | |
has_one association_id, options.merge(:dependent => :destroy) | |
accepts_nested_attributes_for association_id, :allow_destroy => true | |
end |
NewerOlder