Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View efeminella's full-sized avatar

Eric Feminella efeminella

View GitHub Profile
@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: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: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: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: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' )
/* Matches all <em> elements which are the next sibling of a <strong> element */
strong + em {
    /* declarations */
}
@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 / gist:2048192
Created March 16, 2012 02:41
Short-hand convenience functions for Jasmine and jasmine-jquery
// Short-hand convenience functions for Jasmine and jasmine-jquery
/*
* Shorthand convenience for:
*
* expect( $( '#some-id' ) ).toHaveClass( 'someClassName' );
* expectClass( '#some-id', 'someClassName');
*/
var expectClass = function( selector, className )
@efeminella
efeminella / data.point.adapter.js
Created April 3, 2012 22:10
A Highcharts Data Point Adapter for Backbone Models
/*
* Defines a Model which adapts the representation of the relationship
* between two variables defined as x and y, to specific named properties
* which represent 'x' and 'y'.
*
* For example, a data point which models Temperature may represent time
* on the x-axes as x, and degrees on the y-axes as y. A Model can extend
* DataPoint to map x and y to their corresponding named properties defined
* as time and degrees, respectively.
*
@efeminella
efeminella / compress.js
Created December 16, 2012 01:23
Simple node program for js/css minification using yuicompressor
/*
* basic node program for js/css minification using yuicompressor
*
* Compress the file test.js:
* $ node compress.js ../js/test.js
* Created Minified File: ../js/test.min.js
*
* Compress the file test.css
* $ node compress.js ../css/test.css
* Created Minified File: ../css/test.min.css