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 / download.fish
Last active March 19, 2021 15:39
bulk download Archive-It WARC files
#!/usr/bin/env fish
set USER username
set PASS password
set COLLECTION 123456
set JSONFILE data.json
set URLSFILE urls.txt
set DONEFILE done.txt
set LIMIT 8
@phette23
phette23 / delete-empty-subfolders.py
Last active January 14, 2021 23:32
use Panopto API to delete all empty subfolders of given folder
#!python3
import sys
import argparse
import requests
import urllib3
from panopto_folders import PanoptoFolders
from os.path import dirname, join, abspath
sys.path.insert(0, abspath(join(dirname(__file__), '..', 'common')))
@phette23
phette23 / bulk-template.sh
Created December 21, 2020 19:15
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;
done
@phette23
phette23 / blocks-with-duplicates.sql
Last active December 4, 2020 19:35
Moodle - delete duplicate blocks in courses
SELECT b.id, b.blockname, b.parentcontextid, c.id, c.shortname
FROM {prefix}_block_instances b
JOIN (SELECT * FROM {prefix}_context WHERE contextlevel = 50) ctx ON b.parentcontextid = ctx.id
JOIN {prefix}_course c ON c.id = 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
AND c.id IN (
SELECT c.id
@phette23
phette23 / fix-drive-file-modes.sh
Created October 9, 2020 02:12
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 -
done
@phette23
phette23 / master-to-main.fish
Last active July 1, 2020 22:06
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
phette23 / oak-legacy-subject.js
Created May 1, 2020 21:33
add OAK campus legacy MODS subject (openEQUELLA)
// 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
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 / all_full_text.js
Last active February 12, 2020 20:35 — forked from mreidsma/all_full_text.js
Simple script to add link to link resolver in Summon results
setTimeout(() => {
libScope(angular.element('html').scope());
}, 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
phette23 / report2table.js
Created January 7, 2020 18:05
Koha public report -> HTML table
$.get('https://library.cca.edu/cgi-bin/koha/svc/report?id=130', 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