Skip to content

Instantly share code, notes, and snippets.

View jpstroop's full-sized avatar

Jon Stroop jpstroop

  • Princeton University Library
  • Princeton, NJ
View GitHub Profile
#!/usr/bin/env python3
from io import open
from collections import deque
IHDR = b'\x69\x68\x64\x72' # See I.5.3.1 Image Header box
with open('tests/fixtures/images/color.jp2', 'rb') as jp2:
window = deque([], 4)
while bytes(b''.join(window)) != IHDR:
window.append(jp2.read(1))
# The image header box is the only place in the spec where height comes
# first. Go figure.
xquery version "1.0";
declare namespace ead="urn:isbn:1-931666-22-9";
declare option saxon:output 'omit-xml-declaration=yes';
declare variable $collections := collection('/home/jstroop/eclipse_workspace/pudl-data-sparse/mdata/collections?select=*.ead');
declare function local:normalize($str) {
let $norm := replace(normalize-space($str), '"', '\\"')
return $norm
};
@jpstroop
jpstroop / hathi_to_tsv.awk
Last active November 13, 2015 14:51
Filter NJP open content from HathiFiles
# Filter "Hathifiles" (https://www.hathitrust.org/hathifiles) to open content from NJP
# Run w/ e.g., `cat hathi_full_20151101.txt | awk -f hathi_to_tsv.awk`
BEGIN {
FS = "\t";
printf("%s\t%s\t%s\t%s\n", "title", "enum", "URI", "BBID")
}
($1 ~ /^njp/) && ($2 == "allow") {
printf "\"%s\t%s\thttp://hdl.handle.net/2027/%s\t%s\n", $12, $5, $1, $7
@jpstroop
jpstroop / 1_simple_manifest.rb
Last active March 20, 2018 05:13
Example: How to create a bare-bones IIIF Presentation Manifest w/ O'Sullivan
require 'iiif/presentation'
MY_IIIF_IMAGE_SERVER = 'http://libimages1.princeton.edu/loris/'
SOME_IIIF_IMAGES = [
{ id: 'pudl0001%2F4609321%2Fs42%2F00000006.jp2', label: "Page 1" },
{ id: 'pudl0001%2F4609321%2Fs42%2F00000007.jp2', label: "Page 2" },
{ id: 'pudl0001%2F4609321%2Fs42%2F00000008.jp2', label: "Page 3" },
{ id: 'pudl0001%2F4609321%2Fs42%2F00000009.jp2', label: "Page 4" },
{ id: 'pudl0001%2F4609321%2Fs42%2F00000010.jp2', label: "Page 5" }
]
require 'linkeddata'
require 'rdf/cli/vocab-loader'
vocab_sources = {
lifecycle: {
uri: "http://purl.org/vocab/lifecycle/schema#",
source: "http://vocab.org/lifecycle/schema-20080603.rdf",
strict: true
},
exif: {
require 'rdf'
module RDF
class MARC_RELATORS < StrictVocabulary("http://id.loc.gov/vocabulary/relators/")
# Property definitions
property :abr, :label => 'Abridger'
property :act, :label => 'Actor'
property :adp, :label => 'Adapter'
property :rcp, :label => 'Addressee'
property :anl, :label => 'Analyst'
# Specifies a set of ResourceSync Sources
# Entire file could also be used to build the Capability List document
# E.g. engine at /rs/{service_id}
service_id:
- model: MyModel
datastreams:
- descMetadata
- model: MyOtherModel
@jpstroop
jpstroop / tree_spec.md
Last active February 14, 2017 16:52
Archives/EAD Tree Navigation API spec
@jpstroop
jpstroop / jp2_kakadu_pillow.py
Last active August 29, 2015 13:59
PrincetonPy
from PIL import Image
from PIL.ImageFile import Parser
from os import makedirs, path, unlink
import subprocess
import sys
KDU_EXPAND='/usr/local/bin/kdu_expand'
LIB_KDU='/usr/local/lib/libkdu_v72R.so'
TMP='/tmp'
INPUT_JP2='/home/jstroop/workspace/loris/tests/img/01/02/0001.jp2'
{
"@context" : [
"http://iiif.io/api/image-api/context.json",
{
"ab" : "http://penibelst.de/",
"ab:gravity" : {"@type" : "xsd:boolean"}
}
],
"@id" : "http://libimages.princeton.edu/loris",
"contact" : "mailto:admin@example.com",