This file contains hidden or 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
`ps -o rss= -p #{$$}`.to_i |
This file contains hidden or 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
User (references_one Address) | |
Address (referenced_in User) | |
user = User.make | |
address = Address.make | |
user.address = address | |
user.save # does not work, the change does not persist | |
user.address.save # works and change persists |
This file contains hidden or 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
# tl;dr if state_machine is in the model when a record is created, there is a record in Mongo, but you can't do a find() on it | |
# If state_machine is in the model when the record is created: | |
ruby-1.9.2-p0 > Upload.first.id | |
=> BSON::ObjectId('4db2a774c4054453d000000c') | |
ruby-1.9.2-p0 > BSON::ObjectId.from_string('4db2a774c4054453d000000c') | |
=> BSON::ObjectId('4db2a774c4054453d000000c') |
This file contains hidden or 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
require 'benchmark' | |
require 'uuidtools' | |
require 'ffi-uuid' | |
require 'uuid' | |
Benchmark.bm do |x| | |
x.report { 100000.times do; UUIDTools::UUID.timestamp_create.to_s; end; } | |
x.report { 100000.times do; UUID.generate.to_s; end; } | |
x.report { 100000.times do; FFI::UUID.generate_time.to_s; end; } | |
end |
This file contains hidden or 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
require 'benchmark' | |
require 'json' | |
require 'yajl' | |
data = '' | |
f = File.open("test.json", "r") | |
f.each_line do |line| | |
data += line | |
end |
This file contains hidden or 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
require 'ipaddr' | |
require 'benchmark' | |
def iptoint1(ip) | |
IPAddr.new(ip, Socket::AF_INET).to_i | |
end | |
def iptoint2(ip) | |
if (ip.kind_of?(String) && | |
ip =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) |
This file contains hidden or 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
#To see how many models in a Rails project are not using attr_accessible: | |
$find app/models -type f -name \*.rb | wc -l | |
$grep -r -m1 "attr_accessible app/models | wc -l |
This file contains hidden or 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
require 'benchmark' | |
require 'json' | |
require 'yajl' | |
data = '' | |
f = File.open("test.json", "r") | |
f.each_line do |line| | |
data += line | |
end |
This file contains hidden or 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
s = %Q{ | |
Maximum connect burst length: 1 | |
Total: connections 20000 requests 20000 replies 20000 test-duration 592.676 s | |
Connection rate: 33.7 conn/s (29.6 ms/conn, <=1 concurrent connections) | |
Connection time [ms]: min 10.8 avg 29.6 max 11652.5 median 11.5 stddev 217.1 | |
Connection time [ms]: connect 27.6 | |
Connection length [replies/conn]: 1.000 |
This file contains hidden or 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
require 'benchmark' | |
first_name = "first" | |
last_name = "last" | |
Benchmark.bm do |x| | |
x.report { 100000.times do; "#{first_name} #{last_name}" ; end; } | |
x.report { 100000.times do; [first_name, last_name].join(' ') ; end; } | |
x.report { 100000.times do; '%s %s' % [first_name, last_name] ; end; } | |
x.report { 100000.times do; first_name + ' ' + last_name ; end; } |