Skip to content

Instantly share code, notes, and snippets.

@nickthorpe
nickthorpe / latency.markdown
Created December 10, 2020 17:34 — 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

@nickthorpe
nickthorpe / add_user.py
Created July 22, 2020 17:52 — forked from dinigo/add_user.py
Add user to Airflow
#!/usr/bin/python
# This little script creates users in an airflow instance so it can be open to the public.
# It gets the password in plain text so be careful where you run it.
# You can properly invoke the script as follows:
# ./add_user.py <username> <[email protected]> <secretpassword>
import airflow, sys
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
@nickthorpe
nickthorpe / tmux-cheatsheet.markdown
Created June 5, 2020 13:12 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@nickthorpe
nickthorpe / clone_remote_branch.md
Created February 26, 2020 15:57 — forked from ff6347/clone_remote_branch.md
clone remote branch with git
@nickthorpe
nickthorpe / hive.sh
Created February 4, 2020 20:03
execute hive query to .csv
# execute query inline
hive -e 'select count(1) from member' | sed 's/[\t]/,/g' > test.csv
# execute query in file
hive -f test.hql | sed 's/[\t]/,/g' > test.csv
@nickthorpe
nickthorpe / read_full.sql
Last active August 24, 2020 19:18
Read full access in postgres on schema
GRANT USAGE on schema analyzer_django to read_full;
GRANT SELECT ON ALL TABLES IN SCHEMA public to read_full;
GRANT CONNECT ON DATABASE nlp to read_full;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public to read_full;
@nickthorpe
nickthorpe / add_user.sh
Created November 5, 2019 22:03
Add users to SFTP
sudo adduser [user-name]
# type in password to give the user
# run command to find what groups you're in
groups
# add user to the corresponding groups
sudo gpasswd -a [user-name] [group-name]
@nickthorpe
nickthorpe / pandas_apply.py
Created August 4, 2019 17:23
Parallelized Pandas Apply
from multiprocessing import Pool
from functools import partial
import numpy as np
def parallelize(data, func, num_of_processes=8):
data_split = np.array_split(data, num_of_processes)
pool = Pool(num_of_processes)
data = pd.concat(pool.map(func, data_split))
pool.close()
pool.join()
# check if an environment variable is set
if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi
# look at a csv
function pretty_csv {
perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' "$@" | column -t -s, | less -F -S -X -K
}
# look at a psv
function pretty_psv {
@nickthorpe
nickthorpe / useful_sftp_commands.txt
Last active July 30, 2019 13:41
useful sftp commands
# change users password
sudo passwd <username>
# add permission directories for user
sudo chown -R $USER:$USER /var/www