Skip to content

Instantly share code, notes, and snippets.

@liammclennan
liammclennan / gist:7958108
Last active December 31, 2015 08:08
F# Event Sourcing
/// types
type addPersonEvent = { name: string; age: int }
type birthdayEvent = { name: string; }
type event =
| AddPerson of addPersonEvent
| Birthday of birthdayEvent
type person = { name: string; age: int; joined: DateTime }
type aggregateStream = seq<event>
/// event stream for person aggregate
@liammclennan
liammclennan / gist:7446911
Created November 13, 2013 10:30
React component content
/** @jsx React.DOM */
var Hello = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
React.renderComponent(<Hello name="World"><p>foo</p></Hello>, document.body);
@liammclennan
liammclennan / gist:7352790
Last active December 27, 2015 16:09
string calculator
let lToS (l:char list) = System.String.Concat(Array.ofList(l))
let sumString =
let parse (l:string) =
let guessDelimeter (l:string) =
match Seq.toList l with
| '/'::'/'::c::'\n'::_ -> c
| _ -> Seq.find (fun i -> i = ',' || i = '\n') l
let valuePart = (fun (s:string) ->
match Seq.toList s with
@liammclennan
liammclennan / gist:6301387
Created August 21, 2013 23:13
Curl with integrated authentication (NTLM)
$ curl --ntlm http://localhost:50695/Scripts/src.js -u : -o src.js
@liammclennan
liammclennan / gist:6277299
Created August 20, 2013 05:10
Merge dictionaries (ie _.extend)
public static class DictionaryExtensions
{
public static Dictionary<TKey, TValue> Merge<TKey,TValue>(this Dictionary<TKey, TValue> first,
Dictionary<TKey, TValue> second)
{
return new[] {first, second}
.SelectMany(d => d) // flatten dictionaries to IEnumerable<KeyValuePair<TKey,TValue>>
.ToLookup(kvp => kvp.Key, kvp => kvp.Value) // group by key
.ToDictionary(g => g.Key, g => g.Last()); // last value wins
}
_ = require 'underscore'
class SurveyResponse
constructor: (@site, @results) ->
default_result =
'csharp': 0
'fsharp': 0
'haskell': 0
'ruby': 0
@liammclennan
liammclennan / gist:5639688
Last active December 17, 2015 16:38
Strongly typed view functions
public Markup Home(string name) {
return P("Welcome " + name)
}
public Markup Layout(Markup content) {
return Html(
Body (
Div(content).attr(new {@class= "content"})
)
}
; 1.1
10
;10
(+ 5 3 4)
;12
(- 9 1)
;8
@liammclennan
liammclennan / 1.3.ss
Created May 5, 2013 04:36
Sicp 1.1 exercises
(define (doit a b c)
(define descending (sort (list a b c) >))
(+ (square (car descending)) (square (car (cdr descending))))
)
import System.IO
import Control.Concurrent
fibonacci :: Int -> Int
fibonacci 1 = 0
fibonacci 2 = 1
fibonacci n = fibonacci (n-1) + fibonacci (n-2)
nTimes :: Int -> IO ThreadId -> IO ()
nTimes 0 do_this = return ()