Skip to content

Instantly share code, notes, and snippets.

@sphinxid
sphinxid / settings.json
Created November 17, 2024 08:51
vscode microsoft gallery url
"extensions.gallery": {
"serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
"cacheUrl": "https://vscode.blob.core.windows.net/gallery/index",
"itemUrl": "https://marketplace.visualstudio.com/items"
}
@sphinxid
sphinxid / eye_care.py
Created October 21, 2024 06:17
A simple yet effective command-line application that implements the 20-20-20 rule for reducing eye strain while working on computers. The rule suggests that every 20 minutes, you should look at something 20 feet away for 20 seconds.
import time
import datetime
import os
import platform
def clear_screen():
os.system('cls' if platform.system() == 'Windows' else 'clear')
def play_sound(repeat=10):
for _ in range(repeat):
@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 October 13, 2024 06:55
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 (In a real-world scenario, this should be stored securely)
SECRET_KEY = b"SayaOrangPalingGantengSedunia" # Change this in production
# Difficulty (number of leading zeroes required in the hash)
@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 <[email protected]>
#
# 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