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 / insertSVG.js
Created January 2, 2013 22:16
Insert SVG element into existing page using AJAX (multi-browser support) Assumption: SVGWeb is available for old versions of IE Assumption: The GET url returns the SVG data as a valid XML document NOTE: If you ONLY need to support current PC/Android browsers you can just use: document.getElementById('SVGElementHere').innerHTML = xmlhttp.response…
// AJAX variable
var xmlhttp;
// Work out IE Version number (if any)
var ieVer = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
@karlwilcox
karlwilcox / svgpathmanipulation.php
Created January 8, 2013 00:04
PHP SVG Path Manipulation Functions
<?php /* SVG PATH MANIPULATION FUNCTIONS
rotatePath(), mirrorPath(), reversePath(), scalePath(), translatePath(), matrixPath() and makeRelativePath()
The path argument is the string value of the 'd' attribute of the svg 'path' element, NOT the whole element
Other arguments should be self-explanatory
The return value is a string that can used as the value of the 'd' attribute
It is usually best to make the path relative first, then carry out other manipulations
Shortcomings:
@karlwilcox
karlwilcox / Notifier.swift
Last active August 29, 2015 14:20
A very simple notification framework. Objects may register a call back for when pre-defined event types occur, and other objects may indicate that those events have occurred.
//
// Notifier.swift
//
// Created by Karl Wilcox on 07/05/2015.
// Copyright (c) 2015 Karl Wilcox.
//
/* Description: A very simple notification framework.
Objects may register a call back for when pre-defined event types occur, and other objects may indicate that
those events have occurred. A typical use case would be a switching view controller type application
@karlwilcox
karlwilcox / UIColorByHexString.swift
Last active August 29, 2015 14:20
Adds a convenience init to UIColor to allow it to be created from a hex string as in HTML or CSS colour specifications
//
// UIColorByHexString.swift
//
// Created by Karl Wilcox on 10/05/2015.
// Copyright (c) 2015 Karl Wilcox. All rights reserved.
//
import Foundation
import UIKit
@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
@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 / 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 / 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 / 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 / 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();