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
#!/usr/bin/env python3 | |
'''Generate unique random strings or identifiers''' | |
import random, sys | |
# How many new unique identifiers to generate? | |
NUMBER = 100 if len(sys.argv) <= 1 else int(sys.argv[1]) | |
# How many words to combine into a new generated string? | |
LENGTH = 3 if len(sys.argv) <= 2 else int(sys.argv[2]) |
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
# Proper (fast) Python implementations of Dan Bernstein's DJB2 32-bit hashing function | |
# | |
# DJB2 has terrible avalanching performance, though. | |
# For example, it returns the same hash values for these strings: "xy", "yX", "z7". | |
# I recommend using Murmur3 hash. Or, at least, FNV-1a or SDBM hashes below. | |
import functools | |
djb2 = lambda x: functools.reduce(lambda x,c: 0xFFFFFFFF & (x*33 + c), x, 5381) | |
sdbm = lambda x: functools.reduce(lambda x,c: 0xFFFFFFFF & (x*65599 + c), x, 0) | |
fnv1a_32 = lambda x: functools.reduce(lambda x,c: 0xFFFFFFFF & ((x^c)*0x1000193), x, 0x811c9dc5) |
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
#!/usr/bin/env python3 | |
''' | |
A script to generate text files that look like a novel in TXT form. | |
Words are completely made up, but vaguely resemble the Finnish language. | |
The resulting text uses ASCII encoding with only printable characters. | |
Distribution of words follows Zipf's law. | |
Standard parameters generate 1 GB text with 148391 distinct words. |
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
#!/usr/bin/env python3 | |
''' | |
A script to recursively compare two directories (including file size and file hash changes) | |
Usage: python3 compare_dirs.py DIR1 DIR2 | |
''' | |
import os, sys, hashlib, unicodedata | |
COMPARE_FILES = True # should file sizes be compared if their names are the same? |
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
/* | |
* Play duo melody with Arduino | |
* ============================ | |
* | |
* Description: | |
* This sketch simultaneously plays two separate melodies on two (passive) | |
* speakers or buzzers. This creates effect of a "choir". | |
* For simplicity, it uses function play2Tones(), which only plays two notes | |
* of equal duration simultaneosly. | |
* The actual melody here is the Anthem of Ukraine. |
OlderNewer