Skip to content

Instantly share code, notes, and snippets.

View AlexBaranowski's full-sized avatar

Aleksander Baranowski AlexBaranowski

View GitHub Profile
#!/bin/bash
# Author: Aleksander Baranowski
# License: MIT (https://choosealicense.com/licenses/mit/)
# This simple script looks for changed .sh file from the last git commit
# then run shellcheck on them.
# USAGE: shellcheck_ci repo_root_dir
# Exit codes:
# 98 - required command is not installed
# 1 - some file failed check
@AlexBaranowski
AlexBaranowski / remove_hdds.sh
Created October 30, 2019 09:02
Remove all virtualbox disks (hdds)
# Simple script that get UUIDs and remove virtualbox disk (hdds).
hdds=$(vboxmanage list hdds | grep '^UUID' | awk '{ print $2}')
for hd in $hdds; do vboxmanage closemedium disk $hd --delete; done
@AlexBaranowski
AlexBaranowski / simple_home_backup.sh
Last active October 31, 2019 16:00
Backup script
#!/usr/bin/env bash
# Author: Alex Baranowski
# This is trivial backup script
# Backup should be done on **different** physical disk, and as any other file can be moved &&|| replicated.
# Stop on the first error
set -e
[[ -v "$KEEP_DAYS" ]] || KEEP_DAYS=120
@AlexBaranowski
AlexBaranowski / huge_pages_pg_calc.sh
Created February 1, 2019 16:54
Simple script to calculate huge pages for PostgreSQL. Please note that this is baseline and require further tunning.
#!/usr/bin/env bash
[ -z "$PGDATA" ] && echo "PGDATA is not defined!" && exit 1
[ ! -e $PGDATA/postmaster.pid ] && echo "Cannot find $PGDATA/postmaster.pid is PostgreSQL server running?" && exit 1
PG_PID=$(head -1 $PGDATA/postmaster.pid)
PG_MEM_U=$(grep ^VmPeak /proc/$PG_PID/status | awk '{print $3}')
HP_MEM_U=$(grep ^Hugepagesize /proc/meminfo | awk '{print $3}')
[ "$PG_MEM_U" != "$HP_MEM_U" ] && echo "The units differ please calculate the Huge Pages manually" && exit 1
PG_MEM=$(grep ^VmPeak /proc/$PG_PID/status | awk '{print $2}')
HP_MEM=$(grep ^Hugepagesize /proc/meminfo | awk '{print $2}')
@AlexBaranowski
AlexBaranowski / install_newest_git.sh
Last active April 13, 2018 09:50
Install the newest GIT on EuroLinux/Scientific Linux/RHEL/Oracle Linux/CentOS/. Taken from this article: https://pl.euro-linux.com/git-podstawowe-narzedzie-pracy-dewelopera-czesc-ii-troche-komend-troche-praktyki/
#!/bin/bash
# The MIT License (MIT)
# Copyright (c) 2017 EuroLinux
# Author: Alex Baranowski
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@AlexBaranowski
AlexBaranowski / remove_not_used.sh
Created January 15, 2018 20:14
Remove not used packages from pip requirements.txt
#!/bin/bash
diff requirements.txt requirements.txt2 | awk '{print $2}' | xargs pip uninstall -y
@AlexBaranowski
AlexBaranowski / merge_to_tuple.py
Created December 30, 2017 23:14
Very simple merging two files with same line - idea is to make tuple that will be hardcoded.
with open('some_args') as f1:
with open('some_names') as f2:
with open('out', 'w') as f3:
args = f1.readlines()
name = f2.readlines()
print('lenghts :', len(args), len(name))
for i in range(len(args)):
f3.write('(\'{}\', \'{}\'),\n'.format(args[i].strip(), name[i].strip()))
@AlexBaranowski
AlexBaranowski / redshift.conf
Created December 19, 2017 00:30
My redshift conf
; Mostly taken from http://jonls.dk/redshift/
; Global settings for redshift
[redshift]
; Set the day and night screen temperatures
temp-day=5700
temp-night=3200
; Enable/Disable a smooth transition between day and night
; 0 will cause a direct change from day to night screen temperature.
; 1 will gradually increase or decrease the screen temperature.
@AlexBaranowski
AlexBaranowski / find_all_req.sh
Last active December 11, 2017 15:23
Find all python import in given directory with find && grep.
find . -name '*\.py' -exec grep '^import ' {} \; | sort | uniq > req
@AlexBaranowski
AlexBaranowski / v_simple.sh
Last active April 6, 2018 10:39
BASH - check as root and command
#!/bin/bash
#
# name: TODO_NAME
#
# description:TODO_DESC
# default log file: /var/log/TODO_LOG
#
# Copyright 2016 TODO, Inc.
# TODO_NAME <TODO_MAIL>
#