Skip to content

Instantly share code, notes, and snippets.

@dolzenko
dolzenko / symbolic_statuses.rb
Last active September 23, 2015 23:27
Response symbolic statuses sorted by name and code
> Rack::Utils::SYMBOL_TO_STATUS_CODE
{
continue: 100,
switching_protocols: 101,
processing: 102,
ok: 200,
created: 201,
accepted: 202,
non_authoritative_information: 203,
no_content: 204,
@marcinbunsch
marcinbunsch / gist:1044437
Created June 24, 2011 08:30
Rails production prompt change as a Rails initializer
# Put this file in config/initializers/irb.rb
# Works in Rails 3.0+, should also work in 2.3
# Override the IRB, to provide the Rails environment in the prompt
module IRB
class << self
def setup_with_prompt_override(ap_path)
setup_without_prompt_override(ap_path)
env = (Rails.env.to_sym == :production ? "\033[00;31mPRODUCTION\033[00m" : Rails.env)
@chetan
chetan / yardoc_cheatsheet.md
Last active May 10, 2024 02:53
YARD cheatsheet
@jboner
jboner / latency.txt
Last active July 6, 2024 06:48
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@kogakure
kogakure / gist:3187467
Created July 27, 2012 11:21 — forked from edennis/gist:3187189
Ruby: Colorized irb prompt for production: ~/.irbrc
# .irbrc
if defined?(Rails) && Rails.production?
conf = IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]]
red = "\033[0;31m"
reset = "\033[0m"
[:PROMPT_S, :PROMPT_C].each do |p|
conf[p].gsub!(/^(.*)$/, "#{red}\\1#{reset}")
end
conf[:PROMPT_I] = "#{red}%N(%m):%03n:%i (PRODUCTION) > #{reset}"
end
@dolzenko
dolzenko / .Xmodmap
Created November 13, 2012 09:51
Apple compact wired keyboard Layout for Ubuntu
! Swap Alt and Cmd keys.
keycode 37 = Control_L
keycode 133 = Alt_L Meta_L
keycode 64 = Super_L
keycode 108 = Super_R
keycode 134 = Alt_L Meta_L
keycode 108 = Control_R Multi_key
clear Shift
clear Lock
clear Control
-- Primer on representing non-printable characters in Lua code
function assert_equal(a, b)
if a ~= b then
error(a .. ' is not equal to ' .. b)
end
end
-- Escape sequences in string use decimal character codes, i.e.
assert_equal('\97\98\99', 'abc')
@dolzenko
dolzenko / bid_parser.py
Last active July 21, 2017 14:51
Parse Google BidRequest/BidResponse with Python
import bidding_pb2
rq = bidding_pb2.BidResponse()
f = open('bid_response.bin', "rb")
rq.ParseFromString(f.read())
print(rq)
f.close()
rq = bidding_pb2.BidRequest()
f = open('bid_request.bin', "rb")
@dolzenko
dolzenko / irb-tricks.rb
Last active October 13, 2015 03:27
IRB tricks
# Sessions
irb(main):001:0> s = "mystring"
=> "mystring"
irb(main):002:0> irb s
irb#1(mystring):001:0> size
=> 8
> IRB::ReadlineInputMethod::HISTORY.to_a # prints session history