>>> from django.core.management.utils import get_random_secret_key
>>> get_random_secret_key()
A $SHELL one-liner to get all the tables with at least one row of data in a PostgreSQL database.
for table_name in `psql -h<DB_HOST> -U<DB_USER> <DATABASE_NAME> -c "\d"|grep table|awk '{print $3}'`; do echo -n $table_name >> tables_with_data.txt; psql -h<DB_HOST> -U<DB_USER> <DATABASE_NAME> -c "SELECT COUNT(*) FROM $table_name" | grep -B 1 "(1 row)"|grep -v row >> tables_with_data.txt; done
You can then filter out lines in the text file that end with a '0' i.e. that table has a COUNT(*) of 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| import random | |
| import re | |
| def generate_django_secret_key(key_length=53): | |
| if key_length < 53: | |
| key_length = 53 | |
| # Remove 'lookalike' characters | |
| clean_chars = re.sub("i|I|l|L|o|O|s|S|1|5|0", "", string.ascii_letters + string.digits + string.punctuation) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Setting up projects with pyenv and pipenv in short | |
| user@dev-machine:~/src/project_name$ pyenv local 3.6.10 | |
| user@dev-machine:~/src/project_name$ python --version | |
| Python 3.6.10 | |
| user@dev-machine:~/src/project_name$ pipenv --python 3.6.10 | |
| Creating a virtualenv for this project… | |
| ... | |
| ... | |
| user@dev-machine:~/src/project_name$ git init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # removing the virtual envvironment that was created by pipenv | |
| $ pipenv --rm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Invoking shell commands from Python and subprocess (either in the Python interpreter, or in a Python scipt) # | |
| # python-subprocess-invoking-shell-commands # | |
| >>> import subprocess | |
| >>> subprocess.call(["whois", "example.co.ke"]) | |
| >>> subprocess.call(["whois", "-h" "registry.kenic.or.ke", "example.co.ke"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # using-wget-with-socks-proxy | |
| # This should work for everything includeing curl, pip, pipenv, etc | |
| # TLDR: Use proxychains (https://github.com/haad/proxychains) | |
| ## INSTALL PROXY CHAINS ## | |
| $ sudo apt update -y | |
| $ sudo apt install proxychains | |
| ## EDIT PROXYCHAINS CONFIG ## |