This file contains 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
# requires python 3.2.3 or higher | |
import concurrent.futures | |
def f(x): | |
print ("working on task: %s" %{x}) | |
if x-1 > 0 : | |
return x-1 # I want this task back in the queue. | |
def main(): | |
Queue = [x for x in range(4)] |
This file contains 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 functools | |
import time | |
class Stack(object): | |
hits = {} | |
times = {} | |
@classmethod | |
def register(cls, func_name, call_time): | |
if func_name not in Stack.hits: |
This file contains 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
def adder(a,b): # function to test. | |
""" adds a to b""" | |
return a+b | |
options = [9, 9.0, [9], "9"] # options for test function | |
test_template = """ |
This file contains 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 functools | |
import inspect | |
def kwarg_filter(): | |
def decorator(fn): | |
keys = inspect.getfullargspec(fn).args # <-- This reads the signature of the function. | |
@functools.wraps(fn) | |
def inner(*args, **kwargs): |
This file contains 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 |
This file contains 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 tqdm import tqdm | |
import requests | |
# file url | |
url = 'https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-stub-meta-history.xml.gz' #file size is '70.5GB' | |
# stream true is required | |
response = requests.get(url, stream=True) | |
# total file size | |
t = int(response.headers.get('content-length', 0)) | |
block_size = 1024**2 #1 Mbit |
This file contains 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 time | |
import requests | |
import zlib | |
# pip install lz4 pylzma | |
import lz4 | |
import pylzma as lzma | |
def analysis_ratios(source): | |
time_before_zip = time.time() |
This file contains 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
If 2fa is enabled on github switch to ssh instead of https on linux | |
1. generate an ssh keypair on your linux box | |
ssh-keygen -t {rsa|dsa} | |
2. add the public key to github: profile - settings - ssh keys | |
3. switch from https to ssh | |
Check your repo remote: |