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
// check if an item's staging directory contains the same files as its persistent storage does
function log(msg) {
logger.log(currentItem.getUuid() + "/" + currentItem.getVersion() + " LOGGER: " + msg);
}
// use staging API to check those files
if (staging.isAvailable()) {
var stagingFilesAndDirs = staging.listFiles("", "**");
for(var i = 0; i < stagingFilesAndDirs.size(); i++) {
log(stagingFilesAndDirs.get(i));
@phette23
phette23 / redirect.html
Created February 3, 2012 00:34
Screen-size based redirect
<!-- redirect based on screen width -->
<script type="text/javascript">
console.log('Screen width: '+screen.width);
if (screen.width <= 699 && !sessionStorage.getItem("redirecting")) {
window.location.replace("./m/index.html"); //path to your mobile site
}
</script>
<!-- redirect bypass on the mobile site
such that users don't get caught in a redirect loop
uses jQuery cuz mobile site is jQuery Mobile
@phette23
phette23 / cover.php
Created August 29, 2016 18:00
proxy ByWater's Coce cover image cache server (for use on an HTTPS domain)
<?php
// this proxies ByWater Solutions' "COCE" cover image service
// which does not work over HTTPS, so fill in our libraries.cca.edu
// server as our COCE server & it intercepts requests, sending along
// data from ByWater's COCE server
// we're sending JS
header( 'Content-Type:application/javascript; charset=utf-8' );
// requests look like
@phette23
phette23 / g-suite-news.js
Last active November 30, 2018 18:39
g suite services customizations
document.querySelector('.about-us-image-wrapper .about-us-image').src = '/media/images/GSuite_service.width-404.jpg'
document.addEventListener('DOMContentLoaded', main)
function main() {
var url = '/services/instructional-services-technology/g-suite-service/g-suite-news-updates/'
fetch(url).then((resp) => resp.text())
.then((text) => {
// parse text of page to HTML we can navigate
var parser = new DOMParser()
@phette23
phette23 / equella bulk download.js
Created December 6, 2018 00:31
bulk download attachments from a list of item UUIDs (openEQUELLA)
#!/usr/bin/env node
// given a set of item UUIDs, download all their attached files
// .equellarc file with credentials for API use
let options = require('rc')('equella', {})
let headers = { 'X-Authorization': 'access_token=' + options.token }
const fs = require('fs')
const request = require('request')
// construct API URL
@phette23
phette23 / broken link format.js
Last active December 12, 2018 21:15
format a support ticket for reporting a broken link in Summon (paste into dev tools)
@phette23
phette23 / equella-disk-space.sql
Created January 28, 2019 23:25
how much disk space do the attachments for each openEQUELLA collection take up
-- attachment.value1 is the file size for "file" type attachments
-- does not capture a) zip files, b) generated thumbnails
-- but the item.total_file_size column which should include this is inaccurate
SELECT be.uuid, be_name.text AS collection, SUM(CAST(a.value1 AS bigint)) AS "disk space"
FROM item i
INNER JOIN base_entity be ON be.id = i.item_definition_id
LEFT JOIN language_string i_name ON i.name_id = i_name.bundle_id
LEFT JOIN language_string be_name ON be.name_id = be_name.bundle_id
JOIN (SELECT * FROM attachment WHERE attachment.type = 'file') a ON i.id = a.item_id
WHERE i.institution_id = 1165188
@phette23
phette23 / uptaxo.py
Created February 7, 2019 17:39
upload a taxonomy to openEQUELLA using a specially-formatted CSV
#!/usr/bin/env python2
# ################################# #
# UploadTaxonomy.py #
# #
# added CLI by Eric Phetteplace #
# California College of the Arts #
# vault.cca.edu | libraries.cca.edu #
# 2014-07-32 #
# #
# Pearson's notes below #
@phette23
phette23 / inclusion-tests.py
Created April 17, 2019 20:59
trying out a few methods of testing for inclusion in a large list
"""
I tested a few options for testing for inclusion in a very large (millions of items) set. Results if you're curious:
¿ python3 heapq-test.py
> List took 71.93408012390137s time
> Heap took 160.27557826042175s time
> Sorted Containers took 0.004794120788574219s time
sortedcontainers is _real_ fast.
"""
from heapq import *
@phette23
phette23 / get_mdl_categories.py
Created May 3, 2019 19:55
get Moodle course category information from API
import requests
# request URL looks like
# https://moodle.cca.edu/webservice/rest/server.php?wstoken=...&wsfunction=core_course_get_categories&moodlewsrestformat=json&criteria[0][key]=name&criteria[0][value]=2019SP
def get_mdl_categories(filter):
""" obtain a list of JSON representations of Moodle course categories
returns an array of category dicts (see their fields below)