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 / crcheckall.js
Created March 1, 2023 18:56
select all checkboxs on chrome's history page chrome://history
View crcheckall.js
.querySelectorAll('history-item').forEach((hi, i) => {
const cbox = hi.shadowRoot.querySelector('cr-checkbox')
// merely setting checked = true doesn't work, chrome wants you to click them
if (!cbox.checked)
phette23 / homebrew
Created December 1, 2022 17:34
bumping a homebrew formula version in brief
View homebrew

The How to Open a Homebrew Pull Request documentation is great. This doc assumes you've already created a fork of homebrew-core named after your user and a branch tracking the master of the fork.

cd (brew --repository homebrew/core)
brew update
git checkout phette23 # tracks master branch of fork
git pull # might need to sync fork to homebrew?
set FORMULA marcli # name of the project you're bumping
set VERSION 1.1.0 # semantic version
brew bump-formula-pr --no-fork --url$FORMULA/archive/refs/tags/v$VERSION.tar.gz project
phette23 /
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 = ''
to_address = ''
msg = EmailMessage()
phette23 /
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
if ! test -f LICENSE.txt
echo "Downloading license text"
phette23 /
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 /
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
# 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 / projectcount.js
Last active February 1, 2023 00:15
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
const ctxregex = /(@[A-Za-z0-9]+)\s/g
let counts = {}
phette23 /
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 / npm-lsg-unlinked.js
Created May 25, 2021 18:32
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 February 19, 2022 16:18
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>')