Skip to content

Instantly share code, notes, and snippets.

View dogriffiths's full-sized avatar

David Griffiths dogriffiths

View GitHub Profile
@dogriffiths
dogriffiths / Notes.md
Created November 2, 2022 10:53
Add testing to a Svelte application

Add the testing libraries libraries using the following command:

npm install -D @testing-library/jest-dom @testing-library/svelte jest babel-jest @babel/preset-env jest-environment-jsdom jest-transform-svelte @testing-library/user-event

In the package.json file ad the following to the scripts section:

"test": "jest"

Then add the babel.config.js and jest.config.js files to the main application directory (the same one where package.json is)

@dogriffiths
dogriffiths / PostcodeExtractor
Created January 6, 2018 16:44
A class to extract properly formatted UK postcodes from a string. Returns null if it doesn’t find one
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PostcodeExtractor {
private final static List<String> VALID_AREAS = Arrays.asList(
"AB", "AL", "B", "BA", "BB", "BD", "BH", "BL", "BN", "BR", "BS", "BT", "CA", "CB", "CF", "CH", "CM", "CO",
"CR", "CT", "CV", "CW", "DA", "DD", "DE", "DG", "DH", "DL", "DN", "DT", "DY", "E", "EC", "EH", "EN", "EX",
"FK", "FY", "G", "GL", "GU", "HA", "HD", "HG", "HP", "HR", "HS", "HU", "HX", "IG", "IP", "IV", "KA", "KT",
@dogriffiths
dogriffiths / commit-msg
Created September 7, 2016 21:09
Git hook to check that commit messages are in Semantic format.
#!/bin/sh
#
# Git hook to check for semantic commit messages in the form mentioned here
#
# https://seesparkbox.com/foundry/semantic_commit_messages
export TYPE=$(cut -d ':' -f1 < "$1" | xargs)
export VERB=$(cut -d ':' -f2 | cut -d ' ' -f2 < "$1")
(echo "$TYPE" | egrep '^(feat|chore|docs|fix|refactor|style|test)$' > /dev/null) || (echo "Missing type feat|chore|docs|fix|refactor|style|test"; exit 1)
(grep "$VERB" .git/hooks/verbs.txt > /dev/null) || (echo "Missing a verb"; exit 1)