Skip to content

Instantly share code, notes, and snippets.

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

@moki9
moki9 / dump-restore.sh
Created September 11, 2019 13:13
Dump/Restore from Postgres in Docker with gzip
# Dump
#!/usr/bin/env bash
container=`docker ps | awk '/database/ { print $1 }'`
echo "Dumping data from ${container}"
sudo docker exec -t -u postgres "${container}" pg_dumpall -c -U postgres -l databasename | gzip > dump_`date +%d-%m-%Y"_"%H_%M_%S`.tar.gz
echo "Done!"
# Restore
#!/usr/bin/env bash
@moki9
moki9 / cors-nginx.conf
Created September 12, 2019 12:59 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@moki9
moki9 / gcrgc.sh
Created January 18, 2021 06:48 — forked from ahmetb/gcrgc.sh
Script to clean up Google Container Registry images pushed before a particular date
#!/bin/bash
# Copyright © 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@moki9
moki9 / psql-with-gzip-cheatsheet.sh
Created March 17, 2021 07:56 — forked from brock/psql-with-gzip-cheatsheet.sh
Exporting and Importing Postgres Databases using gzip
# This is just a cheat sheet:
# On production
sudo -u postgres pg_dump database | gzip -9 > database.sql.gz
# On local
scp -C production:~/database.sql.gz
dropdb database && createdb database
gunzip < database.sql.gz | psql database
@moki9
moki9 / clean-up-arch-linux.md
Created April 11, 2021 23:56 — forked from rumansaleem/clean-up-arch-linux.md
Instructions to clean up Arch Linux (Manjaro)

Contents

  • Clean pkg cache
  • Remove unused packages (orphans)
  • Clean cache in /home
  • remove old config files
  • Find and Remove
    • duplicates
    • empty files
    • empty directories
  • broken symlinks
@moki9
moki9 / sqlalchemy-truncate_db.py
Created May 10, 2021 00:55 — forked from absent1706/sqlalchemy-truncate_db.py
Sqlalchemy: Truncate all tables
def truncate_db(engine):
# delete all table data (but keep tables)
# we do cleanup before test 'cause if previous test errored,
# DB can contain dust
meta = MetaData(bind=engine, reflect=True)
con = engine.connect()
trans = con.begin()
con.execute('SET FOREIGN_KEY_CHECKS = 0;')
for table in meta.sorted_tables:
con.execute(table.delete())
@moki9
moki9 / GitConfigHttpProxy.md
Created May 12, 2021 07:09 — forked from evantoli/GitConfigHttpProxy.md
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@moki9
moki9 / remove-old-snaps.sh
Created May 26, 2021 23:09
Remove Old Snaps
#!/bin/bash
# https://www.linuxuprising.com/2019/04/how-to-remove-old-snap-versions-to-free.html
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@moki9
moki9 / merge_migration.md
Created July 21, 2021 23:35 — forked from mhipo1364/merge_migration.md
Re-Generate(Merge) Migration Files In Django

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python manage.py migrate --fake command
  • run python manage.py makemigrations command
  • run python manage.py migrate --fake-initial command
  • run python manage.py migrate contenttypes command