Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
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.');
}
/**
* @module LevelStats
* @desc Contains math for determining the user's current level, taps
* required to reach next level and related logic.
*/
var LevelStats = {
/**
* @var {Float} Determines the rate at which level cap requirements increase
*/
levelCapExponent: 1.5,
@codyromano
codyromano / TaskRunner.js
Last active October 17, 2015 20:29
A lightweight module for managing small tasks with interrelated dependencies
/**
* @author Cody Romano
* @module Util
* @desc Generic utility methods
*/
(function(exports) {
'use strict';
var Util = exports.Util = {};
@codyromano
codyromano / jQuery-speed-test.js
Created November 4, 2015 18:23
Demonstrates the performance boost of storing jQuery references
var testLoops = 10000;
(function(testLoops) {
console.time('Calling jQuery repeatedly');
while (testLoops--) {
$("#test").text('foo');
}
console.timeEnd('Calling jQuery repeatedly');
// Sample result: 140.916ms
})(testLoops);
/**
* @module RetroRecorder
* @author Cody Romano
* @desc This is just a demo to illustrate how RetroRecorder might be implemented.
* Please take it with a grain of salt because it's not optimized and the Speech API
* probably isn't the best implementation.
*/
(function(exports) {
'use strict';
function getMockDelay() {
return 1000 + (Math.random() * 4000);
}
async function getProducts() {
return new Promise((resolve) => {
var products = [
{title: 'Wave Runner', category: 'sports', cost: 5000},
{title: 'Mac', category: 'electronics', cost: 2000},
{title: 'Toaster', category: 'kitchen', cost: 10},
/**
* @desc Convert an array of strings to a radix tree
*
* @param {Array}
* @returns {Object}
*/
function radixTree(stringArray) {
return stringArray.reduce(function(result, string) {
var characters = string.split(''),
pointer = result;
/**
* @param {Object}
* @param {String}
* @returns {Boolean}
*/
function radixTreeIncludesString(radixTree, string) {
var pointer = radixTree,
characters = string.split(''),
char;