Skip to content

Instantly share code, notes, and snippets.

View StoneLabs's full-sized avatar
:shipit:
Oh hello there

Levy StoneLabs

:shipit:
Oh hello there
View GitHub Profile
@StoneLabs
StoneLabs / dialog.sh
Created May 7, 2020 13:38
Bash confirmation prompt
ask() {
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
@StoneLabs
StoneLabs / env.py
Created May 7, 2020 13:40
Priting all local python variables
[print("{:<30}{:<30}".format(key, str(val))) for key, val in locals().items() if "__" not in key]
@StoneLabs
StoneLabs / filewait_timeout.sh
Created May 7, 2020 13:40
Wait for file deletion or timeout (bash)
# Function
wait_file() {
local file="$1"; shift
local wait_seconds="${1:-10}"; shift # 10 seconds as default timeout
until test $((wait_seconds--)) -eq 0 -o ! -f "$file" ; do sleep 1; done
((++wait_seconds))
}
@StoneLabs
StoneLabs / google_sub.lst
Created May 7, 2020 13:42
List of all google subdomains
# Semi-Secret
actualities.google.com – alias for news.google.com
d.google.com – same as www.google.com
email.google.com – redirects to mail.google.com (obviously)
fusion.google.com – redirects to www.google.com
locale.google.com – redirects to local.google.com
purchase.google.com – same as www.google.com
relay.google.com – nothing (possibly a mail relay server?)
@StoneLabs
StoneLabs / main.py
Created May 7, 2020 13:43
Binary string to pixel matrix visualization
# Simple script to visualize a binary string as a pixel matrix
# Example input: "01100001110101011100010[...]"
# Note that the data length should be some n^2 to produce a square image
import numpy as np
from math import sqrt
file = open('input.txt', 'r')
cont = file.read()[:-1]
data = [_char == '1' for _char in cont]
@StoneLabs
StoneLabs / main.py
Created May 7, 2020 13:43
Decrypting RSA cipher using CRT in python
#!/usr/bin/env python2.7
from Crypto.Util.number import long_to_bytes
import gmpy2
# values given by private key
p = ...
q = ...
dp = ...
dq = ...
iq = gmpy2.invert(q, p) # or given by private key
@StoneLabs
StoneLabs / main.py
Created May 7, 2020 13:44
Splitting school class format in python
>>> import re
>>> str = "10abc9df7a8z"
>>> searcher = re.compile("[0-9]+[a-zA-Z]+")
>>> blocks = searcher.findall(str)
>>> blocks
['10abc', '9df', '7a', '8z']
>>> searcher = re.compile("[0-9]+|[a-zA-Z]+")
>>> parts = [searcher.findall(block) for block in blocks]
>>> parts
@StoneLabs
StoneLabs / main.js
Created May 7, 2020 13:45
JavaScript String.replaceall
String.prototype.replaceAll = function (search, replacement) { //String replace function
return this.replace(new RegExp(search, 'g'), replacement);
};
@StoneLabs
StoneLabs / main.cpp
Created May 7, 2020 13:46
Float remapping
//Re-maps a number from one range to another.
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
@StoneLabs
StoneLabs / main.js
Created May 7, 2020 13:47
PHP Session ID from JS
var sId = /SESS\w*ID=([^;]+)/i.test(document.cookie) ? RegExp.$1 : false;