Skip to content

Instantly share code, notes, and snippets.

View mmattice's full-sized avatar

Mike Mattice mmattice

View GitHub Profile

Keybase proof

I hereby claim:

  • I am mmattice on github.
  • I am mmattice (https://keybase.io/mmattice) on keybase.
  • I have a public key whose fingerprint is B148 B5B8 B7E9 10CF 6150 442A 655F E1FE 88E6 0DDD

To claim this, I am signing this object:

@mmattice
mmattice / slackcontest
Created February 16, 2015 19:22
Slack webhook input
#!/usr/bin/python
import email
import sys
import json
import requests
url = 'https://hooks.slack.com/services/{{{PUT YOUR URL MAGIC HERE}}}'
payload={"channel": "#general", "username": "ContestBot", "icon_emoji": ":ghost:"}
@mmattice
mmattice / count_server.py
Created November 1, 2014 22:51
example twistd service
from twisted.protocols.amp import AMP
from twisted.internet import reactor
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.application.service import Application
from twisted.application.internet import StreamServerEndpointService
class Count(amp.Command):
arguments = [('n', amp.Integer())]
response = [('ok', amp.Boolean())]
@mmattice
mmattice / gist:53ec257cafd1abe83d85
Created October 7, 2014 18:47
Non-noisy agent connections
from twisted.web import client
class _HTTP11ClientFactory(client._HTTP11ClientFactory):
noisy = False
class HTTPConnectionPool(client.HTTPConnectionPool):
_factory = _HTTP11ClientFactory
@mmattice
mmattice / randomwords
Created September 23, 2014 18:02
Grab some random words from a dictionary file
#!/bin/bash
count=$1
if [[ $count = "" ]]; then count=2 ; fi
shuf -n $count /usr/share/dict/american-english | tr "\n" " "; echo
@mmattice
mmattice / puppet.monit
Created September 17, 2014 14:44
Monit configuration to kick puppet agent processes if they get stuck
check process puppet with pidfile /var/run/puppet/agent.pid
start program = "/etc/init.d/puppet start"
stop program = "/etc/init.d/puppet stop"
check file puppetdlock with path /var/lib/puppet/state/puppetdlock
if timestamp > 1 hour
then exec "/bin/bash -c '/etc/init.d/puppet stop ; rm -f /var/lib/puppet/state/puppetdlock'"
check file agent_catalog_run.lock with path /var/lib/puppet/state/agent_catalog_run.lock
if timestamp > 1 hour
@mmattice
mmattice / gist:f4c0d628f56dabe18d86
Last active August 29, 2015 14:04
Grab a title from a webpage and turn it into ascii (if possible)
import re
from BeautifulSoup import BeautifulSoup
import requests
url = 'http://emojicons.com/e/flipping-tables'
r = requests.get(url)
soup = BeautifulSoup(r.text)
print soup.title.string.encode('ascii', 'ignore')
print re.search( '^.*?(?=::)', soup.title.string ).group()
@mmattice
mmattice / gist:bec94dd77f6671472bad
Created June 26, 2014 18:19
There must be a better way
import informixdb
class TransactionInformixDict:
"""A lightweight wrapper for a DB-API 'cursor' object.
Relays attribute access to the DB cursor. That is, you can call
execute(), fetchall(), etc., and they will be called on the