Skip to content

Instantly share code, notes, and snippets.

View jac18281828's full-sized avatar
🦌

John Cairns jac18281828

🦌
View GitHub Profile
import socket
import select
import sys
__EPOLL_TIMEOUT = 1.0
__BUFFER_SZ = 8192
yeti_request ="GET /bap HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n"
epoll = None
socket_set = {}
@jac18281828
jac18281828 / percentile-fix-primer.md
Last active June 15, 2026 23:01
Simultaneous estimation of Several Percentiles

Streaming-percentile accuracy — a portable diagnose-and-fix guide

A self-contained guide for fixing an inaccurate streaming percentile estimator in any codebase. If your project uses an online/streaming quantile estimator (P² / "P-square" / Raatikainen extended-P² / a 2m+3-marker sketch) and it returns wrong percentiles on real, skewed data, this explains why and how to fix it without abandoning the streaming property. The goal is "still an estimate, only a good one" — keep it O(1)-memory and fast; do not replace it with an exact sort, inflate the marker count, or buffer samples.

(This came out of one concrete case; the originating example is in the appendix. The body is deliberately project-agnostic — apply the pattern, not the names.)

@jac18281828
jac18281828 / filter_unicode.py
Last active July 5, 2018 14:45
Ad Blocking script for dnsmasq. This uses Steven Black's Ad Blocking /etc/hosts file but converts it to dnsmasq format. For use with either an AdBlocking Raspberry PI project (PiHole) or on a Unify EdgeRouter
import sys
for buffer in sys.stdin.read():
for ch in buffer:
if (ord(ch) < 128):
sys.stdout.write(ch)
@jac18281828
jac18281828 / Murmur2.java
Last active March 1, 2017 15:02
Murmur2 in Java - Tweaker Edition
public class Murmur2 {
public static final int BYTE_BITMASK = 0xff;
public static int MURMUR2_SEED1 = 0xe17a1465;
public static int MURMUR2_SEED2 = 0x9747b28c;
public static int MURMUR2_SEED3 = MURMUR2_SEED1*7;
private int defaultSeed = MURMUR2_SEED1;
public Murmur2(final int defaultSeed){
@jac18281828
jac18281828 / Fnv1Collision.java
Created June 26, 2017 16:27
FNV1 Brute Force
import sun.misc.Contended;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAccumulator;
@jac18281828
jac18281828 / seq_lock.h
Last active September 30, 2017 23:33
Hans-J. Boehm sequence lock in c++
#pragma once
#include <stdatomic.h>
#include <atomic>
#include <sys/types.h>
#define PAUSE asm volatile("pause\n": : :"memory");
class seq_lock {
private:
@jac18281828
jac18281828 / DSASigner.java
Created September 19, 2018 13:13
Simple Java DSA Signer Performance Check
package com.covemarkets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
@jac18281828
jac18281828 / sha256
Last active December 15, 2020 17:18
openssl based sha256 checksum utility works on macOS
#!/usr/bin/env /bin/bash
# SHA 256 based on openssl
#
# sha256 similar to the classic "md5sum" command line
#
if [[ ${#} -gt 0 ]]
then
# iterate over all arguments
@jac18281828
jac18281828 / KafkaEmbedded.java
Created September 25, 2018 18:25
Embedded Kafka Server based on Kafka-junit. Works with spring dependency injection
import com.salesforce.kafka.test.AbstractKafkaTestResource;
import com.salesforce.kafka.test.KafkaCluster;
import com.salesforce.kafka.test.KafkaTestCluster;
import com.salesforce.kafka.test.junit4.SharedKafkaTestResource;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
@jac18281828
jac18281828 / StringPerformerTest.java
Created October 11, 2018 16:28
Here is why Java 10 is awesome ;-)
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StringPerformerTest {
private static final Logger log = LoggerFactory.getLogger(StringPerformerTest.class);
private static final String S1 = "table";