Skip to content

Instantly share code, notes, and snippets.

View dyjjones's full-sized avatar

Dylan Jones dyjjones

  • Seattle
View GitHub Profile
@dyjjones
dyjjones / broadcast-channel.md
Created May 14, 2024 18:53 — forked from davestewart/broadcast-channel.md
Example of using BroadcastChannel to communicate with pages in the same domain

screenshot

@dyjjones
dyjjones / latency.txt
Created November 1, 2021 18:13 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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
@dyjjones
dyjjones / dokku_on_digital_ocean.md
Created December 24, 2020 23:39 — forked from henrik/dokku_on_digital_ocean.md
Notes from running Dokku on Digital Ocean.

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.

Commands

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

@dyjjones
dyjjones / deploying_phoenix_on_dokku.md
Created December 23, 2020 05:18 — forked from henrik/deploying_phoenix_on_dokku.md
Deploying Elixir's Phoenix Framework on Dokku.

Deploying Phoenix on 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.

On your local machine, in the app's repo

Create a Dokku app:

#!/bin/bash
set -euo pipefail
########################
### SCRIPT VARIABLES ###
########################
# Name of the user to create and grant sudo privileges
USERNAME=$0
@dyjjones
dyjjones / threaded_scheduler.py
Created April 23, 2017 01:36
threaded scheduler
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
@dyjjones
dyjjones / balanced_dictionary.py
Created November 17, 2016 00:08
symmetric dictionary, i.e. all key-value entries have value-key entries
do
@dyjjones
dyjjones / tracker.py
Created August 9, 2016 02:09
server number tracker
#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):
@dyjjones
dyjjones / base_converter.py
Created August 7, 2016 12:09
base converter
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:
@dyjjones
dyjjones / sleepsort.py
Created August 2, 2016 22:15
sleep sort
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 = []