Skip to content

Instantly share code, notes, and snippets.

View dalemyers's full-sized avatar

Dale dalemyers

View GitHub Profile
def get_entry_size(entry: Any) -> int:
"""Get the approximate size an entry will be in JSON.
Notes: Doesn't check for escaped characters in strings, so the size returned
will essentially always be a lower bound.
:param entry: The entry to get the size of
:returns: A size in bytes
"""
@dalemyers
dalemyers / knights_tour.py
Last active January 12, 2020 12:15
Implementation of the knights tour algorithm in Python
from typing import List, Optional, Tuple
Square = Tuple[int, int]
SIZE = 8
assert SIZE <= 20, "Too large a size will overflow the stack"
def next_possible_squares(x: int, y: int, squares: List[Square]) -> List[Square]:
"""Determine the next possible valid squares based on the current square and the previously visited squares.
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
from optparse import OptionParser
import re
class Parser(object):
@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'
@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
'''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 / 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;
<html>
<head>
<title>Social Media Test</title>
<style>
body{
/*background: #000;*/
}
#content{
width: 600px;
@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:

@dalemyers
dalemyers / pdfcoloursplitter.py
Last active April 1, 2024 15:58
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.