Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/bin/sh | |
| # This shows how to handle combined short options along with | |
| # other long and short options. It does so by splitting them | |
| # apart (e.g. 'tar -xvzf ...' -> 'tar -x -v -z -f ...') | |
| while test $# -gt 0 | |
| do | |
| case $1 in |
| 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 |
| import re | |
| from cPickle import dump | |
| from requests import get | |
| DEFAULT_TICKERS = ['goog', 'aapl'] | |
| URL = 'http://www.sec.gov/cgi-bin/browse-edgar?CIK={}&Find=Search&owner=exclude&action=getcompany' | |
| CIK_RE = re.compile(r'.*CIK=(\d{10}).*') | |
| cik_dict = {} | |
| for ticker in DEFAULT_TICKERS: |
| function condalist -d 'List conda environments.' | |
| for dir in (ls $HOME/miniconda3/envs) | |
| echo $dir | |
| end | |
| end | |
| function condactivate -d 'Activate a conda environment' -a cenv | |
| if test -z $cenv | |
| echo 'Usage: condactivate <env name>' | |
| return 1 |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#Exploring Entity Component Systems in Elm
Entity-Component-System (or ECS) is a pattern for designing programs that is prevalent in the games industry. This pattern consists of three simple parts:
To understand this, let us try to make a simple example: Boxes that move in space:
| import os | |
| import opengl | |
| import glfw/wrapper as glfw | |
| template `&`[T](v: var T): ptr[T] = addr(v) | |
| template `*`[T](v: ptr[T]): T = v[] | |
| template `*`[T](v: ref[T]): T = v[] | |
| """ | |
| Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
| BSD License | |
| """ | |
| import numpy as np | |
| # data I/O | |
| data = open('input.txt', 'r').read() # should be simple plain text file | |
| chars = list(set(data)) | |
| data_size, vocab_size = len(data), len(chars) |
| import pandas as pd | |
| from random import random | |
| flow = (list(range(1,10,1)) + list(range(10,1,-1)))*100 | |
| pdata = pd.DataFrame({"a":flow, "b":flow}) | |
| pdata.b = pdata.b.shift(9) | |
| data = pdata.iloc[10:] * random() # some noise | |
| import numpy as np |