Skip to content

Instantly share code, notes, and snippets.

"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 /
Created Dec 21, 2020
bulk Moodle template restore
# NOTE: make sure the course-list query returns the courses you want and also that the right backup is
# referenced in the course-restore command. The query should probably use shortnames (e.g. example is
# all First Year 4D courses), as opposed to something like categories, because you can target metacourses.
for id in $(moosh -n course-list -i 'shortname LIKE "FYCST-1120%-2021SP"'); do
moosh -n course-restore --overwrite ~/backup-*.mbz $id;
phette23 / blocks-with-duplicates.sql
Last active Dec 4, 2020
Moodle - delete duplicate blocks in courses
View blocks-with-duplicates.sql
SELECT, b.blockname, b.parentcontextid,, c.shortname
FROM {prefix}_block_instances b
JOIN (SELECT * FROM {prefix}_context WHERE contextlevel = 50) ctx ON b.parentcontextid =
JOIN {prefix}_course c ON = ctx.instanceid
-- this list of block types might need to be changed depending on Moodle instance
WHERE b.blockname IN ('search_forums', 'recent_activity', 'calendar_upcoming', 'news_items')
-- must be a better way but I just look for blocks in courses we know have duplicates
-- so we use the other query as a sub-query
phette23 /
Created Oct 9, 2020
fix files modes in Drive git repos
#/usr/bin/env bash
# Google Drive messes up file modes by setting everything to 644 so all your executables are screwed up
# I store a bunch of git repos in a Drive folder (don't ask why) & this fixes the file modes by just checking out everything
for dir in $(ls -d */); do
cd ${dir}
git status 2&>/dev/null && git checkout -- .
cd -
phette23 /
Last active Jul 1, 2020
git branches: master -> main
#!/usr/bin/env fish
# loop over repos and create local & remote "main" branches
set dirs (exa -D) # or could do the less elegant `ls -d */`
for dir in $dirs
set_color --bold
echo "Entering $dir"
set_color normal
cd $dir
# test for git repo
phette23 / oak-legacy-subject.js
Created May 1, 2020
add OAK campus legacy MODS subject (openEQUELLA)
View oak-legacy-subject.js
// only add if not already there, add as last subject with "local" authority
if (!xml.contains('mods/subject/topic', 'Oakland Campus Legacy')) {
var len = xml.count('mods/subject')
xml.set('mods/subject[' + len + ']/@authority', 'local')
xml.set('mods/subject[' + len + ']/topic', 'Oakland Campus Legacy')
phette23 /
Last active Oct 6, 2020
setting up a new Macbook
  • open App Store, start the XCode download (this will take forever, start in on steps below while it's happening) QUESTION is this still necessary? The command-line tools aren't enough?
  • download Google Drive or "Backup & Sync" or whatever they are calling it these days
  • download 1Password
  • open 1P and sync the password VAULT
  • once XCode has finished, start doing command line things
    • git clone
    • git clone
    • git clone
  • run the set up scripts from dotconfig:
    • homebrew first (pretty much everything relies on it)
phette23 / all_full_text.js
Last active Feb 12, 2020 — forked from mreidsma/all_full_text.js
Simple script to add link to link resolver in Summon results
View all_full_text.js
setTimeout(() => {
}, 1000);
function libScope(scope) {
// Watch results feed for changes...
scope.$watchCollection('feed', () => {
// give AngularJS time to update the DOM
// Probably need to wait a few seconds before running this to make sure the DOM loads
setTimeout(function() {
phette23 / report2table.js
Created Jan 7, 2020
Koha public report -> HTML table
View report2table.js
$.get('', function(data) {
// header row
let html = '<table><thead><th>Field One</th><th>Field Two</th><th>Field Three</th></thead><tbody>'
// content rows
data.forEach(row => {
html += '<tr>'
row.forEach(value => html += `<td>${value}</td>`)
html += '</tr>'
// close tags (optional), add to DOM
phette23 / publication.sql
Created Oct 21, 2019
get people's publications from CCA portal
View publication.sql
SELECT u.first_name, u.last_name,, pub.title, pub.published_in, pub.url,, pub.description
FROM people_ppublication pub
JOIN people_portalprofile prof ON (pub.object_id =
JOIN people_userprofile u ON (prof.user_id =
phette23 / dublincore.xml
Created Oct 8, 2019
Complete MODS => OAI DC transformation
View dublincore.xml
<?xml version="1.0"?>
<oai_dc:dc xmlns:oai_dc="" xmlns:dc="">
<dc:title>Do Re Mi</dc:title>