Skip to content

Instantly share code, notes, and snippets.

@bcalmac
bcalmac / CaseInsensitiveSetMultimap.java
Created March 10, 2015 18:34
Case insensitive SetMultimap using Guava
import com.google.common.collect.ForwardingSetMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/** SetMultimap decorator that coverts keys to lower case before delegation */
public class CaseInsensitiveSetMultimap<V> extends ForwardingSetMultimap<String, V> {
@bcalmac
bcalmac / junit-live-templates.txt
Last active August 29, 2015 14:16
IntelliJ live templates for JUnit
# Applicable in : Java statement
# Reformat according to style : true
# Use static import if possible: true
# Shorten FQ names : true
#
# Do nothing about "Edit variables". I wasn't able to define defaults like "expected" and "actual".
org.junit.Assert.assertEquals($EXPECTED$, $ACTUAL$);
$END$
@bcalmac
bcalmac / java-7.reg
Created March 11, 2015 23:06
Java registry entry for AdvancedInstaller
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.7]
"JavaHome"="C:\\tools\\java-7"
"MicroVersion"="0"
@bcalmac
bcalmac / FileTest.java
Created March 15, 2015 16:42
Asserting file content with AssertJ
import java.io.File;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
public class FileTest {
@Test
public void file() {
File actualFile = new File("actual.txt");
@bcalmac
bcalmac / windows-services-util.sh
Created March 17, 2015 18:18
Bash functions to start/stop/restart multiple services on Windows
# start the services passed as arguments
function nst { for s in "$@"; do net start $s; done }
# stop the services passed as arguments
function nsp { for s in "$@"; do net stop $s; done }
# restart the services passed as arguments
function nrs {
# Stop in reverse order
for ((i=$#; i>0; i--)); do net stop ${!i}; done
@bcalmac
bcalmac / JavaStringSplittingQuirks.groovy
Created March 19, 2015 23:38
Java string splitting quirks
// Splitting an empty string returns an array with an empty string
assert "".split(";") == [""]
// Splitting a string consisting of just the delimiter returns an empty array
assert ";".split(";") == []
// Trailing delimiters are ignored
assert "1;;2;;".split(";") == ["1", "", "2"]
// ... but the behavior becomes consistent with a -1 extra argument
assert ";".split(";", -1) == ["", ""]
assert "1;;2;;".split(";", -1) == ["1", "", "2", "", ""]
@bcalmac
bcalmac / .ideavimrc
Created April 7, 2015 17:51
Minimal .vimrc for IDEA Vim
set incsearch
set hlsearch
set ignorecase
set smartcase
set tabstop=4 shiftwidth=4 expandtab
set clipboard=unnamed
@bcalmac
bcalmac / TagFilteredByNestedAttribute.xml
Created April 13, 2015 18:36
IntelliJ structural search for XML tag based on nested attributes
<object type="$obj_type$">
<$tag$/>
<property>
<$tag2$/>
<customtag name="poll"/>
<$tag3$/>
</property>
<$tag4$/>
</object>
@bcalmac
bcalmac / runin.sh
Last active August 29, 2015 14:19
Bash utility function to run a command in a given directory
#!/usr/bin/env bash
# Runs a command in a given directory and preserves the $? of the command
# Example: "runin /src/project mvn install"
function runin {
pushd $1
shift
"$@"
local STATUS=$?
popd
@bcalmac
bcalmac / InfiniteLoop.java
Created June 3, 2015 16:04
Infinite loop in JBoss 7.1.1 on Java 8
package org.jboss.as.server;
import java.util.concurrent.ConcurrentSkipListSet;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.SubDeploymentProcessor;
import org.jboss.as.server.deployment.annotation.AnnotationIndexProcessor;