Skip to content

Instantly share code, notes, and snippets.

View SegFaultAX's full-sized avatar

Michael-Keith Bernard SegFaultAX

View GitHub Profile
@SegFaultAX
SegFaultAX / gist:cc6caa30136f213b5e12
Created March 13, 2015 20:39
Elasticsearch Curator - Index Filtering Proposal #1
import re
import operator
import curator
import elasticsearch
class IndexFilter(object):
def __init__(self,
time_format="%Y.%m.%d",
import argparse
def main():
parser = argparse.ArgumentParser("Do a thing with stuff!")
parser.add_argument("number", type=int)
args = parser.parse_args()
print "nan" * args.number + " batman!"
@SegFaultAX
SegFaultAX / gist:4906429beff41460e6de
Created March 20, 2015 02:46
IPAddr prefix length hack
class OTIPAddr < IPAddr
attr_reader :mask_addr
def prefix_len
@mask_addr.to_s(2).count "1"
end
end
>>> def example():
... return 1, 2, 3
...
>>> example()
(1, 2, 3)
>>> a, b, c = example()
>>> a
1
>>> b
2
@SegFaultAX
SegFaultAX / find_collisions.py
Last active August 29, 2015 14:24
Elasticsearch mapping analyzer
#!/usr/bin/env python
import os
import json
import sqlite3
import argparse
from collections import namedtuple, OrderedDict
from operator import attrgetter
from StringIO import StringIO
@SegFaultAX
SegFaultAX / gist:5344166cd5e937544270
Last active August 29, 2015 14:24
Comparing and benchmarking Levenshtein distance implementations
#!/usr/bin/env python
import copy
import random
import functools
def memoize(fn):
memo = {}
@functools.wraps(fn)
def _wrapper(*args):
@SegFaultAX
SegFaultAX / pypager.py
Created July 20, 2015 20:11
Dumb python pager
import shlex
import tempfile
import subprocess
LOREM = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ornare enim
gravida congue mollis. Nullam imperdiet hendrerit lorem, vitae tempor nisl
facilisis ut. Integer at blandit ipsum, non blandit metus. Pellentesque enim
magna, malesuada sed mi eget, mattis viverra odio. Praesent ut imperdiet libero.
Phasellus varius laoreet quam, eget rutrum enim. Fusce sit amet volutpat arcu.
@SegFaultAX
SegFaultAX / gist:2240921
Created March 29, 2012 17:57
/etc/init.d/ircd
#! /bin/sh
### BEGIN INIT INFO
# Provides: ircd
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the charybdis ircd
# Description: starts charybdis using start-stop-daemon
@SegFaultAX
SegFaultAX / gist:3186788
Created July 27, 2012 08:10
Lua Conway's Game of Life
-- Author: Michael-Keith Bernard
-- Date: July 26, 2012
--
-- Game of Life
--
-- Ported from this Clojure implementation:
--
-- (defn neighbours [[x y]]
-- (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
-- [(+ dx x) (+ dy y)]))
@SegFaultAX
SegFaultAX / gist:3190270
Created July 27, 2012 20:22
Lua Zipper Example
-- Author: Michael-Keith Bernard
-- Date: July 27, 2012
-- Notes: An example Binary Tree Zipper implementation in Lua
function node(v, left, right)
local n = {}
n.value = v
n.left = left
n.right = right
return n