Skip to content

Instantly share code, notes, and snippets.

View jremmen's full-sized avatar

John Remmen jremmen

  • Planning Center
  • San Diego
View GitHub Profile
@jremmen
jremmen / recnumeric.js
Last active December 18, 2015 05:39
js: recursive sum, avg, gcd, and lcm
function sum(n) {
return n.length ? n[0] + sum(n.slice(1)) : 0;
}
function avg(n) {
return sum(n) / n.length;
}
function gcd(n1, n2) {
return n1 % n2 === 0 ? n2 : gcd(n2 % n1, n1);
@jremmen
jremmen / JuicyTwig.tmTheme
Last active December 18, 2015 03:29
juicy sublime text 2 theme with improved twig lighting pulled twig specific portion of php-twig package extra themes, merged with the juicy theme from daye rees, and then tweeked a few things(not by much)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!--
======================================================================
Juicy Twig
======================================================================
A Sublime Text 2 / Textmate theme.
Copyright (c) 2012 Dayle Rees.
Released under the MIT License <http://opensource.org/licenses/MIT>
======================================================================
@jremmen
jremmen / strnumstrnum.js
Created May 26, 2013 20:04
js: alpha numeric string pattern test
// recursive function to test if string follows a pattern
// of repeating single alpha > numeric or numeric > alpha characters
function strnum(s) {
function iter(t, i) {
if(i > s.length - 1) return true;
else {
if(t === 1) {
if(!isNaN(s[i])) return false;
else return iter(2, i += 1);
@jremmen
jremmen / naivefib.js
Created May 26, 2013 19:35
js: naive fib
// naive fibs with memoization
function fib(n, acc) {
if(n >= 1) {
if(acc[n]) {
return acc[n];
} else {
acc[n] = fib(n - 1, acc) + fib(n - 2, acc);
return acc[n];
}
@jremmen
jremmen / programmatic.js
Created May 26, 2013 19:29
js: programmatic
//fixed point example
var programmatic = {
tolerance: 0.0001,
isCloseEnough: function(x, y) {
return Math.abs((x - y) / x) / x < this.tolerance;
},
fixedPoint: function(f) {
return function(firstGuess) {
var iterate = function(guess) {
var next = f(guess);