Skip to content

Instantly share code, notes, and snippets.

View dankrause's full-sized avatar

Dan Krause dankrause

View GitHub Profile
@dankrause
dankrause / pngmeta.py
Created December 21, 2012 18:34
A command-line tool that manipulates png meta-data in a very Unix-like way. Requires the Python Imaging Library (PIL).
#!/usr/bin/env python
import json, optparse, sys
try:
import PIL.Image, PIL.PngImagePlugin
except:
print >> sys.stderr, "Unable to import Python Imaging Library. Please ensure that it is installed."
sys.exit(1)
@dankrause
dankrause / tgtadm.py
Created January 25, 2013 13:14
A drop in replacement for tgtadm. This was written to help troubleshoot some issues with an older version of tgt on CentOS (back when tgtd used the abstract socket namespace for its IPC socket).
#!/usr/bin/python
import socket
import struct
def enum(*args, **kwargs):
kwargs["__getitem__"] = lambda self, key: args[key]
return type('Enum', (object,), dict(zip(args, values), **kwargs))()
class IPCClient(object):
@dankrause
dankrause / _hover_example.py
Last active March 8, 2024 18:31
Example code to use the (unofficial, unsupported, undocumented) hover.com DNS API.
import requests
class HoverException(Exception):
pass
class HoverAPI(object):
def __init__(self, username, password):
params = {"username": username, "password": password}
r = requests.post("https://www.hover.com/api/login", params=params)
@dankrause
dankrause / ssdp.py
Last active April 25, 2024 13:14
Tiny python SSDP discovery library with no external dependencies
# Copyright 2014 Dan Krause
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@dankrause
dankrause / roku.py
Created July 15, 2013 14:19
Tiny Roku remote library. Requires requests and ssdp.py from here: https://gist.github.com/dankrause/6000248
import ssdp
import requests
from xml.etree import ElementTree
class RokuApp(object):
def __init__(self, app_id, name, version, remote=None):
self.id = app_id
self.name = name
self.version = version
self._remote = remote
@dankrause
dankrause / supercmd.py
Last active January 3, 2016 11:49
Run commands with sets of preconfigured environment variables. Mimics supernova (https://github.com/major/supernova) but not tied to Nova (or Openstack) in any way.
#!/usr/bin/env python
"""supercmd
Usage:
supercmd [-c <file>] list
supercmd [-c <file>] show <environment> [<command>]
supercmd [-c <file>] keyring [set|get] <environment> <parameter>
supercmd [-c <file>] <environment> <command> [<args>...]
supercmd -h | --help
@dankrause
dankrause / pagerduty.py
Last active May 30, 2023 00:43
Simple python client for the Pagerduty integration API
#!/usr/bin/env python
"""pagerduty.py
Usage:
pagerduty.py trigger [options] <description> [<incident_key>]
pagerduty.py acknowledge [options] <description> <incident_key>
pagerduty.py resolve [options] <description> <incident_key>
Options:
-c --conf=FILE A path to a config file
@dankrause
dankrause / event.py
Last active August 29, 2015 13:57
Toy pub/sub implementation in python
from functools import partial
from fnmatch import fnmatchcase
from collections import defaultdict
class Event(dict):
handlers = defaultdict(list)
@classmethod
def subscribe(cls, *args):
if not callable(args[-1]):
@dankrause
dankrause / ipc.py
Last active February 16, 2024 16:23
Simple socket IPC in python
# Copyright 2017 Dan Krause
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@dankrause
dankrause / jobclient.py
Last active August 29, 2015 14:00
An example jobboard client for taskflow
#!/usr/bin/env python
"""jobclient.py
Usage:
jobclient.py [options] <jobboard_name> create <name> <details>
jobclient.py [options] <jobboard_name> list
jobclient.py [options] <jobboard_name> delete <uuid>
jobclient.py [options] <jobboard_name> clear
Options: