Skip to content

Instantly share code, notes, and snippets.

@ouyi
ouyi / jdk_keystore.sh
Created April 11, 2018 16:20
Commands for working with Java keystore
$ sudo keytool -storepass changeit -import -file /tmp/root.crt -noprompt -alias my-trusted-ca -keystore /Library/Java//JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/security/cacerts
Password:
Certificate was added to keystore
// changeit is the Java default keystore password
$ keytool -storepass changeit -list -keystore /Library/Java//JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre/lib/security/cacerts | grep my-trusted-ca
my-trusted-ca, Apr 11, 2018, trustedCertEntry,
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.List;
public class PrintJvmOptions {
public static void main(String[] args) {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> options = runtimeMxBean.getInputArguments();
for(String o : options) {
System.out.println(o);
@ouyi
ouyi / intellij_mac_german_keyboard_shotcuts.txt
Last active March 11, 2018 15:42
Intellij MacOS German keyboard shortcuts
go to file begin/end:
fn + cmd + <-/->
file structure popup:
fn + cmd + F12
search everywhere:
shift shift
search for classes:
@ouyi
ouyi / docker_child_images.sh
Created February 15, 2018 07:33
Find docker child images
image_id="$1"
for i in $(docker images -q); do
docker history $i | grep -q "$image_id" && echo $i;
done | sort -u
@ouyi
ouyi / java_thread_dump.sh
Created January 27, 2018 08:51
Thread dump in Java
top # list processes, shift+p to sort processes by CPU usage
top -H -p <pid> # list threads, shift+p to sort threads by CPU usages
printf "%x\n" <tid> # convert tid to hexadecimal, called nid
jstack -l <pid> | grep -i <nid> -A 15 # get stack trace of the thread
@ouyi
ouyi / emr_test_apps.sh
Last active January 24, 2018 15:02
Built-in test apps on EMR 5.x
cat >> input.txt
hello
world
world
<ctrl+D>
wget https://raw.githubusercontent.com/ouyi/tez-demo/master/src/test/resources/input.txt
hadoop fs -copyFromLocal input.txt /tmp/
@ouyi
ouyi / sed_commands.sh
Last active July 22, 2018 22:05
Frequently used sed commands
# Remove trailing whitespaces using sed
sed -i 's/[ \t]*$//' input_file
# Append line after pattern matching
sed -i "/mypattern.*/a 'my new stuff'" input_file
# Print the 2nd line
sed -n '2p' input_file
# Remove the last line
@ouyi
ouyi / git_commands.sh
Last active December 27, 2017 14:12
Frequently used Git commands
# Update commit comments before the push
git commit -m "Fix an issue"
git commit -m "Fix an important issue" --amend
# Throw away all changes on local master and to have it exactly the same as origin/master:
git checkout master
git reset --hard origin/master
# Force origin/master to be the same as local master (dangerous!!!):
@ouyi
ouyi / shell_commands.sh
Last active April 28, 2019 12:40
Frequently used Linux Bash shell commands
# --- Join strings ---
function join_by { local IFS="$1"; shift; echo "$*"; }
# join_by ',' foo bar baz
# https://serverfault.com/questions/311856/portable-unix-way-to-join-strings-with-separator
echo -e "a\nb\nc" | tr '\n' ',' | sed 's/,$//g' # a,b,c
# --- Misc ---
# Retrieve the directory where the current script is in
@ouyi
ouyi / IsStringEmpty.java
Created December 17, 2017 22:50
java 8 test whether a nullable String is empty or not
// java 8 test whether a nullable String is empty or not
if (Optional.ofNullable(s).orElse("").isEmpty()) {
// s is null or empty
}