Skip to content

Instantly share code, notes, and snippets.

View efeminella's full-sized avatar

Eric Feminella efeminella

View GitHub Profile
@efeminella
efeminella / gist:2015388
Created March 11, 2012 07:12
Refresh jQuery Mobile listview
var list = "";
var items = [
{name: "Item A", url: "/#item-a"}
, {name: "Item B", url: "/#item-b"}
, {name: "Item C", url: "/#item-c"}
];
$.each( items, function(i, item) {
list += '<li><a href="' + item.url + '">';
list += item.name;
@efeminella
efeminella / comparator-min.js
Created March 11, 2012 06:21
Simple Comparator API for JavaScript
var Comparator=Comparator||(function(){var c=function(g,f){return this[g]===f};var a=function(f){if(!this.hasOwnProperty(f)){this[f]=undefined}};var b=function(g,m,f){var k=g.prototype,o=(f?f.length:0),j=0,l,h;for(j;j<o;j++){l=f[j];h="is"+l.replace(/^./,l.match(/^./)[0].toUpperCase());if(k[h]===undefined){k[h]=(function(){return c}(m,l))}}};var d=function(g,k,f){var i=g.prototype,h,j;for(h in f){j=f[h];if(i[h]===undefined){i[h]=(function(){return c}(k,j))}}};var e=function(g,h,f){if(g.constructor!=Object){a.call(g.prototype,h);if(Object.prototype.toString.call(f)==="[object Array]"){return b(g,h,f)}return d(g,h,f)}else{throw new Error("Attempting to augment Object prototype")}};return{each:e}}());
@efeminella
efeminella / gist:2008471
Created March 9, 2012 20:21
Simple boilerplate Node Minification with uglify-js
/*
* Simple boilerplate Node Minification build for uglify-js
*
* Install: npm install uglify-js; cd to the this script's dir
* $ node <script-name>.js
*/
var parser = require( 'uglify-js' ).parser
, uglify = require( 'uglify-js' ).uglify
, path = require('path')
, fs = require( 'fs' )
@efeminella
efeminella / gist:1981238
Created March 5, 2012 21:33
Launch a file in a browser from node.js
// For example, launches 'app/index.html' : launch('app/index.html');
var launch = function(path) {
require('child_process' ).spawn('open', [path]);
};
@efeminella
efeminella / gist:1981184
Created March 5, 2012 21:21
RequireJS Test Environment Module Definition Loader
/*
* Defines a utility method on the requirejs global which returns a
* requirejs module definition dependency so as to circumvent having
* to explicitly load test cased (Jasmine, QUnit etc.) as require
* dependencies.
*
* // In a Test/Spec, simply invoke getModule to resolve a require js
* // module definition without implementing Tests/Specs as require js
* // modules.
@efeminella
efeminella / gist:1938101
Created February 29, 2012 05:20
One-time function initializations
// Simply wrap the return value in an immediate function
// and return the result. The below example implements // a test for HTML5 WebSocket Feature detection; however,
// the same concept applies for any function initializer.
var hasWebSockets = ( function (window) {
var prefixes = 'ms O Moz Webkit'.split (' ')
, n = prefixes.length
, i = 0;
for (; i < n; ++i) {
if ( window [prefixes [i] + 'WebSocket'] ){
return true;
@efeminella
efeminella / gist:1938060
Created February 29, 2012 05:13
Function Overwriting in JavaScript
// Initial "getLocation" implementation. Since we only need to test
// for Geolocation support once, we perform the initial test and then
// overwrite the "getLocation" implementation based on the results of
// the test.
var getLocation = function (success, fail, options)
{
var geolocation = navigator.geolocation;
if ( geolocation )
{
@efeminella
efeminella / gist:1937609
Created February 29, 2012 04:13
Loading external Handlebars Templates with jQuery or Zepto
/*
* Extends Handlebars with a basic get method for loading external
* Handlebars templates. Simply pass an options object which contains
* the following properties:
* - path (required) : Path to the external template file to be loaded
* - success (required) : Callback invoked with the compiled loaded template.
* - cache (optional) : true if the template is to be cached, otherwise false.
*
* In addition to the above arguments, any jQuery/Zepto.ajax options argument
* can be specified as well.