Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@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 / showerror.js
Created June 7, 2013 03:18
When called, shows a validation message using jQuery Validation. Can also optionally display the message in the validation summary.
(function ($) {
$.showError = function(element, errorMessage, showInSummary, summaryLinkTargetElement) {
var $element = $(element);
var $form = $element.parents('form').first();
var elementName = $element.attr('name');
var elementLabel = $('label[for={0}]>span:first'.format(elementName)).text();
var $validationSummary;
var $validationLink;
var $target = !summaryLinkTargetElement ? $element : $(summaryLinkTargetElement);
@jonathanconway
jonathanconway / create-react-app-minimal.sh
Last active May 13, 2018 13:47
Minimalist create-react-app. Just enough to write a failing unit-test. 🔴 ✅
################################################################################
#
# 1. Save this file to /usr/local/bin
#
# 2. To make it executable: chmod u+x /usr/local/bin/create-react-app-minimal.sh
#
# 3. To create your app: create-react-app-minimal {app-name}
#
# 4. In your package.json, change this line:
# "test": ...

Keybase proof

I hereby claim:

  • I am jonathanconway on github.
  • I am jonathanconway (https://keybase.io/jonathanconway) on keybase.
  • I have a public key ASA7Vervmw8Z4dy8JI_5Z8sxZKGUfLNvdtjatCLQ6NdtZgo

To claim this, I am signing this object:

@jonathanconway
jonathanconway / genbash
Created May 17, 2017 05:32
Generate an executable bash script
#!/bin/bash
echo #!/bin/bash > $0
chmod u+x $0 # set permissions so that it's to be executable
@jonathanconway
jonathanconway / Timer.js
Created April 5, 2017 07:45
React wrapper for setTimeout ⏲
import React, { PureComponent, PropTypes } from 'react';
export default class Timer extends PureComponent {
static propTypes = {
interval: PropTypes.number,
onExpiry: PropTypes.func
};
constructor(props) {
super(props);
@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 / 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;
}
\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);
});