Skip to content

Instantly share code, notes, and snippets.

View german's full-sized avatar

Dmytro Samoilov german

View GitHub Profile
@german
german / gist:2828602
Created May 29, 2012 14:03
example of active_record methods introspection
Loading development environment (Rails 2.3.5)
>> module ActiveRecord
>> Base.singleton_methods.each do |m|
?> Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
@german
german / active_record_introspection.rb
Created May 29, 2012 13:37
adding introspection to all ActiveRecord methods (putting method's name when it's invoked)
module ActiveRecord
Base.singleton_methods.each do |m|
Base.class_eval <<-EOS
class << self
puts "redefining #{m}"
define_method "#{m}_with_introspection" do |*args|
puts "#{m}"
send(:"#{m}_without_introspection", *args)
end
@german
german / gist:1737767
Created February 4, 2012 13:07
пелевин, ампир в
- Неужели и здесь то же самое? - задал я горький и не вполне понятный вопрос.
- И здесь, и везде, - сказал Иегова. - И всегда. Проследи за тем, что происходит во время человеческого общения.
Зачем человек открывает рот?
Я пожал плечами.
- Главная мысль, которую человек пытается донести до других, заключается в том, что он имеет доступ к гораздо более
престижному потреблению, чем про него могли подумать. Одновременно с этим он старается объяснить окружающим, что
их тип потребления гораздо менее престижен, чем они имели наивность думать. Этому подчинены все социальные маневры.
Больше того, только эти вопросы вызывают у людей стойкие эмоции.
- Вообще-то мне в жизни попадались и другие люди, - сказал я с легкой иронией.
Иегова кротко посмотрел на меня.
@german
german / gist:1237902
Created September 23, 2011 17:05
god config for delayed_job
# run with: god -c /path/to/config.god [add -D if you want to not-deamonize god]
# This is the actual config file used to keep the delayed_job running
APPLICATION_ROOT = "/var/www/application"
RAILS_ENV = "production"
God.watch do |w|
w.name = "delayed_job_production"
w.interval = 15.seconds
w.start = "/bin/bash -c 'cd #{APPLICATION_ROOT}/current; /usr/bin/env RAILS_ENV=#{RAILS_ENV} #{APPLICATION_ROOT}/current/script/delayed_job start > /tmp/delay_job.out'"
@german
german / redis-benchmark
Created July 7, 2011 16:35
redis-benchmark on my old notebook (512 RAM)
$ redis-benchmark
====== PING (inline) ======
10000 requests completed in 0.43 seconds
50 parallel clients
3 bytes payload
keep alive: 1
19.85% <= 1 milliseconds
97.70% <= 2 milliseconds
@german
german / 1.9.x bug in calculation
Created December 8, 2010 11:46
error in multiplication in ruby 1.9.2 && 1.9.3dev
1.9.3dev
$ ruby -v
ruby 1.9.3dev (2010-12-08 trunk 30125) [i686-linux]
$ irb
ruby-head > 125.33 - (125.33/100.0*50.0)
=> 62.66499999999999
ruby-head > 125.33 / 100.0 * 50.0
=> 62.665000000000006
@german
german / ruby187_192_bug
Created December 8, 2010 10:53
bug in ruby 1.8.7 / ruby 1.9.2 preview 1 (wrong rounding)
$ ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
$irb
ruby-1.8.7-p299 > a = (125.33 - (125.33/100.0*50.0))
=> 62.665
ruby-1.8.7-p299 > b = 62.665
=> 62.665
ruby-1.8.7-p299 > (a*100).round
=> 6266
@german
german / fix_rails3b4_ruby192rc2.diff
Created December 7, 2010 09:00
mongo_mapper's gem fix
From 9bed12e78880a4ddce90ca4a846090773bc8538d Mon Sep 17 00:00:00 2001
From: Dmitrii Samoilov <germaninthetown@gmail.com>
Date: Tue, 20 Jul 2010 11:10:51 +0300
Subject: [PATCH] fix for the bug in plugins.rb (const_defined?(:ClassMethods) for whatever reason doesn't work for rails3b4 and ruby1.9.2-rc2)
---
lib/mongo_mapper/plugins.rb | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/mongo_mapper/plugins.rb b/lib/mongo_mapper/plugins.rb
#!/bin/sh
set -u
set -e
# Example init script, this can be used with nginx, too,
# since nginx and unicorn accept the same signals
# Feel free to change any of the following variables for your app:
APP_ROOT=/home/deploy/public_html/rm/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
ENV=production