Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
/**
* 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
import time, os.path, shutil
# Where files are placed for auto-deletion
dirName = '/Users/cromano/Documents/autodelete/'
# Days after which files are considered old
daysUntilDelete = 1
def deleteItem (itemName):
if os.path.isfile(itemName):
function strong (obj, propertyName, type, initValue) {
var propertyValue,
typeErrorMsg = "Property " + propertyName + " must be a " + type;
if (initValue !== undefined && typeof initValue !== type) {
throw new TypeError(typeErrorMsg);
}
propertyValue = initValue;
@codyromano
codyromano / forEachInObj.js
Created June 6, 2015 23:08
Simple helper method for working with JSON
var foods = {
'italian' : 'pizza',
'mexican' : 'burrito',
'japanese' : 'sushi'
};
// Normal way of iterating
for (var category in foods) {
console.log(foods[category], ' is a type of ', category, ' food.');
}