Skip to content

Instantly share code, notes, and snippets.

View kunjee17's full-sized avatar
💭
Functional Programmer for hire. F#, Scala, Rust. For web, mobile, cloud etc.

Kunjan Dalal kunjee17

💭
Functional Programmer for hire. F#, Scala, Rust. For web, mobile, cloud etc.
View GitHub Profile
import { Component } from '@angular/core';
import { Hero } from './hero';
@Component({
selector: 'app-root',
templateUrl: './Component.html',
styleUrls : ['./Component.css']
})
export class AppComponent {
// imports
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { ItemDirective } from './item.directive';
let fizzBuzz x =
match x with
| _ when (x % 15) = 0 -> "FizzBuzz"
| _ when (x % 3) = 0 -> "Fizz"
| _ when (x % 5) = 0 -> "Buzz"
| _ -> ""
let fizzBuzzTo max =
[1..max]
|> List.iter (fun number -> printfn "%d %s" number (fizzBuzz number))
let topRouter = scope {
pipe_through headerPipe
not_found_handler (text "404")
get "/" helloWorld
get "/a" helloWorld2
getf "/name/%s" helloWorldName
getf "/name/%s/%i" helloWorldNameAge
//scopes can be defined inline to simulate `subRoute` combinator
let users =
freyaMachine {
methods [ GET; OPTIONS; POST ]
availableMediaTypes MediaType.json
doPost createUser
handleOk listUsers }
open Giraffe
let webApp =
choose [
route "/ping" >=> text "pong"
route "/" >=> htmlFile "/pages/index.html" ]
type Startup() =
member __.ConfigureServices (services : IServiceCollection) =
// Register default Giraffe dependencies
open System
open System.Threading
open Suave
[<EntryPoint>]
let main argv =
let cts = new CancellationTokenSource()
let conf = { defaultConfig with cancellationToken = cts.Token }
let listening, server = startWebServerAsync conf (Successful.OK "Hello World")
module viewfiles.Main
open System
open Nancy.Hosting
type DemoApp () =
inherit NancyModule()
do
let Get = base.Get
Get.["/"] <- fun parameters -> "Hello from Nancy" :> obj
@kunjee17
kunjee17 / servicestack.fs
Created July 24, 2018 11:11
Sample with service stack and F#
namespace Todos
open System;
open System.IO;
open Microsoft.AspNetCore.Builder;
open Microsoft.AspNetCore.Hosting;
open Microsoft.Extensions.Logging;
open Funq;
open ServiceStack;
open ServiceStack.Configuration;
@kunjee17
kunjee17 / websharper.fs
Created July 24, 2018 11:06
WebSharper example
open WebSharper
open WebSharper.JavaScript
open WebSharper.JQuery
open WebSharper.UI
open WebSharper.UI.Client
[<JavaScript>]
module Code =
// This creates a typed access to the HTML template (see the Markup tab)
type IndexTemplate = Templating.Template<Snippet.IndexHtml>