Skip to content

Instantly share code, notes, and snippets.

View thomas4g's full-sized avatar

Thomas Shields thomas4g

  • Atlanta
View GitHub Profile
@thomas4g
thomas4g / Fom.js
Created July 11, 2011 21:49
Unminified Vodoo with little bench and nodeunit tests
/*
Copyright (c) 2011 Ivo Wetzel.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@thomas4g
thomas4g / gist:2014767
Created March 11, 2012 02:59
Looping vs. Recursion
// solve(num) with isPrime(num)
// approx. time to solve for 600 trillion: several hours
function solve(num) {
var i = num - 1, result = num;
for(;i>1;i--)
{
if(num%i === 0) {
if(isPrime(i))
{
result = i;
@thomas4g
thomas4g / gist:2014989
Created March 11, 2012 04:15
Greatest Prime - Recursion
function factor(num, index) {
if(!index) index = 2;
var lim = Math.ceil(num/2)+1, result=num;
if(index < lim) {
if(num%index === 0) {
return factor2(num/index);
}
result = factor(num, ++index;
}
return result;
@thomas4g
thomas4g / gist:2025777
Created March 13, 2012 00:41
Four Passes
for(;i<nums.length;i++) {
var northeast = nums[i]*nums[i-(n-1)]*nums[i-2*(n-1)]*nums[i-3*(n-1)],
if(northeast > p) p = northeast;
}
for(;i<nums.length;i++) {
var north = nums[i]*nums[i-n]*nums[i-2*n]*nums[i-3*n];
if(north > p) p = north;
}
for(;i<nums.length;i++) {
var east = nums[i]*nums[i+1]*nums[i+2]*nums[i+3];
@thomas4g
thomas4g / gist:2067757
Created March 18, 2012 01:55
Find Collatz Chain Length
var nums = [], lengths = [];
function findNumLength(n) {
//preliminary check to see if
//we've done this number before
var indexOf = nums.indexOf(n);
if(indexOf !== -1) {
return lengths[indexOf];
}
function even (n2) { return n2%2===0; }
if(n===1) {
@thomas4g
thomas4g / gist:2142245
Created March 20, 2012 23:04
Date Prettier
var DATE_PRETTIFIER = {
date: null,
parse: function(input) {
if(input.length >= 8) {
var day, month, year;
day = parseInt(input.substring(6,8), 10);
month = parseInt(input.substring(4,6), 10);
year = parseInt(input.substring(0,4), 10);
this.date = new Date(year, month, day);
}
@thomas4g
thomas4g / gist:2220618
Created March 27, 2012 21:41
Proto OOP JS
var Mail = Mail || {};
Mail.Message = Mail.Message || {
from: "", //Contact
subject: "",
date: "",
body: ""
};
Mail.Contact = Mail.Contact || {
name: "",
email: ""
@thomas4g
thomas4g / gist:2221303
Created March 27, 2012 23:06
using Utils
var messages = document.getElementById("messages"),
i=0;
for(;i<Mail.messages.length;i++) {
function addSender(m, row) {
var cell = row.insertCell(-1);
Utils.traversal.setText(m.from.name, cell);
}
function addSubject(m, row) {
var cell = row.insertCell(-1);
Utils.traversal.setText(m.subject, cell);
@thomas4g
thomas4g / gist:2222844
Created March 28, 2012 02:01
JS Knight

##The Programmer's Tales: Prologue ###The Knight

Thomas Shields

There was a geek, a most distinguished man

Who from the day on which he first began

to code JS had done so elegantly -

@thomas4g
thomas4g / jsmetro
Created September 13, 2012 21:40
Base JS for Windows 8 Metro App
(function () {
"use strict";
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
WinJS.strictProcessing();
app.onactivated = function (args) {