Skip to content

Instantly share code, notes, and snippets.

@sphinxid
sphinxid / redis-test.py
Last active August 9, 2023 10:11
python 3 script to test connection to a redis and do simple GET/SET
import redis
def test_redis(host, port, password=None):
# Connect to Redis
client = redis.StrictRedis(host=host, port=port, password=password, decode_responses=True)
# Set a key-value pair
client.set("test_key", "Hello Redis!")
# Get the value of the key
@sphinxid
sphinxid / simple-api-client-server-pow-simulation.py
Last active June 7, 2023 06:21
This code simulates a client-server interaction using a Proof-of-Work (PoW) system. In such systems, the client must solve a computational challenge set by the server in order to have its request processed. This particular code makes use of SHA3-256 hashing and requires the hash of a unique challenge and a nonce to have a specific number of lead…
import hashlib
import hmac
import time
import secrets
import random
# Secret Key for HMAC
SECRET_KEY = b"SayaOrangPalingGantengSedunia" # please change it to something else lol.
# Challenge (this could be any piece of data)
@sphinxid
sphinxid / whois-asn-ip
Created January 26, 2023 16:08 — forked from bmatthewshea/whois-asn-ip
BASH script that uses 'whois' to lookup ASN number and display all IP4 CIDR associated to it.
#!/bin/bash
# whois-asn-ip (bash script)
# By: Brady Shea - March 15th 2020
# https://www.holylinux.net
# https://gist.github.com/bmatthewshea/dc427f0c30b82429931d5896f548d550
# The whois server to use:
WHOISHOSTNAME=whois.ripe.net
# Uncomment to remove temp files
#DEL_TEMP=true
@sphinxid
sphinxid / get_my_public_ip.sh
Last active June 21, 2023 09:22
Using ipgue.com to get your public IP.
#!/bin/bash
IP=`wget -qO - kodelatte.com`
echo $IP
@sphinxid
sphinxid / kawalcorona.py
Created May 10, 2020 13:07
Parse data dari kawalcorona.com tanpa API
## python3
from lxml import html
import requests
h = {'cookie': 'nocache'}
p = requests.get('https://kawalcorona.com/', headers=h)
c = p.text
x = html.document_fromstring(c)
@sphinxid
sphinxid / gist:06a7afbcf45c2e52c034dc2d8cd67242
Created September 1, 2019 10:26
Bootstrap install python pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py | python3 get-pip.py
@sphinxid
sphinxid / README-reverse-proxy-in-haproxy.md
Created March 26, 2019 05:11 — forked from drmalex07/README-reverse-proxy-in-haproxy.md
Perform simple reverse-proxying in HAProxy. #reverse-proxy #proxy #haproxy #proxypass

A more complete example (with rewriting cookie domains/paths) can be found at http://blog.haproxy.com/2014/04/28/howto-write-apache-proxypass-rules-in-haproxy/

We will try something roughly equivalent to the following ProxyPass directives in Apache2:

ServerName www.example.com
...
ProxyPass        /foo/  http://foo.local
ProxyPassReverse /foo/  http://foo.local

In haproxy.cfg we define a backend, say foo, to reverse-proxy to foo.local backend server.

@sphinxid
sphinxid / count_per_second_nginx_log.sh
Last active September 6, 2023 01:53
This bash script is to help count request per seconds (rps) of nginx access log. (method: tailing the streamed file logs)
#!/bin/bash
#
# sphinxid <firman.gautama@gmail.com>
#
# Example: ./count_per_second_nginx_log.sh /var/log/nginx/*.log
#
RAND_STR=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
INTERVAL=10 #seconds
@sphinxid
sphinxid / sslcheck.sh
Last active July 5, 2023 04:14
bash script to check ssl certificate expiration
#!/bin/bash
hosts=$@
date_cmd=""
if [[ "$OSTYPE" == "darwin"* ]]; then
# make sure you have 'coreutils' -- brew install coreutils
date_cmd="gdate"
else
date_cmd="date"
@sphinxid
sphinxid / .bashrc
Last active January 11, 2018 09:13
sphinx bashrc - Colorful BASHrc config with github branch support displayed.
#git branch
# __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'
# "\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
function parse_git_dirty {
echo -n $(git status 2>/dev/null | awk -v out=$1 -v std="dirty" '{ if ($0=="# Changes to be committed:") std = "uncommited"; last=$0 } END{ if(last!="" && last!="nothing to commit (working directory clean)") { if(out!="") print out; else print std } }')
}
function parse_git_branch {
echo -n $(git branch --no-color 2>/dev/null | awk -v out=$1 '/^*/ { if(out=="") print $2; else print out}')
}