Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@jonathanconway
jonathanconway / string.prototype.format.js
Created August 24, 2014 08:14
Straight-forward string.prototype format method for Javascript.
// Credit: http://joquery.com/2012/string-format-for-javascript
String.prototype.format = function() {
var s = this;
for (var i = 0; i < arguments.length; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i]);
}
return s;
}
@jonathanconway
jonathanconway / withParam.js
Last active August 29, 2015 14:14
Add a query parameter and value to a given URL string
// Usage:
//
// ('http://www.example.com').withParam('foo', 'bar');
// -> http://www.example.com?foo=bar
//
// ('http://www.example.com').withParam('foo');
// -> http://www.example.com?foo
//
// Credit: Lessan Vaezi
// (See: http://stackoverflow.com/a/487084/23341)
@jonathanconway
jonathanconway / createProxy.js
Last active August 29, 2015 14:22
Returns an object with the same hierarchy of properties as the source object, but on invoking any of its properties, a getter is called instead. Might be useful to someone, somewhere, somehow. 😋
/**
* @name constructProxy
*
* @description
* From a source object, generates and returns a proxy object. When a property
* in the source object is invoked, it runs the function provided as the getter,
* passing it the name of the property invoked as well as the full expression
* that was invoked. Properties that are of type 'object' are simply copied over.
*
*/
@jonathanconway
jonathanconway / bootstrap-responsive-buttons.less
Created June 5, 2015 02:33
Make your Bootstrap buttons big and fat on small touch devices, so they're easier to tap. Might help you to comply with ISO 9241-400:2007.
// conditionally make buttons block
@media (max-width: @screen-sm) {
.btn-block-xs {
.btn-block();
}
}
@media (min-width: @screen-sm) and (max-width: @screen-md) {
.btn-block-md {
@jonathanconway
jonathanconway / radioTabbable.ng.js
Last active April 5, 2019 14:03
Angular Directive that makes individual radio-buttons focusable using the keyboard only. (Useful for accessibility, on a case-by-case basis.)
/**
* @ngdoc directive
* @name radioTabbable
* @requires none
* @description
* Makes individual radio buttons focuseable using the TAB key.
* (By default, pressing TAB while on a radio button would have shifted focus to the next control outside of the radio group.)
* @usage
* <input type="radio" name="radioGroup" value="0" radio-tabbable="" />
* <input type="radio" name="radioGroup" value="1" radio-tabbable="" />
@jonathanconway
jonathanconway / radioTabbable.jquery.js
Created June 26, 2015 06:38
jQuery plugin that makes individual radio-buttons focusable using the keyboard only. (Useful for accessibility, on a case-by-case basis.)
$.fn.radioTabbable = function () {
var groups = [];
// group the inputs by name
$(this).each(function () {
var el = this;
var thisGroup = groups[el.name] = (groups[el.name] || []);
thisGroup.push(el);
});
\version "2.18.2"
\header {
title = "16-10-16"
composer = "Jonathan A. Conway"
}
\score {
\new PianoStaff <<
\new Staff {
@jonathanconway
jonathanconway / rm-w
Created November 29, 2016 05:19
Remove (recursively) by wildcard. Bash script that removes all files matching the wildcard recursively from the current directory down.
#!/bin/bash
find ./ -type f -name $1 -delete
@jonathanconway
jonathanconway / midi
Created November 29, 2016 05:23
Plays a midi file. Bash script that calls FluidSynth with SoftSynth sound-bank on a midi file, to play it through the system audio.
#!/bin/bash
exec fluidsynth -i /Library/Audio/Sounds/Banks/GeneralUser\ GS\ v1.47.sf2 $1
@jonathanconway
jonathanconway / mov2gif
Last active August 11, 2023 08:20
Convert QuickTime screencasts to animated GIFs using ffmpeg
#!/bin/bash
# Inspired by solution by StackOverflow user #18664.
# [See: https://apple.stackexchange.com/a/211219/97498]
#
# Usage:
# gif [filename]
#
# filename - name of a .mov file to convert, excluding .mov extension