Skip to content

Instantly share code, notes, and snippets.

View bartelink's full-sized avatar

Ruben Bartelink bartelink

View GitHub Profile
@ploeh
ploeh / gist:9702672
Created March 22, 2014 07:30
ASP.NET Web API 2 ApiController AutoFixture Customization
type ApiControllerCustomization() =
let controllerSpecification =
{ new IRequestSpecification with
member this.IsSatisfiedBy request =
match request with
| :? Type as t when typeof<ApiController>.IsAssignableFrom t ->
true
| _ -> false }
interface ICustomization with
public static class PlaceHolderForProjections {
public static readonly PortfolioProjection = TSql.Projection().
When<PortfolioAdded>(@event =>
TSql.NonQuery(
"INSERT INTO [Portfolio] (Id, Name) VALUES (@P1, @P2)",
new { P1 = TSql.Int(@event.Id), P2 = TSql.NVarChar(@event.Name, 40) }
).
When<PortfolioRemoved>(@event =>
TSql.NonQuery(
"DELETE FROM [Portfolio] WHERE Id = @P1",
@ptrelford
ptrelford / TwitterDataScience.fsx
Last active August 29, 2015 14:06
FsiBot Data Science Prototype
#r "System.Windows.Forms.DataVisualization.dll"
#r @"..\packages\FSharp.Charting.0.90.7\lib\net40\FSharp.Charting.dll"
#r @"..\packages\FSharp.Data.2.0.14\lib\net40\FSharp.Data.dll"
open FSharp.Data
open FSharp.Charting
let wb = WorldBankData.GetDataContext()
type Indicator = Runtime.WorldBank.Indicator
type Indicators = WorldBankData.ServiceTypes.Indicators

To enable parallel build for F# projects in Visual Studio 2013, add a string parameter named IsMultiThreadedBuildEnabled with value 1 into key HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Projects\{f2a71f9b-5d33-465a-a702-920d77279786}

(replace 12.0_Config with 14.0_Config for VS 2015)

Note: At some point this setting may disappear, it seems Visual Studio may erase it. So, you should check whether it's there before run VS.

@eulerfx
eulerfx / EvetStore.fs
Last active February 20, 2016 13:07
EventStore pull-to-push subscription transition
let subscribeAsAsyncSeq (conn:IEventStoreConnection) (stream:string) (resolveLinks:bool) (bufferSize:int) (ct:CancellationToken) = asyncSeq {
use buffer = new System.Collections.Concurrent.BlockingCollection<ResolvedEvent>(bufferSize)
let inline onEvent subs (evt:ResolvedEvent) =
buffer.Add(evt)
let inline onDrop (subs:EventStoreSubscription) (reason:SubscriptionDropReason) (ex:exn) =
printfn "SUBSCRIPTION DROPPED! last position=%i reason=%O ex=%O" (subs.LastEventNumber.GetValueOrDefault()) reason ex
()
let! subs = conn.SubscribeToStreamAsync(stream, resolveLinks, Action<_,_>(onEvent), Action<_,_,_>(onDrop), null) |> Async.AwaitTask
yield! buffer.GetConsumingEnumerable(ct) |> AsyncSeq.ofSeq
}
#r @"c:\prg\Fuchu\Fuchu\bin\Debug\Fuchu.dll" // https://www.nuget.org/packages/Fuchu/
open System
open Fuchu
// Write your tests as a list of string * Async<unit>
let tests = [
"Check google response", async {
use client = new System.Net.WebClient()
let! a = client.AsyncDownloadString (Uri("http://www.google.com"))
@filipw
filipw / gist:9846071
Last active May 3, 2016 18:02
ASP.NET Web API hosted in Azure Worker Role with OWIN in F#
namespace WebApi.AzureWorker
open Owin
open System
open System.Diagnostics
open System.Net
open System.Threading
open System.Net.Http
open System.Web.Http
open Microsoft.Owin.Hosting
@Buthrakaur
Buthrakaur / gist:1613003
Created January 14, 2012 21:44
NHibernate QueryOver.List extension to support casting to anonymous types
public static IList<TRes> ListAs<TRes>(this IQueryOver qry, TRes resultByExample)
{
var ctor = typeof (TRes).GetConstructors().First();
return qry.UnderlyingCriteria
.SetResultTransformer(Transformers.AliasToBeanConstructor(ctor))
.List<TRes>();
}
[Fact]
public void ListAs_Should_CastQueryOverResultToTypeSameAsSupliedExampleInstance()
@gregmac
gregmac / $PROFILE\Microsoft.PowerShell_profile.ps1
Last active December 12, 2019 02:06
PowerShell Set-WindowTitle profile config
# Import posh-git (if installed via scoop)
$poshGitModule = "$HOME\scoop\apps\posh-git\current\posh-git.psd1";
if (Test-Path $poshGitModule) { Import-Module $poshGitModule }
# msbuild convenience alias
Set-Alias MSBuild 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe'
# bash-style completion
Set-PSReadlineKeyHandler -Key Tab -Function Complete
#Set-PSReadlineOption -ShowToolTips
@skleanthous
skleanthous / ParkingLot.cs
Created August 11, 2021 16:44
The parking lot implementation
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using EventStore.Client;
namespace BullOak.Repositories.EventStore.Test.Integration
{
internal record InspectionId(Guid Id);
internal record LicencePlate(string PlateNumber);