Skip to content

Instantly share code, notes, and snippets.

@sehrgut
sehrgut / jquery.evil.js
Last active June 5, 2021 01:23
mask/hijack links with jQuery
/*
jquery.evil.js - mask and hijack links
Copyright (C) 2011 Keith Beckman
Released under the GPLv3
*/
/*
mask(url) replaces the href of each selected link with url, restoring it for
the duration of a click.
@sehrgut
sehrgut / qbsort.js
Created November 11, 2011 17:58
quantum bogosort for javascript
/*jshint forin:true, noarg:true, noempty:true, eqeqeq:true, bitwise:true, undef:true, browser:true, indent:4, maxerr:50 */
/*
qbsort.js - quantum bogosort for javascript
Copyright (C) 3011 Keith Beckman
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
@sehrgut
sehrgut / inheritance-patterns.js
Created April 30, 2013 03:42
Notes in search of the One True Javascript Inheritance Pattern, ideally with minimal boilerplate and no helper functions.
// http://www.bennadel.com/blog/2184-Object-create-Improves-Constructor-Based-Inheritance-In-Javascript-It-Doesn-t-Replace-It.htm
var SuperType = function () {
};
SuperType.prototype = {};
var SubType = function () {
@sehrgut
sehrgut / squint.sh
Last active December 17, 2015 17:19
squint - a bash script for cygwin to rip audio tracks from YouTube video files wihtout transcoding
#!/usr/bin/bash
# Licensed under any of GPLv2, MIT, and BSD 2-clause licenses
FFDIR=`cygpath -u $USERPROFILE`"/bin/ffmpeg/bin"
infile=`cygpath -w "$1"`
outfile=`cygpath -w "${1%.*}"`
echo $1
FFPROBE="$FFDIR/ffprobe.exe"
@sehrgut
sehrgut / libertarians.md
Created July 8, 2013 22:21
some google zeitgeist about us crazy libertarians, from my current node.js project "googlesay".

#Google Say

##about "libertarians are just"

  • "Libertarians are just radical Right-wingers who have not one care for anything or anyone other than themselves." *
  • "The Libertarians are just the Antinomians of the modern age." *
  • "6 Comments to �Libertarians Are Just Republicans Who Smoke Pot�." *
  • "His entire piece is premised upon the idea that libertarians are just another element of the Right that simply needs to be brought back into the..." *
  • "Also, it gives credence to allegations from liberals that libertarians are just conservatives in disguise." *
  • "Otherwise, libertarians are just " all the

Fastest function to intersect a large number of big arrays in javascript, without dependencies

* The compressed version is only 345 caracters long. * Faster than common libraries, even a large number of arrays, or on very big arrays. (See benchmarks) *

Usage

array_intersect(array1, array2, ..., arrayN)

How it works

The idea is simple and comes from here: http://pioupioum.fr/developpement/javascript-array-intersection.html.
@sehrgut
sehrgut / LetterpressSizes.json
Last active April 19, 2018 12:43
Traditional letterpress point size names, in JSON
/*
* Transcribed to JSON from http://en.wikipedia.org/wiki/Point_(typography)#Traditional_point-size_names
* This document is free and open-source software licensed simultaneously under the MIT License, the GPL v2,
* and the two-clause BSD License.
*
* nb. Where conflicts in naming existed (Double Small Pica and Double Pica), the British unit took
* precedence. In all other cases, both US and British units are described.
*/
{
"LetterpressSizes": {
@sehrgut
sehrgut / MeasureAllCharacterRanges.vb
Last active December 21, 2015 13:19
`System.Drawing.Graphics#MeasureCharacterRanges` has a hard limit of 32 `CharacterRange`s for measurement, so here's a workaround. MS has stated they have no intention of fixing this, so get used to it, kids. http://connect.microsoft.com/VisualStudio/feedback/details/96250/setmeasurablecharacterranges-crashes-with-more-than-32-characters#tabs
' This document is free and open-source software licensed simultaneously under the MIT License,
' the GPL v2, and the two-clause BSD License.
Public Function MeasureAllCharacterRanges(ByVal g As Graphics, ByVal txt As String, ByVal font As Font, ByVal dest As RectangleF,
ByVal format As StringFormat, ByVal ranges As IEnumerable(Of CharacterRange)) As IEnumerable(Of Region)
Dim out As New List(Of Region)(ranges.Count)
' Defensive copy to not side-effect caller based on shared GDI format struct
Using fmt As StringFormat = format.Clone
While ranges.Any
@sehrgut
sehrgut / DrawJustifiedString.vb
Last active December 21, 2015 13:38
System.Graphics#DrawString has no facilities for drawing justified text. This method will draw text into a box, justified. It only handles a single line, but TODO is wrap, so it can be a complete drop-in for Graphics#DrawString. As is, it's useful for single lines such as in logotype.
' This document is free and open-source software licensed simultaneously under the MIT License,
' the GPL v2, and the two-clause BSD License.
Public Sub DrawJustifiedString(ByRef g As Graphics, ByVal txt As String, ByVal font As Font,
ByVal brush As Brush, ByVal destination As RectangleF, ByVal format As StringFormat)
Using fmt As StringFormat = format.Clone
fmt.FormatFlags = fmt.FormatFlags Or StringFormatFlags.MeasureTrailingSpaces ' don't lose spaces
fmt.SetMeasurableCharacterRanges({New CharacterRange(0, 1)}) ' Set Graphics#MeasureCharacterRanges to measure first character
fmt.Alignment = StringAlignment.Center ' "Justified" is an alignment. We need to align each character Center in its computed box
@sehrgut
sehrgut / nettest.sh
Last active December 21, 2015 13:58
Useful tool to keep tabs on an iffy network connection.
#!/bin/bash
# Licensed under any of GPLv2, MIT, and BSD 2-clause licenses
TEST_ADDR='4.2.2.1'
INTERVAL=10
VERSION='nettest v0.2a, keith beckman'
args=$(getopt vhi:H:V $*)
function usage () {