Skip to content

Instantly share code, notes, and snippets.

View MatthewWilkes's full-sized avatar

Matthew Wilkes MatthewWilkes

  • Nomensa Ltd
  • Leeds, UK
View GitHub Profile
import math
import tidal
import utime
tidal.enable_peripheral_I2C()
from tidal import i2c, i2cp
class RAMBlockDev:
def __init__(self, block_size, num_blocks):
@MatthewWilkes
MatthewWilkes / colors.css
Created January 17, 2024 10:22
Semitransparent equivalents
// Compiled result
:root {
--colour-soft1-0: #eadbea;
--colour-soft1-25: #efe4ef;
--colour-soft1-50: #f5edf5;
--colour-soft1-75: #faf6fa;
--colour-soft2-0: #ead2d5;
--colour-soft2-25: #efdde0;
--colour-soft2-50: #f5e9ea;
@MatthewWilkes
MatthewWilkes / automated.py
Created January 24, 2019 16:30
Extract deleted commits from a GitHub repo
import argparse
import os
import re
import subprocess
import tempfile
import requests
def get_repo(owner, repo):
@MatthewWilkes
MatthewWilkes / lastiter.py
Created October 15, 2020 14:27
How to get the last item in an iterable
import typing as t
T_iter = t.TypeVar("T_iter")
def which_is_last(data: t.Iterable[T_iter]) -> t.Iterator[t.Tuple[T_iter, bool]]:
"""Given an iterable, return an iterable of value, bool pairs
where the bool is True iff this is the last item."""
last_found: T_iter
has_value = False
import fractions
for num_pads in range(15):
options = {num_pads: fractions.Fraction(1)}
for pad in range(num_pads-1, 0, -1):
free_pads = [p for p in range(num_pads+1) if p > pad]
path_lengths = []
for free_pad in free_pads:
path_lengths.append(options[free_pad] + 1)
options[pad] = sum(path_lengths) / len(path_lengths)
@MatthewWilkes
MatthewWilkes / cheatsheet.md
Created June 26, 2019 15:20
Markdown cheatsheet

Header 1

Header 2

Header 3

Header 4

italic bold bold and italic

  1. Numbered List
  2. With more items
  3. Sub lists are indented
@MatthewWilkes
MatthewWilkes / conftest.py
Created May 8, 2019 00:54
Pyramid functional testing example
from contextlib import contextmanager
import tempfile
from unittest import mock
import factory
import pytest
from betterevidence import models
@MatthewWilkes
MatthewWilkes / calculated_payoffs.py
Last active January 11, 2019 13:01
Utilities for examining cycle 2 experiments
from __future__ import print_function
import argparse
import json
import operator
import pprint
def sort_key(value):
player_id, payoff = value
return int(player_id)
@MatthewWilkes
MatthewWilkes / copy_and_restore.py
Created August 20, 2018 22:04
A custom ZODB recovery script for ZODB
# ZODB recovery script that 'rebases' transactions onto an older copy of the same
# FileStorage. This is useful in the case where a FileStorage is lightly corrupted
# but that is not detected and it remains in production, garnering new transactions.
#
# The corruption in the storage may have prevented various transactions for completing
# and prevents packing or incremental backups, so backup taken before the corruption
# happened is used as a graft for the newer transactions. This only works if all
# the corruption happens to transactions covered by the backup, corruption that affects
# the transactions being appended is not recoverable in this fashion.
#
@MatthewWilkes
MatthewWilkes / update_data.py
Last active August 9, 2018 12:34
Data update script for GU
import sys
filename = sys.argv[1]
import csv
import StringIO
import subprocess
import zipfile
data = zipfile.ZipFile(filename, mode='r')
info_file = data.open('data/info.csv')