Skip to content

Instantly share code, notes, and snippets.

@mtkd
mtkd / gist:3586053
Created September 1, 2012 20:19
Mongoid array timings
#188s
(0..10000).each do
document1.sub_documents << document2
end
#119s
(0..10000).each do
document1.push(:sub_document_ids, document2._id)
end
@mtkd
mtkd / gist:3393155
Created August 19, 2012 07:16
Pretty print a mongoid document
JSON.pretty_generate(JSON.parse(obj.to_json))
@mtkd
mtkd / sublime_user.txt
Last active October 7, 2015 18:57
Sublime User Settings
{
"auto_complete": false,
"auto_match_enabled": false,
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"drag_text": false,
"draw_white_space": "selection",
"fold_buttons": false,
"font_face": "M+ 1M thin",
"font_size": 16.0,
@mtkd
mtkd / status_codes.txt
Created July 6, 2012 19:55
HTTP Status Code Symbols
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
203 Non-Authoritative Information :non_authoritative_information
@mtkd
mtkd / gist:2438167
Created April 21, 2012 16:27
Remove delay from OSX dock show/hide
defaults write com.apple.Dock autohide-delay -float 0 && killall Dock
@mtkd
mtkd / string_test.rb
Created April 13, 2012 23:51
String Concatenation Benchmarks
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; }
@mtkd
mtkd / gist:2263694
Created March 31, 2012 12:44
wlll: parsing values hack
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
@mtkd
mtkd / gist:1974822
Created March 4, 2012 21:16
JSON parsing benchmarks
require 'benchmark'
require 'json'
require 'yajl'
data = ''
f = File.open("test.json", "r")
f.each_line do |line|
data += line
end
@mtkd
mtkd / gist:1974819
Created March 4, 2012 21:15
Models not using attr_accessible
#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
@mtkd
mtkd / ipaddr-to_i-perf.rb
Created January 7, 2012 16:22
IPaddr.new().to_i performance
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]+)$/)