Skip to content

Instantly share code, notes, and snippets.

View cowtowncoder's full-sized avatar

Tatu Saloranta cowtowncoder

View GitHub Profile
@cowtowncoder
cowtowncoder / gist:10593062
Last active August 29, 2015 13:59
Trying to grok how implicits bind so that 'properties' is essentially passed/shared
class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (implicit properties: LinkedHashMap[String, ModelProperty]) {
// ...
def parse = Option(cls).map(parseRecursive(_))
def parseRecursive(hostClass: Class[_]): Unit = {
// ... and way, way deeper down the call stack
properties += name -> param
}
...
}
@cowtowncoder
cowtowncoder / gist:ef6546a3e21ca197c720
Created May 4, 2014 17:49
Simple jvm-serializers codec for Boon JSON
package serializers.json;
import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;
import data.media.MediaContent;
import serializers.*;
public class BoonDatabind<T> extends Serializer<T>
{
@cowtowncoder
cowtowncoder / gist:1bcc39fceb077d9115f7
Created January 12, 2015 23:03
Simple immutable byte[]->Object Trie, in this case for looking up Enum values from raw UTF-8 string
import java.nio.charset.Charset;
import java.util.Arrays;
/**
* Trie container/wrapper, in this case implements Enum-value lookup.
* Sample code to possibly use for streamlined-lookup by dictionary, using
* UTF-8 bytes of {@link Enum#name()} as the key.
*/
public class EnumByBytesLookup<E extends Enum<E>>
{
@cowtowncoder
cowtowncoder / gist:4e0b2308b1f660b8b855
Created February 4, 2015 18:15
Trie (tr13) builder that uses a LevelDB instance to create a tr13 file to use for reading (note: mem usage linear to result size)
import com.ning.tr13.KeyValueSource;
import com.ning.tr13.impl.bytes.BytesValueReader;
import com.ning.tr13.impl.bytes.SimpleBytesTrieBuilder;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Options;
import org.iq80.leveldb.impl.Iq80DBFactory;
import java.io.*;
package test;
import java.util.*;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
/**
* Test root resource to show case use of JSON
*/
package test;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
package test;
import java.util.*;
import javax.ws.rs.core.*;
public final class RestJsonApplication
extends Application
{
public Set<Class<?>> getClasses()
@cowtowncoder
cowtowncoder / jvm-serializers-stream-2011-10-03.txt
Created October 3, 2011 18:34
Preliminary results for jvm-serializers, data-stream
MacBook-Pro% ./run-stream data-stream/media.9.cks
Checking correctness...
[done]
create ser +same deser +shal +deep total size +dfl
java-manual 1405 15819 14622 12907 13581 14259 30077 2337 620
hessian 1411 41665 33286 56918 57621 58584 100249 2481 800
protobuf 2978 39151 20280 23551 24770 26197 65348 2198 654
thrift 2951 42119 38970 24240 25234 26443 68562 3235 717
thrift-compact 2952 40505 37073 24486 25628 26874 67379 2210 639
avro 1995 41140 38919 25841 34465 41194 82334 1999 576
@cowtowncoder
cowtowncoder / gist:1453666
Created December 9, 2011 22:48
Reading CSV data as Maps
private int readAll(File inputFile) throws IOException
{
int count = 0;
CsvMapper mapper = new CsvMapper();
// need a Schema just to force use of header line (to get column names)
CsvSchema schema = CsvSchema.builder()
.setUseHeader(true)
.build();
// read CSV as sequence of Objects, binding as regular Map (not POJO)
@cowtowncoder
cowtowncoder / IncrementalMurmur3Hasher
Created August 29, 2012 00:38
Incremental Murmur3/32bit, my first take (has unit tests, seems to work; caveat emptor)
public final class IncrementalMurmur3Hasher
{
protected final static int c1 = 0xcc9e2d51;
protected final static int c2 = 0x1b873593;
protected final static int c3 = 0xe6546b64;
private final int _seed;
/**