Skip to content

Instantly share code, notes, and snippets.

@kfirshay
kfirshay / latency.markdown
Created October 8, 2016 20:36 — forked from hellerbarde/latency.markdown
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

@kfirshay
kfirshay / passenger_clear_swap.sh
Created May 3, 2016 18:00
passenger_clear_swap.sh
#!/bin/sh
while true; do
value=$( cat /proc/swaps | awk '$4 > 0 {print $4}' | sed s/Used// | awk '$1 > 0 {print $1}' )
if [ ! -z $value ]
then
echo clearing swap...
sudo /etc/init.d/nginx stop
sudo swapoff -a
sudo swapon -a
@kfirshay
kfirshay / fix_yajl-ruby_on_mac_os_x_el_capitan.sh
Last active April 8, 2016 18:45
FIX - dyld: lazy symbol binding failed: Symbol not found: _yajl_set_static_value
cd /Library/Ruby/Gems/2.0.0/gems/yajl-ruby-0.8.2/ext/yajl/
# Now we need to replace 'inline void' to 'static void'. This will also create backup of old files.
sed -i '.bak' 's/inline void/static void/g' yajl_ext.h yajl_ext.c
# Now we must rebuild changed extension
make clean all
# After this you should not have any problems with yajl-ruby
@kfirshay
kfirshay / sqs_none_blocking_send.rb
Last active April 9, 2016 23:28
SQS None Blocking Send
send_sqs_message = lambda { |payload, queue|
queue.send_message("#{payload}:#{Time.now.to_s}")
}
Thread.fork { send_sqs_message.call("our payload", queue) }
module ITunes
def self.mute_or_unmute(command)
matching = command.match(/^(un)?mute\s+(itunes|((?:the|my)\s+)?music)$/i)
is_unmute = matching && matching[1] == "un"
if matching
{
:command => Command.bus({:osx => "tell application \"iTunes\" to set mute to #{ !is_unmute }"}),
:explanation => "#{ is_unmute ? 'Unmutes' : 'Mutes' } iTunes."
}
else