Skip to content

Instantly share code, notes, and snippets.

View petergi's full-sized avatar
💭
Just Busy Living On The Side Of A Square

Peter Giannopoulos petergi

💭
Just Busy Living On The Side Of A Square
View GitHub Profile
@petergi
petergi / glab-project.sh
Created July 13, 2026 12:13
Get gitlab commits for a project
glab api --hostname hostname "projects/project-name/repository/commits" 2>&1 | python3 -c "
import json,sys
d = json.load(sys.stdin)
for c in d:
print(c['short_id'], c['title'])
"
# obviously use your own actionid, org, repo and look for the text you used in your yaml
last=""
while true; do
s=$(gh run view <actionid> --repo org/repo --json status,conclusion,jobs 2>/dev/null) || { sleep 20; continue; }
st=$(echo "$s" | python3 -c "import sys,json;d=json.load(sys.stdin);print(d['status'],d.get('conclusion'))" 2>/dev/null)
cur=$(echo "$s" | python3 -c "
import sys,json
d=json.load(sys.stdin)
out=[]
for j in d.get('jobs',[]):
echo "=== dev vs main divergence ==="; git rev-list --left-right --count origin/main...origin/dev; echo "(left=main-only, right=dev-only)"; echo; echo "=== commits in dev not in main (last 20) ==="; git log --oneline origin/main..origin/dev | head -20; echo; echo "=== commits in main not in dev ==="; git log --oneline origin/dev..origin/main | head -20; echo "(none above = main fully contained in dev)"
@petergi
petergi / Covert to PNG.sh
Created May 22, 2026 02:11
Convert JPG, JPEG, WEBP, and AVIF images to PNG.
#!/usr/bin/env bash
# =========================================================
# to-png
#
# Convert JPG, JPEG, WEBP, and AVIF images to PNG.
#
# Requirements:
# brew install imagemagick
# brew install webp
python3 -m json.tool /path/to/file/my_json_file.json > /dev/null && echo OK
pwd
fnm current
ls .nvmrc .node-version 2>/dev/null
# walk upward looking for a version file:
d=$PWD; while [ "$d" != "/" ]; do ls "$d"/.nvmrc "$d"/.node-version 2>/dev/null; d=$(dirname "$d"); done
@petergi
petergi / Reverse a file in Neovim.txt
Created April 8, 2026 15:53
Reverse entire file. The first pass of :g marks every line matching {pattern}, while the second pass (again starting at the file's beginning and proceeding to the end) performs the [cmd]. Note: if :g processed lines in any order other than from top to bottom, this command would not work.
:g/^/m0
local function system(command)
local file = assert(io.popen(command, "r"))
local output = file:read("*all"):gsub("%s+", "")
file:close()
return output
end
@petergi
petergi / Regex to Match U.S. ZIP and Canadian Postal Codes.sh
Created April 8, 2026 15:51
Matches US ZIP, ZIP + 4, and Canadian Postal Codes
/(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/
// Checks if a date is before another date.
// - Use the less than operator (`<`) to check if the first date comes before the second one.
const isBeforeDate = (dateA, dateB) => dateA < dateB;
isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true