Skip to content

Instantly share code, notes, and snippets.

@donaldgray
donaldgray / iiif_image_api.py
Created August 11, 2021 15:32
Basic class that takes iiif image 2.1 api and generates all possible URLs for tiles at various scale factors.
import math
class IIIFImageApi:
def __init__(self, json: dict):
if not dict:
return
self.Width = int(json.get("width"))
self.Height = int(json.get("height"))
@donaldgray
donaldgray / GPG Public Key
Created July 29, 2021 16:03
GPG Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGECvf0BEAC+uHIo8GCJaP5x7A7IYN5UunR1W1SbI5uIRkFPkmqZcEqgeu1J
S9PSpPhLynsrFNSQwZZVX9ksYfjSN2BMajrU5z2M5IrlSdsLGI2+s7MkGAd+l9zx
q5jwrmBpBliNr7tMl1kSySLQOHh3oCmzGQt8Mm/gMd1qK7LXG1W47U6XDzZhDzK8
Rq1VoLCA47PDnLtRXBXMJgBM4NhXB/nwT/IYyvL1R5TU5MEEUkHLAfBQthJTP+6Z
LxnvuUAd9pd/Udj6ArlIn7Gi9gPBmvaEKg40q6kuihOguRoHC1oyddGlWSRKk93I
EON5SLeYzUADmq0LT4yBPIbpa13hW2v//7H7yCVaOU9C0aaFFfrQjdKkV0Tpx+Sr
RJ3rkGsgsoziyagpbInVWYt/iMm54z/L1055v4xUZ6D5Ktx+RLXait5WdwTLHqdU
YkIiqwpxZLyDmoh63NrhcglVdVuXlN6tZ9oAcVySK/fB7cj1qmbYCS+aMQGF/Fra
@donaldgray
donaldgray / Dockerfile-iipsrv
Created February 11, 2020 10:53
Dockerfile for building iipsrv with openjpeg
FROM ubuntu:18.04
# install required packages
RUN apt-get update && apt-get install -y \
libfcgi0ldbl libjpeg8 zlib1g-dev libstdc++6 libtool cmake wget \
libjpeg-dev libtiff-dev libpng-dev liblcms2-2 libmemcached-dev \
lighttpd memcached git autoconf
# clone openjpeg
RUN mkdir -p /opt && cd /opt && git clone https://github.com/uclouvain/openjpeg.git
@donaldgray
donaldgray / NewRelicReceiveObserver.cs
Created October 25, 2019 10:45
Class for handling MassTransit errors and sending faults to NewRelic.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MassTransit;
using NewRelic.Api.Agent;
/// <summary>
/// <see cref="IReceiveObserver"/> implementation that sends faults to NewRelic.
/// </summary>
public class NewRelicReceiveObserver : IReceiveObserver
@donaldgray
donaldgray / index.js
Created October 3, 2019 08:45
Handler for testing RESTful svc
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
console.log(`${ctx.method} ${ctx.url}`);
const responseCode = ctx.url.startsWith('/') ? ctx.url.substring(1) : 200;
const delay = ctx.response.get('X-Delay-Ms');
if (delay) {
setTimeout(() => {
console.debug('done...');
@donaldgray
donaldgray / DictionaryExtensions.cs
Created July 17, 2018 14:03
A collection Dictionary Extensions for consuming/creating dictionaries
/// <summary>
/// Creates a <see cref="T:System.Collections.Generic.Dictionary`2" /> from an <see cref="T:System.Collections.Generic.IEnumerable`1" /> according to specified key selector and element selector functions.
/// If duplicates keys are present, only the first will be used. Values with duplicate keys will be ignored.
/// </summary>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam>
/// <typeparam name="TValue">The type of the value returned by <paramref name="elementSelector" />.</typeparam>
/// <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to create a <see cref="T:System.Collections.Generic.Dictionary`2" /> from.</param>
/// <param name="keySelector">A function to extract a key from each element.</param>
/// <param name="elementSelector">A transform function to produce a result element value from each element.</para
@donaldgray
donaldgray / DevelopmentNonRunningSchedule.cs
Created March 19, 2018 09:13
DailySchedule for Azure function that will not run if AzureWebJobEnv == "Development"
public abstract class DevelopmentNonRunningSchedule : DailySchedule
{
protected DevelopmentNonRunningSchedule(params string[] times) : base(times)
{
}
protected DevelopmentNonRunningSchedule() : base()
{
}
@donaldgray
donaldgray / replaceTfVars.cs
Created December 1, 2017 11:20
Iterates through tfvars file and replaces values with corresponding values from Octopus Deploy.
var varsFile = Octopus.Parameters["tfvarsfile"];
Console.WriteLine("Parsing tfVarsFile: " + varsFile);
if (string.IsNullOrEmpty(varsFile))
throw new ApplicationException("You must provide a tf vars file location");
if (!File.Exists(varsFile))
throw new ApplicationException(string.Format("Specified tf vars file, {0}, not found", varsFile));
string tempFile = string.Concat(varsFile, "-temp");
@donaldgray
donaldgray / EscapeSingleUser.sql
Created October 24, 2017 15:34
Script to grab single user mode and set back to multi user. Useful in event of DB in single user but something like polling service grabs connection.
-- Check user with access
SELECT
p.loginame
FROM
sys.databases d
inner join sys.sysprocesses p ON (d.database_id = p.[dbid])
WHERE
d.name = 'database_name'
-- Try to grab database 1000 times
@donaldgray
donaldgray / Cake_Teamcity_Metarunner.xml
Created November 10, 2016 08:46 — forked from wwwlicious/Cake_Teamcity_Metarunner.xml
Provides a teamcity metarunner that executes a cake script
<?xml version="1.0" encoding="UTF-8"?>
<meta-runner name="Cake">
<description>Execute a cake script</description>
<settings>
<parameters>
<param name="mr.Cake.script" value="" spec="text description='The location of the Cake Script, relative to the root folder' display='normal' label='Cake Script:'" />
<param name="mr.Cake.target" value="" spec="text description='The name of the Target within the Cake Script to execute' display='normal' label='Target:'" />
<param name="mr.Cake.verbosity" value="" spec="select data_1='Quiet' data_3='Minimal' data_5='Normal' data_7='Verbose' data_9='Diagnostic' description='The logging level for the Cake Script' display='normal' label='Verbosity:'" />
<param name="mr.Cake.arguments" value="" spec="text description='Additional arguments to pass to Cake Script' display='normal' label='Cake Arguments:'" />
</parameters>