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
@jpstroop
jpstroop / bots.py
Created December 4, 2012 16:42 — forked from edsu/bots.py
see what your bot traffic is like
#!/usr/bin/env python
"""
Hack to look for user agent strings in typical Apache style log and
count up the number of requests by bots vs non-bots. The list of bot
user agents comes from http://www.user-agents.org/ but has had some
agents added to it, since the user-agents.org list is pretty out of date, e.g.
no Bing?!
"""
@jpstroop
jpstroop / asdf_which.sh
Last active December 26, 2021 15:58
asdf which extension - adds an option to specify a version as the third arg to the which subcommand and get a path the binary
# (Paste into your bash .profile or whatever you use)
#
# $ asdf which python
# /Users/jstroop/.asdf/installs/python/3.8.5/bin/python # version in .tool-versions
# $ asdf which python 3.7.6
# /Users/jstroop/.asdf/installs/python/3.7.6/bin/python # version from 3rd arg
#
# NOTE: Python < 3.11-dev does not compile on Apple silicon.
# See: https://bugs.python.org/issue43878.
# Use Rosetta if necessary.
@jpstroop
jpstroop / unwatch_all.py
Last active August 22, 2021 12:22
Unwatch all Github repositories.
#!/usr/bin/env python
#
# Unwatch from all Github repositories. Note that it will only work with up to
# 100 repos at a time (pagination is not implemented), so you may need to run
# more than once.
#
# Depends:
# requests : http://docs.python-requests.org/en/master/
#
# Output (to stdout):
@jpstroop
jpstroop / home-nut_notes.md
Last active June 1, 2021 15:51
My Notes on Configuring NUT for Home Use

Setting up Network UPS Tools (NUT) at Home

Note that these instructions use offensive master/slave terminology because they are still necessary keywords in the NUT configuration files. There is work in progress to change this. I am going to use server and client whenever I can, but you can't avoid master/slave in upsd.users or upsmon.conf.

Given two UPS's:

And a Raspberry Pi, I'm setting up my home network and critical hardware to shutdown gracefully when the power fails.

@jpstroop
jpstroop / get_exif.py
Created October 23, 2016 16:19
Get EXIF, IPTC Metadata, etc. with Python & PIllow
from PIL import Image
from PIL.ExifTags import GPSTAGS
from PIL.ExifTags import TAGS
# Keys are listed here:
# https://github.com/python-pillow/Pillow/blob/master/PIL/ExifTags.py
def _map_key(k):
try:
return TAGS[k]
@jpstroop
jpstroop / dzi_to_iiif.py
Last active October 15, 2020 14:09
DZI syntax to IIIF
# Take params from the DZI syntax and turn them into an IIIF request
#
# Copyright (C) 2009 CodePlex Foundation
# Copyright (C) 2010-2013 OpenSeadragon contributors
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
@jpstroop
jpstroop / get_iso_langs.rb
Created December 6, 2013 14:39
Download the ISO 639-2 codes as RDF and convert to CSV
require 'rdf/rdfxml'
require 'csv'
# Gets the ISO639-2 languages from id.loc.gov and saves it as CSV.
SRC_URI="http://id.loc.gov/vocabulary/iso639-2.rdf"
MADS_LANGUAGE = RDF::URI.new("http://www.loc.gov/mads/rdf/v1#Language")
MADS_CODE = RDF::URI.new("http://www.loc.gov/mads/rdf/v1#code")
SAVE_AS = File.expand_path("../../../db/fixtures/iso639-2.csv", __FILE__)
@jpstroop
jpstroop / orient_image.sh
Last active May 22, 2018 14:14
Guess the orientation of an image using OCR and Spellcheck
#!/bin/bash
# Script takes a single argument, which is a path in an image file.
# NOTE: this file will be replaced with the version that this script deems to be 'correct'
file=$1
TMP="/tmp/pulfa/img_harvester/rotation-calc"
# Clean up if there are files from the last run
# (leaving them around is handy for debugging)
if [ -d $TMP ]; then
#!/bin/bash
for md_file in $(find . -name "*.md"); do
gsed -r -i -e 's/([A-z])\.\s{2,3}([A-Z])/\1. \2/g' $md_file
done
@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" }
]