Skip to content

Instantly share code, notes, and snippets.

View t0rik's full-sized avatar
🏠
Working from home

Vadym t0rik

🏠
Working from home
View GitHub Profile
@t0rik
t0rik / BytesConversion.py
Created November 29, 2023 14:38
Bytes conversion Python.
import psutil
def bytes2human(n):
# >>> bytes2human(10000)
# '9.8K'
# >> bytes2human(100001221)
# '95.4M'
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
@t0rik
t0rik / addssh.sh
Created September 12, 2023 07:58
Add ssh user to system and generate RSA keypair
#!/bin/bash
# --------------------
# arguments definition
# --------------------
V_USER=$1
V_PASSWORD=$(openssl rand -base64 12)
# -------------
@t0rik
t0rik / pg_backup_all.sh
Created June 13, 2023 09:35 — forked from powellc/pg_backup_all.sh
Bash script to backup all postgresql databases on a server, run with cron once a day or 5 times a day, whatever. Just updated it so it ignores your postgres db, and also bzips the backups and adds a symlink to a latest directory. Sweet.
#!/bin/bash
# Location to place backups.
backup_dir="/var/backups/databases/"
nightly_dir="/var/backups/databases/latest/"
#String to append to the name of the backup files
backup_date=`date +%d-%m-%Y`
#Numbers of days you want to keep copie of your databases
number_of_days=15
databases=`psql -l -t | cut -d'|' -f1 | sed -e 's/ //g' -e '/^$/d'`
for i in $databases; do if [ "$i" != "postgres" ] && [ "$i" != "template0" ] && [ "$i" != "template1" ] && [ "$i" != "template_postgis" ]; then
@t0rik
t0rik / gist:5e99df2f6c7f65b1f9fb0724fd5ff071
Created May 16, 2023 10:42
Postgresql config for 256Gb RAM
# DB Version: 12
# OS Type: linux
# DB Type: oltp
# Total Memory (RAM): 256 GB
# Number of Connections: 1000
max_connections = 1000
shared_buffers = 64GB
effective_cache_size = 128GB
work_mem = 64554kB
@t0rik
t0rik / zmcertmgr-patch.sh
Created March 4, 2023 17:28
zmcertmgr doesn't work with ellipitical curve certs
#!/bin/sh
#
# BUG: zmcertmgr doesn't work with ellipitical curve certs
# Ref: https://forums.zimbra.org/viewtopic.php?f=15&t=69645
#
zmcertmgr=/opt/zimbra/bin/zmcertmgr
cp $zmcertmgr $zmcertmgr.bak
sed -i -e 's/$self->run("$ssl rsa -noout -modulus -in '$keyf'/$self->run("$ssl pkey -pubout -in '$keyf'/g' \
-e 's/$self->run("$ssl x509 -noout -modulus -in '$crtf'/$self->run("$ssl x509 -noout -pubkey -in '$crtf'/g' $zmcertmgr
@t0rik
t0rik / script.sh
Created March 3, 2023 15:26 — forked from vielhuber/script.sh
PostgreSQL: Backup and restore export import pg_dump with password on command line #sql
# best practice: linux
nano ~/.pgpass
*:5432:*:username:password
chmod 0600 ~/.pgpass
# best practice: windows
edit %APPDATA%\postgresql\pgpass.conf
*:5432:*:username:password
# linux
@t0rik
t0rik / TransactionSeeder.php
Last active September 29, 2022 10:27
Import csv file to laravel
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Transaction;
class TransactionSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
@t0rik
t0rik / Drupal 8 on VestaCP.md
Created July 26, 2022 05:59 — forked from m4tlch/Drupal 8 on VestaCP.md
Templates for Drupal 8 on VestaCP

Each file should be put in /usr/local/vesta/data/templates/web/apache2

Then, when you edit your domain/site, you can change the web template to Drupal8 and just upload your whole project into public_html

@t0rik
t0rik / nginx.yml
Created July 27, 2021 08:49
nginx playbook
---
- hosts: all
tasks:
- name: ensure nginx is at the latest version
apt: name=nginx state=latest
become: yes
- name: start nginx
service:
name: nginx
state: started
@t0rik
t0rik / create_user.yml
Last active July 27, 2021 08:35
Create user playbook
---
- name: Linux Create User and Upload User Public keys
hosts: test
#remote_user: xxxx
#sudo: yes
vars:
user_1: devuser
tasks:
- name: Make sure we have a 'wheel' group
group: