start new:
tmux
start new with session name:
tmux new -s myname
def binary_left(seq, target):
l, r = 0, len(seq) - 1
while l < r:
mid = (l + r) // 2 # always choose the left half
# if seq[mid] == target:
# r = mid
if seq[mid] >= target:
r = mid
else:
def isDAG(G):
# status: 1 discover 2 visited
def has_cycle(G, status, node):
if status[node] == 2:
return False
status[node] = 1
neighbors = G[node]
for neighbor in neighbors:
if status[neighbor] == 1:
// Allow CORS for client side JS tests | |
app.use(function(req, res, next) { | |
res.header("Access-Control-Allow-Origin", '*'); | |
res.header("Access-Control-Allow-Methods", 'HEAD,GET,PUT,POST,DELETE,PATCH,OPTIONS'); | |
// Allow all custom headers in reqeusts | |
res.header("Access-Control-Allow-Headers", req.headers['access-control-request-headers']); | |
// Specify headers | |
//res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, x-ms-client-request-id'); | |
// intercept OPTIONS method |
I hereby claim:
To claim this, I am signing this object:
var createFilter = function(i) { | |
return { | |
before: function(req) { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('[before hook] ' + i); | |
resolve(req); | |
}, 500); | |
}); | |
}, |
#System Design Interview Cheatsheet
Picking the right architecture = Picking the right battles + Managing trade-offs
##Basic Steps
import random | |
import time | |
import unittest | |
__all__=['Cache'] | |
_current_time_ms = lambda: int(round(time.time() * 1000)) | |
""" |
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
class RPN(): | |
_input_priority = { | |
'*': 5, | |
'/': 5, | |
'+': 3, | |
'-': 3, | |
'(': 7, | |
} | |
_instack_priority = { | |
'*': 6, |