Skip to content

Instantly share code, notes, and snippets.

View zdk's full-sized avatar
:octocat:

Di Warachet S. zdk

:octocat:
  • Thailand
  • 09:40 (UTC +07:00)
View GitHub Profile
@zdk
zdk / haproxy.md
Created January 11, 2024 13:16 — forked from guycalledseven/haproxy.md
haproxy conditions

Haproxy conditions

Since I keep forgetting them I've put them here.

To form a condition, you can use the following syntax after the rule that it applies to:

<HAProxy action statement> if|unless [!]acl1 <AND|OR|or|'||'> [!]acl2 ...

  • if - the condition is TRUE if the result of the ACLs is TRUE.
#!/bin/bash
openssl req -nodes -x509 -newkey rsa:2048 -keyout /etc/ssl/private/test.key -out /etc/ssl/private/test.crt -days 30
cat /etc/ssl/private/test.key /etc/ssl/private/test.crt > /etc/ssl/private/test.pem
cat <<EOL >> /etc/haproxy/haproxy.cfg
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
#!/bin/bash
# update, add docker gpg key, and docker apt repo
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
apt-cache policy docker-ce
if [[ $(grep -i microsoft /proc/version) ]]; then
@zdk
zdk / th-address.json
Created November 20, 2023 10:50 — forked from mennwebs/th-address.json
Thai Address from Postal Code - JSON
This file has been truncated, but you can view the full file.
[
{
"zipCode": "10100",
"subDistrictList": [
{
"subDistrictId": "100801",
"districtId": "1008",
"provinceId": "10",
"subDistrictName": "ป้อมปราบ"
},
@zdk
zdk / .zshrc
Last active November 20, 2023 02:11
Kill multi ports
killport() {
while test $# -gt 0
do
port_number=$1
pid=$(lsof -P | grep ':'$port_number'[[:space:]](LISTEN)' | awk '{print $2}')
if ! kill -QUIT $pid > /dev/null 2>&1; then
echo -e "\e[0;31mNo process running on \e[0m $port_number port" >&2
else
echo -e "Kill $port_number \e[0;32msuccessfully\e[0m"
fi
CONFIGURE_ARGS="with-libvirt-include=/usr/include/libvirt with-libvirt-lib=/usr/lib64" vagrant plugin install vagrant-libvirt
@zdk
zdk / haproxy.cfg
Created April 27, 2020 14:59
Super bare minimum HAProxy config
listen http-in
mode http
bind *:80
server web1 172.22.20.21:8080 check
server web2 172.22.20.22:8080 check
server web3 172.22.20.23:8080 check
stats enable
stats refresh 3s
stats show-node
stats uri /haproxy?stats
@zdk
zdk / ssh
Created March 25, 2019 05:07
My stupid SSH script. But it's smart enough to be useful in my daily work.
#!/bin/bash
SSH="/usr/local/bin/ssh"
case "$*" in
*'@'*) $SSH $* ;;
*' -l'*) $SSH $* ;;
*192\.168*) $SSH -l zdk $*;;
*) $SSH -l ec2-user $* ;;
esac
#!/bin/bash
 set -e
 SECRETS_MANAGER="aws secretsmanager"
 REGION="ap-southeast-1"
 
 function get_secret {
$($SECRETS_MANAGER get-secret-value --secret-id $secret --query SecretString --output text --region $REGION)
 }
 
 function parse_secret {
┌───────────────────────────────┐
│ │
│ │
│ ┌────────────────────┐ │ ┌───────────────────┐
│ │ │ │ │ │
│ │ ┌──────────┐ │ ┌──┼─────│AWS Secrets Manager│
│ │ │ APP │ │ │ │ │ │
│ │ ├──────────┤ │ │ │ └───────────────────┘
│ │ ┌─▶│ ENV │ │ │ │