Skip to content

Instantly share code, notes, and snippets.

View edmon1024's full-sized avatar
💭
hello world!!!

Edmundo Andrade edmon1024

💭
hello world!!!
View GitHub Profile
@edmon1024
edmon1024 / admin.py
Created December 1, 2021 19:00 — forked from cansadadeserfeliz/admin.py
Django: validate inline form in main form
from django.contrib import admin
from product.forms import EquipmentForm
@admin.register(Equipment)
class EquipmentAdmin(admin.ModelAdmin):
form = EquipmentForm
inlines = [
EquipmentGalleryInline,
@edmon1024
edmon1024 / random_alphanumeric_string.py
Created March 30, 2021 20:28
Random alphanumeric string
import random, string
def random_string(length):
txt = ""
for x in range(length):
txt += random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits)
return txt

Check the size of the databases:

SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database;

Check the top 10 of the tables in a database that consume the most space:

SELECT relname as table, pg_size_pretty(pg_total_relation_size(relid)) As size, pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as external_size FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC LIMIT 10;

Mysql

backup

    $ mysql -u db_user -p db_name -h localhost > filename.sql

restore

 $ mysql -u db_user -p db_name -h localhost < filename.sql
@edmon1024
edmon1024 / docker-backup-restore.md
Created February 4, 2021 08:50
docker backup/restore

container to image conversion

docker commit -p [CONTAINER_NAME] [IMAGE_NAME]

Image backup

docker save -o [IMAGE_NAME].tar [IMAGE_NAME]

restore image

docker load -i [BACKUP].tar

network creation

@edmon1024
edmon1024 / xiaomi_dns_block.lst
Created January 19, 2021 23:58
PiHole DNS Blocklist Xiaomi
# This is a DNS blocklist for the PiHole (https://pi-hole.net/) to block unnecessary connections to Xiaomi.
#
# License: GPL-3.0-or-later
#
# New Git Repo https://github.com/unknownFalleN/xiaomi-dns-blocklist
# There I will also add further lists e.g. all subdomains.
# Please use the list from the new repo, I will not maintain both lists and delete them here sometime
#
# Please help to collect domains!
### Optimizing jpeg and png images
##### Dependency used jpegoptim and pngquant
```
$ apt install -y jpegoptim pngquant
```
## copy files respecting permissions, user group target
#### -v, --verbose increase verbosity
#### -r, --recursive recurse into directories
#### -l, --links copy symlinks as symlinks
#### -t, --times preserve modification times
#### -D same as --devices --specials
```
rsync -vrltD orig/ dest/
@edmon1024
edmon1024 / iptables-reset.sh
Created September 6, 2019 19:07
reset iptables
#!/bin/sh
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
set autoindent
set hlsearch
set nu
set tabstop=2
set softtabstop=0 noexpandtab
set shiftwidth=2
syntax on