Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
function hasProps(obj) {
var argsLen = arguments.length;
if (typeof obj !== 'object') return false;
if (argsLen <= 1) return false;
for (var i = 1, l = argsLen; i < l; i++)
if (!obj.hasOwnProperty(arguments[i])) return false;
return true;
}
@codyromano
codyromano / gist:8091016
Created December 23, 2013 02:33
Basic example of JS geolocation
var handleLocation = function(pos) {
console.log(pos.coords); // User's approximate latitude and longitude
console.log(pos.coords.accuracy); // Approximate accuracy in meters
};
navigator.geolocation.getCurrentPosition(handleLocation, locError, {maximumAge:10, enableHighAccuracy: true});
/**
* An alias for console.log. Only logs messages if the browser
* supports 'console' and the script is running in a dev environment.
*
* @param {Mixed} Any number of arguments
* @return {Undefined}
*/
var safeLog = (function(){
var url = window.location.href,
logAllowed = url.indexOf('8888') > -1 && window.console;
/**
* Search through an array of objects.
*
* @param {Object} One or more key/value pairs that must exist
* in each object for it to be included in the result.
* @return {Array} Objects that match the search criteria.
*/
Array.prototype.searchObjects = function (params) {
if (typeof params !== 'object') {
throw new TypeError("Must provide search parameters in object form.");
var Network = {
// Host we use for determining connectivity
pingHost: 'http://www.archmi.com',
pingInProgress: false,
// If it's PhoneGap or web app environment
isPhoneGapEnv: network && 'isReachable' in network,
// These default values should not be edited, but they may
// change at runtime
@codyromano
codyromano / getCurrentHead.html
Last active August 29, 2015 14:06
Get the hash for the HEAD of your branch in 12 lines of code. Purely client-side; no dependencies
Current hash for master: <span id="currentHash"></span>
<script>
/**
* This displays the commit hash for the HEAD of your chosen Git branch.
* It helps you stay on the same page with other team members during
* development. If their hash matches yours, your branches are in the same state.
*
* This is useful for web projects that don't follow a standard versioning process.
* If you have an automated process for keeping track of versions, this code may
* complement it.
<script>
var rateLimit = (function () {
'use strict';
var processes = {};
return function (pID, fn, rateLimit) {
var process = processes[pID];
if (!process) {
var vehicles = {
car: {
brand: 'Ferrari'
}
};
// This check is obviously OK
if (vehicles.car.brand) {
}
(function (exports) {
/**
* Dependencies
* - jsbn.js
* - jsbn2.js
* - prng4.js
* - ec.js
* - sec.js
* - rng.js