Skip to content

Instantly share code, notes, and snippets.

jnape / gist:2466342
Created Apr 22, 2012
Aggregate List of all ancestors for a particular type in Java, using foldLeft and recursion
View gist:2466342
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 {
jnape / gist:2571670
Created May 1, 2012
JavaScript Template
View gist:2571670
var Template = function(template) {
this.template = template;
this.bindings = {};
Template.prototype.bind = function(variable, value) {
this.bindings[variable] = value;
return this;
jnape / gist:2623606
Created May 6, 2012
algorithm for creating groups from list in java
View gist:2623606
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 / gist:3266786
Created Aug 5, 2012
Functional solution for computing geometric mean in Java
View gist:3266786
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 / gist:3805024
Created Sep 29, 2012
Levenshtein Ladders
View gist:3805024

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.


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

jnape / gist:3895906
Created Oct 15, 2012
"Run with Jasmine" TextMate CoffeeScript Command
View gist:3895906
# Using the Bundle Editor, add a new command for the CoffeeScript bundle
# Save: Nothing
# Input: Entire Document
# Output: Show as Tool Tip
# Command(s):
jasmine=`which jasmine-node`
jnape / gist:3925124
Created Oct 20, 2012
Leibniz formula for π using Dynamic Collections 1.2.8
View gist:3925124
package com.jnape.dynamiccollection;
import com.jnape.dynamiccollection.lambda.Function;
import com.jnape.dynamiccollection.list.DynamicList;
import static;
import static com.jnape.dynamiccollection.lambda.library.numeric.accumulator.Subtract.minus;
import static com.jnape.dynamiccollection.list.NumericDynamicArrayList.fromTo;
public class LeibnizSeries {
jnape / gist:3984985
Created Oct 31, 2012
Symmetric set difference in Haskell
View gist:3984985
module Example (
) where
unique :: (Eq a) => [a] -> [a]
unique [] = []
unique (x:xs) = x:(unique (filter (/= x) xs))
without :: (Eq a) => [a] -> [a] -> [a]
xs `without` ys = [ x | x <- xs, not (x `elem` ys)]
jnape / gist:4013713
Created Nov 4, 2012
Solution to Project Euler #1 in Haskell
View gist:4013713
module Euler1 where
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
import Data.List (nub)
jnape / gist:4013723
Created Nov 4, 2012
Solution to Project Euler #2 in Haskell
View gist:4013723
module Euler2 where
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.