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 / stille.py
Created January 13, 2023 10:39
Audio power from a WAV file
from dataclasses import dataclass
import librosa
import numpy as np
import matplotlib.pyplot as plt
@dataclass
class Audio:
samples: np.ndarray
rate: int
@rob-smallshire
rob-smallshire / maybe.py
Created November 15, 2022 16:28
A maybe (?Monad)
import random
class Maybe:
def __init__(self, item=None):
self._item = item
def __iter__(self):
if self._item is not None:
@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 / 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
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 / 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.
@rob-smallshire
rob-smallshire / macOS-in-virtualbox.md
Last active November 3, 2024 14:07
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 / 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 / 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 / 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: