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 Aug 27, 2021
create a CSV to populate NSO groups in Moodle > Upload Users
#!/usr/bin/env bash
# accepts three files that are just the copy-pasted email column from a Google Sheet
# some of the rows can be empty, also note that the course shortnames change year to year
# delete empty lines, remove "" from emails
sed -e '/^$/d' -e 's|@cca\.edu||' -i '.bak' $FRESH
sed -e '/^$/d' -e 's|@cca\.edu||' -i '.bak' $GRAD
phette23 /
Last active Aug 20, 2021
connect to Moodle Support Database in Google Cloud
#!/usr/bin/env fish
# Requires: gcloud installed, cca-integrations project config added
set PREVIOUS_PROJECT (gcloud config get-value project 2>/dev/null)
echo "Changing gcloud project from $PREVIOUS_PROJECT to cca-integrations"
gcloud config set project cca-integrations >/dev/null
# NOTE: you'll want to have this secret in your env or hardcoded here
echo $MDL_SUPPORT_DB_PW | pbcopy
set_color --bold
and echo 'The moodle_user password is on your clipboard; paste it at the prompt.'
set_color normal
phette23 / projectcount.js
Created Aug 3, 2021
todo.txt extension - count finished tasks by project references
View projectcount.js
#!/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
let projects = {}
phette23 /
Last active Jun 11, 2021
unenroll all students from Moodle course
# used for instance when First Year wants to drop sophomores from their home & replace with new incoming students
# COURSE = course id
USERS=$(moosh -n user-list --course $COURSE --course-role student)
moosh -n course-unenrol $COURSE $USERS
phette23 / npm-lsg-unlinked.js
Created May 25, 2021
list global npm packages that are not linked
View npm-lsg-unlinked.js
#!/usr/bin/env node
const { exec } = require("child_process")
exec('npm ls --global --json', (err, stdout, stderr) => {
if (err) throw err
const deps = JSON.parse(stdout).dependencies
// dependencies hash looks like:
// "linked-pkg": { "version": "1.0.0", "resolved": "file:..." },
// "global-pkg": { "version": "1.0.0" }, ...
phette23 / hide-pdf-urls.js
Last active Apr 19, 2021
hide 856$u PDFs in Koha if users aren't logged in
View hide-pdf-urls.js
// run 1) on opac-detail pages & 2) if no user is signed in
if (!!location.pathname.match('/cgi-bin/koha/') && !$('.loggedinusername').length) {
// replace 856$u links with a link to login instead
// this would need to be tweaked if there are multiple URLs per record
$('.results_summary.online_resources a')
.replaceWith('<a href="/cgi-bin/koha/">login to view PDF</a>')
phette23 / db-table-size.sql
Created Mar 31, 2021
get size of mysql tables in a database
View db-table-size.sql
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
-- replace DATABASE with the name of the db
WHERE table_schema = 'DATABASE'
ORDER BY (data_length + index_length) DESC
phette23 /
Created Mar 30, 2021
iterate over list of files & write information about them (including MIME type) to CSV
#!/usr/bin/env python3
import csv
import os
import subprocess
with open('files.csv', 'w') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['path', 'size (bytes)', 'time last accessed', 'time last modified', 'time created', 'mime type'])
with open('dbcheck-files.txt', 'r') as listfile:
for path in listfile:
phette23 /
Last active Mar 19, 2021
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 /
Last active Jan 14, 2021
use Panopto API to delete all empty subfolders of given folder
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')))