Skip to content

Instantly share code, notes, and snippets.

@blangel
blangel / example.kt.java
Created February 20, 2012 03:33
Running Kotlin Main
fun main(args : Array<String>) {
println("hello, from Kotlin code!")
}
@blangel
blangel / build.xml
Created February 20, 2012 03:34
Running Kotlin Main - Complete Ant Build
<project name="Kotlin" default="compile">
<property environment="env"/>
<taskdef file="${env.KOTLIN_HOME}/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/antlib.xml">
<classpath>
<fileset dir="${env.KOTLIN_HOME}/dist/kotlinc/lib" includes="*.jar"/>
</classpath>
</taskdef>
<property name="output" value="${basedir}/dist"/>
@blangel
blangel / build_run_snippet.xml
Created February 20, 2012 03:35
Running Kotlin Main - Ant Build Relevant
<path id="classpath.run">
<pathelement path="${output}/"/>
<pathelement path="${env.KOTLIN_HOME}/dist/kotlinc/lib/kotlin-runtime.jar"/>
</path>
<target name="run">
<java classname="namespace">
<sysproperty key="file.encoding" value="UTF-8"/>
<classpath refid="classpath.run"/>
</java>
public class DepX {
// stuff which depends upon Lib-version-1.x
}
public class DepY {
// stuff which depends upon Lib-version-1.y
}
public class UseBothDepXAndDepY {
DepX depX = ClApi.get(DepX.class);
import static net.ocheyedan.clapi.ClApi;
// class structure removed for brevity
void usageExample {
using(ThriftVersion.2);
callCodeDependingUponThriftVersion2();
using(ThriftVersion.3);
@blangel
blangel / javaclassmateusage.java
Created April 9, 2012 15:13
java class-mate usage?
TypeResolver typeResolver = new TypeResolver();
ResolvedType resolvedType = typeResolver.resolve(getClass());
MemberResolver memberResolver = new MemberResolver(typeResolver);
memberResolver.setFieldFilter(new Filter<RawField>() {
@Override public boolean include(RawField element) {
return "name".equals(element.getName());
}
});
ResolvedField[] resolvedFields = memberResolver.resolve(resolvedType, null, null).getMemberFields();
if (resolvedFields.length < 1) {
@blangel
blangel / fieldreflection.java
Created April 9, 2012 15:25
native java reflection field setting
Field nameField;
try {
nameField = getClass().getDeclaredField("name");
} catch (NoSuchFieldException nsfe) {
throw new AssertionError("No field named 'name'");
}
nameField.setAccessible(true);
try {
nameField.set(this, getClass().getName());
} catch (IllegalAccessException iae) {
@blangel
blangel / LoadingMemcache.java
Created October 17, 2013 18:47
LoadingCache impl for memcache
package com.dashlabs.dash.cache;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.CacheStats;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
@blangel
blangel / gist:7530830
Created November 18, 2013 16:30
Setup LocationClient
private static final long UPDATE_INTERVAL_MS = 8000L;
private static final long FASTEST_UPDATE_INTERVAL_MS = 4000L;
...
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(UPDATE_INTERVAL_MS);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_MS);
locationClient.requestLocationUpdates(locationRequest, listener, locationService.getLocationLooper());
@blangel
blangel / gist:7530845
Created November 18, 2013 16:31
Remove updates from LocationClient
locationClient.removeLocationUpdates(listener);