Skip to content

Instantly share code, notes, and snippets.

View flyte's full-sized avatar
😎
Open for project work

Ellis Percival flyte

😎
Open for project work
  • London
View GitHub Profile
@flyte
flyte / check_replication.py
Last active December 29, 2015 08:19
Nagios plugin to check CouchDB replication status
#!/usr/bin/python
import json, urllib2, sys, argparse
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
p = argparse.ArgumentParser()
@flyte
flyte / split_img.py
Last active December 28, 2015 20:29
Split img down the middle vertically.
from PIL import Image
def split_img(img_path):
"""
Splits an image vertically down the middle and returns a tuple
containing (left_half, right_half) Pillow Image objects.
"""
img = Image.open(img_path)
width, height = img.size
half_width = int(width/2)
@flyte
flyte / image_resize.py
Last active December 25, 2015 11:59
Resize an image to multiple different sizes based on their long edge size.
from PIL import Image
import os
import argparse
p = argparse.ArgumentParser()
p.add_argument("img_filename")
sizes = {
"thumbnail": 100,
"small": 240,
@flyte
flyte / render_tmx.py
Created August 23, 2013 19:56
Draw TMX tiles in pygame and save them as an image
import pygame, pytmx, argparse
def draw_tmx(tmx, window):
# For each layer
for l in xrange(0, len(tmx.tilelayers)):
# For each y tile coordinate
for y in xrange(0, tmx.height):
# For each x tile coordinate
for x in xrange(0, tmx.width):
# try not strictly necessary, but a hangover from some old bad code
@flyte
flyte / csv.py
Last active December 20, 2015 03:18
Format a single value for use in an RFC4180 compliant CSV file. Join multiple of the values returned from this function with a comma to create a row.
def _format_csv_value(self, value):
"""Takes a single CSV value string and formats it in compliance with RFC4180.
Multiple values can be joined together by putting them in a list and using ",".join(the_list).
http://tools.ietf.org/html/rfc4180#page-3
:param value: A single value destined to be output among multiple in a CSV row
:return: The escaped and/or quoted string if necessary, otherwise simply returns <value>.
"""
for x in [",", '"', "\n", "\r\n"]: