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 / crcheckall.js
Created March 1, 2023 18:56
select all checkboxs on chrome's history page chrome://history
View crcheckall.js
document
.querySelector('history-app').shadowRoot
.querySelector('history-list').shadowRoot
.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) cbox.click()
})
@phette23
phette23 / homebrew bump.md
Created December 1, 2022 17:34
bumping a homebrew formula version in brief
View homebrew bump.md

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 https://github.com/account/$FORMULA/archive/refs/tags/v$VERSION.tar.gz project
@phette23
phette23 / html-email.py
Created November 22, 2022 00:29
demo of sending HTML email in syllabus reminders project
View html-email.py
from email.message import EmailMessage
import smtplib
from reminders.config import config
from_address = 'ephetteplace@cca.edu'
to_address = 'ephetteplace@cca.edu'
msg = EmailMessage()
@phette23
phette23 / git-license.fish
Created October 26, 2022 23:43
add ECL-2.0 license to current repo
View git-license.fish
#!/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
View convert.py
'''
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
View nso-groups.sh
#!/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 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
phette23 / unenroll-students.sh
Last active June 11, 2021 23:26
unenroll all students from Moodle course
View unenroll-students.sh
# 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
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
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/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>')
}