Skip to content

Instantly share code, notes, and snippets.

@stefan-matic
stefan-matic / unraid-traefik-labels.sh
Last active June 13, 2024 20:27
Automate adding Traefik labels to containers
#!/bin/bash
############################################################################################
# Run the script as ./unraid-traefik-labels.sh main_clicks <APP_NAME> <APP_PORT> #
# Example: ./unraid-traefik-labels.sh main_clicks my-app 5554 #
# #
# To get coordinates for click options place your mouse on the desired location and use: #
# eval $(xdotool getmouselocation --shell) #
# echo $X #
# echo $Y #
@stefan-matic
stefan-matic / unifi_cert_replacement.sh
Created October 18, 2023 20:39
Unifi certificate keystore replacement
#!/bin/bash
#
# This script copies our domain cert over to the gateway. We use a wildcard cert so we can have
# different names for the guest portal and main admin page if we want.
#
# Our pub ssh key is in /root/.ssh/authorized_keys on the gateway so we
# don't need a password to run it.
#
# Call this from cron once in a while to make sure your cert stays updated.
# Not too often though as it restarts the whole network container which isn't very desireable.
@stefan-matic
stefan-matic / transfer.fish
Last active October 18, 2023 14:59
Easy file sharing from the command line using http://transfer.sh through fish shell
function transfer --description 'Easy file sharing from the command line using http://transfer.sh'
if test (count $argv) -eq 0
echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md";
return 1;
end
set tmpfile ( mktemp -t transferXXX );
if tty -s
set basefile (basename $argv[1] | sed -e 's/[^a-zA-Z0-9._-]/-/g');
curl -v --progress-bar --upload-file $argv[1] "https://transfer.sh/$basefile" 2>&1 | grep -i 'https://transfer.sh' >> $tmpfile;
else
@stefan-matic
stefan-matic / init-terraform-backend.sh
Last active October 17, 2023 16:08
Quick and easy script to create an S3 bucket and dynamodb for the Terraform S3 backend. Run the script without parameters to create everything (e.g. ./init-terraform-backend.sh) or call each function individually if you want to do step-by-step (e.g ./init-terraform-backend create_terraform_s3_bucket).
#!/bin/bash
# Edit these variables:
# Make sure that the PROJECT is something unique,
# since the s3 bucket name needs to be globally unique
export PROJECT="YOUR_PROJECT"
export AWS_REGION="YOUR_REGION"
export BUCKET="${PROJECT}-terraform-state-files"
export LOCK_TABLE="${PROJECT}-terraform-locks"
@stefan-matic
stefan-matic / swap-ec2-volumes.sh
Last active May 25, 2022 10:15
Swaps volumes of two EC2 instance using AWS CLI. Includes Terraform to spawn two ec2 instances for testing.
#!/bin/bash
AWS_PROFILE="YOUR-AWS-PROFILE"
AWS_REGION="YOUR-AWS-REGION"
# OLD INSTANCE INFO
OLD_INSTANCE_ID="i-0123456789abcdef0"
OLD_INSTANCE_VOLUME_ID="vol-0123456789abcdef0"
OLD_INSTANCE_MOUNT_POINT="/dev/sda1"
@stefan-matic
stefan-matic / move-files.ahk
Last active April 3, 2022 18:48
Allow moving files to specified folders in the code based on the key pressed. Edit lines 6-10 for key binds and 16-25 for folder paths. F1 suspends the hotkeys so you can use the keyboard normally
GroupAdd, WinGroupFolder, ahk_class CabinetWClass
GroupAdd, WinGroupFolder, ahk_class ExploreWClass
#IfWinActive ahk_group WinGroupFolder
F1::Suspend
q::
t::
f::
g::
d::
@stefan-matic
stefan-matic / copy_to_docker_volume.sh
Created October 28, 2021 15:09
Copies each file in the passed directory to container
#!/bin/bash
# docker cp test.txt pgadmin_container:/var/lib/pgadmin/storage/admin_admin.com/
# change line 7 if more granularity is needed in the search pattern
for i in ${1}/*
do
docker cp $i pgadmin_container:/var/lib/pgadmin/storage/admin_admin.com/
done
@stefan-matic
stefan-matic / psql-import-csv.sh
Created October 28, 2021 14:29
Import CSV files into PostgreSQL
#!/bin/bash
# Pass $1 as the table
# Pass $2 as the path to the csv file
psql -h <HOSTNAME> -U postgres -d <DATABASE> -c "\copy ${1} from ${2} delimiter ',' csv header;"
@stefan-matic
stefan-matic / README.md
Last active January 27, 2021 11:58
Android remote control with scrcpy

You need scrcpy and adb

https://github.com/Genymobile/scrcpy

You need to enable ADB debugging (USB and WiFi) Depending on your phone this can have different naming conventions.

I set it up first normally with scrcpy via USB for testing, and then I use the script above. Be sure to replace <PHONE_IP> with your usual phone's local home IP (e.g. adb connect 192.168.1.120)

@stefan-matic
stefan-matic / gib-server.sh
Last active December 9, 2020 18:17
Interactive droplet spawn tool using doctl and bash
#!/bin/bash
#todo is found at the top and randomly in the script
#spin for sleep time
#https://stackoverflow.com/questions/12498304/using-bash-to-display-a-progress-indicator
#needs a better implementation than wait n seconds to ssh - something like "wait for droplet status to become active"
#allow to use custom image_slug