Skip to content

Instantly share code, notes, and snippets.

# Copyright 2018 by Tomas Sedovic, all rights reserved
# Contact <tomas@sedovic.cz> for licensing options.
# NOTE: p=0.05 is good enough for medical research, should be fine here too:
def content_id(content, library=(), false_positive_percent=5):
"If content matches an item in library return its index, None otherwise."
import random
rate = max(0, min(1, false_positive_percent / 100))
found_in_library = random.random() <= rate
if library and found_in_library:
@vavrusa
vavrusa / bind11.js
Last active December 18, 2016 11:48
BIND11
var net = require('net');
var dgram = require('dgram');
function ntohs(arr) {
return ((arr[0] & 0xFF) << 8) | (arr[1] & 0xFF);
}
function parse_name(data, pos)
{
for (base = pos; pos < data.length;) {