Skip to content

Instantly share code, notes, and snippets.

View phette23's full-sized avatar
🌹
"you're right, no human being would stack books like this"

Eric Phetteplace phette23

🌹
"you're right, no human being would stack books like this"
View GitHub Profile
@phette23
phette23 / update-repos.fish
Last active March 22, 2024 04:34
Shell script to run `git pull` inside all subdirectories which are git repositories. I keep a number of projects in a folder & this helps me avoid manually updating each.
#!/usr/bin/env fish
# similar script in Fish
# still under construction, need to quiet `git status` more effectively
function update -d 'Update git repo'
git stash --quiet
git pull
git stash apply --quiet
end
@phette23
phette23 / vlog.fish
Last active February 28, 2024 16:33
download all EQUELLA logs from a specified day on both app nodes
#!/usr/bin/env fish
# usage: vlog [date string] e.g. `vlog yesterday` or just `vlog` (for today's logs)
# requires SSH aliases for both app nodes (v1 & v2)
set today (gdate "+%Y-%m-%d")
if test -n "$argv[1]"
# need to use gnu date to get the human readable --date parameter
set d (gdate --date="$argv[1]" "+%Y-%m-%d")
# there can be multiple logs per day, rsync does this in only 1 ssh connection (requires rsync 3+)
rsync -ruzvhP v1:/opt/equella/logs/resource-centre/$d/ :/opt/equella/logs/tomcat/$d/ v1-$d
rsync -ruzvhP v2:/opt/equella/logs/resource-centre/$d/ :/opt/equella/logs/tomcat/$d/ v2-$d
@phette23
phette23 / current-dir-in-iterm-tab-title.sh
Last active January 4, 2024 10:20
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see: ss64.com/bash/syntax-prompt.html
@phette23
phette23 / backup-db-table.sh
Last active December 14, 2023 21:54
retroactively add db entries to group
# backup the mdl_data_records table before we modify it
gcloud sql export sql mysql-prod-1 gs://cca-manual-db-dumps/(dt)-mdl_data_records.sql -d m_prod1 -t mdl_data_records
@phette23
phette23 / projectcount.js
Last active October 30, 2023 15:39
todo.txt extension - count finished tasks by project references
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const readline = require('readline')
const todo_dir = process.env.TODO_DIR
// TODO we could make this optionally count todo.txt too e.g. with a CLI flag
const done_file = path.join(todo_dir, 'done.txt')
const projregex = /(\+[A-Za-z0-9]+)(\s|$)/g
const ctxregex = /(@[A-Za-z0-9]+)(\s|$)/g
let counts = {}
@phette23
phette23 / download.fish
Created October 27, 2023 23:01
download all VAULT items
#!/usr/bin/env fish
# download ALL live vault items to item.json and metadata.xml files
# 47283 total items, we can download 50 at a time
set total (eq search -l 1 | jq '.available')
set length 50
set pages (math floor $total / $length)
for i in (seq 0 $pages)
set start (math $i \* $length)
echo "Downloading items $start to" (math $start + $length)
eq search -l $length --info metadata --start $start > .tmp/$i.json
@phette23
phette23 / syllabi-section-check.js
Created October 20, 2023 15:54
check if sections syllabi are on VAULT search results page
// check if these sections appear on EQUELLA search results page
const sections = [
'GELCT-6700-2',
'LITPA-2000-10',
'WRITE-6000-2',
]
console.log(`Checking for ${sections.length} section codes`)
// return list of missing sections
const missing = sections.filter(s => {
@phette23
phette23 / warc-download.sh
Created October 20, 2023 15:40
download Archive-It WARCs to backup
#!/usr/bin/env fish
# used for Art Practical site
# fill in credentials
set USER username
set PASS password
set COLLECTION 15633
# destination files
set JSONFILE data.json
@phette23
phette23 / new-mac.md
Last active October 17, 2023 18:09
setting up a new Macbook
  • xcode-select --install to make git work
  • download Google Drive or "Backup & Sync" or whatever they are calling it these days
  • download 1Password https://1password.com/
  • open 1P and sync the password VAULT
  • once XCode has finished, start doing command line things
    • git clone https://github.com/phette23/dotconfig.git
    • git clone https://github.com/phette23/bashrc.git
    • git clone https://github.com/phette23/fishrc.git
    • these all have bash ./copy.sh scripts to install them
  • run the set up scripts from dotconfig:
@phette23
phette23 / clip.js
Created June 18, 2014 23:55
Pipe to Clipboard in Node.js (Mac OS X only)
var clipboard = require('child_process').spawn('pbcopy')
, data = 'put whatever data here';
clipboard.stdin.write(data);
clipboard.stdin.end();