Skip to content

Instantly share code, notes, and snippets.

View jdforsythe's full-sized avatar

Jeremy Forsythe jdforsythe

View GitHub Profile
@jdforsythe
jdforsythe / join-json.sql
Created July 31, 2019 13:06
PostgreSQL JOINs as nested JSON objects
-- returns a child object with single parent as nested JSON object
--
-- {
-- "id": 155,
-- "name": "Stephen King",
-- "publisher": {
-- "id": 13,
-- "name": "Paladin Books"
-- }
-- }
@jdforsythe
jdforsythe / connect.ps1
Last active February 19, 2024 11:05
Remote Desktop Auto Login Powershell Script
cmdkey /list | ForEach-Object{if($_ -like "*target=TERMSRV/*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
echo "Connecting to 192.168.1.100"
$Server="192.168.1.100"
$User="Administrator"
$Password="AdminPassword"
cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server
#!/bin/bash
sudo fdisk -lu /dev/sdb
# Disk /dev/sdb: 14.9Gib, 1593153946 bytes, 31116288 sectors
# Units: sectors of 1 * 512 = 512 bytes
# Secor size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disklabel type: dos
# Disk identifier: 0x9c4e41cd
@jdforsythe
jdforsythe / mac-build-pgmodeler.md
Last active February 1, 2023 07:05
Build pgmodeler on Mac with Homebrew-installed pg and openssl

Building pgmodeler for Mac

Check requirements at https://pgmodeler.io/installation.

You will need Qt 5.9.x installed, full XCode installed, and homebrew installation of postgres and openssl.

The example below is v10.5 of PG and v5.9.6 of Qt, modify accordingly. Also, replace {{USERNAME}} with you Mac username.

The installation is the same as the instructions at the link above. There are a few path differences due to homebrew installation locations.

@jdforsythe
jdforsythe / .gitconfig
Created March 13, 2019 15:37
Git rename stash alias
[alias]
rename-stash = "!_() { if [ -z \"$1\" ] || [ -z \"$2\" ]; then echo \"git rename-stash 0 NewName\" && echo \"\" && git stash list && exit 1; else stash=\"stash@{$1}\"; rev=$(git rev-parse \"${stash}\"); git stash drop \"${stash}\" || exit 1; git stash store -m \"$2\" \"$rev\" || exit 1; git stash list; fi }; _"
@jdforsythe
jdforsythe / changes-between-commits.sh
Last active October 18, 2021 21:45
Show stats in git repo
#!/bin/bash
# did you pass all the arguments?
nl=$'\n'
if [ $# -lt 3 ]; then
echo 1>&2 "$0: not enough arguments${nl}USAGE: changes-between-commits.sh \"Author Name\" FROM_COMMIT_SHA TO_COMMIT_SHA"
exit 2
elif [ $# -gt 3 ]; then
echo 1>&2 "$0: too many arguments${nl}USAGE: changes-between-commits.sh \"Author Name\" FROM_COMMIT_SHA TO_COMMIT_SHA"
exit 2
@jdforsythe
jdforsythe / write-offenders.sh
Created July 13, 2017 12:40
Highest disk usage offending processes
#!/bin/bash
## requires iotop to be installed
sudo iotop -botqqqk --iter=600 >> iotop.log
cat iotop.log \
## remove characters before write speed
| cut -c 41- \
## look for any write speed that is non-zero
@jdforsythe
jdforsythe / find-parent.sh
Created December 5, 2019 21:54
Git find parent branch
git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//'
@jdforsythe
jdforsythe / oldest-ancestor-alias.sh
Created August 2, 2016 12:29
GIT find commit where branched off
#!/bin/bash
# "master" is the name of your main branch you'll be comparing to, or you can pass the "parent" branch as an argument
# it compares against the current branch by default, but you can pass a second argument to specify a child branch
# this creates a permanent alias so you can use `git oldest-ancestor` to get the oldest ancestor of the current branch at any time
git config --global alias.oldest-ancestor '!zsh -c '\''diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1'\'' -'
@jdforsythe
jdforsythe / sourcetree-open-on-github.bat
Created October 28, 2016 13:48
SourceTree Open on GitHub Custom Actions
ruby d:\dev\sh\sourcetree\sourcetree-open-on-github.rb %1