Skip to content

Instantly share code, notes, and snippets.

View timbutler's full-sized avatar
🤓
Busy coding!

Tim Butler timbutler

🤓
Busy coding!
View GitHub Profile
from time import time
from functools import wraps
MINUTE = 60
HOUR = MINUTE * 60
DAY = HOUR * 24
class Metrics(object):
def __init__(self, redis, keyspace='metrics'):
self.db = redis
@jbrownsc
jbrownsc / gist:4694374
Created February 1, 2013 21:45
Postfix Grok for Logstash Based on previous patterns. I cast the "delay" field into an integer for stats analysis in Kibana I also split out a "Postfix Base" for DRY glory.
# Postfix stuff
QUEUEID (?:[A-F0-9]+|NOQUEUE)
EMAILADDRESSPART [a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote}
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::[0-9]+(.[0-9]+)?)?)?)
@tkorkunckaya
tkorkunckaya / postfix_patterns
Last active December 12, 2015 01:29 — forked from jamtur01/postfix_patterns
Postfix patterns file for logstash
QUEUEID (?:[A-F0-9]+|NOQUEUE)
EMAILADDRESSPART [a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote}
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::%{POSREAL:relayport})?)?)
POSREAL [0-9]+(.[0-9]+)?
DELAYS %{POSREAL:a}/%{POSREAL:b}/%{POSREAL:c}/%{POSREAL:d}
DSN %{POSINT}.%{POSINT}.%{POSINT}
STATUS sent|deferred|bounced|expired
PERMERROR 5[0-9]{2}
MESSAGELEVEL reject|warning|error|fatal|panic
@jamtur01
jamtur01 / postfix_patterns
Created December 27, 2012 05:17
Postfix LogStash patterns
# Postfix stuff
QUEUEID (?:[A-F0-9]+|NOQUEUE)
EMAILADDRESSPART [a-zA-Z0-9_.+-=:]+
EMAILADDRESS %{EMAILADDRESSPART:local}@%{EMAILADDRESSPART:remote}
RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?::[0-9]+(.[0-9]+)?)?)?)
#RELAY (?:%{HOSTNAME:relayhost}(?:\[%{IP:relayip}\](?:%{POSREAL:relayport})))
POSREAL [0-9]+(.[0-9]+)?
#DELAYS %{POSREAL:a}/%{POSREAL:b}/%{POSREAL:c}/%{POSREAL:d}
DELAYS (%{POSREAL}[/]*)+
DSN %{NONNEGINT}.%{NONNEGINT}.%{NONNEGINT}
@chooper
chooper / statsd_instrument.py
Created March 11, 2012 22:04
Decorator to quickly add statsd (graphite) instrumentation to Celery task functions.
"""Decorator to quickly add statsd (graphite) instrumentation to Celery
task functions.
With some slight modification, this could be used to instrument just
about any (non-celery) function and be made abstract enough to customize
metric names, etc.
Stats reported include number of times the task was accepted by a worker
(`started`), the number of successes, and the number of times the task
raised an exception. In addition, it also reports how long the task took
@zollinger
zollinger / getcolor.py
Last active March 11, 2023 15:57
Simple way to get dominant colors from an image in Python
from PIL import Image, ImageDraw
import argparse
import sys
def get_colors(image_file, numcolors=10, resize=150):
# Resize image to speed up processing
img = Image.open(image_file)
img = img.copy()
img.thumbnail((resize, resize))
@mattsgarrison
mattsgarrison / merge_pdfbox.py
Created August 31, 2011 15:35
Jython script to use Apache PDFBox to merge PDFs into a single file.
import sys
from java.io import *
import java.io.InputStream
import java.io.FileInputStream
import java.lang.String # blah....converting String types between Java/Python is tedious
sys.path.append("pdfbox-1.0.0.jar") # or wherever you stashed it
import org.apache.pdfbox
"""
This method merges the FileInputStreams that the streamList points to, into the