Skip to content

Instantly share code, notes, and snippets.


Tom Anderson tomwhoiscontrary

View GitHub Profile
tomwhoiscontrary /
Last active Feb 16, 2021
Some code in need of good names
public class Class1 {
public static <Type1, Type2 extends Collection<Type1>> Type2 method(Supplier<Type2> parameter1, Collection<Type1> parameter2, Collection<Type1> parameter3) {
Type2 variable = Stream.concat(
return variable;
tomwhoiscontrary /
Created Jan 20, 2021
A function that does something with streams ... but what?
class Foo {
public static <T> Function<T, Stream<T>> foo(Predicate<T> predicate) {
return new Function<>() {
private T previous;
public Stream<T> apply(T current) {
if (predicate.test(current)) {
if (previous != null) {
T previous = this.previous;
import jakarta.json.JsonObject;
import jakarta.json.spi.JsonProvider;
public class ParseTest {
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
tomwhoiscontrary /
Created Dec 13, 2020
a python script to roughly tabulate the Sci-Fi London 2020 short films programme from a downloaded copy of the webpage
#! /usr/bin/env python3
import html.parser
import contextlib
import re
import csv
text_pattern = re.compile(r'([A-Z ()&!0-9]+) \(([^)]+)\) (.*)')
meta_pattern = re.compile(r'Dir: ([^,]+),? ([A-Za-z ]+), ([^0-9]+), ([0-9]+) ?mins?.?')
tomwhoiscontrary /
Created Oct 23, 2020
I wasted most of a day trying to copy Clojure's transducers in Java. It works, as far as it goes, and it's more extensible than native streams. No short-circuiting operations though!
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
tomwhoiscontrary / 1. fsck the boot partition
Last active Aug 13, 2020
Fixing MacBook Fedora boot partition again
View 1. fsck the boot partition
[liveuser@localhost-live ~]$ sudo fsck /dev/sda1
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
fsck from util-linux 2.35.1
tomwhoiscontrary /
Created May 5, 2020
A minimal but i believe correct implementation of Python's tzinfo for constant offsets - there is absolutely no excuse for this not being in the standard library!
class constant_tzinfo(datetime.tzinfo):
def __init__(self, offset_mins): self.offset_mins = offset_mins
def utcoffset(self, dt): return datetime.timedelta(minutes=self.offset_mins)
def dst(self, dt): return None
def tzname(self, dt): return '%+03d:%02d' % (int(self.offset_mins / 60.0), abs(self.offset_mins) % 60)
tomwhoiscontrary /
Created Feb 18, 2020
My super sweet Python run-module-in-a-venv script
#! /bin/bash -eu
shopt -s failglob
while getopts "f" flag
case $flag in
f) force=y ;;
tomwhoiscontrary / console.txt
Created Feb 18, 2020
The incredible self-destructing pip
View console.txt
$ python3 --version
Python 3.4.5
$ python3 -m venv myenv
$ cd myenv
$ bin/pip install requests
Collecting requests
Using cached
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
Using cached
Collecting idna<2.9,>=2.5 (from requests)