Skip to content

Instantly share code, notes, and snippets.

@kmlawson
kmlawson / anki1.0.rb
Created July 16, 2012 21:34
This open source script is for Mac OS X or Linux, with Ruby installed. You can run the script via the command line with "ruby anki1.0.rb" for example. This version of the script is very simple: it extracts certain statistics from your Anki decks (edit the
(*
Copyright 2009 Konrad M. Lawson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@kmlawson
kmlawson / vim-life-word-count
Created May 15, 2013 13:32
Vimscript for a live word count. Mixed match code from stackoverflow and added check for empty file: http://stackoverflow.com/questions/114431/fast-word-count-function-in-vim
function! WC()
if getline(1) != ''
if &modified || !exists("b:wordcount")
let l:old_status = v:statusmsg
let position = getpos(".")
execute "silent normal g\<c-g>"
let b:wordcount = str2nr(split(v:statusmsg)[11])
let v:statusmsg = l:old_status
call setpos('.', position)
return b:wordcount
@kmlawson
kmlawson / PDF-word-count.scpt
Last active December 18, 2015 15:08
Very simple pdf word count in Skim PDF reader using AppleScript. Assumes file you want word count for is open.
-- This is a really stripped down and simple version of
-- Daniel Shockley's DocInfo, which I had trouble getting
-- to work on pandoc converted unicode files.
-- Thanks to him for the original script:
-- DocInfo (for Skim)
-- version 1.0, Daniel A. Shockley, http://www.danshockley.com
-- http://www.danshockley.com/files/DocInfo.scpt
tell application "Skim"
set docName to name of document 1
#!/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
@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
@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 / 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 / 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 / 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'};})();
# 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."