Skip to content

Instantly share code, notes, and snippets.

@isaaclw
isaaclw / manage_syncthing.sh
Last active January 10, 2023 14:25
syncthing management
#!/bin/bash
cmd="$1"
get_api_key() {
keyfile="manage_syncthing_api_key"
if ! [ -e ~/.config/"$keyfile" ] || [ -z "$(cat ~/.config/"$keyfile")" ]; then
echo "Get the API key from syncthing, and then paste it below"
read -p "Enter API Key: " API_KEY
echo "$API_KEY" > ~/.config/"$keyfile"
@isaaclw
isaaclw / wordle.sh
Last active November 27, 2022 15:11
wordle
#!/bin/bash
INCLUDE=
EXCLUDE=
COUNT=
while getopts ":i:e:m:ch" flag; do
case $flag in
i|include) INCLUDE="$OPTARG";;
e|exclude) EXCLUDE="$OPTARG";;
c|count) COUNT=1;;
@isaaclw
isaaclw / db age
Created September 17, 2021 19:43
Postgresql database age #postgres #age #database
SELECT (pg_stat_file('base/'||oid ||'/PG_VERSION')).modification, datname FROM pg_database;
@isaaclw
isaaclw / sql_blocking_queries
Last active June 23, 2020 15:54
pg blocking queries #psql #db #postgres #sql
SELECT blocks.pid,
(select query from pg_stat_activity where pid = blocks.pid) as blocked_query,
blocks.blocking_pid,
(select query from pg_stat_activity where pid = blocks.blocking_pid) AS blocking_query
FROM (
SELECT pid, unnest(pg_blocking_pids(pid)) AS blocking_pid
FROM pg_locks
WHERE granted = false
) AS blocks;
@isaaclw
isaaclw / parse_and_date_photos.py
Created May 28, 2020 16:52
Bulk Date Photos #media #pictures
#!/usr/bin/python
"""
Run this script twice:
1) Run it with the 'search' flag, and an output csv file.
- Then edit the csv file, and update the final column. The found date is
used as a reference
If you want to skip a file, don't include it.
The date should be in the format;
%Y:%m:%d %H:%M:%S
@isaaclw
isaaclw / resize_pictures.py
Created May 28, 2020 16:49
Bulk Resize Pictures #media #pictures
#!/usr/bin/python3
"""
Update the LONG_SIZE and SHORT_SIZE
then provide a folder to scan (scan_folder)
and a folder to write new files (output_folder)
"""
import glob
import os
import subprocess
@isaaclw
isaaclw / clean_sync_conflict.sh
Last active November 27, 2022 15:48
Clean up syncthing conflicts #bash #fs #vim
#!/bin/bash
compare_files() {
file="$1"
original="$2"
case "$(file "$original")" in
*JPEG*|*PNG*)
identify "$file"
identify "$original"
if sudo -Hu "$USER" xdpyinfo -display "$DISPLAY" > /dev/null 2>&1; then
gthumb "$file" "$original"
@isaaclw
isaaclw / mysql_add_user.sql
Last active February 11, 2020 14:14
MySQL add user
CREATE DATABASE matomo_db_name_here;
CREATE USER 'matomo'@'localhost' IDENTIFIED BY 'my-strong-password-here';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON matomo_db_name_here.* TO 'matomo'@'localhost';
flush privileges;
@isaaclw
isaaclw / random_words
Created November 25, 2019 15:02
List 10 random words #bash
#!/bin/bash
WORDFILE="/usr/share/dict/words"
NUMWORDS=10
#Number of lines in $WORDFILE
tL=`awk 'NF!=0 {++c} END {print c}' $WORDFILE`
for i in `seq $NUMWORDS`; do
rnum=$((RANDOM%$tL+1));
sed -n "$rnum p" $WORDFILE;
@isaaclw
isaaclw / long_running.sql
Created November 22, 2019 17:59
Get Long Running Queries #psql #load
select pid, now() - query_start, query
from pg_stat_activity
where state = 'active' and now() - query_start > '5min';