Skip to content

Instantly share code, notes, and snippets.

@carstenlenz
carstenlenz / ConsoleRunner.groovy
Last active August 9, 2016 11:48
Use a Groovy Console for an interactive Geb Session
package my
/**
* This pre-initializes the Console
*/
class ConsoleRunner {
static void main(String[] args) {
def script = args[0]
def console = new Console()
console.run()
@carstenlenz
carstenlenz / multimethod.js
Created June 26, 2013 11:21
Clojure-inspired multimethod mechanism in JavaScript Needs * Underscore.js (http://underscorejs.org/) * QUnit (http://qunitjs.com/) for tests Have a look at unittests for samples.
var multimethod = (function(_) {
var method = function(multi, dispatchValue, method) {
multi.methodTable.push([dispatchValue, method]);
return method;
};
var defaultmethod = function(multi, method) {
multi.default = ["default", method];
@carstenlenz
carstenlenz / optional.js
Created June 24, 2013 08:34
JavaScript optional result values
var optional = (function() {
var noneInternal = function() {};
noneInternal.prototype.isNone = function() { return true; };
noneInternal.prototype.isSome = function() { return false; };
noneInternal.prototype.bind = function(fun) { return none(); };
var none = function() {
return new noneInternal(); // make fiddling less probable
};
@carstenlenz
carstenlenz / Option.cs
Created March 1, 2012 11:22
Option Type for C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OptionType
{
public abstract class Option<T>
{
public abstract T Value { get; }
@carstenlenz
carstenlenz / filter
Created September 16, 2011 12:28
Eclipse Java code templates for google guava collections functionality
${retIt:newType(java.lang.Iterable)}<${iterable_type}> ${name:newName(retIt)} = ${itbls:newType(com.google.common.collect.Iterables)}.filter(${iterable}, new ${pred:newType(com.google.common.base.Predicate)}<${iterable_type}>() {
@Override public boolean apply(${iterable_type} ${input}) {
return ${false};
}
});