Skip to content

Instantly share code, notes, and snippets.

View bartelink's full-sized avatar

Ruben Bartelink bartelink

View GitHub Profile
@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()
@jboner
jboner / latency.txt
Last active May 2, 2024 09:45
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@bradwilson
bradwilson / Cacheability.cs
Created January 23, 2014 20:53
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@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
@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
@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
}
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",
#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"))
@isaacabraham
isaacabraham / idiomaticjsonserialiser.fs
Created September 7, 2014 21:17
This JSON.Net converter handles F# discriminated unions with more "idiomatic" JSON than what is generated by the current version of JSON .NET. Option types and single case DUs are transparently handled, and tuple-style properties are used rather than array notation.
namespace Newtonsoft.Json.Converters
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
type IdiomaticDuConverter() =
inherit JsonConverter()
[<Literal>]