Skip to content

Instantly share code, notes, and snippets.

View microbial's full-sized avatar

Dwayne Ford microbial

View GitHub Profile
@microbial
microbial / resort_by_value.js
Last active August 29, 2015 14:18
Resort a word list by sum of letter value
// 'abc, ghi, def, abd1, g4hi' => 'abc, abd1, def, ghi, g4hi'
// Ignores non-letters in valuation but preserves them in return
function resortByValue(group) {
function __getWordVal(word) {
var alphaVals = {
a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10, k: 11, l: 12, m: 13,
n: 14, o: 15,p: 16, q: 17, r: 18, s: 19, t: 20, u: 21, v: 22, w: 23, x: 24, y: 25, z: 26
},
wordSum = 0;
@microbial
microbial / factorial.js
Last active August 29, 2015 14:18
Factorial
function factorial(n) {
var product = 1;
while(n > 1) {
product = product * n;
n--;
}
return product;
}
@microbial
microbial / array_to_object.js
Last active August 29, 2015 14:13
Array to Object Utility
//Makes array of objects into an object sorted by a requested key
//--> Key must be unique or collisions will happen and data lost
/** (v0.0.2) Works better!
-- softer failures (i.e. returns empty object instead of blowing up)
-- use key names from on inner levels (eg. name.first)
**/
function arrayToObject(keyToReplaceIndex, arr) {
var obj = {};
if(arr && arr.constructor === Array) {
@microbial
microbial / spike-test.js
Last active August 29, 2015 13:58
Spike-Test - Useful for test driving spikes and snippets
/*********TinyTest********
* The test function will test if two returned values are exactly the same
* //Pass and Fail Examples
* test(square(3), 9) -> Pass: 9 === 9
* test(square(3), 6) -> Fail: 9 expected but got 6
**/
function test(conditionToTest, expectedResult) {
var failMsg = 'Fail: ' + expectedResult + ' expected but got ' + conditionToTest,
passMsg = 'Pass: ' + expectedResult + ' === ' + conditionToTest,
@microbial
microbial / onAvailable.js
Created February 21, 2014 20:32
onAvailable
//not mine
$.fn.onAvailable = function(fn) {
var sel = this.selector;
var timer;
var self = this;
if (this.length > 0) {
fn.call(this);
} else {
timer = setInterval(function() {
if ($(sel).length > 0) {
@microbial
microbial / tng_play_setup_spec.js
Last active December 28, 2015 05:59
Play Setup Requirements
describe("Play functionality to be tested", function (){
it("should start with a round", function () {
expect(Round).toBeDefined();
});
describe("Play intialization for a new round", function () {
var myRound = new Round();
it("should start with hole 1 if hole is unspecified", function () {
@microbial
microbial / tng_play_reqs.js
Last active December 28, 2015 05:59
Play Requirements
/**
* Possible Test Requirements for Tracker App
*/
describe("Normal play conditions", function(){
it("should provide a list of clubs when requested");
it("should select a club when requested");
it("should ask for a moodswing after a club is selected");
it("should prompt for What's next? after moodswing has been saved", function() {
//next_shot();
@microbial
microbial / speak-code
Last active December 26, 2015 01:49
Translation of linguistic objects into programming objects and methods
Linguistic - disection of a sentence or command
[subject] = noun (always implied)
object = noun (person, place, or thing, i.e. "car")
objectAttributes = adjectives (desribes a noun, i.e. "red")
action = verb (action word, i.e. "drive")
actionAttributes = adverb (describes an action, i.e. "slowly")
SENTENCE = subject + action + object (i.e., [I] drive [the] red car slowly.)
Mapping of linguistic elements to programming objects
linguistic.object.objectAttributes = new Object [ i.e. new Car or new Car.color = 'red' ]