Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@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 / 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 / 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 / .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 / 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 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 / 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 / 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 / TypeExtensions.IsSimpleType.cs
Created August 12, 2012 08:09
Determine whether a type is simple.
public static class TypeExtensions
{
/// <summary>
/// Determine whether a type is simple (String, Decimal, DateTime, etc)
/// or complex (i.e. custom class with public properties and methods).
/// </summary>
/// <see cref="http://stackoverflow.com/questions/2442534/how-to-test-if-type-is-primitive"/>
public static bool IsSimpleType(
this Type type)
{
@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