Skip to content

Instantly share code, notes, and snippets.

@chrismckelt
chrismckelt / WebApiRoutesValidFixture.cs
Last active August 29, 2015 14:01
Web API Test to ensure public routes do not change
[TestFixture]
public class RouteTestFixture
{
[Test]
public void Routes_should_not_change()
{
const string good = @"admin/event/lasteventhandlererror/;admin/event/search/AdminEventSearch;admin/event/{id}/AdminEventGet;admin/event/{seq}/byseq/AdminEventGetBySeq;admin/event/max/GetMaxEvent;admin/event/previous/GetEventBefore;admin/event/seq/GetSeq;admin/event/publish/test/;admin/event/skip/{seq=}/;admin/event/skipend/;admin/event/maxseq/;address/addressSearch;address/warnings/{state}/{suburb}/addressWarnings;calendar/{calendarName}/allCalendars;jobAddress/search/;booking/{bookingId}/documents/AddBookingDocuments;booking/{bookingId}/document/{documentId}/TagBookingDocument;booking/{bookingId}/document/{documentId}/DeleteBookingDocument;getStructerreValidGuid/GetStructerreValidGuid;booking/{id}/GetBooking;bookings/NewBooking;booking/{id}/UpdateBooking;booking/{id}/DeleteBookingDraft;booking/{id}/submit/SubmitBooking;bookingproject/{projectId}/bookingProjectDetails;b
@chrismckelt
chrismckelt / gist:dec703509eec3f49beae
Created June 26, 2014 09:24
PowerShell - Schedule Task via Windows Scheduler
$Until = New-TimeSpan -End "2036-01-01"
$User = "SYSTEM"
$Path = Resolve-Path MyCustom.Tasks.exe
Function ScheduleTask($name, $task, $time)
{
$Trigger = New-ScheduledTaskTrigger -Once -At $time -RepetitionInterval (New-TimeSpan -Days 1) -RepetitionDuration $Until
module ChrisMcKelt
open System
open System.ServiceModel
open Microsoft.FSharp.Linq
open Microsoft.FSharp.Data.TypeProviders
open System.Linq
let rec chop (arr:array<int>, low:int, high:int, value:int) =
if (high < low) then
null
@chrismckelt
chrismckelt / gist:a29224804af1a1ae30d8
Last active August 29, 2015 14:05
Code Dojo - TypeScript - Simple checkout with alternate discounts
/* tslint:disable */
var files = {
jquery: "./app/scripts/jquery-1.10.2.js",
angular: "./app/scripts/angular.js",
angularAnimate: "./app/scripts/angular-animate.js",
angularSanitize: "./app/scripts/angular/angular-sanitize",
angularUIRouter: "./app/scripts/angular-ui/angular-ui-router",
angularMocks: "./app/scripts/angular/angular-mocks",
underscore: "./app/scripts/underscore",
@chrismckelt
chrismckelt / gist:9a6d36a6f0ebe9accb51
Last active August 29, 2015 14:05
Dispatcher with static typed cache for fast MethodInfo lookup
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Castle.Windsor;
using Iesi.Collections;
using Newtonsoft.Json;
using Structerre.MetaStore.Framework.Events;
using Structerre.MetaStore.Framework.Handlers;
using Structerre.MetaStore.Framework.Logging;
@chrismckelt
chrismckelt / NSubstituteExtensions_AllPropertiesMatch.cs
Last active August 29, 2015 14:08
NSubstitute Extensions–AllPropertiesMatch -- argument matcher for object to object checking with support for dynamic DTO comparison
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Dynamic;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using NSubstitute;
@chrismckelt
chrismckelt / 3-different-ways-to-create-anon-objects
Last active August 29, 2015 14:08
Strong typed anon objects from lambda expressions - sample
[Fact]
public void PopulatesFranchiseSummary()
{
When(_ => _handler.Handle(_createdEvent));
Then(session =>
{
var loanContract = session.Get<PersonalLoanContract>(_createdEvent.AggregateId);
//original - manual anon
@chrismckelt
chrismckelt / TestExtensions.cs
Last active August 29, 2015 14:08
var exp1 = @event.ToDto<CustomerCreatedEvent,CustomerDetail>( x=> x.AggregateId.As("CustomerId"), x => x.Email, x => x.FirstName, x => x.Surname);
public static dynamic ToDynamic(this object value)
{
IDictionary<string, object> expando = new ExpandoObject();
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(value.GetType()))
expando.Add(property.Name, property.GetValue(value));
return expando as ExpandoObject;
}
@chrismckelt
chrismckelt / asyncseq-anagram-checker
Last active August 29, 2015 14:10
F# AsyncSeq anagram checker -- async run through a list pulling out found results
namespace CodeDojo
module CodeDojo_Anagram =
open System
open System.ServiceModel
open System.Collections.Generic
open Microsoft.FSharp.Linq
open FSharp.Control
@chrismckelt
chrismckelt / DatabaseBackup.fs
Created December 23, 2014 10:14
DatabaseBackup.fs - backup all databases to a folder
#if INTERACTIVE
namespace Database
#endif
module DatabaseBackup
#if INTERACTIVE
=
#r "System.dll"