Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
sfussenegger / LICENSE
Last active August 29, 2015 14:07 — forked from mrinaudo/LICENSE
The MIT License (MIT)
Copyright (c) 2014 Matteo Rinaudo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@sfussenegger
sfussenegger / indices.groovy
Last active December 23, 2015 06:09
Groovy script to copy settings and mappings from one elasticsearch cluster to another
#!/usr/bin/env groovy
import groovy.json.*
/*
* usage:
*
* cd `mktemp -d`
*
* curl -s -XGET 'http://localhost:9200/_cluster/state?pretty=true&filter_nodes=true&filter_routing_table=true&filter_blocks=true' \
@sfussenegger
sfussenegger / thread.log
Created April 23, 2013 15:29
elasticsearch thread dump while using 100% of a single core on a dual core machine
2013-04-23 13:06:41
Full thread dump OpenJDK 64-Bit Server VM (23.7-b01 mixed mode):
"Attach Listener" daemon prio=10 tid=0x00007f9f9c019000 nid=0x71a5 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"elasticsearch[Dittomaster‎][search][T#3894]" daemon prio=10 tid=0x00007f9f940b7800 nid=0x7196 waiting on condition [0x00007f9f904e4000]
@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;
@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 / 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 / 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
}
}
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 / 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>
@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;