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 / 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 / mkvenv
Created January 20, 2013 12:49
A shell script to create a new Python 3.3 virtualenv, and then download and install distribute and pip into it.
#!/bin/bash
# Create a new Python 3.3 venv and configure it with pip
# Usage: source path/to/mkvenv <path>
set -e
pyvenv $1
cd $1
source bin/activate
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
@rob-smallshire
rob-smallshire / csv_to_dict.py
Created December 7, 2013 03:29
Read a CSV file into a dictionary of lists, using the column names in the first row as dictionary keys mapping to lists of numeric column data taken from subsequent rows in the CSV file.
import csv
with open('faithful.dat', newline='') as csvfile:
reader = csv.reader(csvfile, quoting=csv.QUOTE_NONNUMERIC)
names = next(reader)
columns = zip(*reader)
data = {name: column for name, column in zip(names, columns)}
@rob-smallshire
rob-smallshire / client_controller.py
Created November 17, 2012 20:01
Arduino Web Service and Python Client for a Digital Thermometer with LED display
"""
A Python web service client which GETs temperatures over a web service API
from an Arduino based server and PUTs the status of LEDs back to the Arduino
to provide a visual temperature indication.
The intent of this system is to demonstrate how control logic can be moved
to remote systems which communicate with the Arduino over the network.
Pass the base url of the server e.g. "http://192.168.1.101" as the
only command line argument.
@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 / 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
@rob-smallshire
rob-smallshire / temperature.py
Last active August 22, 2019 06:53
Dynamic temperature types in Python
import operator
ABSOLUTE_ZERO = 0
class Temperature:
_scale_classes = {}
_promotion_rules = {}
@classmethod
@rob-smallshire
rob-smallshire / roundedcube.scad
Created January 25, 2020 13:12 — forked from groovenectar/roundedcube.scad
roundedcube.scad - Fork me and make me better!
// More information: https://danielupshaw.com/openscad-rounded-corners/
// Set to 0.01 for higher definition curves (renders slower)
$fs = 0.15;
module roundedcube(size = [1, 1, 1], center = false, radius = 0.5, apply_to = "all") {
// If single value, convert to [x, y, z] vector
size = (size[0] == undef) ? [size, size, size] : size;
translate_min = radius;
@rob-smallshire
rob-smallshire / proxy.pac
Last active March 28, 2022 11:42
PAC file for routing iPlayer requests over a local SOCKS proxy
function FindProxyForURL(url, host)
{
if (shExpMatch(url, "*.bbc.co.uk/iplayer*")
|| shExpMatch(url, "*.bbc.co.uk/mediaselector*")
|| shExpMatch(url, "zaphod-live.bbc.co.uk.edgesuite.net/*")
|| shExpMatch(url, "bbcfmhds.vo.llnwd.net/*"))
{
return "SOCKS 127.0.0.1:8080";
}
else