Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
Byobu is a suite of enhancements to tmux, as a command line
tool providing live system status, dynamic window management,
and some convenient keybindings:
F1 * Used by X11 *
Shift-F1 Display this help
F2 Create a new window
Shift-F2 Create a horizontal split
Ctrl-F2 Create a vertical split
Ctrl-Shift-F2 Create a new session
@devhero
devhero / py_remote_extract_tar_gzip.py
Last active May 24, 2023 18:50
python download and extract remote file tar.gzip
# Instruct the interpreter to create a network request and create an object representing the request state. This can be done using the urllib module.
import urllib.request
import tarfile
thetarfile = "http://file.tar.gz"
ftpstream = urllib.request.urlopen(thetarfile)
thetarfile = tarfile.open(fileobj=ftpstream, mode="r|gz")
thetarfile.extractall()
# The ftpstream object is a file-like that represents the connection to the ftp server. Then the tarfile module can access this stream. Since we do not pass the filename, we have to specify the compression in the mode parameter.
@devhero
devhero / ffmpeg cookbook
Last active January 19, 2023 10:56
ffmpeg cookbook
# rotate
ffmpeg -i input.mp4 -map_metadata 0 -c copy -metadata:s:v rotate="180" output.mp4
# extract subs from mp4
# https://superuser.com/questions/393762/how-to-extract-subtitles-from-mp4-and-mkv-movies
ffmpeg -i video.mp4 subtitle.srt
# convert audio (using vbr)
ffmpeg -i input.mkv -c:a libopus -b:a 256k -vbr 1 -af "channelmap=channel_layout=5.1" output.mkv
from django.db import connection
def idseq(model_class):
return '{}_id_seq'.format(model_class._meta.db_table)
def get_next_id(model_class):
cursor = connection.cursor()
sequence = idseq(model_class)
cursor.execute("select nextval('%s')" % sequence)
row = cursor.fetchone()
@devhero
devhero / av1 encoding params
Last active December 14, 2022 19:35
av1 #av1
# ENCODING PARAMS (AOMENC):
--cpu-used=4 --end-usage=q --tile-columns=1 --tile-rows=1
--bit-depth=10 --lag-in-frames=28 --threads=2
--enable-dist-wtd-comp=0 --enable-qm=1 --quant-b-adapt=3
--mv-cost-upd-freq=2 --enable-chroma-deltaq=1
--enable-fwd-kf=1
# av1an docker SDR 1080p (pre=6,cq=25,denoise=0,grain=15):
docker run --privileged -v "$(pwd):/videos" --user $(id -u):$(id -g) -it --rm masterofzen/av1an:master --encoder aom -s ./movie-scenes.json -c mkvmerge -m lsmash -k --workers 6 -a " -an " --video-params " --bit-depth=10 --cpu-used=6 --cq-level=25 --end-usage=q --lag-in-frames=48 --enable-fwd-kf=1 --aq-mode=1 --deltaq-mode=1 --enable-chroma-deltaq=1 --quant-b-adapt=1 --enable-qm=1 --min-q=1 --enable-keyframe-filtering=2 --arnr-strength=1 --arnr-maxframes=4 --disable-trellis-quant=0 --disable-kf --threads=64 --sharpness=3 --enable-dnl-denoising=0 --denoise-noise-level=15" -i "movie.1080.mkv" -o "movie-aom-pre6-cq25-sharp3-den0-gr15-kff2.mkv"
@devhero
devhero / js_iterate_object
Last active May 12, 2022 06:50
js iterate through an object #js
// iterate through
Object.entries(myObject).forEach(([key, value]) => {
console.log(`${key}: ${value}`)
});
// return a new array
Object.entries(myObject).map(([key, value]) => {
return {
key,
value
@devhero
devhero / encrypt SHA1 htpasswd
Last active May 6, 2022 11:34
htpasswd #encrypt #sha1
htpasswd -nbBC 10 USER topsecret
# USER:$2y$10$vDtCxgJ4DIZ1itAAq6NDkedmaDFHlPdlpLY.EiEa3QBXHnH0oLatW
# used with traefik
echo $(htpasswd -nb USER topsecret) | sed -e s/\\$/\\$\\$/g
# USER:$$apr1$$rjtvYgpl$$urvcY8G0rd9ZpskQc0u28.
@devhero
devhero / postgres_backup_restore
Last active April 29, 2022 10:16
postgres backup/restore
sudo su postgres
# BACKUP
vacuumdb -U postgres --full --analyze --dbname $DBNAME && pg_dump $DBNAME -Ft -v -U postgres -f /tmp/$DBNAME.tar
# RENAME TARGET DB
psql
alter database $T_DBNAME rename to NEWNAME
# OR DROP TARGET DB
@devhero
devhero / zsh_shortcuts.md
Created January 26, 2018 09:08
zsh shortcuts

Source

Shortcuts to improve your bash & zsh productivity

So, you hate using a terminal? That might be, because you use the arrow keys to navigate character by character through a long command just to change a paramater at the other end of the line, right? Here's a list of my most-used bash & zsh shortcuts, that will definitely boost your productivity and will help you to improve your command line experience.

Shortcut Action
CTRL + A Move to the beginning of the line
@devhero
devhero / pytest cookbook
Last active March 14, 2022 11:15
pytest cookbook #pytest
# run specific method in a file
pytest app_folder/file.py -k "method keyword"
# enable debugger
pytest app_folder/file.py -k "method keyword" --pdb
# check for setup errors (wrong imports, etc)
pytest --setup-only