Skip to content

Instantly share code, notes, and snippets.

@sphinxid
sphinxid / gist:e8b46899959bc9d3382f
Last active August 29, 2015 14:24
Javascript: Call URL before Exit from Page
window.onbeforeunload = function() {
var URL = '//preview.adskom.net/test12345.js';
var request = null;
if (window.XMLHttpRequest){
request = new XMLHttpRequest();
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP");
}
@sphinxid
sphinxid / concurrent-phantomjs-example.py
Created November 27, 2016 18:04
How to Render a Html Page with Selenium Webdriver + PhantomJS in Python
#
# 20160929 - [email protected]
#
from selenium import webdriver
import time
import concurrent.futures
import signal
from concurrent.futures import ThreadPoolExecutor
from random import randint
@sphinxid
sphinxid / palindrome.c
Last active December 12, 2016 09:24
simple palindrome checker in C
/*
* 2016/12/12
*
* palindrome.c
* Simple palindrome checker for small string. (cAsE sEnsiTivE)
*
* Firman Gautama <[email protected]>
*
*/
#include <stdio.h>
@sphinxid
sphinxid / anagram.php
Created December 12, 2016 07:55
Simple anagram checker in PHP
<?php
/*
* 2016/12/12
*
* anagram.php
* Simple anagram checker. (cAsE sEnsiTivE)
*
* Firman Gautama <[email protected]>
*
@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}')
}
@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 / 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
@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 / 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 / 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)