Skip to content

Instantly share code, notes, and snippets.

View wulymammoth's full-sized avatar
processing unit

David W wulymammoth

processing unit
View GitHub Profile
@wulymammoth
wulymammoth / dummy-web-server.py
Created May 19, 2019 21:26 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python. Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost
@wulymammoth
wulymammoth / domain_driven_design.md
Created January 21, 2019 23:30
Domain-Driven Design

Domain-driven Design (DDD)

Context mapping

Exercise to help us discover all the concepts living in our organization, and our systems

Get everyone in a room and discover the...

  • Nouns - entities
  • Verbs - events
@wulymammoth
wulymammoth / next_permutation.py
Created January 16, 2019 19:23
Compute next "lexicographical" permutation
def next_permutation(nums):
'''
brute force:
- generate all permutations, loop and find the matching, return the next
- time: O(N^2 * N!) + O(N) [printing/string/char concatenation is the N^2]
procedure:
1. find largest increasing suffix
2. get pivot
3. find pivot's right-most successor in suffix
@wulymammoth
wulymammoth / meta.txt
Created December 4, 2018 00:41
Getting ctrl + f and ctrl + b (meta) on MacOS
Open iTerm.
Go to iTerm > Preferences... > Profiles > Keys
Under Profile Shortcut Keys, click the + sign.
Type your key shortcut (option-b, option-f, option-d, option-left, etc.)
For Action, choose Send Escape Sequence.
Write b, d or f in the input field.
@wulymammoth
wulymammoth / dtp_00.txt
Created October 1, 2018 16:07
daily technical problem 00
#0: Given an input, accounts, write a function to produce the given output. Feel free to ask questions
accounts = [
["John", "[email protected]", "[email protected]"],
["John", "[email protected]"],
["John", "[email protected]", "[email protected]"],
["Mary", "[email protected]"]
]
Output: [
@wulymammoth
wulymammoth / randhash.py
Created September 28, 2018 14:34 — forked from gennad/randhash.py
Generate random hashcode in Python
import random
random.seed()
hash = random.getrandbits(128)
print "hash value: %016x" % hash
from collections import deque
class TrieNode:
def __init__(self, char):
self.char = char
self.is_word = False
self.children = {}
class Trie:
def __init__(self):
from heapq import *
from collections import *
def djikstra(graph, start, end):
"""
algo:
- bfs with PQ
- track total weight from start to a given vertex
- initialize a table where each weight is infinite, except for the starting vertex (w = 0)
- keep updating the total weight if we encounter a path that is smaller in weight
@wulymammoth
wulymammoth / dijkstra.py
Created July 24, 2018 18:43 — forked from kachayev/dijkstra.py
Dijkstra shortest path algorithm based on python heapq heap implementation
from collections import defaultdict
from heapq import *
def dijkstra(edges, f, t):
g = defaultdict(list)
for l,r,c in edges:
g[l].append((c,r))
q, seen, mins = [(0,f,())], set(), {f: 0}
while q:
@wulymammoth
wulymammoth / latency.txt
Created July 16, 2018 02:27 — 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