Skip to content

Instantly share code, notes, and snippets.

View ride90's full-sized avatar
🛠️

Oleh Pshenychnyi ride90

🛠️
View GitHub Profile
@ride90
ride90 / killer.sh
Last active July 25, 2021 04:41
Process killer by name
#!/usr/bin/env bash
# Author: Oleh Pshenychnyi
# Date: 13.02.2021
#
# Kill all processes matching a provided pattern.
#
# Usage:
#
# >> bash killer.sh celery
@ride90
ride90 / bash_docs.sh
Created February 12, 2021 16:39
Bash docs
#!/usr/bin/env bash
# First line of the script is the shebang which tells the system how to execute
# the script: http://en.wikipedia.org/wiki/Shebang_(Unix)
# As you already figured, comments start with #. Shebang is also a comment.
# Simple hello world example:
echo Hello world! # => Hello world!
# Each command starts on a new line, or after a semicolon:
echo 'This is the first line'; echo 'This is the second line'
@ride90
ride90 / kill_processes_regex.sh
Created February 10, 2021 12:10
Kill all processes amtch regex
kill -9 $(ps aux | grep "REGEX" | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1
@ride90
ride90 / run_ssh_agent.sh
Created June 28, 2020 09:18
Keeps the details of the auth agent in a file, tries to load it, checks if that agent is still running, and if not, starts another one.
#!/bin/bash
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
(umask 066; /usr/bin/ssh-agent > "${SSH_ENV}")
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add;
}
@ride90
ride90 / db_backup_and_rotate.md
Last active March 15, 2020 17:49
Dump postgresql DB every day and keep dump files not older than 30 days

create a sh script for a cron

db_backup.sh

#!/bin/bash

# make a backup
pg_dump -Fc --no-owner --dbname=postgresql://user:pswd@host:port/db_name > /folder/with/backups/db_`date +\%Y-\%m-\%d_\%T`.dump;
# delete files with *.dump older than 30 days
find . -name "*.dump" -type f -mtime 30 -exec rm -f {} \;
@ride90
ride90 / postgres-cheatsheet.md
Last active February 14, 2021 15:15 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Link with tutorial which covers a lot https://www.postgresqltutorial.com/

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

@ride90
ride90 / ubuntu_18.04_server_setup.md
Last active February 14, 2024 10:42
My Ubuntu 18.04 server setup

Ubuntu 18.04 server setup

Preword

This manual contains some basic things I do for Ubuntu 18.04 server setup.
In general, it's not a mature production-ready setup, but it might be if you know how to polish it.
I use it for my personal needs e.q. file sharing, cloud file storage, serving static pages, running python/node apps, etc.

⚠️ I'm not a system administrator, so don't try it at home!

@ride90
ride90 / mongo_cascade_delete.js
Last active April 23, 2024 17:40
How to implement a cascade delete in MongoDB
// equivalent of cascade delete in MongoDB
/**
* Let's assume you have 2 related collections with next data structure.
*
* - `archive`
* {
* "_id" : ObjectId("5ce5138efe985e8424a79304"),
* "type" : "text",
* "headline" : "Curabitur non nulla sit amet nisl tempus convallis quis ac lectus."