Skip to content

Instantly share code, notes, and snippets.

View digi9ten's full-sized avatar

Jay digi9ten

View GitHub Profile
@digi9ten
digi9ten / generate_alphanumeric_string.py
Last active December 15, 2018 21:39
Within Python 3.X, produces a random, alphanumeric string of desired length, with optional mixed case.
import string
import random
from functools import reduce
USABLE_SEQUENCE_WITH_LOWER = string.ascii_letters + string.digits
USABLE_SEQUENCE_WITHOUT_LOWER = string.ascii_uppercase + string.digits
def generate_secret(length=50, mixed_case=False):
"""
@digi9ten
digi9ten / addition_to_bashrc
Created March 6, 2017 19:54
Small addition to your .bashrc that creates a alias that you can pass a url to, and it will retry it until it resolves
plsresolve() {
pls_resolve_rc=1
until [ $pls_resolve_rc -eq 0 ]; do curl "$1"; let pls_resolve_rc=$?; sleep 5; done
}
alias plsresolve=plsresolve
@digi9ten
digi9ten / setup_database_if_needed.txt
Created February 17, 2017 01:51
For Kong users, on Postgres. Checks if the postgres DB exists, then creates it if need be. Creates a pgpass file for the ec2-user, just in case.
function setup_database_if_needed {
##
## Since Kong does not actually create the DB automatically, we need to do that here...
##
if [ ! -f ~/.pgpass ]; then
echo "*:*:*:${KONG_RDS_USER}:${KONG_RDS_PASS}" | tee -a ~/.pgpass
chmod 0600 ~/.pgpass
fi
@digi9ten
digi9ten / requirements.txt
Created January 17, 2017 20:25
python - all your requirements.txt should look like this
# Please add requirements to setup.py
-e .
@digi9ten
digi9ten / generate_alphanumeric_string.py
Last active December 15, 2018 21:12
Within Python 2.X, produces a random, alphanumeric string of desired length, with optional mixed case.
import string
USABLE_SEQUENCE_WITH_LOWER = string.ascii_letters + string.digits
USABLE_SEQUENCE_WITHOUT_LOWER = string.ascii_uppercase + string.digits
def generate_secret(length=40, mixed_case=False):
"""
Produces a random, alphanumeric string of a desired length.
:param length: the length of the produced string.
@digi9ten
digi9ten / replace_inline_infile.py
Created November 14, 2016 19:26
When doing a search and replace of strings that contain '/', ie: URLs, sed and or printf make not always work. Use this.
import argparse
#
# Long story short, using sed/printf does always handle strings that contain '/' them (e.g.: urls)
#
parser = argparse.ArgumentParser()
parser.add_argument('fileToSearch', type=file)
parser.add_argument('textToSearch', type=str)
parser.add_argument('textToReplace', type=str)