Skip to content

Instantly share code, notes, and snippets.

View ekiara's full-sized avatar
🎯
Focusing

Eric Kiara ekiara

🎯
Focusing
View GitHub Profile
@ekiara
ekiara / ssh-as-socks-proxy.md
Created February 12, 2023 16:08
Use SSH as a SOCKS4/SOCKS5 proxy

Use SSH as a SOCKS4/SOCKS5 proxy

SSH config

ssh -D 13337 -q -C -N <the-vps-you-are-connecting-with>

Browser config

@ekiara
ekiara / howto-get-a-list-of-all-postgresql-tables-that-have-data.rst
Last active February 4, 2022 00:57
howto-get-a-list-of-all-postgresql-tables-that-have-data.rst

HOWTO get a list of all PostgreSQL tables that have data

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
@ekiara
ekiara / quick-django-secret-key-generation
Created February 5, 2021 03:51
Quick Django SECRET_KEY Generation
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)
@ekiara
ekiara / setting-up-ng-serve-for-the-first-time.md
Last active February 6, 2020 11:06
setting-up-ng-serve-for-the-first-time

Want to setup and Angular dev environment so you can do ng serve?

Update or install npm

OPTION #1: Update (npm)

npm install -g npm
@ekiara
ekiara / setting-up-projects-with-pyenv-and-pipenv-in-short
Created December 22, 2019 10:21
Setting up projects with pyenv and pipenv in short
# 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
@ekiara
ekiara / removing-the-virtualenv-that-was-created-by-pipenv
Last active December 22, 2019 10:10
removing the virtual envvironment that was created by pipenv
# removing the virtual envvironment that was created by pipenv
$ pipenv --rm
@ekiara
ekiara / python-subprocess-invoking-shell-commands
Created December 11, 2019 05:51
Invoking shell commands from Python and subprocess (either in the Python interpreter, or in a Python scipt)
# 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"])
@ekiara
ekiara / using-wget-with-socks-proxy
Last active April 7, 2025 12:17
Using wget with socks proxy
# 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 ##
@ekiara
ekiara / sqlite3-dump-schema-and-data
Created November 13, 2019 08:10
sqlite3-dump-schema-and-data
# 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
@ekiara
ekiara / django-migration-specifically-to-load-fixture-data
Created November 12, 2019 05:26
Django migration specifically to load fixture data
# 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