Skip to content

Instantly share code, notes, and snippets.


Geraint geraintluff

View GitHub Profile
geraintluff / unit-range-reciprocal.hpp
Last active Dec 2, 2021
A map from [0-1] to an arbitrary range, specified using low/mid/high values. Pulled out from some Signalsmith Audio internal code.
View unit-range-reciprocal.hpp
class UnitRangeMapReciprocal {
double vMin, vTopFactor, vBottomFactor;
UnitRangeMapReciprocal() : UnitRangeMapReciprocal(0, 1) {}
UnitRangeMapReciprocal(double min, double mid, double max) {
vMin = min;
double k = (mid - min)/(max - mid);
vTopFactor = max*k - min;
vBottomFactor = k - 1;
View peano-map.json
"": {
"exact": 0
"": {
"relative": "",
"N": 30900
"": {
"relative": "",
geraintluff /
Created Mar 30, 2016 — forked from clayton/
Install FFMPEG on OS X with HomeBrew to convert Mp4 to WebM
# Installation
brew install ffmpeg --with-vpx --with-vorbis --with-libvorbis --with-vpx --with-vorbis --with-theora --with-libogg --with-libvorbis --with-gpl --with-version3 --with-nonfree --with-postproc --with-libaacplus --with-libass --with-libcelt --with-libfaac --with-libfdk-aac --with-libfreetype --with-libmp3lame --with-libopencore-amrnb --with-libopencore-amrwb --with-libopenjpeg --with-openssl --with-libopus --with-libschroedinger --with-libspeex --with-libtheora --with-libvo-aacenc --with-libvorbis --with-libvpx --with-libx264 --with-libxvid
# Easy Peasy
ffmpeg -i video.mp4 video.webm
geraintluff / base64-web-safe.js
Created Oct 9, 2015
Convert base64 to and from web-safe variant
View base64-web-safe.js
// Convert from normal to web-safe, strip trailing "="s
function webSafe64(base64) {
return base64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
// Convert from web-safe to normal, add trailing "="s
function normal64(base64) {
return base64.replace(/\-/g, '+').replace(/_/g, '/') + '=='.substring(0, (3*base64.length)%4);
geraintluff /
Last active Aug 29, 2015
Your Unix machine is awaited in Valhalla - witness!

The shutdown messages on the Mac/Linux command line are baked into the /sbin/shutdown executable.

This replaces the messages with suitable Mad Max: Fury Road quotes. You can make your own, but since you're patching a binary file the replacements MUST, I repeat MUST be exactly the same number of characters as the original, or your computer will not ride eternal, shiny and chrome.

The two versions below are for a Ubuntu Linux variant, and Mac OS X Yosemite (both versions Work For Me on at least one machine).

geraintluff / index.html
Created Apr 28, 2015
Page to generate self-decrypting web pages
View index.html
body {
margin: 0;
padding: 0;
a {
display: block;
<div id="drop" style="width: 100%; height: 69%; margin: 0; padding-top: 30%; text-align: center; font-family: Tahoma, sans-serif;">
geraintluff / data-url.txt
Created Dec 31, 2014
Small single HTML file that securely loads libraries (SHA256-verified). User can then drag files onto the page and they appear PGP-encrypted in a DropBox account.
View data-url.txt
geraintluff /
Last active Aug 29, 2015
AMD define() and require() in 550 bytes

Asynchronous Module Definitions, in 550 bytes

This provides implementations of Asynchronous Module Definition's define() and require() functions. The minified code comes out around 550 bytes.

This enables module definitions, but it doesn't actually fetch any modules that are missing. If you want to automatically fetch modules, see "Extending" below.

The "CommonJS"-style hacks are not supported (e.g. special behaviour for dependencies "module", "require" or "exports").


geraintluff / crush.js
Created Nov 20, 2014
JavaScript Crusher
View crush.js
// Copyright 2014 Geraint Luff
// MIT Licensed
function crush(code, searchLimit) {
var originalCode = code;
searchLimit = searchLimit || 15;
var substitutions = [];
var bannedChars = /[\r\n"'\\]/;
for (var charNum = 32; charNum < 127; charNum++) { // ASCII printable ("safe") characters
var char = String.fromCharCode(charNum);
geraintluff / asyncReplace.js
Created Aug 28, 2014
Asynchronous replace() for JavaScript
View asyncReplace.js
String.prototype.asyncReplace = function (subStr, replacer, callback) {
var str = this;
var replacements = {};
var pending = 0;
var checkDone = function () {
if (!--pending) {
var result = str.replace(subStr, function (match) {
var args =, 0);
var pos = args[args.length - 2];
var key = pos + '-' + match.length;