Skip to content

Instantly share code, notes, and snippets.

View rob-smallshire's full-sized avatar

Robert Smallshire rob-smallshire

View GitHub Profile
@rob-smallshire
rob-smallshire / conj.py
Created January 9, 2015 15:00
A Python 3.4 conj function for mutable and immutable sequences and strings.
from functools import singledispatch
from collections import Sequence, MutableSequence
@singledispatch
def conj(sequence, item):
raise TypeError("conj() not supported for type '{}'".format(type(sequence)))
@conj.register(MutableSequence)
def _(sequence, item):
sequence.append(item)
@rob-smallshire
rob-smallshire / test_extended_textual_header.py
Last active August 29, 2015 14:19
A Hypothesis 1.2 strategy for creating multiline strings.
PRINTABLE_ASCII_RANGE = (32, 127)
def multiline_ascii_encodable_text(min_num_lines, max_num_lines):
"""A Hypothesis strategy to produce a multiline Unicode string.
Args:
min_num_lines: The minimum number of lines in the produced strings.
max_num_lines: The maximum number of lines in the produced strings.
@classmethod
def bisecting_planes(cls, p, q):
"""Determine the bisector of two planes.
Args:
p, q: The two planes to be bisected.
Returns:
The plane bisecting planes p and q.
@rob-smallshire
rob-smallshire / invariant.py
Created May 18, 2015 15:16
A decorator for checking that class invariants are established and maintained.
import functools
def invariant(predicate):
"""Create a class decorator which checks a class invariant.
Args:
predicate: A callable to which, after every method invocation,
the object on which the method was called will be passed.
The predicate should evaluate to True if the class invariant
@rob-smallshire
rob-smallshire / scanner.ino
Created October 23, 2015 08:52
Arduino sketch for a slide scanner using a GAF 503 slide projector and a Canon 20D camera
int NUM_SLIDES = 50;
// Pin 2 has a slide projector connected
int PROJECTOR_ADVANCE_PIN = 2;
int CAMERA_FOCUS_PIN = 3;
int CAMERA_SHUTTER_PIN = 4;
int ARDUINO_LED_PIN = 13;
// the setup routine runs once when you press reset:
@rob-smallshire
rob-smallshire / palindrome.py
Last active May 20, 2016 12:38
The longest palindromic primes of n-digits reproducing the first part of an integer sequence seen in a mural at Oslo Gardermoen airport
# The longest palindromic primes of n-digits
# reproducing the first part of an integer
# sequence seen in a mural at Oslo Gardermoen
# airport
from urllib.request import urlopen
def main():
with urlopen('https://oeis.org/A002385/b002385.txt') as response:
@rob-smallshire
rob-smallshire / class_decorators.py
Created March 18, 2017 15:34
Multiple class decorators
from abc import ABC, abstractmethod
import functools
def invariant(predicate):
"""Create a class decorator which checks a class invariant.
Args:
predicate: A callable to which, after every method invocation,
the object on which the method was called will be passed.
@rob-smallshire
rob-smallshire / macOS-in-virtualbox.md
Last active April 3, 2024 19:03
Notes on getting macOS Sierra running in Virtualbox on a Windows 10 host

On Mac

Download, but don't run, the Sierra installer from the Mac App Store. This places the installer at /Applications/Install\ macOS\ Sierra.app/.

Now run the following commands to build a suitable VM image from the installer:

git clone https://github.com/jonanh/osx-vm-templates
cd osx-vm-templates/packer

sudo ../prepare_iso/prepare_vdi.sh -D DISABLE_REMOTE_MANAGEMENT -o macOS_10.12.vdi /Applications/Install\ macOS\ Sierra.app/ .

@rob-smallshire
rob-smallshire / diffusion.py
Created September 22, 2017 14:33
Diffusion Limited Aggregation - solution to Exercise 4d in Sixty North's Boost.Python workshop
# Diffusion limited aggregation simulation
# as an example solution to Sixty North's
# Boost.Python workshop.
#
# Usage:
#
# python diffusion.py 128 128 4096 diffusion.bmp
#
# To produce a 128x128 image with 4096 sticky
# 'grains' diffused into it.
acrobat africa alaska albert albino album
alcohol alex alpha amadeus amanda amazon
america analog animal antenna antonio apollo
april aroma artist aspirin athlete atlas
banana bandit banjo bikini bingo bonus
camera canada carbon casino catalog cinema
citizen cobra comet compact complex context
credit critic crystal culture david delta
dialog diploma doctor domino dragon drama
extra fabric final focus forum galaxy