Skip to content

Instantly share code, notes, and snippets.

View smat's full-sized avatar

Stian Mathiassen smat

  • 2Park
  • Oslo
View GitHub Profile
#!/bin/bash
BRANCHES=$(git show -s --pretty=%d HEAD)
REVISION=$(git log --format=format:"%H %ci" -1)
echo "$REVISION $BRANCHES"
@smat
smat / HoganGenerator.java
Last active August 29, 2015 13:56
Render Mustache-templates in Java with Hogan.js
import org.mozilla.javascript.*;
import org.apache.commons.io.IOUtils;
import java.io.*;
public class HoganGenerator {
private StringBuilder parseFile(GeneratorContext context, String file) throws IOException {
StringBuilder javaScriptString = new StringBuilder();
String variableName = String.format("template['%s']", file);
class A<E extends A> {
private String name;
E withName(String name) {
this.name = name;
return (E) this;
}
}
class B extends A<B> {
private String job;
@smat
smat / Example.java
Created July 1, 2011 13:50
Missing asMap-implementation (for Java)
public class Example {
public void example() {
Map<String, String> map = MapUtil.asMap("key", "value").entry("key2", "value2");
}
}
@smat
smat / MapUtils.java
Created July 11, 2011 18:45
Java List to Map implementation
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MapUtils {
public static <K, V> Map<K, V> listToMap(Class<K> keyClass, List<V> list, String valueToKeyFunctionName) {
HashMap<K, V> map = new HashMap<K, V>();
for (V value : list) {
@smat
smat / file.clj
Created September 17, 2011 10:26
Exercise on BEKK-course of clojure
(ns testproj.exercise1
(:use [clojure.test])
(:use [midje.sweet])
)
(unfinished procedures animals in-use? can-be-done?)
(defn on-animal [predicate arg]
(fn [x] (predicate arg x)))
@smat
smat / life.clj
Created September 17, 2011 14:34
Conway's Game of Life
(ns test.life
(:use [clojure.test])
(:use [midje.sweet])
)
(unfinished )
(defn neighbours [cell]
(map (fn [offset] (map + cell offset)) [[-1 -1] [-1 0] [-1 1] [0 -1] [0 1] [1 -1] [1 0] [1 1] ]))
@smat
smat / Test.java
Created September 20, 2011 07:47
Builder-pattern
public class Test {
private String text;
public String getText() {
return text;
}
public class Builder {
boolean isBuilt = false;
@smat
smat / ResultSetMock.java
Created October 14, 2011 08:42
ResultSetMock
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringUtils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;
import java.util.HashMap;
public class ResultSetMock {
@smat
smat / 2connect.sh
Created November 4, 2011 14:26
Dualscreen display for two or more ssh hosts
#!/bin/sh
tmux new-session -d -s miniapp -n 'Miniapp' 'ssh host1'
tmux split-window -t miniapp 'ssh host2'
#tmux split-window -t miniapp 'ssh host3'
tmux select-layout -t miniapp even-vertical
tmux set-window-option -t miniapp synchronize-panes on