Skip to content

Instantly share code, notes, and snippets.

View kkarad's full-sized avatar

Konstantinos Karadamoglou kkarad

View GitHub Profile
# for every directory run multiple commands
find . -maxdepth 1 -type d -exec sh -c "cd {} && mvn clean && cd -" \;
#when disk is out of space identify directory which occupies most space
df -h
du -s * | sort -r -n | head -n 10
package org.kkarad.metrics;
import org.HdrHistogram.Histogram;
import gnu.trove.map.hash.TObjectLongHashMap;
public class Metrics {
private static final Histogram histogram = new Histogram(3600000000000L, 3);
private static TObjectLongHashMap<String> map = new TObjectLongHashMap<String>(1000, 0.5f, -1);
#Taken from: http://www.binarytides.com/linux-commands-hardware-info/
#kernel and distro
cat /etc/*release
cat /proc/version
#cpu
cat /proc/cpuinfo
#memory
#!/bin/bash
#set -x
# Prints the date difference of "start" and "end" date in milliseconds
function datediff {
startsec=$(date -d "$1" +%s)
while [[ $startsec = 0* ]]; do startsec=${startsec#0}; done
endsec=$(date -d "$2" +%s)
while [[ $endsec = 0* ]]; do endsec=${endsec#0}; done
@kkarad
kkarad / merge-2-lines.sh
Created March 20, 2014 23:27
awk merge two clusteredlines
kostas@localhost ~$ cat fix.log
2014-03-20 10:30:20,123 123456.123456789 MassQuote
2014-03-20 10:30:20,133 123456.123456789 MassQuoteAcknowledgement
2014-03-20 10:31:20,234 123456.123456789 MassQuote
2014-03-20 10:31:20,240 123456.123456789 MassQuoteAcknowledgement
kostas@localhost ~$ cat fix.log | awk '!(NR%2){printf("%s %s %s %s\n",p,$1,$2,$3)}{p=$1" "$2}'
2014-03-20 10:30:20,123 2014-03-20 10:30:20,133 123456.123456789
2014-03-20 10:31:20,234 2014-03-20 10:31:20,240 123456.123456789
@kkarad
kkarad / fixtail.sh
Last active December 18, 2015 11:09
tail -f fix.log | tr '\1' '|' | grep "whatever"
@kkarad
kkarad / Identifiable.java
Last active December 10, 2015 23:38
Implementation of the ReversedEnumMap as described at: http://www.javaspecialists.co.za/archive/Issue113.html. The implementation uses google-guava as a dependency but it can be easily removed.
public interface Identifiable<T> {
T getId();
}
@kkarad
kkarad / BaseSpringTest.java
Last active March 6, 2019 07:41
SpringTest setup example with mock properties loaded during context initialization
package ork.kkarad.examples;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.mock.env.MockPropertySource;
@kkarad
kkarad / PrintDnsCacheExpiryTime.java
Last active September 26, 2015 05:47
Find jvm's default dns cache expiry time
public class Foo {
public static void main(String[] args) {
System.out.println(sun.net.InetAddressCachePolicy.get());
}
}
public class PanelViewer {
public static void main(String[] args) {
JFrame frame = new JFrame("Gui Test");
frame.getContentPane().setLayout(new FlowLayout());
//frame.add(new PerspectivePanel());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();