Skip to content

Instantly share code, notes, and snippets.

View dain's full-sized avatar

Dain Sundstrom dain

View GitHub Profile
"Name","Retained Size","Shallow Size"
"byte[3703132]","3703144","3703144"
"_bytes of org.mortbay.io.ByteArrayBuffer","3703200","56"
"_buf of org.mortbay.jetty.HttpConnection$Output","3703256","56"
"_out of org.mortbay.jetty.HttpConnection","3705144","104"
"_connection of org.mortbay.jetty.nio.SelectChannelConnector$ConnectorEndPoint","3709968","64"
"[2985] of java.lang.Runnable[3000]","1886724728","12016"
"_jobs of org.mortbay.thread.QueuedThreadPool","1886728176","128"
"this$0 of org.mortbay.thread.QueuedThreadPool$PoolThread [Stack Local, Thread, Monitor Used] "4353837@qtp-27187756-191"","2240","112"
public class Example {
public static interface Foo<T extends Bar> {
T[] getEnumValues();
}
public static interface Bar {
}
import java.util.Arrays;
import java.util.Collection;
public class Glommer<T>
{
public static <T> Glommer<T> glommer()
{
return new Glommer<T>();
}
@dain
dain / LZFCodec
Created June 21, 2011 22:32
Hadoop CompressionCodec for com.ning.compress-lzf
import com.ning.compress.lzf.LZFInputStream;
import com.ning.compress.lzf.LZFOutputStream;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionInputStream;
import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor;
import java.io.IOException;
import java.io.InputStream;
cd src/hadoop-lzo
tar xzvf ~/Downloads/lzo-2.05.tar.gz
cd lzo-2.05
CFLAGS="-arch x86_64" ./configure --build=x86_64-darwin --enable-shared --disable-asm --prefix=$HOME/hadoop-0.20.2/lzo
make -j4
make install
cd ..
env \
JAVA_HOME=/Library/Java/Home \
C_INCLUDE_PATH=$HOME/hadoop-0.20.2/lzo/include \
@dain
dain / JsonPretty.java
Created July 11, 2012 17:59
Json pretty-print an object
import org.codehaus.jackson.map.ObjectMapper;
import java.io.IOException;
import static org.codehaus.jackson.map.SerializationConfig.Feature.INDENT_OUTPUT;
public class JsonPretty {
private static final ObjectMapper mapper = new ObjectMapper().configure(INDENT_OUTPUT, true);
public static String toPrettyJson(Object instance)
{
@dain
dain / Directions
Created August 12, 2012 00:27
Code that demonstrates problems with MLVM
Build the code with ASM 4 and Guava 12 as follows:
$ javac -cp $HOME/.m2/repository/org/ow2/asm/asm-all/4.0/asm-all-4.0.jar:$HOME/.m2/repository/com/google/guava/guava/12.0/guava-12.0.jar:. FibGeneratedAsm.java
Code can be run with:
$ ~/jdk-back/1.8.0-mlvm-2012_08_01_10_07/Contents/Home/bin/java -cp $HOME/.m2/repository/org/o/asm/asm-all/4.0/asm-all-4.0.jar:$HOME/.m2/repository/com/google/guava/guava/12.0/guava-12.0.jar:. FibGeneratedAsm
<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
</exclusions>
</dependency>
package org.weakref.algorithms.graph;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import static java.lang.String.format;
import static java.util.Arrays.asList;
@dain
dain / CallException.java
Created December 11, 2012 18:25
Java7 exception flow analysis
public class CallException
implements Callable<Boolean>
{
@Override
public Boolean call()
throws IOException
{
try {
if (Math.random() > 0) {
throw new IOException("random io failure");