Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@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 / 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 / .gitconfig
Last active September 2, 2023 07:20
Useful Git aliases. Append this code to the .gitconfig file in your %USERPROFILE% folder.
[user]
name = Jonathan Conway
email = jonathan.conway@gmail.com
[alias]
bn = !git for-each-ref --format='%(refname:short)' `git symbolic-ref HEAD`
br = branch
c = commit
co = checkout
com = checkout master
cp = cherry-pick $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 / 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.
@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;