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
| #!/usr/bin/env python | |
| """ | |
| Very simple HTTP server in python. | |
| Usage:: | |
| ./dummy-web-server.py [<port>] | |
| Send a GET request:: | |
| curl http://localhost |
| 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 |
| 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. |
| #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: [ |
| 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 |
| 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: |
| 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 |