Skip to content

Instantly share code, notes, and snippets.

@superbob
superbob / FilterInhibitor.java
Created February 21, 2013 15:06
Servlet filter inhibitor, usefull when you want to bypass an undesired filter sometimes.
/*
*/
package com.github.superbob.demo.servlets.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@superbob
superbob / SpyInstanciations.java
Created June 17, 2013 08:08
Simple but powerfull Java TimeSpy. It wraps up a java method call in a spy class (method proxy) and records total elapsed time in successive calls. 1) [SpyInstanciations.java] Create an anonymous class extending TimeSpy which defines the run() method and returns something. 2) [SpyRuns.java] Run run(), instead of "your" method 3) [SpyResult.java]…
TimeSpy<Boolean> rsSpy = new TimeSpy<Boolean>() {
protected Boolean run() throws Exception {
return resultSet.next();
}
};
TimeSpy<Boolean> statementSpy = new TimeSpy<Boolean>() {
protected Boolean run() throws Exception {
return statement.execute();
}
@superbob
superbob / ByteUtil.java
Last active June 24, 2018 14:33
byte array initialization from a int/long/short literal => byte[] array = toBytes(0x01020304);
package com.example.util;
import java.nio.ByteBuffer;
public final class ByteUtil {
private ByteUtil() {
}
/**
@superbob
superbob / powerline.zsh-theme
Created March 17, 2016 15:55
My own zsh theme, inspired by agnoster (https://gist.github.com/3712874)
# vim:ft=zsh ts=2 sw=2 sts=2
#
# A Powerline-inspired theme for ZSH
# Mainly base on agnoster's Theme - https://gist.github.com/3712874
# with some slight additions: RPROMPT, segment colored status
# to make it look even more like powerline !
#
# # README
#
# In order for this theme to render correctly, you will need a
@superbob
superbob / BookShop.scala
Last active May 25, 2016 07:01
Up-to-date GameOfThrones Kata solution (see https://github.com/ludopradel/DojoGOT). The last test was fixed expect 51,20€ instead of 51,60€
object BookShop {
case class Book(id: Int)
val ONE_BOOK_PRICE = 8
val TWO_DISTINCT_BOOKS_WITH_PROMO_PRICE = 15.2
val THREE_DISTINCT_BOOKS_WITH_PROMO_PRICE = 21.6
val FOUR_DISTINCT_BOOKS_WITH_PROMO_PRICE = 25.6
val FIVE_DISTINCT_BOOKS_WITH_PROMO_PRICE = 30
type Basket[T] = List[List[T]]
@superbob
superbob / .zshrc
Created October 28, 2017 12:33
A .zshrc for use with oh-my-zsh on MacOS, fixes COLOR issues (ls colors, tab completion colors) and more.
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="powerlevel9k/powerlevel9k"
DEFAULT_USER="..."
export LS_COLORS="di=34;40:ln=36;40:so=35;40:pi=33;40:ex=32;40:bd=1;33;40:cd=1;33;40:su=0;41:sg=0;43:tw=0;42:ow=34;40:"
@superbob
superbob / powerlevel9k-nano-git.zsh-theme
Created April 19, 2018 13:29
A lighter and faster powerlevel9k git vcs segment (for windows)
prompt_nano_git() {
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ $CURRENT_BRANCH == "HEAD" ]]; then
COMMIT_ID=$(git rev-parse --short HEAD 2>/dev/null)
if [[ -n $COMMIT_ID ]]; then
CURRENT_BRANCH="$(git rev-parse --short HEAD 2>/dev/null) (detached)"
else
CURRENT_BRANCH="master (empty)"
fi
fi
@superbob
superbob / AssertJMatcher.java
Last active November 13, 2024 21:47
Use AssertJ assertions in Mockito verify argument matchers
import java.util.function.Consumer;
import org.assertj.core.matcher.AssertionMatcher;
import org.hamcrest.Matcher;
import org.mockito.hamcrest.MockitoHamcrest;
/**
* Allow using AssertJ assertions for mockito matchers.
* @see MockitoHamcrest#argThat(Matcher)
* @see AssertionMatcher
@superbob
superbob / ddns_provider.conf
Last active January 27, 2024 00:57
Namecheap Synology DSM DDNS provider
#Insert this at the end of /etc.defaults/ddns_provider.conf
[Namecheap]
modulepath=/usr/syno/bin/ddns/namecheap.php
queryurl=https://dynamicdns.park-your-domain.com/update