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 / django-manually-generate-random-secret-key.md
Created February 17, 2023 06:52
Django manually generate random secret key

Django manually generate random secret key

>>> from django.core.management.utils import get_random_secret_key
>>> get_random_secret_key()
@ekiara
ekiara / docker-container-with-2GB-RAM-limit.md
Created February 12, 2023 16:21
Docker container with 2GB RAM limit

Docker container with 2GB RAM limit

docker run -it --entrypoint "/bin/bash" --cpus="1.0" --memory="2g" ubuntu:22.10
@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 ##