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 / lfm-recent-tracks.html
Created Feb 19, 2012 Recent Tracks API
View lfm-recent-tracks.html
<h3> Scrobbles</h3>
<!-- div below will be filled in with formatted contents of API response -->
<div id="recent-tracks" style="display:none;"><a href=""></a> data hasn't loaded yet.</div>
<!-- leave as display:none for the fade in effect -->
phette23 /
Last active Sep 7, 2021
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see:
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 / hashcode.js
Last active Jul 21, 2021
find hash in openEQUELLA file storage path
View hashcode.js
#!/usr/bin/env node
//jshint node:true
// useful for finding location of files on server, for non-advanced storage config location is
// {{data dir}}/Institutions/{{institution name}}/Attachments/${hashCode(uuid)}/${uuid}/${version}
// for advanced storage config it's
// {{data dir}}/Institutions/{{institution name}}/Attachments/${collection UUID}/${hashCode(uuid)}/${uuid}/${version}
const readline = require('readline')
let hashCode = function(str){
let hash = 0
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 / doaj.php
Last active May 11, 2021
Web Scraping Examples in a Few Languages
View doaj.php
// need to download simple_html_dom.php from SourceForge
// and place it in the same directory as this script
require_once( 'simple_html_dom.php' );
$base = '';
$query = urlencode( 'librarianship' );
phette23 / one-liners.js
Last active Apr 24, 2021
A few JavaScript One-Liners
View one-liners.js
// taken from
// and expanded, unreadable one-liners are kind of pointless
//pad zeroes
function pad(num) {
return ('0' + num).split('').reverse().splice(0,2).reverse().join('')
// get page query params
var qp =^\?)/,'')