Skip to content

Instantly share code, notes, and snippets.

@ouyi
ouyi / auto_scroll.js
Created November 23, 2020 20:41
Automatically scroll page up and down in JavaScript
setInterval(() => { window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, 0); }, 60000)
@ouyi
ouyi / setup_openvpn.sh
Last active October 16, 2021 15:28
Setting up OpenVPN with Docker in a public cloud
# Install docker
yum check-update
curl -fsSL https://get.docker.com/ | sh
systemctl start docker
systemctl status docker
systemctl enable docker
systemctl status docker
# Set up the server-side of things
@ouyi
ouyi / raspberrypi_install_syncthing.sh
Created May 24, 2020 14:23
raspberrypi_install_syncthing.sh
# https://apt.syncthing.net/
# Add the release PGP keys:
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
# Add the "stable" channel to your APT sources:
echo "deb https://apt.syncthing.net/ syncthing stable" | sudo tee /etc/apt/sources.list.d/syncthing.list
# Update and install syncthing:
sudo apt-get update
@ouyi
ouyi / pi_temperatures.sh
Created June 16, 2020 20:28
Bash script for displaying the CPU and GPU temperatures of Raspberry Pi 3B+
#!/usr/bin/env bash
# Display the CPU and GPU temperatures of Raspberry Pi 3B+
set -e
cpu_temp=$(</sys/class/thermal/thermal_zone0/temp)
cpu_temp=$(printf %.1f $((10 * cpu_temp/1000))e-1)
gpu_temp=$(vcgencmd measure_temp)
@ouyi
ouyi / raspberrypi_install_AdGuardHome.sh
Created May 24, 2020 14:26
raspberrypi_install_AdGuardHome.sh
# https://github.com/AdguardTeam/AdGuardHome/wiki/Raspberry-Pi
cd $HOME
wget https://static.adguard.com/adguardhome/release/AdGuardHome_linux_arm.tar.gz
tar xvf AdGuardHome_linux_arm.tar.gz
cd AdGuardHome
sudo ./AdGuardHome -s install
@ouyi
ouyi / german_umlaut_unicode.txt
Created May 30, 2019 19:47
German umlaut unicode
Char Unicode
---------------
Ä \u00c4
ä \u00e4
Ö \u00d6
ö \u00f6
Ü \u00dc
ü \u00fc
ß \u00df
@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 / 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 / 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 / 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