Skip to content

Instantly share code, notes, and snippets.

@ouyi
ouyi / copy_reinvented.sh
Last active November 29, 2018 22:10
Bash boilerplate code for parsing command-line args
#/usr/bin/env bash
#set -euo pipefail
EXIT_SUCCESS=0
EXIT_FAILURE=1
IFS='' read -r -d '' USAGE <<HEREDOC
Copy-reinvented to showcase Bash heredoc usage and command-line arguments handling.
@ouyi
ouyi / minikube-sierra.md
Created December 4, 2018 21:41 — forked from inadarei/minikube-sierra.md
Minikube Setup: Docker for Mac / Sierra

Prerequisite: latest Docker for Mac on MacOS Sierra

$ brew update
$ brew install --HEAD xhyve
$ brew install docker-machine-driver-xhyve
$ sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
$ sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.18.0/minikube-darwin-amd64 &amp;&amp; chmod +x minikube &amp;&amp; sudo mv minikube /usr/local/bin/
@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 / 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 / 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 / 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