Skip to content

Instantly share code, notes, and snippets.

Avatar

Tom Anderson tomwhoiscontrary

View GitHub Profile
@tomwhoiscontrary
tomwhoiscontrary / install-concourse-on-ubuntu.sh
Created Aug 22, 2016
A shell script to install Concourse on a systemd-based Ubuntu using the plain binary
View install-concourse-on-ubuntu.sh
#! /bin/bash -eu
EXTERNAL_URL_HOST_NAME="$1"
ADMIN_USERNAME="$2"
ADMIN_PASSWORD="$3"
CONCOURSE_VERSION=${CONCOURSE_VERSION:-v1.1.0}
apt-get update
apt-get install -y postgresql postgresql-contrib
@tomwhoiscontrary
tomwhoiscontrary / Main.java
Last active Sep 22, 2020
A simple Java web server with basic logging, tracing, health check, graceful shutdown and zero dependencies
View Main.java
import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
@tomwhoiscontrary
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
tomwhoiscontrary / constant_tzinfo.py
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!
View constant_tzinfo.py
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
tomwhoiscontrary / venvexec.sh
Created Feb 18, 2020
My super sweet Python run-module-in-a-venv script
View venvexec.sh
#! /bin/bash -eu
shopt -s failglob
force=
while getopts "f" flag
do
case $flag in
f) force=y ;;
esac
done
@tomwhoiscontrary
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 https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
Using cached https://files.pythonhosted.org/packages/e8/74/6e4f91745020f967d09332bb2b8b9b10090957334692eb88ea4afe91b77f/urllib3-1.25.8-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests)
@tomwhoiscontrary
tomwhoiscontrary / TimeTabulator.java
Created Nov 29, 2019
Program to help work out time correspondence between timezones
View TimeTabulator.java
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class TimeTabulator {
@tomwhoiscontrary
tomwhoiscontrary / rant.md
Created Oct 30, 2019
Comment on "Propose implicit named arguments for formatting macros" #2795
View rant.md

comment on https://github.com/rust-lang/rfcs/pull/2795 which i think is actually completely wrong, so cancelling

Do i understand correctly that this would be a special case in the language, understood by the compiler itself? That this isn't a change to the definition of the format_args! macro?

Would this be specific to format_args!, or could syntax like this be used by other, user-written, macros, which don't build on format_args!?

I understand that format_args! is currently special, implemented as a compiler built-in, rather than as a real macro. However, i've always seen this as an unfortunate wart, something that had to be done because we needed good print statements, and the macro system wasn't strong enough to implement them yet. It would be nice to remove that wart one day. Even while it's in place, it's useful to be able to gloss over it, and describe format_args! as just another macro, not doing anything any other macro couldn't do.

If i've understood correctly, then adding this featur

@tomwhoiscontrary
tomwhoiscontrary / build.sh
Created Oct 1, 2019
Failing to price a seasoned SONIA OIS with QuantLib
View build.sh
#! /bin/bash -eu
cd "$(dirname "$0")"
$GCC_HOME/bin/g++ -std=c++17 -Wall -g -I $QL_PATH/include -L $QL_PATH ${GCC_OPTS:-} sonia_demo.cpp -lQuantLib -o sonia_demo
LD_LIBRARY_PATH=$QL_PATH ./sonia_demo
@tomwhoiscontrary
tomwhoiscontrary / ErrorCollector.java
Last active Sep 25, 2019
ErrorCollector for JUnit 5
View ErrorCollector.java
import org.hamcrest.Matcher;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.opentest4j.MultipleFailuresError;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
You can’t perform that action at this time.