Skip to content

Instantly share code, notes, and snippets.

View ognevsky's full-sized avatar

Andrey Ognevsky ognevsky

View GitHub Profile
⇥ 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
version 2
@ognevsky
ognevsky / fizzbuzz.rb
Created January 26, 2011 12:17
Simple fizzbuzz problem, solved in ruby
(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"
# 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
@ognevsky
ognevsky / rvm.sh
Created November 2, 2010 09:16
using several versions of ruby w/o rvm
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"
# 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
files = File.join(File.dirname(__FILE__), "folder", "start_with_*.rb")
Dir.glob(files).each {|file| require file}
>> city.text
=> "Россия, Москва"
>> city.country
=> "Россия"
>> city.pos
=> ["37.609218", "55.753559"]
# Sneaky attr_accessible clone for MongoMapper
class Filter
def initialize(hash)
@hash = hash
end
def accessible(*values)
@accessible = []
values.each {|value| @accessible<< value }