Skip to content

Instantly share code, notes, and snippets.

@stefan-matic
stefan-matic / AllowCloudFlareIPsOnly-80-443.ps1
Last active September 4, 2019 10:56
This will allow only CloudFlare IPs to access your webserver in order to limit origin IP leaks. Be sure to compare the IPs with the current CloudFlare list: (https://www.cloudflare.com/ips/)
New-NetFirewallRule -DisplayName "CloudFlare IPs" -Direction Inbound -LocalPort 80, 443 -Protocol TCP -Action Allow -RemoteAddress 173.245.48.0/20, 103.21.244.0/22, 103.22.200.0/22, 103.31.4.0/22, 141.101.64.0/18, 108.162.192.0/18, 190.93.240.0/20, 188.114.96.0/20, 197.234.240.0/22, 198.41.128.0/17, 162.158.0.0/15 ,104.16.0.0/12 ,172.64.0.0/13 ,131.0.72.0/22, 2400:cb00::/32, 2606:4700::/32, 2803:f800::/32, 2405:b500::/32, 2405:8100::/32, 2a06:98c0::/29, 2c0f:f248::/32
@stefan-matic
stefan-matic / dbbackup.bat
Created November 11, 2019 12:20
DB backup script using mysqldump.exe and S3 storage. Check variables to set your environment correctly.
@echo off
call "%LOCALAPPDATA%\Apps\Apps\nutcracker.bat"
:: Get data and time.
for /f "skip=1" %%d in ('wmic OS GET LocalDateTime') do (set ldt=%%d & goto PARSELDT)
:PARSELDT
set date=%ldt:~0,8%_%ldt:~8,4%
SETLOCAL EnableDelayedExpansion
@stefan-matic
stefan-matic / s3uploader.bat
Created November 14, 2019 08:47
Allows uploading to S3 using AWS CLI. Create folder "s3-upload" on your C:\ (root), and inside create the folder "files". Place the bat inside "s3-upload"
@echo off
color 02
SETLOCAL EnableDelayedExpansion
set s3-folder=C:\s3-upload
set test=specific-test-folder/
set demo=specific-demo-folder/
set prod=specific-production-folder/
set test-link=https://bucket-name.s3.eu-central-1.amazonaws.com/Path/To/S3/Folder
set demo-link=https://bucket-name.s3.eu-central-1.amazonaws.com/Path/To/S3/Folder
@stefan-matic
stefan-matic / AllowUniFiController.ps1
Created March 2, 2020 08:22
AllowUniFiController.ps1
New-NetFirewallRule -DisplayName "Unifi Controller TCP" -Direction Inbound -LocalPort 8080, 8443, 8880, 8843, 6789, 27117 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "Unifi Controller UDP" -Direction Inbound -LocalPort 3478, 5656-5699, 10001, 1900 -Protocol UDP -Action Allow
@stefan-matic
stefan-matic / docker-compose.yaml
Created May 28, 2020 11:44
Runs mysql under docker and enables automatic backups
version: '3.5'
volumes:
mysql_data:
external: true
driver: local
services:
mysql:
container_name: mysql
@stefan-matic
stefan-matic / InstallPowerToys.ps1
Created September 7, 2020 07:32
Download and Run Latest PowerToys Release
# Credits to MarkTiedemann for providing the original script and Splaxi for improving it
# https://gist.github.com/MarkTiedemann/c0adc1701f3f5c215fc2c2d5b1d5efd3
$repo = "microsoft/PowerToys"
$filenamePattern = "*.msi"
$innerDirectory = $true
$preRelease = $false
if ($preRelease) {
$releasesUri = "https://api.github.com/repos/$repo/releases"
@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
@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 / 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 / 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