Skip to content

Instantly share code, notes, and snippets.

View Dzoukr's full-sized avatar
:octocat:
Hacking F#

Roman Provazník Dzoukr

:octocat:
Hacking F#
View GitHub Profile
@Dzoukr
Dzoukr / Dockerfile
Created October 2, 2015 11:31
F# on Mono docker file
FROM ubuntu:latest
MAINTAINER Roman Provaznik <dzoukr@dzoukr.cz>
ENV LANG C.UTF-8
RUN apt-get update && apt-get -y -q install mono-complete fsharp
ADD . app/
EXPOSE 8083
ENTRYPOINT ["mono", "/app/SuaveIO.exe"]
module FSharp.Rop
let bind2 f x y =
match x, y with
| Ok xR, Ok yR -> f xR yR
| Error e, _ | _, Error e -> Error e
let apply resultF result =
match resultF with
| Ok f -> Result.map f result
module Chiron.Extensions
let tryDeserializeWith (fromJson : Json<'a>) : Json -> Choice<'a, string> =
fun json ->
match fromJson json with
| JsonResult.Value x, _ -> Choice1Of2(x)
| JsonResult.Error err, _ -> Choice2Of2(err)
let tryDeserializeWithP (_, fromJson : Json<'a>) : Json -> Choice<'a, string> =
tryDeserializeWith fromJson
@Dzoukr
Dzoukr / Dapper.fs
Created August 3, 2017 09:53 — forked from vbfox/Dapper.fs
Minimal dapper in F#
module DapperFSharp =
open System.Data.SqlClient
open System.Dynamic
open System.Collections.Generic
open Dapper
let dapperQuery<'Result> (query:string) (connection:SqlConnection) =
connection.Query<'Result>(query)
let dapperParametrizedQuery<'Result> (query:string) (param:obj) (connection:SqlConnection) : 'Result seq =
@Dzoukr
Dzoukr / Dapper.Extensions.fs
Last active June 19, 2021 01:50
F# extensions for Dapper
module Dapper.Extensions
open System
open System.Data.SqlClient
open Dapper
let extractValue (x:obj) =
match x with
| null -> null
| _ -> match x.GetType().GetProperty("Value") with
@Dzoukr
Dzoukr / View.fs
Last active April 4, 2022 17:09
Feliz.Bulma button (minimal example)
Bulma.button [
button.isPrimary
prop.children [
Html.i [ prop.className "fas fa-user"; prop.style [ style.marginRight 5 ] ]
Html.text "Hello Feliz.Bulma"
]
]
let inline websocket<'Data> =
FunctionComponent.Of(fun (props: {| url : string; retryTimeSpan : TimeSpan; onConnected: bool -> unit; onMessage: 'Data -> unit |}) ->
let mutable currentlyConnected = false
let mutable wasAlreadyConnected = false
let connected = Hooks.useState false
let mutable webservice = null
let connect() =
if currentlyConnected then () else
let ws = WebSocket.Create(props.url)
@Dzoukr
Dzoukr / App.fs
Created June 12, 2020 12:30 — forked from aspnetde/App.fs
Feliz – MVU with React Function Components
module App
open Elmish
type State =
{ CurrentUser: string option }
type Msg =
| SignIn of string
| SignOut
@Dzoukr
Dzoukr / pre-request.js
Created August 10, 2020 18:16 — forked from landy/pre-request.js
Load Bearer token on each postman request
//add this as pre-request script on postman collection
const moment = require("moment")
const {
apiRoot,
authPath,
username,
password,
bearerTokenValidUntil
} = pm.variables.toObject();
@Dzoukr
Dzoukr / Declarative.cs
Last active February 16, 2021 14:14 — forked from rarous/1.cs
Imperative vs Declarative
static Maybe<string> TryGetErrorMessage(XElement html)
{
return html.GetElementsByClassName("ErrorMessage").MaybeFirst().
Where(x => !x.Attributes("style").Any()
|| !x.Attribute("style").Value.Contains("visibility:hidden")).
Or(html.GetElementsByClassName("ErrorText").MaybeFirst()).
Select(x => x.Value.Trim());
}