Skip to content

Instantly share code, notes, and snippets.

View ivuorinen's full-sized avatar

Ismo Vuorinen ivuorinen

View GitHub Profile
@ivuorinen
ivuorinen / release.sh
Created March 23, 2020 11:58
Git-Flow Release Automation with version bumping and changelog generation
#!/usr/bin/env bash
# Git-flow release automation with
# version bumping and changelog generation
#
# Based on many great starting points:
# https://gist.github.com/mareksuscak/1f206fbc3bb9d97dec9c
# https://gist.github.com/pete-otaqui/4188238
# https://gist.github.com/bclinkinbeard/1331790
@ivuorinen
ivuorinen / ip.php
Last active March 16, 2020 12:16
Displays visitor IP
<?php
function getUserIpAddr() {
if(!empty($_SERVER['HTTP_CLIENT_IP'])){
return $_SERVER['HTTP_CLIENT_IP'];
}
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
@ivuorinen
ivuorinen / traefik-truncate-log.sh
Last active May 7, 2025 08:38
Find and truncate Traefik log
#!/usr/bin/env bash
# Truncate Traefik high volume log
# CRONTAB: 0 */2 * * * /root/scripts/traefik-truncate-log.sh > /dev/null 2>&1
TRAEFIK=$(docker ps --no-trunc | grep 'traefik' | awk '{ print $1 }');
TRAEFIK_PATH="/var/lib/docker/containers/$TRAEFIK/";
/usr/bin/find "$TRAEFIK_PATH" -type f \( -name "*-json.log" \) -size +5M -exec bash -c 'echo "" > "$1"' _ {} \;
@ivuorinen
ivuorinen / install-letsencrypt-to-older-jre.sh
Created February 17, 2020 13:48
Install Let's Encrypt CA to JRE keystore, for you know, older JIRA for example
#!/bin/bash
set -e
STORE_PASS=changeit
JAVA_HOME=${1-text}
[ $# -eq 0 ] && { echo "Usage: sudo $0 \$(/usr/libexec/java_home -v '1.8*')" ; exit 1; }
KEYSTORE=$JAVA_HOME/jre/lib/security/cacerts
@ivuorinen
ivuorinen / docker-mssql-database-restore.sh
Last active January 21, 2020 09:33
Docker MSSQL Database: Copy backup to container
# Run these as root or prefix with sudo on the Docker host machine
# $MACHINE = Container ID, or part of it.
# Usually 3 first chars are enough. Get it with `docker ps|grep mssql-server`
# Create backup folder
docker exec -it $MACHINE mkdir /var/opt/mssql/backup
# Copy backups to the machine
docker cp backup.bak $MACHINE:/var/opt/mssql/backup
@ivuorinen
ivuorinen / reset-git-password.sh
Created May 5, 2019 09:01
resets stored git passwords on macOS
# in terminal write the following lines,
# after the last just push enter twice.
git credential-osxkeychain erase
host=bitbucket.org
protocol=git
@ivuorinen
ivuorinen / date-regexp.php
Created January 22, 2019 13:47
From 20190122-124559 to 2019-01-22 12:45:59 with preg_replace
<?php
// From 20190122-124559 to 2019-01-22 12:45:59
$patterns = '/(19|20)(\d{2})(\d{1,2})(\d{1,2})-(\d{1,2})(\d{1,2})(\d{1,2})/';
$replace = '\1\2-\3-\4 \5:\6:\7';
$date = preg_replace($patterns, $replace, $date);
@ivuorinen
ivuorinen / docker_clean.sh
Created January 8, 2019 14:40
Docker cleanup
#!/bin/sh
for image in $(/usr/bin/docker images -q -f dangling=true);
do
/usr/bin/docker rmi $image;
done
for volume in $(/usr/bin/docker volume ls -qf dangling=true);
do
/usr/bin/docker volume rm $volume;
@ivuorinen
ivuorinen / swapper.sh
Created January 2, 2019 13:17
swapfile automation
#!/bin/bash
# Swapfile generator
#
# Copyright 2019 Ismo Vuorinen <[email protected]>
# Licensed under MIT <https://opensource.org/licenses/MIT>
_err () {
echo "(!) Error: $1" >&2; exit 1
}
# Remove files from your specified path.
git filter-branch --force --index-filter 'git rm --cached -r --ignore-unmatch dir/with/large/files/*' --prune-empty --tag-name-filter cat -- --all
rm -rf .git/refs/original/ && git reflog expire --expire=now --all && git gc --prune=now && git gc --aggressive --prune=now