Skip to content

Instantly share code, notes, and snippets.

View loyd's full-sized avatar
🐷

Paul Loyd loyd

🐷
View GitHub Profile
@loyd
loyd / approximations.md
Last active June 14, 2023 08:47
Useful approximations

Useful approximations

Just random approximations sometimes useful in work for "mental" calculation.

Bloom filter, space

b(p) ≈ 1.44 * log₂(p)
  • b — bits per element
  • p — false positive probability
#!/usr/bin/env python3
from subprocess import check_output
from json import loads
from time import sleep
from datetime import datetime
class Stats:
def __init__(self):
self.min = float('inf')
@loyd
loyd / main.rs
Created September 15, 2018 13:52
Compare rust fast hashers
/*
count = 10000000
len = 512
name min max spent (s)
---- --- --- ----
fnv 19525 19537 2.417305
fx 19531 19532 0.48344
@loyd
loyd / pi
Created January 4, 2015 20:50
Workaround for cross compiling with rust (rustc, cargo, etc.).
#!/bin/sh
RUST=~/builds/pi-rust
TOOLCHAIN=~/builds/pi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64
LINKER=arm-linux-gnueabihf-gcc
# Rust uses `cc` as linker.
if [ ! -f "$TOOLCHAIN/bin/cc" ]; then
@loyd
loyd / vector.c
Created December 3, 2014 17:43
Indexed dynamic vector in C99.
/* Usage:
* int *nums = new_vec(int);
*
* vec_push(&nums, 1);
* vec_push(&nums, 5);
*
* for (int i = 0; i < vec_len(nums); ++i)
* printf("%d", nums[i]);
*
* Advanced usage:
@loyd
loyd / ovrload
Last active February 16, 2018 18:13
Script to use file sharing with troloload.ru
#!/bin/bash
# ovrload.ru file uploader
# ovrload — former troloload
VERSION='v0.1.3'
URL='http://ovrload.ru'
SHORTER_URL='http://tinyurl.com'
FAILURES=0 # number of upload fails
LONGTIME=0 # whether to make long-time links