Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jonathan Conway jonathanconway

⌨️
Typing
View GitHub Profile
@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
\version "2.18.2"
\header {
title = "16-10-16"
composer = "Jonathan A. Conway"
}
\score {
\new PianoStaff <<
\new Staff {
@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);
});
@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 / 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 / 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 / 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 / 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 / ndm-test
Created July 8, 2014 00:33
Solutions to NDM test questions
NDM Javascript Code Test Solutions
==================================
1. Fix the below Javascript code so that the correct index is printed to console.log on each iteration.
Solution:
(function() {
var index,
length = 10;
@jonathanconway
jonathanconway / addthis_reload.js
Created April 1, 2014 23:45
Reload (or initialize) addThis social share buttons. Useful when implementing addThis in a SPA (Single Page Application).
// Reload (or initialize) addThis social share buttons.
// IMPORTANT: make sure you put in a correct pubid on line 7.
window.addthis_reload = function () {
if (!window.addthis) {
// Load addThis, if it hasn't already been loaded.
window['addthis_config'] = { 'data_track_addressbar' : false };
$('body').append('<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={YOUR PUBID HERE}"></script>');
} else {
// Already loaded? Then re-attach it to the newly rendered set of social icons.
// And reset share url/title, so they don't carry-over from the previous page.