Skip to content

Instantly share code, notes, and snippets.

View HeinrichHartmann's full-sized avatar

Heinrich Hartmann HeinrichHartmann

View GitHub Profile
@HeinrichHartmann
HeinrichHartmann / dropbox-statsd.sh
Last active January 18, 2019 15:35
Publish dropbox "files remaining" as statsd metrics
statsd=localhost:8125
dropbox=$HOME/bin/dropbox.py
socat=/usr/bin/socat
grep=/bin/grep
sed=/bin/sed
# Example output of `drobox.py status`
# ```
# Syncing (51,938 files remaining, 2 mins left)
# Downloading 51,938 files (3,069 KB/sec, 2 mins left)
@HeinrichHartmann
HeinrichHartmann / bcat.sh
Created September 23, 2016 10:10
Read data from std in and show in a browser
#!/bin/bash
#
# Read data from std in and show in a browser.
#
# E.g. curl google.com | bcat
#
EXT=${1:-.html}
TMPFILE=`mktemp '/tmp/bcat.XXXXXXXX'`"$EXT" || exit 1
cat > $TMPFILE
@HeinrichHartmann
HeinrichHartmann / Monitoring Gloassary.md
Last active July 3, 2016 11:33
Monitoring Glossary

Glossary of Monitoring

  • A system is a set of connected components

The definition of connected and components is missing. I think we can go with definitions like:

  • A components is a set of processes (in the OS sense)
  • Two components are connected if they can talk to each other (over a network or IPC).

Example: A LAMP system, consists of components:

@HeinrichHartmann
HeinrichHartmann / pinbuffer.el
Created June 15, 2016 16:06
Pin an buffer to a window in #emacs
;; Similar to: http://stackoverflow.com/questions/43765/pin-emacs-buffers-to-windows-for-cscope/65992#65992
(defun pin-buffer ()
"Pin buffer to current window."
(interactive)
(message
(if (let (window (get-buffer-window (current-buffer)))
(set-window-dedicated-p window (not (window-dedicated-p window))))
"pinned buffer" "un-pinned buffer")
))
@HeinrichHartmann
HeinrichHartmann / histogram.py
Created January 15, 2016 13:56
Simple (inefficient) example of how to create a histogram with python
from matplotlib import pyplot as plt
import numpy as np
X = np.genfromtxt("DataSets/RequestRates.csv", delimiter=",")[:,1]
bins = [500, 700, 800, 900, 1000, 1500, 1800, 2000, 2200]
bin_count = len(bins) - 1
sample_counts = [0] * bin_count
for x in X:
for i in range(bin_count):
if (bins[i] <= x) and (x < bins[i + 1]):
sample_counts[i] += 1
@HeinrichHartmann
HeinrichHartmann / GoogleSheetsExample.py
Last active December 5, 2016 20:34
Convenient Access to Google Spreadsheets
# Copyright (c) 2015 Heinrich Hartmann
# MIT License http://choosealicense.com/licenses/mit/
import gdata.spreadsheet.service
class GoogleDriveConnection(object):
def __init__(self, email, password):
self.client = gdata.spreadsheet.service.SpreadsheetsService()
self.client.ClientLogin(email, password)
@HeinrichHartmann
HeinrichHartmann / _G.lua
Last active August 29, 2015 14:15
Lua Global Environment
{
_G = nil --[[ref]],
_VERSION = "Lua 5.1",
arg = {
[-1] = "/usr/bin/lua",
[0] = "main.lua"
} --[[table: 0xbcbef0]],
assert = assert --[[function: 0xbc5310]],
collectgarbage = collectgarbage --[[function: 0xbc5370]],
coroutine = {
@HeinrichHartmann
HeinrichHartmann / sensor-server.py
Last active August 29, 2015 14:11
RaspberryPi Serving Sensor Data over HTTP
#!/usr/bin/env python
# Import the ADC driver:
# https://gist.github.com/HeinrichHartmann/27f33798d12317575c6c
import ADC0832 as ADC
import sys
import BaseHTTPServer
import json
from BaseHTTPServer import BaseHTTPRequestHandler
@HeinrichHartmann
HeinrichHartmann / RPi_ADC8032.py
Created December 14, 2014 21:04
Raspbery Pi Analog Input with ADC0832
#!/usr/bin/env python
#
# Analog Input with ADC0832 chip
#
# Datasheet: http://www.ti.com/lit/ds/symlink/adc0838-n.pdf
# Part of SunFounder LCD StarterKit
# http://www.sunfounder.com/index.php?c=show&id=21&model=LCD%20Starter%20Kit
#
import time
@HeinrichHartmann
HeinrichHartmann / TimeSeriesTools.py
Last active August 29, 2015 14:11
TimeSeries convenience functions
import numpy as np
import matplotlib.pylab as plt
from scipy import stats
from collections import *
from itertools import *
#
# Convenience Class for Time Series
#
# Series Objects can be added and subtracted using infix operators.