This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
My notes for Dokku on Digital Ocean.
These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.
Install dokku-cli (gem install dokku-cli) for a more Heroku-like CLI experience (dokku config:set FOO=bar).
# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)
ssh henroku dokku
Worked 2015-09-08 for Phoenix 1.0.1 on Dokku 0.3.25.
These instructions assume you've set up Dokku. If not, go find a tutorial for that part. My notes for setting it up on Digital Ocean.
Create a Dokku app:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| ######################## | |
| ### SCRIPT VARIABLES ### | |
| ######################## | |
| # Name of the user to create and grant sudo privileges | |
| USERNAME=$0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sched, threading, time | |
| from concurrent.futures import ThreadPoolExecutor | |
| from math import ceil | |
| class ThreadedScheduler: | |
| def __init__(self, f, delay=0, period=1, poolsize=2): | |
| # delay is initial delay from now until first schedule run | |
| # period is the amount of time between each call | |
| # though that probably still contains problems | |
| # if the time to run each call to f exceeds 1 second |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #server numbers | |
| from collections import defaultdict | |
| def next_server_number(numbers): | |
| for i,n in enumerate(sorted(numbers), 1): | |
| if i != n: | |
| return i | |
| return len(numbers) + 1 | |
| def split_letter_digit(s): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from string import digits, ascii_lowercase | |
| int_to_base_36 = digits + ascii_lowercase | |
| base_36_to_int = {v:k for k,v in enumerate(int_to_base_36)} | |
| def largest_multiple(n, multiplier): | |
| print(type(n), type(multiplier)) | |
| exp = 1 | |
| while True: | |
| if multiplier**(exp+1) > n: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from concurrent.futures import ThreadPoolExecutor | |
| from time import sleep | |
| from collections import Counter | |
| from random import shuffle | |
| from pprint import pprint | |
| x = ThreadPoolExecutor(1000) | |
| lst = list(range(10)) | |
| def sleepsort(l): | |
| sorted_l = [] |
NewerOlder
