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 / html-email.py
Created November 22, 2022 00:29
demo of sending HTML email in syllabus reminders project
from email.message import EmailMessage
import smtplib
from reminders.config import config
from_address = '[email protected]'
to_address = '[email protected]'
msg = EmailMessage()
@phette23
phette23 / git-license.fish
Created October 26, 2022 23:43
add ECL-2.0 license to current repo
#!/usr/bin/env fish
if ! git status 2&>/dev/null
echo "Must be run inside a git repo, run 'git init' first if need be" >&2
exit 1
end
begin
if ! test -f LICENSE.txt
echo "Downloading license text"
wget https://raw.githubusercontent.com/cca/koha_snippets/main/LICENSE.txt
@phette23
phette23 / convert.py
Created September 16, 2022 18:22
Convert KBART to Serials Solution 360 Core database template
'''
Translate KBART file from OAPEN into Serials Solutions Client Center aka 360
Core database format. See the DatabaseTemplate.txt file for details.
'''
import csv
def get_first_isbn(isbns):
""" return the first in a list of semicolon-separated ISBNs
@phette23
phette23 / nso-groups.sh
Created August 27, 2021 22:03
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
FRESH=$1
GRAD=$2
TRSFR=$3
# delete empty lines, remove "cca.edu" from emails
sed -e '/^$/d' -e 's|@cca\.edu||' -i '.bak' $FRESH
sed -e '/^$/d' -e 's|@cca\.edu||' -i '.bak' $GRAD
@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 / unenroll-students.sh
Last active June 11, 2021 23:26
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
phette23 / npm-lsg-unlinked.js
Created May 25, 2021 18:32
list global npm packages that are not linked
#!/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
phette23 / hide-pdf-urls.js
Last active February 19, 2022 16:18
hide 856$u PDFs in Koha if users aren't logged in
// run 1) on opac-detail pages & 2) if no user is signed in
if (!!location.pathname.match('/cgi-bin/koha/opac-detail.pl') && !$('.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/opac-user.pl">login to view PDF</a>')
}
@phette23
phette23 / db-table-size.sql
Created March 31, 2021 14:56
get size of mysql tables in a database
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
phette23 / files.py
Created March 30, 2021 23:45
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: