Skip to content

Instantly share code, notes, and snippets.

@ouyi
ouyi / ansible-list-hosts.sh
Created January 26, 2019 16:51
Ansible list hosts from a host group
#!/usr/bin/env bash
if (( $# < 2 )); then
echo "Usage: $0 inventory host_group [other ansible options]"
exit 1
fi
inventory="$1"
host_group="$2"
@ouyi
ouyi / docker_run_gui.sh
Created January 26, 2019 16:58
Run a Docker container with GUI support
#!/usr/bin/env bash
USAGE="$0 args"
if (( $# == 0 )); then
echo "$USAGE"
exit 1
fi
function get_ip() {
@ouyi
ouyi / ansible-decrypt-vaulted-string.sh
Created January 30, 2019 12:56
Ansible decrypt vaulted strings
ansible --vault-password-file my-vault-password.txt -m debug -a 'var=my_secret_password' \
-i my_inventory my_host.mydomain.com
@ouyi
ouyi / remmina_post_install.sh
Created February 9, 2019 18:16
Commands after installing remmina
sudo snap connect remmina:avahi-observe :avahi-observe
sudo snap connect remmina:cups-control :cups-control
sudo snap connect remmina:mount-observe :mount-observe
sudo snap connect remmina:password-manager-service :password-manager-service
@ouyi
ouyi / pkg_mgmt_cmds.sh
Last active February 15, 2019 18:45
Frequently used package management commands on popular Linux systems
# Find the owning package of a file / which package installed this file
rpm -qf my_file_or_dir
dpkg -S filename_search_pattern
# List all files of a package
rpm -ql package_name
dpkg -L package_name
pip show -f package_name
@ouyi
ouyi / mvn_commands.sh
Last active February 25, 2019 13:10
Frequently used Maven commands
# --- Maven ---
# Skip test execution
mvn package -DskipTests
# Skip test compilation
mvn package -Dmaven.test.skip=true
# Retrieve the project version
@ouyi
ouyi / kafka_python_client.py
Created March 16, 2019 16:06
Kafka Python client code
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['localhost:19092'])
data = bytes('hello', encoding='utf-8')
producer.send('test', value=data)
from kafka import KafkaConsumer
consumer = KafkaConsumer('test', bootstrap_servers=['localhost:19092'], consumer_timeout_ms=2000, auto_offset_reset='earliest')
event = next(consumer)
@ouyi
ouyi / lessons-learned.txt
Created April 18, 2019 12:47
Lessons learned from the recent years
Lessons learned
I. Software engineering
1. Automate everything, have CI/CD and test automation from the beginning
2. Security shall not be an afterthought (have TLS and avoid plain text passwords from the start)
3. Component shall be stateless, state shall be extracted and kept in a external store (key-value store or databases)
4. Favor open source and off-the-shelf solutions instead of building proprietary solutions
5. Avoid hard-coding dependencies, try to inject them via command line parameters, configuration files, env variables, etc
@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 / german_umlaut_unicode.txt
Created May 30, 2019 19:47
German umlaut unicode
Char Unicode
---------------
Ä \u00c4
ä \u00e4
Ö \u00d6
ö \u00f6
Ü \u00dc
ü \u00fc
ß \u00df