Skip to content

Instantly share code, notes, and snippets.

@kleptog
kleptog / test_haproxy.py
Created April 20, 2024 13:35
Python script to validate haproxy optimisation
# Based on https://github.com/haproxy/haproxy/blob/50d8c187423d6b7e9b1083e05370885f6d12e844/src/h1.c#L578
test_nums = list(range(0x20, 0x27)) + list(range(0x7b, 0x81))
def test1(a, b, c, d):
# What I expected the code to skip given the comment
return all([0x24 <= a <= 0x7e, 0x24 <= b <= 0x7e,0x24 <= c <= 0x7e,0x24 <= d <= 0x7e])
def test3(a, b, c, d):
# What it actually does skip
return all([0x24 <= a, 0x24 <= b, 0x24 <= c, 0x24 <= d]) and any([a <= 0x7e, b <= 0x7e, c <= 0x7e, d <= 0x7e])
@kleptog
kleptog / cache.ex
Created November 29, 2019 14:00
shortner
defmodule Shortener.LinkManager.Cache do
@moduledoc false
use GenServer
@table_name :my_cache
def start_link(args) do
GenServer.start_link(__MODULE__, args, name: __MODULE__)
end
@kleptog
kleptog / cnf_index.py
Created October 29, 2018 08:04
Python implementation for boolean expression index
# coding=utf8
# This is a python implementation of the boolean expression algorithm
# described in the paper "Indexing Boolean Expressions" by Whong et al.
# https://theory.stanford.edu/~sergei/papers/vldb09-indexing.pdf
# Note this really only uses the index ideas from the paper, because the
# ctual algorithm it describes involves shuffling through lists, something
# which is extremely difficult to do efficiently in python. I went for the
# easier route of simply counting entries. As such, I don't give any
@kleptog
kleptog / enelogic.py
Created June 12, 2018 20:03
A simple example for how to export data from the Enelogic API (WSSE)
# From: https://enelogic.docs.apiary.io/#introduction/option-1.-wsse-authentication
# Go to the developer center: enelogic.com/nl/developers.
# Add your app and choose a desired redirect url (only for OAuth2 purposes, if using WSSE just fill in a URL e.g. enelogic.com)
# Fill in values below
import hashlib
import json
import os
import requests
@kleptog
kleptog / check_fdb.py
Last active March 6, 2018 07:54
Script to check Docker Swarm fdb
#!/usr/bin/python
from subprocess import check_output as run
import glob
# Get nodes
nodes = run(['docker', 'node', 'ls', '-q']).split()
self = run(['docker', 'node', 'inspect', 'self', '--format={{.ID}}']).strip()
nodeinfo = {}
@kleptog
kleptog / sessstats.py
Created June 27, 2016 06:53
SQLAlchemy Session Stats
import sys
import inspect
import time
import traceback
from sqlalchemy import event
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
@kleptog
kleptog / cantenna.md
Last active October 5, 2023 10:14
Cantenna mathematics
martijn@martijn-jessie:~/git/ctm/docker$ sudo /usr/lib/postgresql/9.4/bin/pg_xlogdump -p /tmp/pgtest/postgres/pg_xlog/ 000000010000000000000001 |grep -wE '16386|16384|16390'
rmgr: Storage len (rec/tot): 16/ 48, tx: 0, lsn: 0/016A79C8, prev 0/016A79A0, bkp: 0000, desc: file create: base/12139/16384
rmgr: Sequence len (rec/tot): 158/ 190, tx: 683, lsn: 0/016B4258, prev 0/016B2508, bkp: 0000, desc: log: rel 1663/12139/16384
rmgr: Storage len (rec/tot): 16/ 48, tx: 683, lsn: 0/016B4318, prev 0/016B4258, bkp: 0000, desc: file create: base/12139/16386
rmgr: Storage len (rec/tot): 16/ 48, tx: 683, lsn: 0/016B9468, prev 0/016B9418, bkp: 0000, desc: file create: base/12139/16390
rmgr: Sequence len (rec/tot): 158/ 190, tx: 683, lsn: 0/016BC938, prev 0/016BC880, bkp: 0000, desc: log: rel 1663/12139/16384
rmgr: Sequence len (rec/tot): 158/ 190, tx: 683, lsn: 0/016BCAF0, prev 0/016BCAA0, bkp: 0000, desc: log: rel 1663/1213