Skip to content

Instantly share code, notes, and snippets.

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 / bulk-template.sh
Created Dec 21, 2020
bulk Moodle template restore
View bulk-template.sh
# 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 Dec 4, 2020
Moodle - delete duplicate blocks in courses
View blocks-with-duplicates.sql
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 Oct 9, 2020
fix files modes in Drive git repos
View fix-drive-file-modes.sh
#/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 Jul 1, 2020
git branches: master -> main
View master-to-main.fish
#!/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
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
phette23 / new-mac.md
Last active Oct 6, 2020
setting up a new Macbook
View new-mac.md
  • 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 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
  • run the set up scripts from dotconfig:
    • homebrew first (pretty much everything relies on it)
@phette23
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(() => {
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 Jan 7, 2020
Koha public report -> HTML table
View report2table.js
$.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
@phette23
phette23 / publication.sql
Created Oct 21, 2019
get people's publications from CCA portal
View publication.sql
SELECT u.first_name, u.last_name, u.email, pub.title, pub.published_in, pub.url, pub.date, pub.description
FROM people_ppublication pub
JOIN people_portalprofile prof ON (pub.object_id = prof.id)
JOIN people_userprofile u ON (prof.user_id = u.id)
@phette23
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="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>Do Re Mi</dc:title>
</oai_dc:dc>