Skip to content

Instantly share code, notes, and snippets.

View luminousmen's full-sized avatar

Kirill luminousmen

View GitHub Profile
@luminousmen
luminousmen / latency.markdown
Created July 29, 2023 02:38 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@luminousmen
luminousmen / bloom_1.py
Last active January 31, 2023 22:40
Sample bloom filter implementations
# Hash implementations from
# http://www.partow.net/programming/hashfunctions/index.html
# Author: @luminousmen
class BloomFilter:
def __init__(self, size: int):
self.size = size
self.bitmap = size * [0]
def FNV(self, key: str):
@luminousmen
luminousmen / retry.sh
Created December 22, 2022 04:24
Bash retry function
function retry {
local retries=3
local count=0
until "$@"; do
exit=$?
wait=$((10 ** $count))
count=$(($count + 1))
if [ $count -lt $retries ]; then
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
@luminousmen
luminousmen / mail.sh
Created December 22, 2022 04:23
Bash send mail
echo "this is the body" | mail -s "this is the subject" "to@address"
import random
letters = [
"Person 1",
"Person 2",
"Person 3",
"Person 4",
]
print(f"Next: `{random.choice(letters)}`")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@luminousmen
luminousmen / test_bucketing.py
Created November 10, 2019 09:08
Example bucketing in pyspark
import os
import pyspark.sql.functions as F
from pyspark.sql import SparkSession
if __name__ == "__main__":
spark = SparkSession.builder.master("local").getOrCreate()
spark.conf.set(
@luminousmen
luminousmen / Makefile
Created October 31, 2019 08:40 — forked from lumengxi/Makefile
Makefile for Python projects
.PHONY: clean-pyc clean-build docs clean
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
from weakref import WeakValueDictionary
class Singleton(type):
_instances = WeakValueDictionary()
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
instance = super(Singleton, cls).__call__(*args, **kwargs)
cls._instances[cls] = instance
return cls._instances[cls]