Skip to content

Instantly share code, notes, and snippets.

@borgar
borgar / pngfix.sh
Created May 18, 2010 11:53
A bash script to run PNGs through both pngcrush and opticrush using unreasonably zealous settings.
View pngfix.sh
#!/bin/bash
# This script attacks either all file arguments given to it, or all png's in a subtree (if
# a directory or no argument is given), and runs both pngcrush and optipng on them with liberal settings.
CRUSH=$(which pngcrush)
OPTI=$(which optipng)
OPTS1='-rem cHRM -rem gAMA -rem iCCP -rem sRGB -q'
OPTS2='-quiet -fix -o4'
TEMP="/tmp/temp.png"
BEFORE=0
@borgar
borgar / Tiny JavaScript tokenizer.js
Created June 24, 2010 12:33
A compact tokenizer written in JavaScript.
View Tiny JavaScript tokenizer.js
/*
* Tiny tokenizer
*
* - Accepts a subject string and an object of regular expressions for parsing
* - Returns an array of token objects
*
* tokenize('this is text.', { word:/\w+/, whitespace:/\s+/, punctuation:/[^\w\s]/ }, 'invalid');
* result => [{ token="this", type="word" },{ token=" ", type="whitespace" }, Object { token="is", type="word" }, ... ]
*
*/
@borgar
borgar / each.js
Created November 15, 2010 22:18
A yielding each function for large collections.
View each.js
/*
* A variation on a jQuery style each function for massive or labour intensive
* loops where the thread is yielded every so often to prevent script timeouts.
*
* (c) Borgar Thorsteinsson
* Licenced under the terms of the MIT/GPL software licenses.
*
* The function accepts these arguments:
*
* `obj`: an array, object, or string to be looped though.
@borgar
borgar / pre-commit
Created September 19, 2011 19:48
Git pre-commit hook to prevent JS trailing commas being checked in to projects.
View pre-commit
#!/usr/bin/env python
"""
Git pre-commit hook to prevent JS trailing commas being checked in.
They have a tendency to sneak into the project and they crash MSIE7.
"""
import sys
import re
import subprocess
@borgar
borgar / uniroot.js
Last active December 28, 2022 02:08
JavaScript port of Brent's method
View uniroot.js
/**
* Searches the interval from <tt>lowerLimit</tt> to <tt>upperLimit</tt>
* for a root (i.e., zero) of the function <tt>func</tt> with respect to
* its first argument using Brent's method root-finding algorithm.
*
* Translated from zeroin.c in http://www.netlib.org/c/brent.shar.
*
* Copyright (c) 2012 Borgar Thorsteinsson <borgar@borgar.net>
* MIT License, http://www.opensource.org/licenses/mit-license.php
*
@borgar
borgar / keybase
Created October 1, 2014 18:58
Keybase ID
View keybase
### Keybase proof
I hereby claim:
* I am borgar on github.
* I am borgar (https://keybase.io/borgar) on keybase.
* I have a public key whose fingerprint is 1964 9E49 702A CC81 3B14 14F0 5A96 CA4A A3F8 E964
To claim this, I am signing this object:
@borgar
borgar / .block
Last active March 28, 2020 11:57
Population pyramid
View .block
license: mit
height: 500
@borgar
borgar / .block
Last active March 8, 2016 22:03
Broad Street Pump
View .block
license: mit
height: 800
@borgar
borgar / .block
Last active March 9, 2016 12:53
Marey's Train Timetable
View .block
license: mit
height: 500
border: no
@borgar
borgar / .block
Last active November 2, 2023 14:35
PRS B1919+21
View .block
license: cc-by-nc-sa-4.0
height: 500
border: no