Skip to content

Instantly share code, notes, and snippets.

View glowinthedark's full-sized avatar

glowinthedark glowinthedark

  • URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
  • HTTPError: HTTP Error 403: Forbidden
View GitHub Profile
@glowinthedark
glowinthedark / url-validation-regex.js
Created April 11, 2019 18:36
URL validation regex
urlPattern = /^(https?:\/\/)?(((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-zA-Z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-zA-Z]|\d|-|\.|_|~|[\u00A0-\uD7
@glowinthedark
glowinthedark / twisted-webserver-ssl-authentication.py
Created April 11, 2019 18:39
Twisted SSL webserver with basic authentication using plain in-memory passwords. The first argument is the path of the directory to serve; if not provided then the current folder is used (".").
#!/usr/bin/env python
"""
Twisted SSL webserver with basic authentication using plain in-memory passwords.
The first argument is the path of the directory to serve; if not provided then the current folder is used (".").
INSTALL DEPENDENCIES:
pip install twisted
pip install pyOpenSSL
pip install service_identity
@glowinthedark
glowinthedark / gmail-imap4.py
Created April 11, 2019 18:39
GMail IMAP4 reader (IMAP has to be enabled in Gmail > Settings)
#!/usr/bin/env python
# Run without args to get message headers for the last 3 days.
# gmail.py 10 - display message headers for the last 10 days.
# gmail.py 10 full - display message headers with bodies.
import sys
import os
import imaplib
import getpass
@glowinthedark
glowinthedark / twisted-ssl-fileserver.py
Created June 5, 2019 19:49
Twisted SSL fileserver
#!/usr/bin/env python
# http://blog.vrplumber.com/index.php?/archives/1638-HowTo-Create-an-SSL-web-server-in-Twisted-Crude-approach,-but-it-works....html
# AND http://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#auto2
# Resource from: http://jcalderone.livejournal.com/54128.html
# ##### FOR HTTP YOU CAN USE INSTEAD THIS:
# ####### twistd -n web --path /
@glowinthedark
glowinthedark / javascript-reduce-example.js
Created June 13, 2019 14:52
javascript reduce example
var args = {
quoted_prop1: " oneEE",
quoted_prop1aaaa: " first level another",
quoted_I18N__prop2: " tWo (must be under I18N)",
quoted_I18N__weprop2bbb: " tWo and a half (must be under I18N)",
quoted_API__JUJUJ__prop3: " THREE",
quoted_API__JUJUJ__prop3BBBB: " THREE--beeee",
quoted_API__JUJUJ__LAST__prop3ZZZZ: " THREE--zzzzz",
quoted_API__prop4: " __FOUR__",
quoted_prop3232aaaa: " more first level another",
@glowinthedark
glowinthedark / bottle file server
Created July 6, 2019 22:57
Python Bottle file server with directory index
#!/usr/bin/env python3
import os
import sys
import bottle
from bottle import run, static_file
def resolve_path(path):
@glowinthedark
glowinthedark / apktool-installer.sh
Created August 14, 2019 17:32
apktool installer
# Get latest version from https://bitbucket.org/iBotPeaches/apktool/downloads
export APKTOOL_VERSION=2.4.0
sudo -E sh -c 'wget https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_$APKTOOL_VERSION.jar -O /usr/local/bin/apktool.jar'
sudo chmod +r /usr/local/bin/apktool.jar
sudo sh -c 'wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool -O /usr/local/bin/apktool'
sudo chmod +x /usr/local/bin/apktool
# https://gist.github.com/bmaupin/48140926ce11fbeddec2
@glowinthedark
glowinthedark / disable.sh
Created September 30, 2019 09:39
Disable bunch of #$!@ in Catalina (It's back!)
#!/bin/bash
# IMPORTANT: Don't forget to logout from your Apple ID in the settings before running it!
# IMPORTANT: You will need to run this script from Recovery. In fact, macOS Catalina brings read-only filesystem which prevent this script from working from the main OS.
# This script needs to be run from the volume you wish to use.
# E.g. run it like this: cd /Volumes/Macintosh\ HD && sh /Volumes/Macintosh\ HD/Users/sabri/Desktop/disable.sh
# WARNING: It might disable things that you may not like. Please double check the services in the TODISABLE vars.
# Get active services: launchctl list | grep -v "\-\t0"
# Find a service: grep -lR [service] /System/Library/Launch* /Library/Launch* ~/Library/LaunchAgents
@glowinthedark
glowinthedark / autoreboot.py
Last active June 16, 2022 02:40
Automatic Reboot Manager script
#!/usr/local/bin/python3.7
# Reboot linux box when connection to router lost
# Reboot router when connection to internet lost
# Run via cron as root every minute
# After 5 (ticks) failures a reboot will be initiated
# After 3 reboots wait for 30 reboot ticks before rebooting again
# # sudo crontab -e
# Add line
@glowinthedark
glowinthedark / mac_rsync_backup_home.sh
Last active October 22, 2019 09:54
mac backup rsync home folder
/usr/local/bin/rsync --progress -av \
--exclude '.DS_Store*' \
--exclude .fseventsd \
--exclude '.Spotlight-V100*' \
--exclude '.TemporaryItems*' \
--exclude '.Trashes*' \
--exclude '.Trash*' \
--exclude 'tmp*' \
--exclude 'Application\ Support' \
--exclude '.PKInstallSandboxManager*' \