Skip to content

Instantly share code, notes, and snippets.

View hanbei's full-sized avatar

Florian Schulz hanbei

View GitHub Profile
@hanbei
hanbei / create gradle source folders
Created April 5, 2013 21:50
A gradle task to create the initial project structure
apply plugin: 'java'
task initProject () << {
if (hasProperty(initPlugins)) {
initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } }
}
project.sourceSets*.allSource.srcDirTrees.flatten().dir.each { dir ->
dir.mkdirs()
}
@hanbei
hanbei / bash_rc
Last active January 10, 2018 12:57
my bashrc settings
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1)\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi
unset color_prompt force_color_prompt
# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
@hanbei
hanbei / git_config
Last active September 22, 2020 07:08
Git Config
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
whitespace = red reverse
meta = yellow bold
frag = magenta bold
@hanbei
hanbei / KnnSimple
Created August 27, 2013 18:46
Simplest Knn implementation in Scala
class KnnSimple {
var trainData: List[Array[Double]] = null
def train(trainData: List[Array[Double]]) {
this.trainData = trainData
}
def nearestNeighbour(k: Int, point: Array[Double]) : List[Array[Double]] = {
nearestNeighbour(k, point, (x, y) => Math.sqrt(x.zip(y).map(pair => (pair._1 - pair._2) * (pair._1 - pair._2)).sum))
# How to perform a release with git & maven following the git flow conventions
# ----------------------------------------------------------------------------
# Finding the next version: you can see the next version by looking at the
# version element in "pom.xml" and lopping off "-SNAPSHOT". To illustrate,
# if the pom's version read "0.0.2-SNAPSHOT", the following instructions would
# perform the release for version "0.0.2" and increment the development version
# of each project to "0.0.3-SNAPSHOT".
# branch from develop to a new release branch
git checkout develop
@hanbei
hanbei / concurrent_hashmap_idioms
Last active August 29, 2015 13:59
ConcurrentHashMap idioms
X x = map.get(key);
if (set == null) {
final X value = new X();
x = map.putIfAbsent(key, value);
if (x == null) {
x = value;
}
}
@hanbei
hanbei / HeapDumper
Last active August 29, 2015 14:01
HeapDumper
import com.sun.management.HotSpotDiagnosticMXBean;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
public class HeapDumper {
// This is the name of the HotSpot Diagnostic MBean
private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";
// field to store the hotspot diagnostic MBean
@hanbei
hanbei / MemoryAnalyzer
Created May 16, 2014 11:55
Memory Analyzer
import java.io.PrintWriter;
public class MemoryStatistics {
private static final int MB = 1024 * 1024;
private static Runtime runtime = Runtime.getRuntime();
public static long getUsedMemory() {
return (runtime.totalMemory() - runtime.freeMemory()) / MB;
@hanbei
hanbei / delete_docker_images
Created August 5, 2014 14:29
Delete all docker images that are not tagged
for i in `sudo docker images|grep \<none\>|awk '{print $3}'`;do sudo docker rmi $i;done
@hanbei
hanbei / useful git commands
Last active January 4, 2017 13:02
Prune local branches
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
# fetch all repos
find . -maxdepth 1 -type d -exec echo {} \; -exec git --git-dir={}/.git --work-tree=$PWD/{} fetch \;
# prune all repos
find . -maxdepth 1 -type d -exec echo {} \; -exec git --git-dir={}/.git --work-tree=$PWD/{} remote prune origin \;