Skip to content

Instantly share code, notes, and snippets.

View SegFaultAX's full-sized avatar

Michael-Keith Bernard SegFaultAX

View GitHub Profile
@SegFaultAX
SegFaultAX / example_shell_script.py
Last active October 23, 2015 00:18
Example shell script
#!/usr/bin/env python
# The MIT License (MIT)
#
# Copyright (c) 2015 David Woodruff, Michael-Keith Bernard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@SegFaultAX
SegFaultAX / query.json
Last active December 12, 2015 01:41
[elasticsearch] Example timestamp query
{
"aggs": {
"counts_by_servicetype": {
"aggs": {
"by_servicetype": {
"terms": {
"field": "servicetype",
"size": 0
}
}
@SegFaultAX
SegFaultAX / sensu_checks.py
Last active March 14, 2016 02:12
Find active sensu checks
#!/usr/bin/env python
# The MIT License (MIT)
# Copyright (c) 2016 Michael-Keith Bernard
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@SegFaultAX
SegFaultAX / dotted.rb
Created February 29, 2016 04:56
Dotted path expansion for Ruby hashes
def expand_dotted_keys(hash, recursive = true)
deep_merge = lambda do |h1, h2|
merger = proc do |k, v1, v2|
v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2
end
h1.merge(h2, &merger)
end
recursive_insert = lambda do |h, path, val|
h ||= {}
@SegFaultAX
SegFaultAX / reader.py
Created March 15, 2016 00:39
Simple lisp-like reader
#!/usr/bin/env python
# Much of this code is either directly copied from or heavily inspired by the
# following example lisp interpreter. The essential structure of this parser is
# mostly an exact replica, and for that I thank the original author for his
# inspirational work.
# Author: Peter Norvig
# Source: http://norvig.com/lispy2.html (http://norvig.com/lispy.py)
@SegFaultAX
SegFaultAX / es_log_parser.py
Last active February 15, 2018 01:11
Quick and dirty slow log parser for elasticsearch (sqlite3 output)
#!/usr/bin/env python
# The MIT License (MIT)
# Copyright (c) 2016 Michael-Keith Bernard
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@SegFaultAX
SegFaultAX / fabfile.py
Last active April 29, 2016 20:59
Simple restart manager
# Example fabric task
import elasticsearch
from restartmanager import RestartManager
@task
def do_the_restart():
# fab qa:es-master do_the_restart
r = RestartManager("/path/to/db")
r.schedule(*env.hosts)
@SegFaultAX
SegFaultAX / sums.py
Created June 30, 2016 00:15
AWS Billing Data parser
import csv
import argparse
import operator
# {'AvailabilityZone': '',
# 'BlendedCost': '0.00',
# 'BlendedRate': '0.00',
# 'InvoiceID': 'xxx',
# 'ItemDescription': '$0.05 per GB-month of Magnetic provisioned storage - US East (Northern Virginia)',
# 'LinkedAccountId': 'xxx',
@SegFaultAX
SegFaultAX / .gitconfig
Last active October 3, 2016 23:25
gitconfig
[user]
name = <fullname>
email = <email>
signingkey = <key>
[alias]
st = status
co = checkout
up = !git pull --ff-only --all -p && git submodule update --init --recursive
fup = !git fetch --multiple upstream origin
ci = commit
@SegFaultAX
SegFaultAX / coroutine.py
Created November 17, 2016 10:04
Python Simple Coroutine Decorator
import functools
def coroutine(f):
@functools.wraps(f)
def coro(*args, **kwargs):
c = f(*args, **kwargs)
next(c)
def cb(*args, **kwargs):
if not (args or kwargs):
next(c)