Skip to content

Instantly share code, notes, and snippets.

View Himura2la's full-sized avatar
💭
Nya?

Himura Kazuto Himura2la

💭
Nya?
View GitHub Profile
@Himura2la
Himura2la / csv_sup.py
Last active July 4, 2023 11:38
CSV Supplementer
import json
import os
import csv
from urllib.request import urlopen, Request, HTTPError
csv_path = os.path.expanduser(r"~\Desktop\data.csv")
additional_cols = []
def fetch_additional_data(row):
# TODO
@Himura2la
Himura2la / add-user.sh
Last active June 29, 2023 14:46
Create a linux user for another person
new_user=''
user_public_key=''
sudo useradd -mG sudo -s /bin/bash $new_user
sudo passwd --delete $new_user
sudo mkdir /home/$new_user/.ssh
echo "$user_public_key" | sudo tee /home/$new_user/.ssh/authorized_keys
sudo chmod -v 700 /home/$new_user/.ssh
sudo chmod -v 600 /home/$new_user/.ssh/authorized_keys
sudo chown -vR $new_user:$new_user /home/$new_user/.ssh

"([^"]+)"$ ➡️ $1

This regex is used for the following CSV transformation:

... requests
... SY 167,DSW 167
... DSJ 119
... KA 330,INS 251,K 153
@Himura2la
Himura2la / certbot-wildcard.sh
Last active June 6, 2023 10:24
Renew a wildcard certificate using certbot
#!/bin/bash
set -xe
export domain='change.me'
certbot --config ./cli-certbot.ini certonly -d "*.$domain"
# Follow the instructions.
ansible-vault encrypt "./tmp/config/live/$domain/privkey.pem" --output "./${domain}_privkey.pem.vault"
cat "./tmp/config/live/$domain/fullchain.pem" > "./${domain}_fullchain.pem"
@Himura2la
Himura2la / hashicorp-cluster-discover.sh
Last active February 23, 2023 06:54
Discover HA cluster of HashiCorp tools (Consul, Nomad, and Vault)
#!/bin/bash
hash curl || exit 1
hash jq || exit 2
usage_msg="
Usage:
$0 <leader|followers> <consul|nomad|vault> <host_address> [<query_string>]
Examples:
$0 leader vault my-vault.example.com
@Himura2la
Himura2la / install_azure_addswap.sh
Created September 20, 2022 12:03
Use Azure temporary disk for swap without waagent (on Debian)
cat <<'EOF' | sudo tee /usr/local/sbin/addswap.sh
#!/bin/sh
if [ ! -f /mnt/swapfile ]
then
/usr/bin/fallocate -l 30G /mnt/swapfile
/usr/bin/chmod 600 /mnt/swapfile
/usr/sbin/mkswap /mnt/swapfile
/usr/sbin/swapon /mnt/swapfile
fi
@Himura2la
Himura2la / url-converter.html
Last active May 20, 2022 14:23
awfice-style URL encoder/decoder
<body><style>textarea{width:99%;height:49%;}body{margin:0;}textarea{width:99%;font-size:18px;padding:0.5em}</style><textarea placeholder="Decoded" id="d"></textarea><textarea placeholder="Encoded" id="e"></textarea><script>document.querySelectorAll("textarea").forEach(t=>t.addEventListener("keyup",function(e){switch(e.target.id){case"d":document.getElementById("e").value=encodeURIComponent(e.target.value);break;case"e":document.getElementById("d").value=decodeURIComponent(e.target.value);break;}}))</script></body>
#!/bin/bash
groupA0=(
"group-A0 item-0"
"group-A0 item-1"
)
groupB0=(
"group-B0 item-0"
"group-B0 item-1"
"group-B0 item-2"
)
#!/bin/sh
url='https://httpstat.us/500'
attempts=3
delay_sec=3
curl_return_code=1
while [ $curl_return_code -ne 0 ] && [ $attempts -gt 0 ]
do
echo "--- requesting..."
@Himura2la
Himura2la / nsupdate.sh
Last active April 12, 2022 08:03
Update a DNS record automatically after getting an IP address from DHCP
#!/bin/sh
# /etc/dhcp/dhclient-exit-hooks.d/nsupdate
[ "$interface" != "eth0" ] && return
[ "$new_domain_name" != "example.org" ] && return
if [ "$reason" = BOUND ] || [ "$reason" = RENEW ] ||
[ "$reason" = REBIND ] || [ "$reason" = REBOOT ]
then
host="$(hostname)"