Skip to content

Instantly share code, notes, and snippets.

@jsnape
jsnape / ReferralsCount.feature
Created June 28, 2013 20:48
Referral feature
Feature: Referrals Count
As an operational manager
I want to see counts of referrals
So I can plan capacity and monitor the number of patients in the system
Scenario: Simple Referral
Given the following referrals:
| Patient | Referral Date |
| Jane Smith | 2013-01-01 |
| Robert Jones | 2013-01-02 |
@jsnape
jsnape / EnumerableReader.fs
Last active November 21, 2018 14:52
F# IEnumerable<'T> -> IDataReader
open System
open System.Reflection
open System.Collections.Generic
open System.Data
open System.Linq
open System.Linq.Expressions
type private accessor<'T> = { Index: int; Name: string; Getter: 'T -> obj }
/// IEnumerable to IDataReader wrapper class
@jsnape
jsnape / Program.cs
Created July 20, 2014 10:32
Harriet Emulator
using System;
using System.Threading;
namespace ConsoleApplication2
{
class Program
{
// Harriet emulator...
static void Main(string[] args)
{
@jsnape
jsnape / CteSequence.sql
Created September 13, 2017 08:18
CTE as a sequence generator
declare @start int = 0;
declare @end int = 1000;
with numberSequence
as (
select @start as nextValue
union all
select nextValue + 1
from numberSequence
where nextValue + 1 < @end
@jsnape
jsnape / dbo.DimDate.sql
Last active August 5, 2019 19:21
CteDate View
alter view dbo.DimDate
as
with DateSeq(DateValue) as (
select cast('2015-01-01' as date) as DateValue
union all
select dateadd(day, 1, DateValue) as DateValue
from DateSeq
where year(DateValue) < year(getdate()) + 2
)
select *,
@jsnape
jsnape / extract.ps1
Created December 7, 2019 13:47
Script to Web scrape BCP Council Election results
Install-Module -Name PowerHTML -Scope CurrentUser
Import-Module PowerHTML
$resultPages = @(
'alderney-bourne-valley-results.aspx'
'bearwood-merley-results.aspx'
'boscombe-east-pokesdown.aspx'
'boscombe-west-results.aspx'
'bournemouth-central-results.aspx'
'broadstone-results.aspx'
@jsnape
jsnape / EnumerableDataReader.cs
Created April 16, 2020 10:36
EnumerableDataReader.cs
// Copyright 2013 James Snape
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Import-Module posh-git
Set-StrictMode -Off
# Get Account for the logged on user
function Get-WhoIAm {
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
# Create a new object
Write-Output (New-Object -TypeName PSCustomObject -Property ([ordered] @{
Account = $windowsIdentity.Name
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
namespace Foo
{
using System;
using System.Linq;
using System.Linq.Expressions;
@jsnape
jsnape / IWorkerPermitPolicy.cs
Last active March 25, 2021 11:52
Snowflake Sequence Generator
using System.Threading.Tasks;
/// <summary>
/// IWorkerLeasePolicy interface definition.
/// </summary>
public interface IWorkerPermitPolicy
{
/// <summary>Initializes the specified maximum workers.</summary>
/// <param name="maxWorkers">The maximum number workers.</param>
/// <param name="sequenceSizeBytes">The sequence size in bytes.</param>