Skip to content

Instantly share code, notes, and snippets.

View t0yv0's full-sized avatar
🎯
Focusing

Anton Tayanovskyy t0yv0

🎯
Focusing
View GitHub Profile
#lang racket
(define (quadratic a b c)
(let* ([det (- (* b b) (* 4 a c))]
[x1 (/ (- (sqrt det) b) (* 2 a))]
[x2 (/ (- (- (sqrt det)) b) (* 2 a))])
(vector x1 x2)))
module My.Blogs
open System
open System.Collections.Generic
open System.Web
open IntelliFactory.WebSharper.Sitelets
type Id = int
type Html = string
module Client =
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Formlet
[<Rpc>]
let CreateBlog blog =
Model.WithBlogs <| fun db ->
db.CreateBlog { blog with Date = DateTime.UtcNow }
[<Rpc>]
let Main : Sitelet<Action> =
{
Controller = Controller
Router = Router
}
let Controller =
let handle = function
| ShowRecentBlogs ->
let blogs = Model.WithBlogs <| fun db -> db.GetRecentBlogs()
View.ShowRecentBlogs blogs
| CreateBlog ->
View.CreateBlog ()
| ReadBlog id ->
let blog = Model.WithBlogs <| fun db -> db.ReadBlog id
match blog with
let Router : Router<Action> =
Router.Table [ShowRecentBlogs, "/"]
<|> Router.Infer()
ShowRecentBlogs <=> /ShowRecentBlogs
CreateBlog <=> /CreateBlog
ReadBlog $x <=> /ReadBlog/$x
UpdateBlog $x <=> /UpdateBlog/$x
DeleteBlog $x <=> /DeleteBlog/$x
let Router : Router<Action> = Router.Infer()
let Router : Router<Action> =
let route = function
| GET (_, SPLIT_BY '/' []) ->
Some ShowRecentBlogs
| GET (_, SPLIT_BY '/' ["create"]) ->
Some CreateBlog
| GET (_, SPLIT_BY '/' ["read"; INT id]) ->
Some (ReadBlog id)
| GET (_, SPLIT_BY '/' ["update"; INT id]) ->
Some (UpdateBlog id)
type Id = int
type Action =
| ShowRecentBlogs
| CreateBlog
| ReadBlog of Id
| UpdateBlog of Id
| DeleteBlog of Id