Skip to content

Instantly share code, notes, and snippets.

@ramnathv
ramnathv / gh-pages.md
Created March 28, 2012 15:37
Creating a clean gh-pages branch

Creating a clean gh-pages branch

This is the sequence of steps to follow to create a root gh-pages branch. It is based on a question at [SO]

cd /path/to/repo-name
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
@gusty
gusty / trampoline.fsx
Last active February 27, 2024 08:04
Trampolines in F#
let trampoline f c n =
let rec loop = function
| Choice1Of2 x -> x
| Choice2Of2 x -> loop (f x)
loop (Choice2Of2 (c,n))
// Test
let factorial n =
let rec factorialT (current, n) =
if n = bigint 0 then Choice1Of2 current
@jdh30
jdh30 / JsonParser.fs
Last active January 30, 2024 14:06
Simple JSON parser written in F# using active patterns
type Json =
| Null
| Bool of bool
| Number of float
| String of string
| Array of Json list
| Object of (string * Json) list
type Bracket = Open | Close
@alfonsogarciacaro
alfonsogarciacaro / Deploy.md
Last active March 3, 2023 09:50
Deploying an F# ASP.NET Core app (Giraffe) to Azure

Deploying an F# ASP.NET Core app to Azure

Last week I spent a lot of time trying to deploy an F# ASP.NET Core app (a Giraffe app, specifically) to Azure because the information to complete all the steps was scattered in several places. So I'm writing this hopefully it will save the pain to others :)

Preparation

The following steps are mostly taken from this guide and it's only necessary to do them once:

  1. Create an account in Azure (or use an existing one)
  2. Create a resource group (or use an existing one)
@szoio
szoio / EventSourcing.scala
Created February 23, 2017 11:17
Event Sourcing with Free Monads
package eventsourcing
import java.time.Instant
import cats._
import cats.data.Coproduct
import cats.free.{Free, Inject}
import cats.implicits._
import doobie.imports._
import fs2.Stream
@mnebes
mnebes / chords.fsx
Created December 9, 2022 14:03
Chord progressions with F#
open System
type Interval =
| PerfectUnison
| MinorSecond
| MajorSecond
| MinorThird | AugmentedSecond // Enharmonically the same in 12TET
| MajorThird
| PerfectFourth
| DiminishedFifth | AugmentedFourth // Enharmonically the same in 12TET
@mausch
mausch / gist:3188428
Created July 27, 2012 14:43
Async exception handling in F#
open System
open System.Net
// exception handling in async using Async.Catch
let fetchAsync (name, url:string) =
async {
let uri = new System.Uri(url)
let webClient = new WebClient()
let! html = Async.Catch (webClient.AsyncDownloadString(uri))
match html with
@isaacabraham
isaacabraham / io-monad.fsx
Last active November 1, 2022 23:58
F# port of the first half of John De Goes "FP to the max" (https://www.youtube.com/watch?v=sxudIMiOo68)
#load @".paket\load\net452\FSharpPlus.fsx"
open FSharpPlus
open System
[<AutoOpen>]
module rec IO =
let run (IO computation) = computation()
type IO<'T> =
@dsyme
dsyme / gist:bfed2eed788c7ba58ccc
Last active July 4, 2022 22:23
Naked type aliases can add and name constraints
// This F# language suggestion wants a way to name collections of constraints:
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/8509687-add-constraints-as-a-language-construct
//
// This is a type alias X<T> = T, so X<int> = int etc.
type X<'T> = 'T
// This is a type alias X<T> = T which adds a constraint
type WithStruct<'T when 'T : struct> = 'T
@battermann
battermann / free.fsx
Last active February 17, 2022 23:26
Free Monad like pattern in F#
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs"
type Continuation<'output, 'next> = 'output -> 'next
module TerminalDsl =
open Chessie.ErrorHandling
type Terminal<'next> =
| WriteLine of string * Continuation<unit, 'next>
| ReadLine of unit * Continuation<string, 'next>