Skip to content

Instantly share code, notes, and snippets.

View smat's full-sized avatar

Stian Mathiassen smat

  • 2Park
  • Oslo
View GitHub Profile
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
@smat
smat / ProxyGenerator.java
Created December 7, 2011 14:57
Generate Mock-objects from a hashmap
import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
public class ProxyGenerator {
@smat
smat / pom.xml
Created February 22, 2012 15:49
Commit id in production
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<!-- outputFile doesn't work in the regular v1.2 (see MEXEC-86) -->
<version>1.2.1-BRING</version>
<executions>
<execution>