Skip to content

Instantly share code, notes, and snippets.

@nojaf
nojaf / script.fsx
Created January 12, 2018 08:25
List of options to list of value
[Some 7; None; Some 6; Some 5]
|> List.choose id
// [7;6;5]
@nojaf
nojaf / index.html
Created December 21, 2017 07:39
Basic html structure
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge"> <!-- † -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Page Title</title>
</head>
<body>
</body>
</html>
@nojaf
nojaf / subPath.fsx
Last active August 26, 2019 19:15
Suave subPath
open System
open Suave
open Suave.Filters
let subPath path (ctx:HttpContext) =
async {
let localPath = ctx.request.url.LocalPath
let result =
match (localPath.StartsWith(path)) with
| false -> None
@nojaf
nojaf / index.js
Created November 24, 2017 07:02
Simple node server
const http = require('http')
const port = 3000
const requestHandler = (request, response) => {
console.log(request.url)
response.end('Hello Node.js Server!')
}
const server = http.createServer(requestHandler)
@nojaf
nojaf / mapPartition.fs
Created October 2, 2017 11:23
Split Result list into oks and errors
let mapPartition (partitioner : 'T -> Result<'U1, 'U2>) list : 'U1 list * 'U2 list =
// OPTIMIZATION : If the input list is empty, immediately return empty results.
if List.isEmpty list then
[], []
else
// Mutable variables are used here instead of List.fold for maximum performance.
let mutable list = list
let mutable resultList1 = []
@nojaf
nojaf / Program.fs
Created September 30, 2017 07:27
Add cors to giraffe
// <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.0" />
let configureApp (app : IApplicationBuilder) =
app.UseGiraffeErrorHandler errorHandler
app.UseCors(fun builder ->
builder.WithOrigins("http://localhost:8080").AllowAnyMethod().AllowAnyHeader() |> ignore
) |> ignore
let configureServices (services : IServiceCollection) =
services.AddCors() |> ignore
@nojaf
nojaf / QuerySelector.fs
Created September 26, 2017 08:37
Fable querySelector
module Helper
open Fable.Import.Browser
let private toList (nodeList:NodeListOf<Element>) =
let length = nodeList.length - 1.0
[0.0 .. length]
|> List.map (fun i -> nodeList.item i :?> HTMLElement)
let dollar selector (element:HTMLElement) =
@nojaf
nojaf / one.fs
Created September 25, 2017 12:47
Fable I
open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
type App() =
member this.ChangeColor selector color =
let element = Browser.document.querySelector selector :?> Browser.HTMLElement
element.style.color <- color
@nojaf
nojaf / Yield.cs
Created September 18, 2017 12:33
yield!
/// <summary>Wraps this object instance into an IEnumerable<T> consisting of a single item.</summary>
/// <typeparam name="T"> Type of the object. </typeparam>
/// <param name="item"> The instance that will be wrapped. </param>
/// <returns> An IEnumerable<T> consisting of a single item. </returns>
public static IEnumerable<T> Yield<T>(this T item)
{
yield return item;
}
@nojaf
nojaf / debugger.fs
Created September 18, 2017 06:03
debugger; @ Fable
Fable.Core.JsInterop.Debugger