Skip to content

Instantly share code, notes, and snippets.

View jovaneyck's full-sized avatar

Jo Van Eyck jovaneyck

View GitHub Profile
@jovaneyck
jovaneyck / gist:8c81bf83e2e1dacd4548
Last active August 29, 2015 14:21
Working with Thread.CurrentPrinciple in unit tests by providing a very thin abstraction layer
public interface IPrincipalInformationProvider
{
bool IsLoggedIn { get; }
...
}
public class ThreadBasedPrincipalInformationProvider : IPrincipalInformationProvider
{
public bool IsLoggedIn
(define lorem
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
)
;; tests
;; (equal? (split (list 1 2 3) 0) (list () (list 1 2 3)) )
;; (equal? (split () 5) (list () ()) )
;; (equal? (split (list 1 2 3) 4) (list (list 1 2 3) ()) )
@jovaneyck
jovaneyck / gist:dc66da9fb2d52ccdbc9f
Last active December 8, 2015 10:42
How to write this in idiomatic F#?
let isValid input =
input
|> parse
/*smelly and doesn't scale, what's the F# way of combining predicates?*/
|> (fun p -> predicate1 p && predicate2 p)
@jovaneyck
jovaneyck / CrossriderStub.js
Last active December 14, 2015 09:18
A basic stub for the Crossrider javascript API I use for local unit testing of browser extensions. It's by no means complete, so feel free to add/improve. Usage: *first reference this stub in your test html to make the stub available for your own code *next, reference the background.js in your test html (the order of script includes is important…
var appAPI = (function () {
var tabListener;
var backGroundListener;
var storedValue = null;
return {
ready: function (callback) { callback(); },
message: {
addListener: function (listener) {
@jovaneyck
jovaneyck / gist:706f19eb5aa80b4bfa75a2568dbcdd69
Last active May 25, 2016 10:52
I'm trying to define a function with type signature (int option -> int option -> int option). It results in a Some containing the sum or None when one of the arguments is None. I have an implementation but it looks needlessly verbose. Is there a more idiomatic way to achieve this?
let add : (int option -> int option -> int option) =
(fun fst snd ->
fst
|> Option.bind
(fun f ->
snd
|> Option.bind (fun s -> Some (f + s))))
test <@ add (Some 1) (Some 2) = Some 3 @>
test <@ add None (Some 2) = None @>
@jovaneyck
jovaneyck / gist:82292e28df6ea6446c9c7f5d106fced9
Created October 11, 2016 08:02
Unit testing SQL stored procedures
BEGIN TRAN
DELETE FROM [oltp.cq.logging.2.10.0.x].dbo.AUD_EXC
DELETE FROM [oltp.cq.logging.2.10.0.x].dbo.AUD_ACT
USE [oltp.cq.stage.2.10.0.x]
DELETE FROM QCD_CYC
DELETE FROM QCD_EVT
DELETE FROM QUA_CYC
@jovaneyck
jovaneyck / voting.fsx
Created May 19, 2017 11:44
F# script to tally up AE hackathon 2017 scores
#r @"C:\nuget_local\Unquote.3.1.1\lib\net45\Unquote.dll"
open Swensen.Unquote
type Vote = {voter : string; first : string; second : string; third : string}
let lines =
System.IO.File.ReadAllLines(@"C:\Users\ext_jvy\Desktop\hubspot-form-submissions-ae-hackathon-2017-public-voting-2017-04-28 (1).csv")
|> List.ofArray
|> List.skip 1
@jovaneyck
jovaneyck / gist:e23f80b396d376c7bb6a939c0854744a
Created May 22, 2017 12:52
ASP.NET MVC Bundle cache bust
internal static class BundleExtensions
{
public static Bundle WithLastModifiedToken(this Bundle sb)
{
sb.Transforms.Add(new LastModifiedBundleTransform());
return sb;
}
public class LastModifiedBundleTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
@jovaneyck
jovaneyck / rover.fsx
Last active November 11, 2017 22:20
Playing around with functional calisthenics and property-based testing on the Mars Rover kata
type Direction = North | East |South | West
type Location = { x : int; y : int}
type Rover = { Location : Location; Direction : Direction}
let createRover location direction = {Location = location; Direction = direction}
type Command =
| Forward
| Backward
| TurnLeft
@jovaneyck
jovaneyck / notes.md
Last active January 18, 2018 11:45
Kennis & Pasta - Test pyramid