Skip to content

Instantly share code, notes, and snippets.

@dalemyers
dalemyers / TypeChecker.py
Last active December 26, 2015 03:19
Example of using Python decorators to verify parameter and return value types
class TypeCheck(object):
def __init__(self,*args):
self.flags = args
def __call__(self, original_func):
decorator_self = self
def check( *args, **kwargs):
if len(decorator_self.flags) != len(args):
raise TypeError("Incorrect number of arguments")
types = zip(decorator_self.flags,args)
for (t,a) in types:
@dalemyers
dalemyers / xtermcolour.txt
Last active December 26, 2015 03:19
Setting vim's correct colour scheme in putty
if &term =~ "xterm"
"256 color --
let &t_Co=256
endif
@dalemyers
dalemyers / pdfcoloursplitter.py
Last active June 9, 2024 07:50
PDF Colour Splitter
#!/usr/bin/env python
# Python 2 and 3 compatible.
#This script takes in a PDF and creates two new PDFs. One has the black and
#white pages and the other has the colour pages. It also takes duplex printing
#into account. So a black and white side which is on the same sheet as a colour
#side will be placed into the colour PDF.
#This is from a script created by Iain Murray. The original comment is below.
#This version simply has some different defaults and removes the PDFtoPPM.
@dalemyers
dalemyers / keybase.md
Last active September 18, 2017 19:38

Keybase proof

I hereby claim:

  • I am dalemyers on github.
  • I am dalemyers (https://keybase.io/dalemyers) on keybase.
  • I have a public key ASA6z5CEfbp4l-cv9-sX6AR0s_6smhQ9hgi3Q6OWHHXP-Ao

To claim this, I am signing this object:

<html>
<head>
<title>Social Media Test</title>
<style>
body{
/*background: #000;*/
}
#content{
width: 600px;
@dalemyers
dalemyers / Base64TextCompress.c
Created July 11, 2015 22:19
A simple ASCII text compressor using base 64 encoding
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define CHARACTERS_LENGTH 62
char initialised = 0;
char *characters;
'''This script is a "simulation" of an external merge sort in a DBMS. In a DBMS
you will read pages from disk and be able to hold a particular number in
memory. This implementation allows you to set the number of pages by setting
the MAX_BUFFERS variable, and the size of a page by setting the
MAX_BUFFER_SPACE variable.'''
import sys
import os
import tempfile
@dalemyers
dalemyers / Photo_Archiver.py
Created June 18, 2016 02:54
Small photo archiving script for personal use
import Tkinter
import tkFileDialog
import os
import hashlib
import datetime
import pytz
import shutil
from PIL import Image
from PIL.ExifTags import TAGS
@dalemyers
dalemyers / UKMapGenerator.py
Created December 22, 2016 11:10
Generate map of the UK from OpenStreetMap
#!/usr/bin/env python
# Generated by BigMap 2. Permalink: http://bigmap.osmz.ru/bigmap.php?xmin=472&xmax=527&ymin=288&ymax=351&zoom=10&scale=256&tiles=mapnik
import io, urllib2, datetime, time, re, random
from PIL import Image, ImageDraw
# ^^^^^^ install "python-pillow" package | pip install Pillow | easy_install Pillow
(zoom, xmin, ymin, xmax, ymax) = (9, 236, 144, 264, 176)
layers = ["http://tile.openstreetmap.org/!z/!x/!y.png"]
attribution = 'Map data (c) OpenStreetMap'
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
from optparse import OptionParser
import re
class Parser(object):