Skip to content

Instantly share code, notes, and snippets.

View calebds's full-sized avatar
🤖

Caleb calebds

🤖
View GitHub Profile
@calebds
calebds / fibs.js
Created March 28, 2013 17:38
Various JavaScript implementations of a generator for the Fibonacci numbers.
// Naive -> fib(30) runs 2692537 times
var fibNaive = function(num) {
if (num === 0) return 0;
if (num === 1) return 1;
return fibNaive(num - 1) + fibNaive(num - 2);
}
// Memoized -> fib(30) runs 59 times
var memo = {};
var fibMemo = function(num) {
@calebds
calebds / addOne.java
Created May 15, 2012 00:49
Increment an integer represented by an int array
/**
* Adds one to the integer represented by the input array
*
* @param input
* an array representation of an integer > -1, e.g. {1,2,3}
* @return
* an array representation of the input integer, plus one
*/
int[] addOne(int[] input) {
for (int i = input.length - 1; i >=0; i--) {
@calebds
calebds / ImageResize.js
Created May 3, 2012 17:06
Downloads, re-sizes and centers an image to fit a display area, with padding.
/**
* Downloads, re-sizes and centers an image to fit a display area, with padding. Uses jQuery.
*
* Example markup + CSS:
*
* <div id="gallery-slide"></div>
*
* #gallery-slide {
* width: 200px;
* height: 400px;