Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@jonathanconway
jonathanconway / gist:735792
Created December 10, 2010 04:37
The times() method - a more pleasant way to do for-loops in Javascript
Number.prototype.times = function(fn) { for (var i = 0; i < this; i++) { fn(i); } }
@jonathanconway
jonathanconway / gist:1263611
Created October 5, 2011 04:09
InsertGenerator stored proc (which can escape single-quotes)
CREATE PROC InsertGenerator
(@tableName varchar(100)) as
--Declare a cursor to retrieve column specific information
--for the specified table
DECLARE cursCol CURSOR FAST_FORWARD FOR
SELECT column_name,data_type FROM information_schema.columns
WHERE table_name = @tableName
@jonathanconway
jonathanconway / Grunt.sublime-build
Created September 28, 2012 13:33
GruntJS build profile for Sublime editor.
/* Put it in: "%appdata%\Sublime Text 2\Packages\User" */
{ "cmd": ["grunt.cmd"] }
@jonathanconway
jonathanconway / AbnIsActiveAttribute.cs
Created October 6, 2012 06:49
An ASP.NET MVC ValidationAttribute that ensures that an ABN (Australian Business Number) is both registered and Active.
public class AbnIsActiveAttribute : ValidationAttribute
{
private static string AbnValidationUrl = "http://abr.business.gov.au/abrxmlsearch/AbrXmlSearch.asmx/ABRSearchByABN?searchString={0}&includeHistoricalDetails=N&authenticationGuid=74fd05cb-bbf6-4525-a68f-c553f6349222";
private static string ShouldContainString = "<entityStatusCode>Active</entityStatusCode>";
public AbnIsActiveAttribute()
{
ErrorMessage = "This ABN is inactive or invalid.";
}
@jonathanconway
jonathanconway / .gitconfig tagcommit
Last active December 17, 2015 20:19
tagcommit alias. Pass it a tag name, it gives you a commit hash. From: http://stackoverflow.com/a/1863712/23341
[alias]
tagcommit = !sh -c 'git rev-parse --verify $0~0'
@jonathanconway
jonathanconway / underscore.extendPick.js
Created August 9, 2013 13:29
Copies values from the left to the right, where they already exist in the left. (For .NET folks, it's the Javascript equivalent of AutoMapper.)
_.mixin({
extendPick: function (objectA, objectB) {
return _.extend(objectA, _.pick(objectB, _.keys(objectA)));
}
});
@jonathanconway
jonathanconway / express-viewresolver.js
Created October 10, 2013 08:36
Allows you to customize ExpressJS's view rendering so that you can, say, use views in a 'mobile' folder when user is accessing site through a mobile device.
// dependencies: requirejs, express
define(['express'], function (express) {
return function (app, resolver) {
return function(req, res, next) {
var oldRender = res.render;
res.render = function (view, model) {
return oldRender.call(this, resolver.call(this, req, res) + view, model);
};
next();
@jonathanconway
jonathanconway / jquerygo-contrib.js
Created December 11, 2013 05:30
A few handy functions to use with jQueryGo.
exports.jquerygocontrib = function () {
var $ = require('jquerygo');
$.evaluate = function (functionToEvaluate, callback, args) {
$.getPage(function (page) {
page.evaluate(functionToEvaluate, callback, args);
});
};
$.getlength = function (selector, callback) {
@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 {