Skip to content

Instantly share code, notes, and snippets.

View VMuliadi's full-sized avatar

Vinsen Muliadi VMuliadi

View GitHub Profile
@VMuliadi
VMuliadi / response_track.sh
Last active January 4, 2021 09:28
Tracking HTTP/S Response Time, DNS resolution time, and Response Status Code
#!/bin/bash
function trace_and_track_request() {
website=$(echo $1 | awk -F'/' '{print $3}')
echo "timestamp,time_total,response_code,dns_time_namelookup,time_connect" > ${website}.csv
while true; do
echo "$(date +"%c"),$(curl --silent -XGET https://api.acceltest.net/version \
-w "%{time_total},%{response_code},%{time_namelookup},%{time_connect}" \
-o /dev/null)"; echo; sleep 1
done | tee ${website}.csv
}
@VMuliadi
VMuliadi / kde_tips_and_tricks.md
Last active September 12, 2020 19:26
My personal tips and trick for KDE. Mostly a workaround to make KDE works like GNOME (previously I'm using GNOME and recently `Sep 10, 2020` moved to KDE since it has less memory footprint than GNOME. Also I want to master both worlds (both KDE and GNOME), so ...

Spectacle Screenshot to Clipboard

Please install xclip on your computer first. This script is dependent to xclip package

  • Open System Settings > Notifications > Application: Configure
  • Spectacle > Configure Events
  • Tick a checkbox on Run command
  • Put /usr/bin/xclip -selection clipboard -t image/png -i ~/Pictures/$(ls ~/Pictures/ -c | head -n1); rm ~/Pictures/$(ls ~/Pictures/ -c | head -n1) as value
  • Click Apply and OK
  • Click Apply button

The screenshot will put into clipboard and will not written as a file. If you want to save it, just remove rm ~/Pictures/$(ls ~/Pictures/ -c | head -n1) from the script. I put it because most of the case I want to send it to chat rather than save it into my disk. If I want to save it as a file, I open the File Manager, paste it, give it a name, and then save it.


@VMuliadi
VMuliadi / supervisord.conf
Last active August 1, 2020 17:09
Supervisor configuration using eventlistener
[eventlistener:audiod]
directory=/home/pi/audio-player/
command=/home/pi/.local/bin/gunicorn --bind 0.0.0.0:5000 wsgi:app ; the program (relative uses PATH, can take args)
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
umask=022 ; umask for process (default None)
user=pi ; setuid to this UNIX account to run the program
autorestart=unexpected ; autorestart if exited after running (def: unexpected)
stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
autostart=true ; start at supervisord start (default: true)
@VMuliadi
VMuliadi / elastigrate.sh
Last active July 31, 2020 11:10
1st positional parameter: ES source. 2nd positional argument: ES target. 3rd positional argument: Action (backup/migrate)
#!/usr/bin/bash
dependency=()
command -v elasticdump > /dev/null || dependency+="elasticdump "
command -v curl > /dev/null || dependency+="curl "
command -v jq > /dev/null || dependency+="jq "
if [[ ${#dependency[@]} -gt 0 ]]; then
echo "Missing dependency: ${dependency[@]}"
exit 1
fi
@VMuliadi
VMuliadi / cheat_sheet.sh
Created June 10, 2020 01:59
Snippet to get things faster in kubernetes
# Get AWS EC2 Instance internal DNS name from Instance Group
# For `kubectl describe nodes` or whatever you want
$ kubectl get nodes -o json | jq '.items[] | select(.metadata.labels["kops.k8s.io/instancegroup"] == "nodes").metadata.labels["kubernetes.io/hostname"]' | tr -d '"'
ip-10-121-1-185.us-west-2.compute.internal
ip-10-121-2-138.us-west-2.compute.internal
ip-10-121-2-47.us-west-2.compute.internal
ip-10-121-4-147.us-west-2.compute.internal
ip-10-121-5-75.us-west-2.compute.internal
@VMuliadi
VMuliadi / netflix_route.py
Last active June 25, 2020 16:47
pip install --user requests beautifulsoup4; sudo python netflix_route.py (GATEWAY_IP)
#!/usr/bin/env python
import requests
import socket
import json
from sys import argv, exit
from bs4 import BeautifulSoup
from subprocess import check_output
@VMuliadi
VMuliadi / deployment.yaml
Created March 12, 2020 08:29
AWS EFS Deployment - YAML (without helm)
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs
provisioner: example.com/efs
---
apiVersion: v1
kind: ConfigMap
metadata:
name: efs-provisioner
@VMuliadi
VMuliadi / getChecksum.go
Last active February 5, 2020 10:59
Get SHA256 from file in golang
package main
import (
"bufio"
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
)
@VMuliadi
VMuliadi / pushbullet_vnc_notification.sh
Created January 13, 2020 03:31
Send an public endpoint complete with the port from `ngrok` to pushbullet
#!/bin/bash
PUSHBULLET_API_TOKEN="<PUSHBULLET_API_TOKEN>"
vncserver 2&>1 /dev/null; ngrok tcp 5901 --region=ap > /dev/null &
until [[ $(curl -sL http://localhost:4040/api/tunnels) ]]; do sleep 1; done
NGROK_PUBLIC_ENDPOINT=$(curl -sL http://localhost:4040/api/tunnels | \
jq .tunnels[0].public_url | tr -d '"') # get public_url from API
DATETIME=$(date +'%x %X')
curl --silent -XPOST "https://api.pushbullet.com/v2/pushes" \
-H "Access-Token: ${PUSHBULLET_API_TOKEN}" \
@VMuliadi
VMuliadi / jq_common_command.sh
Last active September 2, 2021 05:27
Common JQ command to parse JSON
#!/bin/bash
BIODATA='''
[{"_id":"5e0f13e6ad3dc1310495216c","index":0,"eyeColor":"green",
"name":"Gabrielle","gender":"female"},{"_id":"5e0f13e6976ab8447d76e206",
"index":1,"eyeColor":"blue","name":"Maryanne","gender":"female"}]
''' # https://www.json-generator.com/
# get the length of an array in JSON
echo ${BIODATA} | jq '. | length' # 2