Skip to content

Instantly share code, notes, and snippets.

Stephen Salt Kntajus

  • InfoSum
  • Basingstoke, United Kingdom
Block or report user

Report or block Kntajus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View NationalInsuranceNumber.cs
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Diuturnal {
/// <summary>
/// Represents a UK National Insurance number.
/// </summary>
/// <remarks>
/// Based on the specification found at
View Range.cs
using System;
namespace Diuturnal {
public class Range<T> where T : IComparable<T> {
private T _start;
private T _end;
public Range(T first, T second) {
if (first.CompareTo(second) > 0) {
Kntajus / LocalStorage
Last active Aug 29, 2015
Used to show broken localStorage in IE11
View LocalStorage
<title>LocalStorage fundamentally broken in IE11</title>
String length: <input id="length" type="text" value="2000" /><br />
<button onclick="set(null);">Clear</button>
<button onclick="store('A');">Store w/ A</button>
<button onclick="store('B');">Store w/ B</button>
<button onclick="show();">Show value</button>
Kntajus / SpeechElements
Last active Aug 29, 2015
Turns an integer into an array of strings that correspond to the correct wav file names to read out.
View SpeechElements
let emptyIfZero f x =
match x with
| 0 -> []
| _ -> f x
let elementsBetween0And20 = emptyIfZero (fun x -> [ string x ])
let elementsBetween21And99 x = string (x - (x % 10)) :: elementsBetween0And20 (x % 10)
let ifGreaterThan y f g x = if x > y then f x else g x
let elementsFor2DigitNumber = ifGreaterThan 20 elementsBetween21And99 elementsBetween0And20
let elementsBetween100And999 x = string (x / 100) :: "hundred" :: emptyIfZero (fun x -> "and" :: elementsFor2DigitNumber x) (x % 100)
Kntajus / FormView.aspx
Created Jan 31, 2013
Databinding with a LoginView inside a FormView
View FormView.aspx
<asp:FormView ID="fvApplication" runat="server">
<h1>Application Form</h1>
<!-- Lots of detail about application in here -->
<asp:LoginView ID="lvOptions" runat="server">
<asp:RoleGroup Roles="Provider">
<asp:LinkButton runat="server" OnClick="Offer_Click"
Visible='<%# ApplicationStatus.Sent == (ApplicationStatus) Eval("Status") %>'>Make Offer</asp:LinkButton>
Kntajus / DirectoryHelper.cs
Created Jan 31, 2013
Multiple search patterns with DirectoryInfo.GetFiles()
View DirectoryHelper.cs
namespace Diuturnal.Utility {
public class DirectoryHelper {
public static FileInfo[] GetFiles(DirectoryInfo directory,
params string[] searchPatterns) {
List<FileInfo> allFiles = new List<FileInfo>();
foreach (string pattern in searchPatterns) {
Kntajus / DoubleKeyedCollection.cs
Created Jan 31, 2013
Multiple keys with KeyedCollection
View DoubleKeyedCollection.cs
namespace Diuturnal.Utility {
public abstract class DoubleKeyedCollection<TKey, TSecondKey, TItem>
: KeyedCollection<TKey, TItem> {
private Dictionary<TSecondKey, TKey> _secondKeyIndex =
new Dictionary<TSecondKey, TKey>();
public TItem GetItem(TSecondKey secondKey) {
Kntajus / Postcode.cs
Created Jan 31, 2013
UK Postcode Implementation
View Postcode.cs
namespace Diuturnal.Utility {
public struct Postcode {
private const string ValidationString =
@"^\s*(?<out>[A-Z]{1,2}[0-9R][0-9A-Z]?) *(?<in>[0-9][A-Z-[CIKMOV]]{2})\s*$";
private static readonly Regex _validator =
new Regex(ValidationString);
public static readonly Postcode Empty =
new Postcode(string.Empty, string.Empty);
private string _outCode;
Kntajus / HttpRequest.cs
Created Jan 31, 2013
Manually creating an HttpRequest for testing
View HttpRequest.cs
// Whip up a fake HttpRequest
HttpRequest httpRequest = new HttpRequest("default.aspx", "", string.Empty);
// Have to access the Headers collection first as this creates the internal collection we're about to hack
NameValueCollection headers = httpRequest.Headers;
// Accessing Headers property above will have created the private _headers member, so now we can grab it
headers = (NameValueCollection) httpRequest.GetType().GetField("_headers", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(httpRequest);
PropertyInfo readOnlyInfo = headers.GetType().GetProperty("IsReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);
Kntajus / CompilerFail.cs
Created Jan 31, 2013
Break the compiler by building this in Visual Studio 2010!
View CompilerFail.cs
public class CompilerFail {
public int[] Numbers { set { ; } }
public int FirstNumber { get { return Numbers[0]; } }
You can’t perform that action at this time.