Skip to content

Instantly share code, notes, and snippets.

View joelpurra's full-sized avatar
🗺️
Working remotely

Joel Purra joelpurra

🗺️
Working remotely
View GitHub Profile
@moshen
moshen / devonly_tag.rb
Created April 17, 2012 04:53
Jekyll Dev Only Tag
#
# Jekyll Dev Only Tag
#
# Author : Colin Kennedy
# Usage :
#
# The markup/script/css included within the `devonly` tags
# is included in the rendered page when either:
#
# * `server` mode is used
@joelpurra
joelpurra / InheritedClassModelBinder.cs
Created April 18, 2012 18:26
InheritedClassModelBinder: A ModelBinder for ASP.NET MVC3 that handles creating concrete class instances mapped to an abstract superclass. Based on code by Kelly.
namespace JoelPurra.Web.Binders
{
using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Mvc;
using rDoing.Scraper.Web.Mvc.Controllers.ViewModels.Binder.Helpers;
/// <remarks>
/// Based on
@joelpurra
joelpurra / changepolling.joelpurra.js
Created June 17, 2012 15:53
A jQuery plugin to check if the value has changed in an input/select/textarea without relying on the jQuery .change() event. This is perfomed using polling at a configurable interval, which will then trigger the .change() event.
/*!
* @license ChangePolling
* Copyright © 2012 Joel Purra <http://joelpurra.se/>
* Released under MIT, BSD and GPL license. Comply with at least one.
*
* A jQuery plugin to check if the value has changed in an input/select/textarea
* without relying on the jQuery .change() event. This is perfomed using polling
* at a configurable interval, which will then trigger the .change() event.
*/
// https://gist.github.com/2944926
@joelpurra
joelpurra / objectcomparator.joelpurra.js
Created June 24, 2012 20:17
A javascript plugin to create a comparator for one or more properties of an object. Comparators are useful for sorting arrays of objects, and for general comparisons in, for example, if statements. The comparison is done only if the types of both objects'
/*!
* @license ObjectComparator
* Copyright © 2012 Joel Purra <http://joelpurra.se/>
* Released under MIT, BSD and GPL license. Comply with at least one.
*
* A javascript plugin to create a comparator for one or more properties of an object.
* Comparators are useful for sorting arrays of objects, and for general comparisons
* in, for example, if statements.
* The comparison is done only if the types of both objects' property matches.
*/
@joelpurra
joelpurra / README.md
Last active October 6, 2015 16:57
A jQuery plugin to show and hide follow up questions in a form. The follow ups are specified through HTML5 [data-*] attributes.
@getify
getify / gist:3667624
Last active June 25, 2022 16:26
escape all (not-already-escaped) double-quote chars in a string
// NOTE: only escapes a " if it's not already escaped
function escapeDoubleQuotes(str) {
return str.replace(/\\([\s\S])|(")/g,"\\$1$2"); // thanks @slevithan!
}
escapeDoubleQuotes(`ab`); // ab => ab (nothing escaped)
escapeDoubleQuotes(`a"b`); // a"b => a\"b
escapeDoubleQuotes(`a\\"b`); // a\"b => a\"b (nothing escaped)
escapeDoubleQuotes(`a\\\\"b`); // a\\"b => a\\\"b
escapeDoubleQuotes(`a\\\\\\"b`); // a\\\"b => a\\\"b (nothing escaped)
@joelpurra
joelpurra / pubsublogging.joelpurra.js
Created September 28, 2012 21:35
Overriding $.publish() to capture the event for logging purposes. For use with jQuery pub/sub plugin by Peter Higgins.
/*!
* @license PubSubLogging
* Copyright © 2012 Joel Purra <http://joelpurra.se/>
* Released under MIT, BSD and GPL license. Comply with at least one.
*
* Overriding $.publish() to capture the event for logging purposes.
*
* For use with jQuery pub/sub plugin by Peter Higgins (dante@dojotoolkit.org)
* http://higginsforpresident.net/
* https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js
@opie4624
opie4624 / annex-cost.sh
Created December 30, 2012 01:12
Calculate git-annex cost based on ping times for remote hosts.
#!/bin/sh
#
PING="/sbin/ping"
PACKET_SIZE=64
PACKET_COUNT=10
PING_INTERVAL=1
TIMEOUT=2
BASE_COST=200