This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string ToVerbsString(ApplyTo verbs) | |
{ | |
return string.Join(" ", Enum.GetValues(typeof(ApplyTo)).Cast<ApplyTo>().Where(x => x != ApplyTo.All && x != ApplyTo.None && verbs.Has(x)).Select(x => x.ToString().ToUpper())); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegisterUserService : IService<RegisterUser> | |
{ | |
public object Execute(RegisterUser request) | |
{ | |
//save user | |
//map saved user from User to UserResponse | |
return new UserResponse(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChildModelBindingPlugin : IPlugin | |
{ | |
public void Register(IAppHost appHost) | |
{ | |
appHost.RequestFilters.Add(RequestFilter); | |
} | |
static void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto) | |
{ | |
requestDto = Bind(requestDto, req.FormData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RomanNumeral | |
{ | |
static readonly List<RomanNumeral> RomanNumerals; | |
readonly int integer; | |
readonly string roman; | |
static RomanNumeral() | |
{ | |
RomanNumerals = new List<RomanNumeral> | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Useful functions: | |
Convert number to array of numbers: | |
Seq.unfold (function | x when x = 0 -> None | x when x > 10 -> Some(x / 10, x % 10) | x -> Some(x, 0)) 81 | |
Primes: | |
Seq.filter (fun x -> {2..x |> float |> sqrt |> int} |> Seq.forall(fun y -> x = 2 || x % y > 0)) | |
----------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Given | |
{ | |
protected static When Given_(Action action) | |
{ | |
action(); | |
return new When(); | |
} | |
protected class When | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let random low hi len = | |
let random = Random() | |
seq {for i in 1..len -> char <| random.Next(int low, int hi) } |> String.Concat | |
let text() = | |
random 'a' 'z' 10 | |
let email() = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<TestFixture>] | |
type When() = | |
[<DefaultValue>] val mutable message : string | |
do | |
printfn "Constructor" | |
[<TestFixtureSetUp>] | |
member x.TestFixtureSetUp() = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module IISExpress | |
open System.Diagnostics | |
open System | |
open System.IO | |
let killProcess processName = | |
let processStartInfo = ProcessStartInfo(FileName = "taskkill", | |
Arguments = "/F /IM " + processName, | |
UseShellExecute = false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Result = | |
| Text of string | |
| Number of int | |
override self.ToString() = match self with | Text s -> s | Number i -> i.ToString() | |
let (>>=) f1 f2 m = match f1 m with | Text _ as r -> r | Number i -> f2 i | |
let rule f s = function | i when f i -> Text s | i -> Number i | |
let fizz = rule (fun i -> i % 3 = 0) "fizz" | |
let buzz = rule (fun i -> i % 5 = 0) "buzz" | |
let fizzbuzz = rule (fun i -> i % 3 = 0 && i % 5 = 0) "fizzbuzz" | |
let lucky = rule (fun i -> i.ToString().Contains "3") "lucky" |
OlderNewer