Skip to content

Instantly share code, notes, and snippets.

View DotNetNerd's full-sized avatar

Christian Holm Diget DotNetNerd

View GitHub Profile
@DotNetNerd
DotNetNerd / NancyBoostrapper
Created January 18, 2012 18:34
Nancy service bootstrapper sample
public class ServiceBootstrapper : NancyBootstrapperBase<IWindsorContainer>
{
bool _modulesRegistered;
protected override IEnumerable<IStartup> GetStartupTasks()
{
return ApplicationContainer.ResolveAll<IStartup>();
}
protected override INancyEngine GetEngineInternal()
@DotNetNerd
DotNetNerd / FUnit and Foq
Created May 8, 2013 07:31
FUnit and Foq sample
namespace Library1.Tests
open NUnit.Framework
open FsUnit
open Foq
type person = {Name : string ; PhoneNumber: string}
type IPhoneNumberRepository =
abstract member FindPhoneNumber : string -> string
@DotNetNerd
DotNetNerd / CLIMutable
Created May 8, 2013 07:33
Using F# CLIMutable and ImpromptuInterface.FSharp with Dapper
[<CLIMutable>]
type Person = { Name : string; Age : int }
//Nuget: ImpromptuInterface.FSharp
use conn = new SqlCeConnection("Data Source=C:\Databases\MyDB.sdf;Persist Security Info=False;")
conn.Open()
let result =
conn.Query("SELECT * FROM People")
@DotNetNerd
DotNetNerd / Canopy
Created May 8, 2013 07:35
Basic webtest with canopy
open canopy
open runner
start firefox
"Go to fona and add to basket" &&& fun _ ->
url "http://www.fona.dk"
let numberOfLineItems = (elements "#miniCartProducts li").Length
let total = read ".miniCartValue"
@DotNetNerd
DotNetNerd / JsRx buffer clicks
Created May 8, 2013 08:15
Shows buffering of clicks using Reactive extentions in JavaScript
.Add("/scripts/libs/rx.min.js")
.Add("/scripts/libs/rx.time.min.js")
.Add("/scripts/libs/rx.jquery.min.js")
var observer = $(e.target).clickAsObservable().bufferWithTime(200)
.subscribe(function (events) {
console.log(events.length);
var $item = $(e.target).closest('.productItem');
var quantity = parseInt($.trim($item.find('.qty').html())) + events.length + 1;
@DotNetNerd
DotNetNerd / Unity with F#
Created May 8, 2013 08:48
Sample of using Unity from F#
open Microsoft.Practices.Unity
type IRepository =
abstract member FindPhoneNumber : string -> string
type Repository() =
interface IRepository with
member this.FindPhoneNumber(name) = match name with "John" -> "87654321" | _ -> ""
let container = new UnityContainer() :> IUnityContainer
@DotNetNerd
DotNetNerd / F# ExtensionMethods
Created May 8, 2013 08:54
Sample of extension method in F#
namespace ExtensionFSharp
module CollectionExtensions =
type System.Collections.Generic.IEnumerable<'a> with
member this.ForEach(f:'a -> unit) =
for item in this do
f item
@DotNetNerd
DotNetNerd / App.xaml
Created May 10, 2013 12:32
Sample of a viewmodel with Reactive UI
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml" xmlns:local="clr-namespace:WpfApplication1.ViewModels">
<Application.Resources>
<local:ApplicationViewModel x:Key="MyApplicationViewModel" />
</Application.Resources>
</Application>
@DotNetNerd
DotNetNerd / App.xaml
Created May 13, 2013 08:02
WPF IOC wireup
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="App_OnStartup">
<Application.Resources>
<Style TargetType="Button">
<Setter Property="FontSize" Value="20" />
</Style>
</Application.Resources>
@DotNetNerd
DotNetNerd / CustomElements
Created May 22, 2013 08:54
Use of custom elements with Polymer
<html>
<body>
<style>
element {
display:none;
}
</style>
<script src="CustomElements/custom-elements.js"></script>