Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
/**
* @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 = {};
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});
/**
* @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;
/**
* @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;