Skip to content

Instantly share code, notes, and snippets.

@sasuw
sasuw / .gitignore
Last active October 28, 2021 11:26
Wildfly root directory .gitignore
*
!domain
!domain/configuration
!domain/configuration/*
!standalone
!standalone/configuration
!standalone/configuration/*
!bin
!bin/*
@sasuw
sasuw / remove-java-comments.sh
Last active August 22, 2019 09:27
Remove java comments in-file
#one file
perl -i -0pe 's|//.*?\n|\n|g; s#/\*(.|\n)*?\*/##g;' file.java
#multiple files
find . -name "*.java" -type f | while read fname; do perl -i -0pe 's|//.*?\n|\n|g; s#/\*(.|\n)*?\*/##g;' "$fname"; done
@sasuw
sasuw / hibernate-java-add-repository-tag-to-Dao-class-without-it.sh
Created August 29, 2018 09:24
Adds @repository annotation and import to all java files ending with DAOImpl not containing the annotation
#tested on OS X
grep -Lir --include \*DAOImpl.java '@Repository' . | xargs sed -i '' -e "s/public class/import org.springframework.stereotype.Repository;\\`echo -e '\r'`@Repository\\`echo -e '\r'` public class/"
@sasuw
sasuw / add-serialVersionUID-to-Java-files.sh
Created May 23, 2018 12:54
Automatically modify Java files adding serialVersionUID for all classes implementing Serializable, if they do not already contain serialVersionUID
!#!/bin/bash
grep -lir --include \*.java -e 'implements java.io.Serializable' -e 'implements Serializable' . | xargs grep -Lir -e 'serialVersionUID' | while read -r line ; do awk '/implements (java.io.)?Serializable/{print;print "\n\t\nprivate static final long serialVersionUID = 1L;";next}1' $line > temp.java && mv temp.java $line ; done
@sasuw
sasuw / find-invalid-jars-in-maven-repo.sh
Created May 17, 2018 12:53
Find invalid jar files in maven repository
#!/bin/bash
find ~/.m2/repository/ -name "*jar" | xargs -L 1 zip -T | grep error | grep invalid
@sasuw
sasuw / gist:ffda2e3ccf8db1592e956772c21fca5d
Created May 7, 2018 11:46
Replace tag content with sed (works with GNU and non-GNU sed)
sed -e '/<version>.*<\/version>/{s//<version>new<\/version>/;:a' -e '$!N;$!ba' -e '}'
@sasuw
sasuw / list-git-changed-files.sh
Created November 30, 2017 13:59
Chronological list of files which have been changed in GIT
find git-dir/ -type f \( -name "*.sql" \) -exec sh -c 'git log --name-only -1 --date=format:'\''%Y-%m-%d %H:%M:%S'\'' '\''{}'\'' | sed -n '\''3p;7p'\'' | awk '\''{key=$0; getline; print key ", file " $0;}'\''' -- {} \; | sort
@sasuw
sasuw / curl-output-only-http-code
Created January 16, 2017 10:21
Get only HTTP code from Curl
curl -s -I http://127.0.0.1:8080/ | grep HTTP/1.1 | awk {'print $2'}
When Maven outputs errors like
error: unmappable character for encoding UTF8
you can remove the illegal characters in Mac OS bash with this
for f in $(find /private/tmp -name '*.java' 2>/dev/null); do iconv -f utf-8 -t utf-8 -c "$f" > "$f.new" ; mv -f "$f.new" "$f"; done
N.B. iconv has to be installed first, e.g. using homebrew (brew install iconv)
@sasuw
sasuw / apache_commons_conf_load_ext_file.java
Created May 11, 2016 09:23
Apache Commons Configuration: load external file
private static void loadConfiguration(String argConfigurationName, String argFilename) {
PropertiesConfiguration config = new PropertiesConfiguration();
config.setBasePath("file:/initech/Temp/scraper-ext-conf/");
config.setFileName(argFilename);
try {
//when setting the file name explicitly, the load method has to be called manually
config.load();
} catch (ConfigurationException e) {
e.printStackTrace();
}