Skip to content

Instantly share code, notes, and snippets.

View jroyalty's full-sized avatar

James Royalty jroyalty

View GitHub Profile
@jroyalty
jroyalty / one_pass_wrs.py
Last active August 16, 2019 20:18
One-pass weighted random sample (without replacement). Based on *Weighted Random Sampling* (2005; Efraimidis, Spirakis) [https://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf]. Longer treatment here: https://krlmlr.github.io/wrswoR/articles/internal/wrswoR.html
import math
import random
class Item(object):
def __init__(self, label, weight):
self.label = label
self.weight = weight
self.nonce = 0.0
@jroyalty
jroyalty / CMakeLists.txt
Created May 5, 2017 04:23
Little CMake config for LMDB
# vim: set ai ts=4 expandtab:
# ::=========================================================================::
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
# The following must be set BEFORE doing project() or enable_language().
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type defined; defaulting to 'Debug'")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"The type of build. Possible values are: Debug, Release, RelWithDebInfo and MinSizeRel.")
@jroyalty
jroyalty / nfqlistener.py
Created December 28, 2016 20:14
Twisted listener for NFQ
import logging
import socket
from twisted.internet import abstract, address, interfaces, defer
from zope.interface import implementer
try:
import netfilterqueue
except:
netfilterqueue = None
@jroyalty
jroyalty / frugal.py
Created June 2, 2016 20:26
Python implemention of frugal streaming algorithms for estimating quantiles. See: http://arxiv.org/abs/1407.1121
class frugal1_estimator(object):
def __init__(self, qtile):
self.qtile_target = qtile
self.m = 0.0
def add(self, new_data):
r = random.random()
if new_data > self.m and r > (1.0 - self.qtile_target):
self.m += 1
elif new_data < self.m and r > self.qtile_target:
@jroyalty
jroyalty / CMakeLists.txt
Last active April 28, 2023 03:52
Work in progress CMake file for Redis simply for use in CLion
# vim: set ai expandtab:
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
# The following must be set BEFORE doing project() or eanble_language().
# ::-------------------------------------------------------------------------::
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type defined; defaulting to 'Debug'")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"The type of build. Possible values are: Debug, Release, RelWithDebInfo and MinSizeRel.")
@jroyalty
jroyalty / test.c
Created January 19, 2016 20:36
Netmask for IPv4 source
#include <stdio.h>
#include <stdlib.h>
#include <maxminddb.h>
int main(int argc, const char * argv[]) {
MMDB_s *mmdb = (MMDB_s *)malloc(sizeof(MMDB_s));
MMDB_open("/tmp/GeoIP2-City_20160105/GeoIP2-City.mmdb",
MMDB_MODE_MMAP, mmdb);
int gai_error = 0;
UP
@jroyalty
jroyalty / Rule.java
Created January 19, 2015 04:07
OpenTSDB KV match rule
public class Rule {
static enum MatchAction {
OUTPUT, OUTPUT_WITH_TAGS, IGNORE;
};
static enum OutputFormat {
KV, KV_DELIM, KV_JSON, LIST, LIST_DELIM, LIST_JSON, HASH;
};
private String metricMatch;
@jroyalty
jroyalty / init.js
Last active August 29, 2015 14:07
A Javascript-based query library for time series data. This is particular to OpenTSDB-style data at the moment.
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
@jroyalty
jroyalty / crack.sh
Created July 19, 2014 21:43
Open an OS X PKG file
## If the package won't let you "Show Package Content" on right-click then...
pkgutil --expand Foo.pkg some/path
## This will probably yield one more more child .pkg files. Inside them
## look for the Payload file. Then...
mv Payload Payload.gz
gunzip Payload.gz
## Which results in Payload uncompressed. Use 'cpio' to extract files...
cpio -iv < Payload