Skip to content

Instantly share code, notes, and snippets.

View bjartwolf's full-sized avatar

Bjørn Einar Bjartnes bjartwolf

View GitHub Profile
@bjartwolf
bjartwolf / antshort.fs
Created December 15, 2014 17:31
antshort
module ant
[<EntryPoint>]
let main argv =
List.fold(fun((x,y),d,b)_-> let a=[|0;1;0;-1;0|] in let p=x+a.[d+1],y+a.[d] in p,(d+if b-set[p]=b then 3 else 1)%4,(b-set[p])+(set[p]-b))((100,100),0,set[])[0..15000] |> printfn "%A"
System.Console.ReadLine() |> ignore
0
@bjartwolf
bjartwolf / smsservice.fs
Created December 15, 2014 18:17
smsservice.fs
namespace FDK.SmsSender
open PSWinCom.Gateway.Client;
open SmsTypes;
type ISmsService = abstract member SendSms: FdkSms -> SmsStatus
type Sender = string
type SmsService(sender: Sender, client: IGatewayClient) =
interface ISmsService with
member this.SendSms fdkSms=
let receiverNumber, body = fdkSms
@bjartwolf
bjartwolf / smstypes.fs
Created December 15, 2014 18:18
smstypes.fs
module SmsTypes
open PSWinCom.Gateway.Client;
type SmsStatus = Response of MessageResult | Error of System.Exception
type FdkSms = string * string
type UnknownError = { Error: string}
type SmsLogMessage = { ReceiverNumber : string;
@bjartwolf
bjartwolf / sendingsms.fs
Created December 15, 2014 18:20
sendingsms
let lang = (new LanguageUtil(logger)).getLanguageAndLogIfUnknown evt
let wrapContentWithPhonenumber x = (evt.PhoneNumber, x) : FdkSms
let smsContent = updatePhoneNumberFormatter evt lang
smsContent |> // Start with the contents of a message
wrapContentWithPhonenumber |>
sms.SendSms |>
logResultOfSending logger evt.PhoneNumber smsContent |>
throwExceptionsWhenMessagesAreNotSent
@bjartwolf
bjartwolf / loggingandthrowing.fs
Created December 15, 2014 18:21
logging and rhrowing exceptions
let logResultOfSending (logger: IEventIDLog) (receiverNumber : string) (body : string) (status : SmsStatus) =
match status with
| Response result ->
let logg = logresponse receiverNumber body result
match result with
| Success -> logg SmsSent.EventId logger.Info
| Fail -> logg SmsError.EventId logger.Error
| Error ex ->
logger.Error(SmsError.EventId, "error sending sms", ex)
status
type Rod = Dagger | Sword | Fork
type Plate = GoldPlate | SilverPlate | BronzePlate
type Bottom = Rod | Plate
type shish<'A> =
Bottom of 'A
| Onion of shish<'A>
| Lamb of shish<'A>
| Tomato of shish<'A>
let a = Onion(Onion(Bottom GoldPlate))
@bjartwolf
bjartwolf / morekebab.fs
Last active August 29, 2015 14:14
kebabs
type Rod = Dagger | Sword | Fork
type Plate = GoldPlate | SilverPlate | BronzePlate
type Bottom = Rod | Plate
type shish<'A> =
Bottom of 'A
| Onion of shish<'A>
| Lamb of shish<'A>
| Tomato of shish<'A>
let rec isVeg kebab =
match kebab with
let R2 n =
let xs = [-n .. n]
seq { for x in xs do for y in xs do yield x,y }
let TaxicabNorm (x, y) = abs x + abs y
let radius = 10
let indexedLetters =
['A' .. 'Z'] |> Seq.mapi (fun i l -> i,l)
open System
// We can not work with radius of the diamond outside 0 to 25
let CreateRadius (i:int) =
match i with
| i when i = 0 && i < 26 -> Some i
| _ -> None
let radius = CreateRadius 20 |> Option.get
let axis = [|-radius .. radius|]
@bjartwolf
bjartwolf / noworks.fs
Last active August 29, 2015 14:20
would be nice if it worked
type foo<'A> = { Name: string; things : 'A list}
let bar = { Name = "Bjorn"; things = [1;2;3;4]}
let baz = {Name = bar.Name; things = bar.things |> List.map (fun x -> x.ToString())}
let baznoworky = { bar with things = (bar.things |> List.map (fun x -> x.ToString()))}