Skip to content

Instantly share code, notes, and snippets.

View en0's full-sized avatar

Ian Laird en0

View GitHub Profile
@en0
en0 / etcd-init
Last active August 26, 2015 07:25
#!/bin/bash
### BEGIN INIT INFO
# Provides: etcd
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Init for etcd
# Description: etcd 2.0 distributed key-value store
### END INIT INFO
@en0
en0 / keybase.md
Last active February 16, 2017 08:05

Keybase proof

I hereby claim:

  • I am en0 on github.
  • I am irlaird (https://keybase.io/irlaird) on keybase.
  • I have a public key ASCzVEanCrduuo0vHWY1xnGAneMkHGIkA5UdakQnwzvsuQo

To claim this, I am signing this object:

from binascii import a2b_base64 as b64decode, b2a_base64 as b64encode
a, b = 13, 7
PUB = 5
PRIV = 29
MAX = a * b
def cycleBit(v, c, m):
v2 = v
for i in range(c - 1):
@en0
en0 / FindClosest.js
Created October 10, 2017 18:32
Find the index of the closest or exact match in an ordered list.
function findClosest(haystack, needle, comp, lo, hi) {
var mid, cmp;
lo = lo || 0;
hi = hi || haystack.length - 1;
while(lo <= hi) {
mid = lo + (hi - lo>>1);
cmp = comp(haystack[mid], needle);
@en0
en0 / rxjs_operators_by_example.md
Last active December 13, 2017 16:57 — forked from btroncone/rxjs_operators_by_example.md
RxJS 5 Operators By Example
#!/usr/bin/env node
const fs = require("fs");
const path = process.argv.pop();
const code = fs.readFileSync(path, "utf8");
const lines = code.split("\n");
const ret = JSON.stringify(lines, null, 2);
process.stdout.write(ret);
@en0
en0 / WhatSortIsThis.py
Created November 6, 2018 17:25
Late night whiteboard session yielded this sort algorithm. I am unsure what the algorithm it is called.
def sort(s):
for i in range(len(s) - 1):
j = len(s) - 1
while j > i:
if s[i] > s[j]:
s[i], s[j] = s[j], s[i]
j -= 1
return s
@en0
en0 / equalish.c
Created November 10, 2018 15:55
Compute equality on floating points within variance
void eqish(f1, f2) {
static float e = 1.0e-nf; // where n is the precision
return abs((f1 - f2) < e);
}
@en0
en0 / is_prime.py
Last active November 10, 2018 16:31
O(1) Prime test
def is_prime(p):
"""Not Perfect - Do not use."""
if p > 2:
return ((2**(p-1)) % p) == 1
return p == 2
@en0
en0 / tail_recursion.py
Created July 4, 2019 20:50
Tail Recursion Optimizations in Python
class BreakOutStack(Exception):
"""Raised to clear stack frame and reset"""
def __init__(self, *args):
self.args = args
def tail_recursive(fn):
def _wrapped_tail_recursive(*args):
while True:
try: