ssh -D 13337 -q -C -N <the-vps-you-are-connecting-with>
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 ## |
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
# RESOURCES | |
# | |
# https://www.sqlitetutorial.net/sqlite-dump/ | |
# | |
$ sqlite3 ./myDatabase__BACKUP_20191113.sql | |
SQLite version 3.24.0 2018-06-04 19:24:41 | |
Enter ".help" for usage hints. | |
sqlite> .output myDatabase__BACKUP_20191113.sql | |
sqlite> .dump |
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
# Django migration specifically to load fixture data | |
# https://dev.to/guin/writing-a-django-data-migration-with-real-world-example-40m | |
# https://docs.djangoproject.com/en/1.7/howto/initial-data/#automatically-loading-initial-data-fixtures | |
# https://stackoverflow.com/questions/25960850/loading-initial-data-with-django-1-7-and-data-migrations <-- THIS | |
python manage.py makemigrations --empty <yourapp> --name load_intial_data | |
/// EDIT YOUR MIGRATION |