Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
jaytaylor / etc-init-api.conf
Created August 30, 2012 22:21
SendHub API Ubuntu Upstart init script
# SendHub API Service
description "Play-Framework 2.0.x SendHub API"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@jaytaylor
jaytaylor / camel_case_to_snake_case.py
Created September 6, 2012 21:41
Convert camel-case to snake-case in python.
#!/usr/bin/env python
"""
Convert camel-case to snake-case in python.
e.g.: CamelCase -> snake_case
Relevant StackOverflow question: http://stackoverflow.com/a/1176023/293064
"""
@jaytaylor
jaytaylor / etc-init-splunkforwarder.conf
Created October 4, 2012 22:48
SplunkStorm Forwarder Upstart script
# SplunkStorm Forwarder
description "SplunkStorm Forwarder"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@jaytaylor
jaytaylor / check_pathmtime.sh
Created October 30, 2012 23:15
Nagios NRPE plugin: Check the number of seconds since a file or directory was last modified
#!/usr/bin/env bash
##
# @author Jay Taylor [@jtaylor]
#
# @date 2012-10-30
#
# @description Nagios NRPE plugin: Check the number of seconds since a file
# or directory was last modified.
#
"""
@author Jay Taylor [@jtaylor]
@date 2010-11-01
Copyright Jay Taylor 2010
"""
#import socks
import socket
@jaytaylor
jaytaylor / DynamicallyGenerateTransformedAttributes.py
Last active December 14, 2015 07:48
Function which dynamically generates a class with "foo_<suffix>" properties which apply and return the transformed value of "foo" after passing it through the mapping function.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Real-world use case:
--------------------
class MyModel(
MainModel,
DynamicallyGenerateTransformedAttributes(str, '_str', 'id', 'user_id')
@jaytaylor
jaytaylor / dynamicClassImport.py
Created March 1, 2013 19:18
One-liner for dynamically importing a class from a module.
imp = lambda path: reduce(lambda module, next: getattr(module, next), path.split('.')[1:], __import__(path[0:path.index('.')]))
@jaytaylor
jaytaylor / etc-init-pgbouncer.conf
Created April 4, 2013 00:08
Stunnel and PgBouncer upstart scripts for Ubuntu 12.04 "Precise"
# PgBouncer Upstart script
description "pgbouncer"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@jaytaylor
jaytaylor / serving.py
Last active July 25, 2022 12:22
MyFancyRequestHandler extends the werkzeug BaseRequestHandler to provide HTTP request execution time to the server log. NB: The associated tutorial is: http://jaytaylor.com/blog/?p=305
import time
from werkzeug.serving import BaseRequestHandler
class MyFancyRequestHandler(BaseRequestHandler):
"""Extend werkzeug request handler to suit our needs."""
def handle(self):
self.fancyStarted = time.time()
rv = super(MyFancyRequestHandler, self).handle()
return rv
@jaytaylor
jaytaylor / select2insert.py
Last active December 17, 2015 14:59
Utility to enable generation of SELECT SQL which executes to INSERT SQL (NB: only tested for compatibility with Postgres).
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Utility to enable generation of SELECT SQL which executes to INSERT SQL.
NB: only tested for compatibility with Postgres.
"""
__author__ = 'Jay Taylor [@jtaylor]'