Skip to content

Instantly share code, notes, and snippets.

Avatar

Geraint geraintluff

View GitHub Profile
@geraintluff
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;
public:
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
{
"https://twitter.com/every_peano/status/590740112625008641": {
"exact": 0
},
"https://twitter.com/every_peano/status/1058469466714132480": {
"relative": "https://twitter.com/every_peano/status/592203098388566016",
"N": 30900
},
"https://twitter.com/every_peano/status/1057001290117595139": {
"relative": "https://twitter.com/every_peano/status/1058469466714132480",
@geraintluff
geraintluff / ffmpeg-install.sh
Created Mar 30, 2016 — forked from clayton/ffmpeg-install.sh
Install FFMPEG on OS X with HomeBrew to convert Mp4 to WebM
View ffmpeg-install.sh
# 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
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
geraintluff / README.md
Last active Aug 29, 2015
Your Unix machine is awaited in Valhalla - witness!
View README.md

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
geraintluff / index.html
Created Apr 28, 2015
Page to generate self-decrypting web pages
View index.html
<style>
body {
margin: 0;
padding: 0;
}
a {
display: block;
}
</style>
<div id="drop" style="width: 100%; height: 69%; margin: 0; padding-top: 30%; text-align: center; font-family: Tahoma, sans-serif;">
@geraintluff
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
data:text/html,%3Cbody%3E%3Cscript%3Efunction%20sha256(a)%7Bfunction%20b(a,b)%7Breturn%20a%3E%3E%3Eb%7Ca%3C%3C32-b%7Dfor(var%20c,d,e=Math.pow,f=e(2,32),g=%22length%22,h=%22%22,i=%5B%5D,j=8*a%5Bg%5D,k=%5B%5D,l=%5B%5D,m=0,n=%7B%7D,o=2;64%3Em;o++)if(!n%5Bo%5D)%7Bfor(c=0;313%3Ec;c+=o)n%5Bc%5D=o;k%5Bm%5D=e(o,.5)*f%7C0,l%5Bm++%5D=e(o,1/3)*f%7C0%7Dfor(a+=%22%5Cx80%22;a%5Bg%5D%2564-56;)a+=%22%5Cx00%22;for(c=0;c%3Ca%5Bg%5D;c++)%7Bif(d=a.charCodeAt(c),d%3E%3E8)return;i%5Bc%3E%3E2%5D%7C=d%3C%3C(3-c)%254*8%7Dfor(i%5Bi%5Bg%5D%5D=j/f%7C0,i%5Bi%5Bg%5D%5D=j,d=0;d%3Ci%5Bg%5D;)%7Bvar%20p=i.slice(d,d+=16),q=k;for(k=k.slice(0,8),c=0;64%3Ec;c++)%7Bvar%20r=p%5Bc-15%5D,s=p%5Bc-2%5D,t=k%5B0%5D,u=k%5B4%5D,v=k%5B7%5D+(b(u,6)%5Eb(u,11)%5Eb(u,25))+(u&k%5B5%5D%5E~u&k%5B6%5D)+l%5Bc%5D+(p%5Bc%5D=16%3Ec?p%5Bc%5D:p%5Bc-16%5D+(b(r,7)%5Eb(r,18)%5Er%3E%3E%3E3)+p%5Bc-7%5D+(b(s,17)%5Eb(s,19)%5Es%3E%3E%3E10)%7C0),w=(b(t,2)%5Eb(t,13)%5Eb(t,22))+(t&k%5B1%5D%5Et&k%5B2%5D%5Ek%5B1%5D&k%5B2%5D);k=%5Bv+w%7C0%5D.concat(k),k%5B4%5D=k%5B4%5D+v%7C0%7Dfor(c=0
@geraintluff
geraintluff / README.md
Last active Aug 29, 2015
AMD define() and require() in 550 bytes
View README.md

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").

Usage

@geraintluff
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
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 = Array.prototype.slice.call(arguments, 0);
var pos = args[args.length - 2];
var key = pos + '-' + match.length;