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 / 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 / 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 / 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 / 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 {
Common.context('#news-page', function($) {
console.log(this.html());
});
// output:
// <div id="#news-page">
// <h2>Australian broadband news and information</h2>
// <p>Friday round-up</p>
@jonathanconway
jonathanconway / gist:652644
Created October 29, 2010 00:33
Load the current querystring parameters into an associative array, taking into account repeated keys
// By JonathanConway.net
// Based off original code by Andy E. http://stackoverflow.com/questions/901115/get-querystring-values-with-jquery/2880929#2880929
Object.prototype.isArray = function () {
/// <summary>
/// Returns true if this object is an array.
/// </summary>
return !(this.push === undefined);
};
@jonathanconway
jonathanconway / jquery-checked-filter
Created November 17, 2010 07:11
A 'checked' filter that actually works
jQuery.extend(jQuery.expr[':'], {
/// <summary>
/// Filter out checkboxes which are checked.
/// </summary>
checked: function(element) {
return element.checked;
}
});
@jonathanconway
jonathanconway / gist:709722
Created November 22, 2010 09:23
ASP.NET MVC - Output full-HTML validation errors
public static class ValidationExtensions
{
public static MvcHtmlString ValidationMessageHtmlFor<TModel, TProperty>(
this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression,
bool htmlEncode)
{
return new MvcHtmlString(
HttpUtility.HtmlDecode(
htmlHelper.ValidationMessageFor<TModel, TProperty>(
@jonathanconway
jonathanconway / gist:726593
Created December 3, 2010 04:49
jQuery CSS filter
$.extend($.expr[':'], {
/// <summary>
/// Filters on whether the element has the same css property & value as specified.
/// Example: $('a:css(color:blue)') returns only links which are blue.
/// </summary>
css: function(element, index, params) {
var style = params[3].split(':');
return element.style[style[0]] === style[1];
}
});
@jonathanconway
jonathanconway / gist:734237
Created December 9, 2010 02:15
between() method for number types
Number.prototype.between = function(n1, n2) { return this >= n1 && this <= n2; }