Skip to content

Instantly share code, notes, and snippets.

View danielrbradley's full-sized avatar

Daniel Bradley danielrbradley

View GitHub Profile
@danielrbradley
danielrbradley / uk-number-plate-validation.md
Last active April 4, 2024 09:36
Regular Expression to Validate UK Number Plates

Regular Expression to Validate UK Number Plates

Regular Expression

(?<Current>^[A-Z]{2}[0-9]{2}[A-Z]{3}$)|(?<Prefix>^[A-Z][0-9]{1,3}[A-Z]{3}$)|(?<Suffix>^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(?<DatelessLongNumberPrefix>^[0-9]{1,4}[A-Z]{1,2}$)|(?<DatelessShortNumberPrefix>^[0-9]{1,3}[A-Z]{1,3}$)|(?<DatelessLongNumberSuffix>^[A-Z]{1,2}[0-9]{1,4}$)|(?<DatelessShortNumberSufix>^[A-Z]{1,3}[0-9]{1,3}$)|(?<DatelessNorthernIreland>^[A-Z]{1,3}[0-9]{1,4}$)|(?<DiplomaticPlate>^[0-9]{3}[DX]{1}[0-9]{3}$)

For use in JavaScript (with named groups removed):

(^[A-Z]{2}[0-9]{2}\s?[A-Z]{3}$)|(^[A-Z][0-9]{1,3}[A-Z]{3}$)|(^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(^[0-9]{1,4}[A-Z]{1,2}$)|(^[0-9]{1,3}[A-Z]{1,3}$)|(^[A-Z]{1,2}[0-9]{1,4}$)|(^[A-Z]{1,3}[0-9]{1,3}$)|(^[A-Z]{1,3}[0-9]{1,4}$)|(^[0-9]{3}[DX]{1}[0-9]{3}$)
@danielrbradley
danielrbradley / JasmineTemplates.DotSettings
Created May 21, 2014 13:11
Jasmine templates for ReSharper
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=9FFD516F2767AE4AAFBB8FA1580513C8/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=9FFD516F2767AE4AAFBB8FA1580513C8/Shortcut/@EntryValue">it</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=9FFD516F2767AE4AAFBB8FA1580513C8/Description/@EntryValue">Jasmine Spec</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=9FFD516F2767AE4AAFBB8FA1580513C8/Text/@EntryValue">it('$description$', function() { $END$ });</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=9FFD516F2767AE4AAFBB8FA1580513C8/Reformat/@EntryValue">True<
@danielrbradley
danielrbradley / type.test.ts
Created September 15, 2017 15:25
Testing JSON matches TypeScript types
import { writeFileSync, mkdirSync, existsSync } from 'fs'
import { resolve } from 'path'
import * as ts from 'typescript'
function checkForTypeErrors(jsonContent: string) {
const tempDir = resolve('.tmp')
const tempFilePath = resolve(tempDir, 'typecheck.ts')
if (!existsSync(tempDir)) {
mkdirSync(tempDir)
}
@danielrbradley
danielrbradley / README.md
Last active December 15, 2022 16:18
Generate cross-language Pulumi examples
  1. Edit Pulumi.yaml
  2. Run ./convert.sh
  3. Copy content of example.md
@danielrbradley
danielrbradley / Pulumi+Prettier+ESLint-setup.md
Created October 22, 2019 10:03
Setting up ESLint & Prettier for Pulumi

Setting up ESLint & Prettier for Pulumi

This is my process for addint ESLint and Prettier support for a new Pulumi TypeScript project.

Install packages

yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-airbnb-base eslint-config-prettier eslint-plugin-import eslint-plugin-prettier prettier
@danielrbradley
danielrbradley / EnumDropdownExtenstions.cs
Created June 21, 2012 10:56
ASP.NET MVC Enumeration Dropdown Extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace System.Web.Mvc.Html
{
@danielrbradley
danielrbradley / IsinValidation.fs
Created December 6, 2016 16:33
Validate an ISIN (International Securities Identification Number) in F#
module Isin
open System.Text.RegularExpressions
// See: http://en.wikipedia.org/wiki/International_Securities_Identification_Number
[<Literal>]
let private AsciiZero = 48
[<Literal>]
let private AsciiNine = 57
@danielrbradley
danielrbradley / index.ts
Created September 16, 2021 19:53
AWS API Gateway, JWT Authorizer with Cognito and CORS support
/**
* Annotated, real-world example of how to use
* AWS API Gateway V2 + JWT authorizer + Cognito
* with support for CORS & good security practices
* deployed with Pulumi (https://www.pulumi.com/)
*/
import * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import serverlessExpress from '@vendia/serverless-express';
import express from 'express';
@danielrbradley
danielrbradley / Stream Analytics UDS int overflow.md
Last active March 2, 2021 10:38
Reproduction of Stream Analytics Query UDF integer overflow

When returning a number from a UDF function which is greater than 2,147,483,647 but less than long.MaxValue and bound to a Stream Analytics bigint type then the number is shown as a negative which indicates that the integer has been overflowed. This error does not happen when using the local or portal query tester.

The workaround we've used to return the value as a string. However, this behaviour does not match the documentation: https://docs.microsoft.com/en-us/azure/stream-analytics/stream-analytics-javascript-user-defined-functions#stream-analytics-and-javascript-type-conversion

@danielrbradley
danielrbradley / aws-auth.sh
Last active January 8, 2020 12:23
Get console session with AWS access for 36 hours when using MFA
#!/bin/bash
# Note: Depends on having jq and AWS CLI installed: `brew install jq`, `brew install awscli`
set -e # stop on error
AWS_ACCOUNT="1234567890"
AWS_USERNAME="YOUR_AWS_USERNAME"
MFA_SERIAL="arn:aws:iam::$AWS_ACCOUNT:mfa/$AWS_USERNAME"
export AWS_CONFIG_FILE='/dev/null' # ignore config file so CLI doesn't pick up MFA config
read -p "Enter MFA code for $MFA_SERIAL: " MFA