Skip to content

Instantly share code, notes, and snippets.

@reikje
reikje / AuditableInvoker.java
Created December 23, 2011 09:32
Using reference maps for caches and listeners
package javasplitter;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.TreeSet;
public class AuditableInvoker {
private final Auditable[] invokeables;
private final NavigableSet<AuditableLifecycleListener> listeners;
@reikje
reikje / ExecutionTimingAuditableLifecycleListenerGuava.java
Created December 23, 2011 09:53
Using reference maps for caches and listeners 2
package javasplitter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.concurrent.ExecutionException;
public class ExecutionTimingAuditableLifecycleListener implements AuditableLifecycleListener {
@reikje
reikje / ChangeAwareDynamicProperty.java
Created January 19, 2012 18:16
Maybe I should have used a Lock here
public class ChangeAwareDynamicProperty extends DynamicProperty {
// current value of property. May be null, if the value has never been fetched
private volatile String currentVersion;
private final ConcurrentMap<String, Long> changedVersion = new ConcurrentHashMap<String, Long>();
@Override
public String toString() {
final String version = super.toString();
@reikje
reikje / pom-external-war.xml
Created January 23, 2012 12:50
Starting the WAR Artifact of a Dependency in the maven-jetty-plugin
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<contextPath>/</contextPath>
<webApp>
@reikje
reikje / Base64EncoderTest.java
Created February 2, 2012 14:58
patterntesting
@RunWith(ParallelRunner.class)
public class Base64EncoderTest {
@reikje
reikje / Main.java
Created April 18, 2012 11:29
Mimicking a circular buffer
// create a cyclic iterator
final Iterator<Element> cycle = Iterators.cycle(elements);
while (cycle.hasNext()) {
final Element e = cycle.next();
// do stuff with e
cycle.remove();
}
@reikje
reikje / NonServletRequestCleanupAspect.java
Created April 20, 2012 13:30
Don't let these ThreadLocals escape
/**
* A aspect which has the same functionality as the ServletRequestCleanupFilter. The {@link NonServletRequestCleanupAspect}
* is useful when code is executed which is not wrapped by the servlet filter, i.e. the handling of events in the
* thread pools.
*
* @author reik, 4/19/12
*/
@Aspect
public class NonServletRequestCleanupAspect {
@reikje
reikje / amd64.sh
Created July 17, 2012 20:36
Compiling FiSH for irssi Debian 64bit
make amd64
@reikje
reikje / distribute.sh
Created August 8, 2012 06:39
Backup corporate Email when changing Jobs
pip install distribute==0.6.25
@reikje
reikje / redis.c
Created August 28, 2012 15:20
Build Redis on cygwin
#ifdef __CYGWIN__
#ifndef SA_ONSTACK
#define SA_ONSTACK 0x08000000
#endif
#endif