Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
sfussenegger / import.groovy
Created November 5, 2010 09:32
skeleton script for a CSV to MySQL import
#!/usr/bin/env groovy
import groovy.grape.Grape
import groovy.sql.Sql
import com.csvreader.CsvReader
@Grab(group='net.sourceforge.javacsv', module='javacsv', version='2.0')
class Import {}
Grape.grab(
@sfussenegger
sfussenegger / pom.xml
Created November 29, 2010 09:31
Simple Maven plugin example
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-beautifyeclipse-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0</version>
@sfussenegger
sfussenegger / Test.java
Created December 1, 2010 12:42
setlist.fm client API test
package fm.setlist.client;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import fm.setlist.api.model.Setlist;
public class Test {
@sfussenegger
sfussenegger / UserAccountIdExtractor.java
Created March 24, 2011 08:29
extract accountId from User set as "user" property at session scope
package org.example;
import java.io.Serializable;
import org.springframework.social.web.connect.AccountIdExtractor;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;
// your own User class
import org.example.User;
@sfussenegger
sfussenegger / pom.xml
Created May 16, 2011 15:13
Spring configuration for spring-social with spring-security, i.e. spring-social-security
<dependencies>
<dependency>
<groupId>at.molindo.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>at.molindo.social</groupId>
<artifactId>spring-social-facebook-security</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
import java.io.IOException;
import java.io.StringReader;
import java.util.Random;
import java.util.Scanner;
public class ScannerTest {
public static void main(String[] args) throws IOException {
int chars = (37 * 1000 * 1000);
StringBuilder buf = new StringBuilder(chars);
@sfussenegger
sfussenegger / StringLiterals.java
Created June 24, 2011 13:34
Stackoverflow: Single character String
public class StringLiterals {
public static void main(String[] args) {
String s1 = "abc"; // interned by default
String s2 = new String(new char[] {'a', 'b', 'c'}); // no chance to intern here
System.out.println(s1 == s2); // false
System.out.println(s1 == s2.intern()); // true - uses interned s1
}
}
@sfussenegger
sfussenegger / gist:2651930
Created May 10, 2012 08:42
Elasticsearch object mapping creating an aggregated index with the object's name
{
"city" : {
"properties" : {
"country" : {
"properties" : {
"code" : {
"type" : "multi_field",
"path" : "just_name",
"fields" : {
"code" : {
@sfussenegger
sfussenegger / analysis.json
Created June 6, 2012 13:47
ES analysis conf
"analysis": {
"char_filter": {
"my_mapping": {
"type": "mapping",
"mappings": [ /* snip */ ]
}
},
"filter": {
"my_stop": {
"type": "stop",
@sfussenegger
sfussenegger / AsyncCacheLoader.java
Created March 21, 2013 10:32
A simple Google Guava CacheLoader implementation that submits Function execution to an ExecutorService thus making a LoadingCache asynchronous. Note that threads won't be wasted waiting (at least as long as one doesn't wait on a Future's get() method).
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import com.google.common.base.Function;
import com.google.common.cache.CacheLoader;
public class AsyncCacheLoader<K, V> extends CacheLoader<K, Future<V>> {
private final ExecutorService _executor;