Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am tobywf on github.
  • I am tobywf (https://keybase.io/tobywf) on keybase.
  • I have a public key whose fingerprint is 90A8 0C6B 788D 1574 F349 AA29 B0BF 051F 9B20 2065

To claim this, I am signing this object:

@tobywf
tobywf / meldmerge.rb
Last active October 14, 2016 01:32
Homebrew cask for yousseb's Meld.dmg
cask 'meldmerge' do
version 'osx-9'
sha256 '324e096e0253e8ad4237f64a90cdda200fe427db8cf7ebc78143fc98e2d33ebc'
url "https://github.com/yousseb/meld/releases/download/#{version}/meldmerge.dmg"
name 'Meld'
homepage 'https://yousseb.github.io/meld/'
app 'Meld.app'
binary "#{appdir}/Meld.app/Contents/MacOS/Meld", target: 'meld'
@tobywf
tobywf / rounding.py
Created April 9, 2017 16:24
Decimal rounding to the nearest multiple (plus unit tests)
from decimal import Decimal, ROUND_CEILING, ROUND_FLOOR
ONE = Decimal(1)
def round_up(number, quantum):
"""Round a decimal number up to the nearest multiple of quantum"""
return (number / quantum).quantize(ONE, rounding=ROUND_CEILING) * quantum
@tobywf
tobywf / generate-newline-csvs.py
Last active August 19, 2017 12:04
Generate CSV files with all permutations of common line endings
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
from itertools import product
import sys
try:
encoding = sys.argv[1]
except IndexError:
encoding = 'utf-8'
@tobywf
tobywf / config.yml
Created January 29, 2018 02:40
My SVGO configuration file
multipass: true
plugins:
- removeDoctype
- removeXMLProcInst
- removeComments
- removeMetadata
- removeXMLNS
- removeEditorsNSData
- cleanupAttrs
- minifyStyles
@tobywf
tobywf / unicode-csv-excel-legacy-python.py
Created August 19, 2017 10:40
Generate a UTF-8 comma separated value (CSV) file that Excel reads reliably (Legacy Python 2, shame)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from backports import csv
from io import open
with open('test.csv', 'w', encoding='utf-8-sig', newline='') as fp:
writer = csv.writer(fp)
writer.writerow(['Row', 'Emoji'])
for i, emoji in enumerate(['🎅', '🤔', '😎']):
writer.writerow([str(i), emoji])
@tobywf
tobywf / make-test-repo.sh
Created January 25, 2018 15:18
A script to generate a test repo with two feature branches for the git merge vs git rebase tutorial
#!/bin/bash
set -eux
create_commit() {
git checkout "$1"
echo "$2" > src.txt
git commit -am "$2"
git log --graph --pretty=format:'%s %C(yellow)%d%Creset'
sleep 2 # make the commits distinctive in time
@tobywf
tobywf / build-dvisvgm.sh
Last active March 30, 2023 02:29
Build dvisvgm and kpathsea on macOS
#!/bin/bash
set -xeuo pipefail
IFS=$'\n\t'
PREFIX="${1:-/usr/local/dvisvgm}"
TEX="$(kpsewhich -var SELFAUTOLOC)"
echo "$PREFIX, $TEX"
brew install automake freetype ghostscript potrace
@tobywf
tobywf / sbix_extract.py
Created April 6, 2020 04:54
Extract SBIX glyphs from a font
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html
# requires fonttools lib (`pip install fonttools>=4.7.0`)
import sys
from fontTools.ttLib import TTFont
font = TTFont(sys.argv[1])
sbix = font["sbix"]
max_ppem = max(sbix.strikes.keys())
strike = sbix.strikes[max_ppem]
@tobywf
tobywf / boto3-gzip.py
Last active October 18, 2023 17:32
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""