Skip to content

Instantly share code, notes, and snippets.

View mastoj's full-sized avatar

Tomas Jansson mastoj

View GitHub Profile
@mastoj
mastoj / build.cmd
Last active August 29, 2015 14:23
FAKE question about parameters
@echo off
cls
"NuGet.exe" "Install" "FAKE" "-OutputDirectory" "packages" "-ExcludeVersion"
"packages\FAKE\tools\Fake.exe" build.fsx %*
pause
@mastoj
mastoj / money.cs
Created June 11, 2015 11:39
Simple implementation of money for C#
namespace Money
{
public class Money<TCurrency> where TCurrency : ICurrency
{
private readonly decimal _value;
public Money(decimal value)
{
_value = value;
}
@mastoj
mastoj / Person.cs
Last active August 29, 2015 14:21
Helps clearify things for this blog post: http://blog.bjartwolf.com/?p=4522
public class Person
{
private readonly PersonState _state;
public Person(string name)
{
_state = new PersonState(name);
}
public string GetName()
module Person =
open System
type PersonState = private { id: Guid; name: string; age: int}
let createPerson id name age = {id = id; name = name; age = age}
let changeName name personState = {personState with name = name}
let changeAge age personState =
// some crazy business rule involving age
{personState with age = age}
module SomeOtherModule =
// Implemented Jimmy Bogard's https://github.com/jbogard/presentations/tree/master/WickedDomainModels/After in F#
namespace FSharp.Wicked
open System
module Types =
type Id = Id of Guid
type Entity<'T> = Id * 'T
let createEntity state = Guid.NewGuid(), state
@mastoj
mastoj / lottery.fsx
Created March 23, 2015 18:15
F# Draw for meetup on meetups.com
#r "./FSharp.Data.2.2.0/lib/net40/FSharp.Data.dll"
open FSharp.Data
open System
let rnd = Random()
@mastoj
mastoj / CustomDirectRouteProvider .cs
Created February 19, 2015 09:16
CustomDirectRouteProvider with inherited route prefix
public class CustomDirectRouteProvider : DefaultDirectRouteProvider
{
protected override IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(HttpActionDescriptor actionDescriptor)
{
return actionDescriptor.GetCustomAttributes<IDirectRouteFactory>
(inherit: true);
}
protected override string GetRoutePrefix(HttpControllerDescriptor controllerDescriptor)
{
@mastoj
mastoj / Diamond.fs
Created February 9, 2015 20:23
F# Diamond
open System
type CharSpec = {Char:char; SndOffset: int}
type DiamondSpec = CharSpec list
let printDiamondRow charSpec =
match charSpec with
| {Char = x; SndOffset = 0} -> sprintf "%c" x
| {Char = x; SndOffset = y} -> sprintf "%c%s%c" x (String(' ', (y-1))) x
let padRow size (row:string) =
@mastoj
mastoj / luke1.fsx
Last active August 29, 2015 14:10
Kalender 2014
open System
let toDecStr = sprintf "%i"
let toOctStr = sprintf "%o"
let revStr (x:string) = String(x.ToCharArray() |> Array.rev)
let isPalindrom x = x = (revStr x)
let numPalCheck conv x = x |> conv |> isPalindrom
let decCheck = numPalCheck toDecStr
let octCheck = numPalCheck toOctStr
let checker x = (octCheck x) && (decCheck x)
let result = [1..1000000] |> Seq.filter checker |> Seq.length
@mastoj
mastoj / chocolateyInstall.ps1
Created October 20, 2014 18:08
Chocolatey install script for SQL Server 2012
$setupExe = "c:/files/SQLEXPRWT_x64_ENU.exe"
$adminsGroupName = (New-Object Security.Principal.SecurityIdentifier 'S-1-5-32-544').Translate([Security.Principal.NTAccount]).Value
Install-ChocolateyPackage 'SqlServer2012Express' 'exe' "/Q /INDICATEPROGRESS /ACTION=Install /FEATURES=SQL,Tools /TCPENABLED=1 /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT=`"NT AUTHORITY\Network Service`" /SQLSYSADMINACCOUNTS=`"$adminsGroupName`" /AGTSVCACCOUNT=`"NT AUTHORITY\Network Service`" /IACCEPTSQLSERVERLICENSETERMS " $setupExe -validExitcodes @(0,3010)
#The exe referenced is the official for SQL Express 2012, http://download.microsoft.com/download/8/D/D/8DD7BDBA-CEF7-4D8E-8C16-D9F69527F909/ENU/x64/SQLEXPRWT_x64_ENU.exe