Skip to content

Instantly share code, notes, and snippets.

@jnape
jnape / gist:3925124
Created October 20, 2012 22:56
Leibniz formula for π using Dynamic Collections 1.2.8
package com.jnape.dynamiccollection;
import com.jnape.dynamiccollection.lambda.Function;
import com.jnape.dynamiccollection.list.DynamicList;
import static com.jnape.dynamiccollection.lambda.library.numeric.accumulator.Add.plus;
import static com.jnape.dynamiccollection.lambda.library.numeric.accumulator.Subtract.minus;
import static com.jnape.dynamiccollection.list.NumericDynamicArrayList.fromTo;
public class LeibnizSeries {
@jnape
jnape / gist:3895906
Created October 15, 2012 22:09
"Run with Jasmine" TextMate CoffeeScript Command
# Using the Bundle Editor, add a new command for the CoffeeScript bundle
# Save: Nothing
# Input: Entire Document
# Output: Show as Tool Tip
# Command(s):
input="$TM_FILEPATH"
regex=".spec.(js|coffee)$"
jasmine=`which jasmine-node`
@jnape
jnape / gist:3805024
Created September 29, 2012 19:34
Levenshtein Ladders

Levenshtein Ladders: A Team Game with Which to Teach Levenshtein Differences

This is a derivative of a word ladders, or word "doublets", in which a word is intended to be transmuted into a different word through successive alterations of individual letters, presuming each alteration results in a real word, each time. The game can be further altered through the constraints of scoring based on Levenshtein Differences, a way to measure the difference between two words through the number or alterations necessary to morph the starting word into the destination word. Furthermore, the added constraint of reversal can be accomplished, but at the cost of a 2 point addition, and only under the condition that every word up to, but excluding, the last transformation must be a word, with the last transformation being the reverse of the destination word. Scoring is symmetric to golf, in which lower numbers are better scores, and higher numbers are worse scores.

Examples:

[Cat => Dog] Cat -> Cot (+1) -> Dot (+1)

@jnape
jnape / gist:3266786
Created August 5, 2012 19:23
Functional solution for computing geometric mean in Java
package com.jnape.dynamiccollection;
import com.jnape.dynamiccollection.lambda.Accumulator;
import static com.jnape.dynamiccollection.factory.DynamicListFactory.list;
import static java.lang.Math.pow;
public class GeometricMean {
public static final Accumulator<Integer, Integer> TIMES = new Accumulator<Integer, Integer>() {
@jnape
jnape / gist:2623606
Created May 6, 2012 18:14
algorithm for creating groups from list in java
package com.jnape.dynamiccollection.operation;
import com.jnape.dynamiccollection.list.DynamicArrayList;
import com.jnape.dynamiccollection.list.DynamicList;
import java.util.List;
import static java.lang.Math.min;
public class InGroupsOf {
@jnape
jnape / gist:2571670
Created May 1, 2012 21:42
JavaScript Template
var Template = function(template) {
this.template = template;
this.bindings = {};
};
Template.prototype.bind = function(variable, value) {
this.bindings[variable] = value;
return this;
}
@jnape
jnape / gist:2466342
Created April 22, 2012 19:33
Aggregate List of all ancestors for a particular type in Java, using foldLeft and recursion
package example;
import com.jnape.dynamiccollection.lambda.Accumulator;
import com.jnape.dynamiccollection.list.DynamicList;
import java.util.List;
import static com.jnape.dynamiccollection.DynamicCollectionFactory.list;
public class Example {