Skip to content

Instantly share code, notes, and snippets.

@kmlawson
kmlawson / CSL JSON with Tags.js
Last active October 27, 2023 14:29
Zotero Export Translator CSL JSON with Tags
{
"translatorID": "955a4265-fa78-4410-b937-d3e57b799ba6",
"translatorType": 3,
"label": "JSON with Tags",
"creator": "Simon Korblith",
"target": "json",
"minVersion": "3.0",
"maxVersion": null,
"priority": 100,
"inRepository": true,
@kmlawson
kmlawson / zotero-collection-merge.sh
Created March 16, 2021 17:46
Takes a set of exported bibtex collections from Zotero using Better BibTeX plugin, converts them to bibliography entries in markdown format with sub-headings for each collection.
#!/bin/sh
# Can be used to create a merged bibliography from a set of exported collectiions
# list files by name length:
MAINCOLLECTION=`ls *.bib | perl -e 'print sort { length($a) <=> length($b) } <>' | head -n 1`
MAINROOT=$(echo "$MAINCOLLECTION" | cut -f 1 -d '.')
rm -f "$MAINCOLLECTION Bibliography.md" # In case we already created one before
for FILE in *.bib
#!/usr/bin/env python3
# Requires pypinyin, can be installed with pip: https://github.com/mozillazg/python-pinyin
# Thanks to XerCis on CSDN: https://blog.csdn.net/lly1122334/article/details/105380586
# Example: psort file-with-Chinese-words-on-each-line.txt
import sys
from pypinyin import pinyin, Style
from itertools import chain
# Here is a workaround for lack of pause in curl:
# example:
# kurl 20 “http://myurl.com/[1-10].jpg”
# Will download with a 20 second pause
# Assumes $1 is pause in seconds between requests
# Assumes $2 is URL, with [x-y] as range inside it
# Assumes output is .jpg file
if [ -z "$1" ] 2> /dev/null; then
echo "No parameters found. Exiting."
@kmlawson
kmlawson / st-a-title-bookmarklet.js
Created September 22, 2019 21:23
A bookmarklet for St Andrews library to show only books/books that contain the search term in the title
javascript:(function(){p=prompt('Find book or ebook at St Andrews by Keyword:','');if(p){document.location.href='https://encore.st-andrews.ac.uk/iii/encore/plus/C__S'+escape(p)+'__Ff%3Afacetfields%3Atitle%3Atitle%3ATitle%3A%3A__Orightresult__U__X0__T?lang=eng&suite=def'};})();
@kmlawson
kmlawson / st-a-bookmarklet.js
Created September 22, 2019 21:18
Bookmarklet for St Andrews Library to just return books/ebooks, no database results
javascript:(function(){p=prompt('Find book or ebook at St Andrews by Keyword:','');if(p){document.location.href='https://encore.st-andrews.ac.uk/iii/encore/plus/C__S'+escape(p)+'__Orightresult__U__X0__T?lang=eng&suite=def'};})();
@kmlawson
kmlawson / dragon2.sh
Created October 24, 2018 21:14
Level upped the previous script to allow download of a list of NLA maps
# assumes dezoom.sh is in the same directory
# assumes list.txt containing URLs on separate lines to each of the NLA maps
# the URL should point to the jpg to the tile in the bottom right of the seadragon zoom tiles
# NLA offers jpg and tiff download but former is low resolution and latter are way too massive in size
# echo Paste in the highest tile on zoom level 14:
listfile="/Users/kml/shell/list.txt"
lines=`cat $listfile`
totallines=`grep -c ".*" list.txt`
count=0
for line in $lines; do
@kmlawson
kmlawson / dragon.sh
Last active October 13, 2019 15:01
Creates a simple command line interface to openseadragon, making use of dezoom.sh
# This is a wrapper for: https://github.com/lovasoa/dezoom.sh
# Running that command can be tedious if you have a regular URL pattern from openSeaDragon,
# such as the NLA format: https://nla.gov.au/[some image id]/dzi?tile=14/44_38.jpg
# Running this will prompt you for the url pointing to the highest X_Y tile and will
# then construct the appropriate dezoom.sh command using -X and -Y parameters
# it assumes you have wget and ImageMagick installed, and that the dezoom.sh file
# is in the same directory.
echo Paste in the highest tile on zoom level 14:
read fullurl
@kmlawson
kmlawson / main.m
Last active November 25, 2015 23:48
//
// main.m
// keyswitch
//
// Created by K. M. Lawson on 2015.11.25.
//
//
// com.apple.inputmethod.Korean.2SetKorean
// com.apple.inputmethod.Kotoeri.Japanese
// com.apple.inputmethod.TCIM.Pinyin
#!/usr/bin/env ruby
# Rename and save this as fbsetup.rb, and add a fbsetup alias to your bash setup to point to this script
# This script is to designed to be run from the command line within a directory where you have a list of student assignments you will mark.
# The command, to be run in the directory of the target feedback form takes the format of:
# fbsetup [modulename] [assessmentname-one-word] [duedate-year-month-day]
# Example:
# fbsetup 3335 Short-Essay-1 2015-10-20
# It will:
# 1. The student assignments downloaded from MMS have the student number as the first 9 characters. It will grab these first 9 characters and assume they are the student number