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 / lfm-recent-tracks.html
Created Feb 19, 2012
Last.fm Recent Tracks API
View lfm-recent-tracks.html
<h3>Last.fm Scrobbles</h3>
<!-- div below will be filled in with formatted contents of API response -->
<div id="recent-tracks" style="display:none;"><a href="http://last.fm/">Last.fm</a> data hasn't loaded yet.</div>
<!-- leave as display:none for the fade in effect -->
@phette23
phette23 / current-dir-in-iterm-tab-title.sh
Last active Sep 7, 2021
Set the iTerm tab title to the current directory, not full path.
View current-dir-in-iterm-tab-title.sh
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# 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: ss64.com/bash/syntax-prompt.html
@phette23
phette23 / nso-groups.sh
Created Aug 27, 2021
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 / moodle-support-db.fish
Last active Aug 20, 2021
connect to Moodle Support Database in Google Cloud
View moodle-support-db.fish
#!/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
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
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
phette23 / unenroll-students.sh
Last active Jun 11, 2021
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
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 / doaj.php
Last active May 11, 2021
Web Scraping Examples in a Few Languages
View doaj.php
<?php
// need to download simple_html_dom.php from SourceForge
// http://sourceforge.net/projects/simplehtmldom/files/
// and place it in the same directory as this script
require_once( 'simple_html_dom.php' );
// http://simplehtmldom.sourceforge.net/manual_api.htm
$base = 'http://www.doaj.org/doaj?func=search&template=&uiLanguage=en&query=';
$query = urlencode( 'librarianship' );
@phette23
phette23 / one-liners.js
Last active Apr 24, 2021
A few JavaScript One-Liners
View one-liners.js
// taken from https://medium.com/html5-css3/7c80a4b731f8
// 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 = document.location.search.replace(/(^\?)/,'')