Skip to content

Instantly share code, notes, and snippets.

View karlwilcox's full-sized avatar
🏠
Working from home

Karl R. Wilcox karlwilcox

🏠
Working from home
View GitHub Profile
@karlwilcox
karlwilcox / img-server.js
Created September 28, 2023 14:08
Node.js Image Conversion Services over HTTP
// receive POST to /convert, with POST fields:
// svg - SVG image data
// format - format to convert image to (see switch below)
// width - width of converted image in pixels
// height - height of converted image in pixels
const express = require('express');
const multer = require('multer');
const upload = multer({ limits:{fieldSize: 25 * 1024 * 1024} });
const sharp = require("sharp");
@karlwilcox
karlwilcox / admin-bot.js
Created December 16, 2022 15:32
Discord bot with Github issues integration (credentials in separate .env file, replace <STUFF> with your own data)
const Discord = require('discord.js');
const fetch = require('node-fetch');
require('dotenv').config();
const querystring = require('querystring');
const client = new Discord.Client();
const prefix = '!';
const { exec } = require("child_process");
@karlwilcox
karlwilcox / drawshield.py
Created April 19, 2021 14:55
Code to embed DrawShield shield renders and heraldic definitions in Jupyter Notebooks
import requests
import base64
from IPython.display import Image, display
# example usage:
# drawshield("azure a bend or")
# For more detailed information use
# drawshield("azure a bend or", True)
def drawshield(blazon, debug = False):
url = "https://drawshield.net/include/drawshield.php"
@karlwilcox
karlwilcox / edges.php
Created March 28, 2021 14:17
Generate Variant edge types for drawshield (assumes directory called 'edges' in current dir)
<?php
$subArg = '';
function subFunc( $match ) {
global $subArg;
if ( $match[0]{2} == '}' ) {
return $subArg;
} else {
$val = floatVal(substr($match[0],3));
@karlwilcox
karlwilcox / drawshield.js
Created March 18, 2021 10:56
Drawshield Discord Bot
const Discord = require('discord.js');
const fetch = require('node-fetch');
const querystring = require('querystring');
const crypto = require('crypto');
const fs = require('fs');
const { exec } = require('child_process');
const limit = 500;
const client = new Discord.Client();
@karlwilcox
karlwilcox / define.js
Last active December 24, 2020 10:41
Discord Bot to provide various heraldry services
const Discord = require('discord.js');
const fetch = require('node-fetch');
const querystring = require('querystring');
const client = new Discord.Client();
const prefix = '!';
const helpInfo = {
define: "*!define <term>*\nProvide a brief definition of a heraldic term (Searches Parker's heraldic dictionary, and Elvins' Heraldic dictionary) and provides a link to the full entry.",
@karlwilcox
karlwilcox / convertWPtoEJS.xsl
Created July 12, 2017 21:08
XSL Transform to Convert a WordPress Page/Post export XML to separate files and build a _data.json file (e.g. for converting sites to HarpJs / EJS)
<?xml version="1.0"?>
<!--
Basic XSL transform to convert a WordPress "export" file into a set of separate files, one for each WordPress Page (or Post). This uses
xsl:result-document and so needs an XSL 3.0 processor such as
Michael Kay's SaxonHE. A typical command line would be:
java -jar saxon9HE.jar <WORDPRESS-EXPORT-FILE>.xml convertWPtoEJS.xsl > _data.json
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<!-- The content is enclosed in CDATA, we want to output the raw text -->
<xsl:output method="text" cdata-section-elements="content:encoded"/>
@karlwilcox
karlwilcox / word.sh
Created January 29, 2017 15:25
Simple front end to grep and the dictionary word list to help in solving word based puzzles, for example, if you stuck on those in "The GCHQ Puzzle Book"
#!/bin/bash
# Various utilities to help with the GCHQ Puzzle Book...
wordlist="/usr/share/dict/british-english"
formatter="column"
# turn off filename globbing (we never need it)
set -f
if [[ $# -lt 2 ]]; then
@karlwilcox
karlwilcox / EdgeSVGFix.js
Last active October 29, 2016 18:51
Edge Browser SVG Fix
// This is a combination of an SVG import function from http://stackoverflow.com/users/405017/phrogz
// and a posting by Daniel McCabe https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5579311/
// It allows an SVG object (obtained for example, from an AJAX request) to be correctly displayed in the
// Microsoft Edge browser (which otherwise would change some of the attribute names to all Upper Case)
// For example, I call this function if (navigator.userAgent.indexOf('Edge') > 0)
function cloneAndFix(node,doc){
var corrections = new Array (
'attributeName',
'attributeType',
'baseFrequency',
@karlwilcox
karlwilcox / HTMLBuilder.swift
Created May 10, 2015 21:49
An object which builds HTML code for subsequent use in a UIWebView. The HTML code is always valid as elements are created and closed automatically as required.
//
// HTMLBuilder.swift
//
// Created by Karl Wilcox on 16/03/2015.
// Copyright (c) 2015 Karl Wilcox. All rights reserved.
//
import Foundation
/// Builds and returns valid HTML for use in UIWebView