Skip to content

Instantly share code, notes, and snippets.

View ognevsky's full-sized avatar

Andrey Ognevsky ognevsky

View GitHub Profile
# Sneaky attr_accessible clone for MongoMapper
class Filter
def initialize(hash)
@hash = hash
end
def accessible(*values)
@accessible = []
values.each {|value| @accessible<< value }
>> city.text
=> "Россия, Москва"
>> city.country
=> "Россия"
>> city.pos
=> ["37.609218", "55.753559"]
files = File.join(File.dirname(__FILE__), "folder", "start_with_*.rb")
Dir.glob(files).each {|file| require file}
# 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
@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"
# 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 / 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"
version 2
⇥ 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
@ognevsky
ognevsky / gist:1170670
Created August 25, 2011 13:34
TMail Ruby 1.9.2 installation error
Installing tmail (1.2.3.1) with native extensions /Users/elfxf/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/elfxf/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
creating Makefile
make
gcc-4.2 -I. -I/Users/elfxf/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-darwin11.1.0 -I/Users/elfxf/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/Users/elfxf/.rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -D_FILE_OFFSET_BITS=64 -o tmailscanner.o -c tmailscanner.c
tmailscanner.c:19:16: error: re.h: No such file or directory
tmailscanner.c: In function 'mails_s_new':
tmailscanner.c:75: error: 'struct RStri