This file contains 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
⇥ rails generate model user | |
invoke active_record | |
create db/migrate/20110703115918_create_users.rb | |
create app/models/user.rb | |
invoke test_unit | |
create test/unit/user_test.rb | |
create test/fixtures/users.yml |
This file contains 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
version 2 |
This file contains 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
(1..100).each do |x| | |
if (x % 3).zero? && (x % 5).zero? | |
puts "FizzBuzz" | |
elsif (x % 3).zero? | |
puts "Fizz" | |
elsif (x % 5).zero? | |
puts "Buzz" |
This file contains 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
# Adjust sessions so they work across subdomains | |
# This also will work if your app runs on different TLDs | |
# from: http://szeryf.wordpress.com/2008/01/21/cookie-handling-in-multi-domain-applications-in-ruby-on-rails/ | |
# modified to work with Rails 2.3.0 | |
module ActionControllerExtensions | |
def self.included(base) | |
base::Dispatcher.send :include, DispatcherExtensions | |
end |
This file contains 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
function r19 { | |
switch-ruby $(brew --prefix)/Cellar/ruby/1.9.2-p0/bin | |
} | |
function r18 { | |
switch-ruby $(brew --prefix)/Cellar/ruby-enterprise-edition/2010.02/bin | |
} | |
function switch-ruby { | |
echo "using $1" |
This file contains 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
# inspiration | |
# http://github.com/jnstq/rails-nginx-passenger-ubuntu | |
# sudo this sudo that bollocks | |
sudo -i | |
# system-related stuff | |
apt-get install htop strace sysstat | |
dpkg-reconfigure sysstat | |
apt-get install ntp |
This file contains 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
files = File.join(File.dirname(__FILE__), "folder", "start_with_*.rb") | |
Dir.glob(files).each {|file| require file} |
This file contains 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
>> city.text | |
=> "Россия, Москва" | |
>> city.country | |
=> "Россия" | |
>> city.pos | |
=> ["37.609218", "55.753559"] |
This file contains 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
# Sneaky attr_accessible clone for MongoMapper | |
class Filter | |
def initialize(hash) | |
@hash = hash | |
end | |
def accessible(*values) | |
@accessible = [] | |
values.each {|value| @accessible<< value } |
NewerOlder