Skip to content

Instantly share code, notes, and snippets.

@larshaendler
larshaendler / decompile_java.md
Created March 27, 2019 07:32
Decompile Java class or Jar container under Linux Mint / Ubuntu
View decompile_java.md

Lee Benfield's Java decompiler CFR is straight forward and can even batch decompile jar container. 

  1. Download the most recent version of CFR (crf 0.1.15 at the time of writing)
wget http://www.benf.org/other/cfr/cfr_0_115.jar
  1. Run decompile with output into terminal
java -jar cfr_0_115.jar javaclasstodecompiles.class
@larshaendler
larshaendler / install_avconv_ubuntu.md
Created March 27, 2019 07:26
Install avconv on Linux Mint or Ubuntu
View install_avconv_ubuntu.md

avconv is part of the libav tools. Just install those:

sudo apt install libav-tools
@larshaendler
larshaendler / advanced_sort_options.md
Created March 27, 2019 07:08
Use sort -k option / flag for advanced linux command line sorting
View advanced_sort_options.md

Sometimes you have a data file that needs sorting not just from left to right but by multiple values in the middle of each line. That is when you make use of the -k option / flag. 

Let's look at the following data file; let's call it test.txt. It starts with a timestamp in the German date format; meaning dd.mm.yyyy.

19.09.1942 12:34              Nekros
05.03.1945 20:15              Inaros
01.01.1969 23:55              Banshee
02.01.1969 20:15              Mesa
03.01.1969 12:00              Nezha
19.02.1969 17:38 Nova
@larshaendler
larshaendler / find_and_delete_console.md
Created March 27, 2019 07:04
Find & delelte all files older than 30 days recursively on Linux console
View find_and_delete_console.md

find all files older than 30 days recursively in current directory

find ./ -type f -mtime +30

Variation 1 - find all files older than 30 days that end with .log

find ./ -name "*.log" -type f -mtime +30

Variation 2 - delete all files older than 30 days that end with .log

@larshaendler
larshaendler / sprintf_for_java.md
Created March 20, 2019 11:16
sprintf for Java is callled String.format, a better string replace
View sprintf_for_java.md

PHP example:

$location = 'tree';
$format = 'There are 5 monkeys in the %s';
echo sprintf($format, $location);
#output: There are 5 monkeys in the tree

Java String.format

@larshaendler
larshaendler / parent_directory.java
Created February 19, 2019 16:51
Get parent directory path in Java
View parent_directory.java
//inputPath format "/usr/bin/java/"
public static String getParentDirectoryPath(String inputPath)
{
String resultString = "";
String regEx = "(.*\\/)\\S+\\/$";
Pattern regexPattern = Pattern.compile(regEx);
Matcher match = regexPattern.matcher(inputPath);
if(match.find()) {
resultString = match.group(1);
@larshaendler
larshaendler / iconv_usage.md
Created February 18, 2019 15:55
Convert file from ISO to UTF-8 in Linux console
View iconv_usage.md
iconv -f ISO-8859-1 -t UTF-8 in.txt > out.txt

-f ENCODING the encoding of the input -t ENCODING the encoding of the output

@larshaendler
larshaendler / create_import_mysql_dump.md
Created January 31, 2019 14:10
Create and import MySQL / MariaDB dump
View create_import_mysql_dump.md

Create a MySQL / MariaDB dump on command line

mysqldump -u [uname] -p db_name > db_backup.sql

Import a dump into MySQL / MariaDB

mysql -u username -p db_name < db_backup.sql

Additional info

@larshaendler
larshaendler / regex_group_java.md
Created January 31, 2019 14:05
Extract String pattern with regex group in Java
View regex_group_java.md

Extracting a certain pattern (e.g. date) with regex grouping from a string (e.g. file name).

String resultString = "";
String fileName = "012345467_20120502T230108_file-name.zip";
String regex = "_(\\d{8})T.*?"; //regex for date

Pattern regexPattern = Pattern.compile(regex);
Matcher match = regexPattern.matcher(fileName);

if(match.find())
@larshaendler
larshaendler / atom_linux_mint.md
Created January 30, 2019 14:46
Installing Atom editor on Linux Mint & Ubuntu
View atom_linux_mint.md

There are two ways to install Atom using a repository. The first is by added the repo to apt and the second is just using snap for installation.

Install Atom using apt

sudo add-apt-repository ppa:webupd8team/atom
sudo apt update
sudo apt install atom

Install Atom using snap If you have not installed snap yet: