Skip to content

Instantly share code, notes, and snippets.

@9cardinals
9cardinals / gist:7313305
Created November 5, 2013 03:16
simple string interpolation example in ruby
p "hello #{3}"
num = 5
p "hello #{num}"
@9cardinals
9cardinals / compound interest
Last active February 3, 2020 21:13
simple compound interest calculator using math operations in ruby
# principal amount
p = 10_000
# annual rate of interest
r = 0.05
# number of years
t = 5
@9cardinals
9cardinals / url method
Created November 5, 2013 04:12
method to call url and text
def link(address, text)
"URL is at: <a href='#{address}'>, #{text}</a>"
end
p link("http://www.github.com/9cardinals/", "my github")
@9cardinals
9cardinals / simpleCombinationLock
Created November 8, 2013 05:38
simple ruby combination lock
def lock(key1,key2,key3,key4)
if
(key1 == 3 || key1 == 5 || key1 == 7) && (key2 == 2) && (key3 == 5 || key3 == 6) && (key4 == 8 || key4 == 9 || key4 == 0)
then
"unlocked"
else
"locked"
end
end
@9cardinals
9cardinals / gist:7634167
Created November 24, 2013 23:51
unable to bundle install
here's the gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
group :production do
gem 'pg'
end
@9cardinals
9cardinals / gist:7634206
Created November 24, 2013 23:56
new error after correcting gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
group :production do
gem 'pg'
end
@9cardinals
9cardinals / gemfile
Created November 25, 2013 00:07
problematic gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
group :production do
gem 'pg'
end
@9cardinals
9cardinals / gist:7634439
Created November 25, 2013 00:24
still having problems with this gemfile. error terminator at line 54. for comparison i am looking at gemfile here for gem versions: https://github.com/Bloc/rails-tutorial/blob/master/Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '3.2.12'
# Use sqlite3 as the database for Active Record
group :production do
gem 'pg'
end
@9cardinals
9cardinals / gist:7635641
Created November 25, 2013 03:04
rails no longer generating models/controllers, starting server, etc when switching from 4.0.1 and 3.2.12. Earlier today rails was working with no issues. I then made some changes to a gem which required switching dependencies from 3.2.12 ==> 4.0.1 and back. After that, Rails completely stopped working on all commands aside from -v
Last login: Sun Nov 24 18:05:32 on console
vera:code monicacardinal$ cd bloccit/
vera:bloccit monicacardinal$ ls -a
. Gemfile app db tmp
.. Gemfile.lock bin lib vendor
.git README.md config log
.gitignore Rakefile config.ru public
vera:bloccit monicacardinal$ rails s
Usage:
rails new APP_PATH [options]
@9cardinals
9cardinals / gist:7652799
Created November 26, 2013 02:55
error on model generation
vera:bloccit monicacardinal$ bundle exec bin/rails generate model Post title:string body text
invoke active_record
/Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.12/lib/active_record/dynamic_matchers.rb:55:in `method_missing': undefined method `migration_error=' for #<Class:0x007fa9d3fdaca8> (NoMethodError)
from /Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.12/lib/active_record/railtie.rb:66:in `block (3 levels) in <class:Railtie>'
from /Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.12/lib/active_record/railtie.rb:65:in `each'
from /Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.12/lib/active_record/railtie.rb:65:in `block (2 levels) in <class:Railtie>'
from /Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/monicacardinal/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.12/lib/active_support/lazy_load_hooks.rb:36