Skip to content

Instantly share code, notes, and snippets.

@andrewbridge
andrewbridge / generate.ts
Created March 11, 2021 18:34
Barebones static site generator
import { join, extname } from "https://deno.land/std@0.89.0/path/mod.ts";
import { ensureDir, ensureFile, walk } from "https://deno.land/std@0.89.0/fs/mod.ts";
import marked from 'https://cdn.skypack.dev/marked';
import { DOMParser, Element } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
const inputRelDir = './src';
const outputRelDir = './dist';
const titleReplacementStr = '{%PAGE_TITLE%}';
const contentReplacementStr = '{%PAGE_CONTENT%}';
@andrewbridge
andrewbridge / url-polyfill.js
Created May 17, 2019 09:50
IE doesn't have the URL method, I needed to parse a URL with potential IE11 support. Polyfill the bare minimum of the method with regex. Doesn't support username:password pairs in URLs
if (typeof window.URL !== 'function') {
window.URL = function(url) {
var badUrl = new TypeError("Failed to construct 'URL': Invalid URL");
if (typeof url !== 'string') {
throw badUrl;
}
var match = url.match(/^(?<origin>(?<protocol>[^\/]+?)\/\/(?<host>(?<hostname>[^:]+)(:|)(?<port>[^\/]*?)))(?<pathname>\/[^\?\n]*)(?<search>(\?|)[^\n]*)/);
if (match === null) {
throw badUrl;
}
@andrewbridge
andrewbridge / linux-setup.sh
Created January 13, 2019 14:16
Basic linux setup script
#!/bin/sh
echo "Installing nix package manager"
curl https://nixos.org/nix/install | sh
echo "Setting up nix"
. /home/andrew/.nix-profile/etc/profile.d/nix.sh
echo "Installing CLI packages"
nix-env --install node yarn zsh zsh-completions git hub gnupg tldr
@andrewbridge
andrewbridge / mac-setup.sh
Last active December 5, 2018 08:48
Basic Mac setup script
#!/bin/sh
echo "Install the following manually:\n - Cinch (https://www.irradiatedsoftware.com/cinch/)"
# no solution to automate AppStore installs
read "Press any key to continue... "
echo '\n'
echo "Install xcode developer tools"
xcode-select --install
read "Press any key to continue..."

Keybase proof

I hereby claim:

  • I am andrewbridge on github.
  • I am andrewbridge (https://keybase.io/andrewbridge) on keybase.
  • I have a public key whose fingerprint is 692E B865 EE87 95B1 958B BFB0 DA49 6B4A 4415 34BD

To claim this, I am signing this object:

@andrewbridge
andrewbridge / LockableValue.js
Last active August 23, 2017 11:02
Access controlled variable in javascript using Proxy
/**
* LockableValue
*
* An object that can hold a value and control the read and write access to that value.
*
* Example:
* var VIPValue = new LockableValue();
* VIPValue.value = 'Really important, can't be changed';
* var release = VIPValue.lock(); // Default behaviour is to lock write access
* VIPValue.value = 'Something else'; // No change, a console error is shown
@andrewbridge
andrewbridge / filterMultivCardFile
Created March 2, 2015 15:53
Filter a multi-card vCard file (vcf) by any exact match similarity. Almost too simple to bother with a gist.
/**
* filter
*
* Takes a string containing uniform, plaintext data strucutures (such as vCard data)
* and filters the data by the given similarity in those data structures you wish to keep.
*
* @param str The string to perform the filtering on.
* @param similarity The similarity to filter by.
* @param exclude A boolean as to whether similar data structures should be included or
* excluded. Default is false.
@andrewbridge
andrewbridge / mvrt.sh
Created October 28, 2013 18:18
When using MAMP (i.e. the Mac flavour of XAMP), I like to switch between projects quickly. The simplest way to me, is changing the document root of MAMP. I added this to /usr/bin and now I can make the current directory accessible at localhost:8888 by simply typing "mvrt". All simple stuff, so I see no compatibility issues so long as you have ba…
#! /bin/bash
DIR=`pwd`
MAMP_DIR="/Applications/MAMP/htdocs"
rm -f "$MAMP_DIR"
ln -f -s "$DIR" "$MAMP_DIR"

Dealing with XML in ColdFusion is fairly straightforward. ColdFusion provides many built-in functions for doing all sorts of XML based operations. Some of those functions provide streamlined access to create, read, and search an xml document. You can also validate XML data against a DTD or schema and transform XML using XSLT.

Reading an XML Document