Skip to content

Instantly share code, notes, and snippets.

View enocom's full-sized avatar

Eno Compton enocom

View GitHub Profile

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

# Here are a handful of good practice problems, some of which may show up in interviews.
# 1. Write an anagram function.
# After that, try writing an anagram function without using #sort and iterating over each word only once
anagram("orchestra", "carthorse") # returns true
anagram("orchestra", "apple") # returns false
# 2. Write a function to test for balanced parentheses.
# This was a Twitter interview question, by the way.
balanced("()") # returns true

Sharing files using netcat

The receiver

nc -l 5566 > data-dump.sql

Listen on port 5566 and redirect output to data-dump.sql

The sender

require "net/http"
require "uri"
require "json"
require "openssl"
require "yaml"
OAUTH_TOKEN = "some token goes here"
uri = URI.parse("https://api.github.com/users/enocom/repos")