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
class TestController < ApplicationController | |
# To benchmark ActiveRecord connection-pool size | |
# connection pool 5 | |
def ping | |
t1 = Time.now | |
1.upto(10) { Product.find(Integer(rand*1000)) } | |
time_taken = (Time.now - t1) | |
render :text => "time taken: #{time_taken.inspect}" | |
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
# how to name keys in redis for keyvalue stores | |
http://code.google.com/p/redis/wiki/TwitterAlikeExample | |
http://rediscookbook.org/introduction_to_storing_objects.html | |
http://www.slideshare.net/playnicelyapp/redis-schema-design-for-playnicely-redis-london-meetup | |
antirez has a book about keyvalue design in the pipeline | |
http://code.google.com/p/redis/wiki/IntroductionToRedisDataTypes | |
schema: | |
<namespace>:<globalObject> |
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
# ri does not show private methods | |
# why and any way to force it to index and show private methods | |
ri Date#hour | |
ri DateTime #hour is a private method | |
ri DateTime#hour #is not shown |
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
# ruby caches the const lookup like method lookup | |
# due to this no need to explicitly memonize in code | |
# although, i think eval will break this cache | |
# TODO: what will clear the const/method cache | |
# http://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/ | |
require 'benchmark' | |
LOGGER = 10 |
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
# -*- coding: utf-8 -*- | |
# http://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/ | |
# Nathan de Vries, Posted February 25, 2010, 2:27 am | |
# From PickAxe: | |
# “If the last argument to a method is preceded by an ampersand, Ruby assumes that it is a Proc object. It removes it from | |
# the parameter list, converts the Proc object into a block, and associates it with the method.” | |
# Hence being referred by some as the “blockinator”. i.e. take the argument prefixed by “&” and convert it to a block so that | |
# the receiver can invoke it via “yield”. This idea of conversion to a block is what steered people towards overriding | |
# to_proc (for better or worse). |
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
class Foo | |
puts "define_method: #{defined?(define_method).inspect}" | |
define_method(:bar) { puts "one" } | |
end | |
a = Foo.new | |
a.bar | |
class Foo | |
class << self |
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
deepak@octo:~$ rvm debug | |
ree-1.8.7-2010.02: | |
/home/deepak/.rvm/scripts/info: line 12: zsh: command not found | |
rvm 1.0.0 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/] | |
ree-1.8.7-2010.02: | |
system: | |
uname: "Linux octo 2.6.32-25-generic #44-Ubuntu SMP Fri Sep 17 20:05:27 UTC 2010 x86_64 GNU/Linux" | |
zsh: "" |
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
T0 = Thread.main | |
t1 = Thread.new(Thread.current) { |x| Thread.current[:parent] = x; sleep 1_00_000; } | |
t2 = Thread.new(Thread.current) { |x| Thread.current[:parent] = x; sleep 1_00_000; } | |
(t1[:parent] == t2[:parent]) && (t1[:parent] == T0) | |
__END__ | |
# to find out the parent of a thread, ie. was spawned by which thread |
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
> type rvm | head -n1 | |
=> rvm is a function | |
> rvm debug > r.out 2> r.err.out | |
> cat r.out | |
=> | |
ree-1.8.7-2010.02: | |
rvm 1.0.0 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/] | |
ree-1.8.7-2010.02: |
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
# went on a refactoring/beautification overdrive just so that the lines are under 80 columns | |
# ruby statements that overflow into the next row are an abomination :-) | |
# mangled production-code to remove const-names. It is not production or even code which has been run before | |
# please refactor!! | |
# * Any better way to make sure the long condition string is properly formatted | |
# * the gsub(/\s/, '') is also suspect as it would replace spaces etc in a proper sql | |
Comment.count(:id, | |
:include => [:person, :had_commented], |