Skip to content

Instantly share code, notes, and snippets.

def test
name = 'jim'
puts "hi"
puts yield
puts "hi"
end
name = 'bob'
test do
# fax.extension= looks nicer than fax.qualifier
def extension=(ext)
write_attribute(:qualifier, ext)
end
# fax.extension looks nicer than fax.qualifier
def extension
read_attribute(:qualifier)
end
mysql> DESCRIBE grades;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | UNI | NULL | |
| position | int(11) | NO | | 0 | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
describe "#years" do
it "should return a list of years" do
Time.stub(:now).and_return Time.parse("2005-01-01")
Membership.years.should == [["04-05",2004], ["05-06",2005], ["06-07",2006], ["07-08",2007]]
Time.stub(:now).and_return Time.parse("2007-01-01")
Membership.years.should == [["06-07",2006], ["07-08",2007], ["08-09",2008], ["09-10",2009]]
end
end
2.0.0p247 :027 > Time.parse("5/6", Time.now)
=> 2014-05-06 00:00:00 -0700
2.0.0p247 :029 > Time.parse("5/6/2014")
=> 2014-06-05 00:00:00 -0700
2.0.0p247 :030 > Time.parse("2014/5/6")
=> 2014-05-06 00:00:00 -0700
$ rake -T spec
rake spec # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers # Run the code examples in spec/controllers
rake spec:helpers # Run the code examples in spec/helpers
rake spec:models # Run the code examples in spec/models
>
$ rake spec:models
rake aborted!
Don't know how to build task 'spec:models'
function F() {
var arr = [], i;
for (i = 0; i < 3; i++) {
arr[i] = (function (x) {
return function () {
return x; };
}(i)); }
return arr; }
This gives you the expected result:
> var arr = F(); > arr[0]();
@benlieb
benlieb / gist:7938148
Created December 13, 2013 00:32
RedCloth fails to install
Installing RedCloth (4.0.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/benlieb/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
creating Makefile
make "DESTDIR="
compiling redcloth_attributes.c
ext/redcloth_scan/redcloth_attributes.c: In function ‘redcloth_attribute_parser’:
ext/redcloth_scan/redcloth_attributes.c:445: warning: implicit conversion shortens 64-bit value into a 32-bit value
$ bundle install
Fetching source index from http://rubygems.org/
Using rake (10.1.0) from system gems
Using RedCloth (4.0.1) from bundler gems
Using activesupport (2.3.18) from bundler gems
Using activerecord (2.3.18) from bundler gems
Using aasm (2.3.1) from bundler gems
Using rack (1.1.6) from bundler gems
Using actionpack (2.3.18) from bundler gems
Using actionmailer (2.3.18) from bundler gems
@benlieb
benlieb / Gemfile
Last active December 29, 2015 01:29
source 'http://rubygems.org'
gem "rails", "2.3.14"
gem 'will_paginate', "2.3.16"
gem "money", "1.7.1"
gem "aasm", "0.0.2"
gem "hpricot", "0.6.0"
gem "webrat", "0.2.0"
gem "RedCloth", "4.0.1"
gem "awesome_print"