Skip to content

Instantly share code, notes, and snippets.

(**
# Ukulele
_This post is part of the [F# Advent Calendar in English 2015](https://sergeytihon.wordpress.com/2015/10/25/f-advent-calendar-in-english-2015/) project._
_Check out all the other great posts there! And special thanks to Sergey Tihon for organizing this._
Hi something fun and not too technical for end the year !
As everyone knows, the [favorite instrument of Santa Claus is Ukulele](https://www.google.fr/search?q=santa+claus+ukulele&biw=1024&bih=677&tbm=isch&source=lnms&sa=X&ved=0ahUKEwiHw5H8p-HJAhVE0xQKHZTdDuEQ_AUIBigB) !
So let's play some music, and especialy some Ukulele !
@thinkbeforecoding
thinkbeforecoding / Mindstorm.fsx
Created June 17, 2015 13:17
Mindstorm API in F# with the lego computation expression.
open System
open System.Threading.Tasks
open System.Text
type Opcode =
| UIRead_GetFirmware = 0x810a
| UIWrite_LED = 0x821b
| UIButton_Pressed = 0x8309
| UIDraw_Update = 0x8400
| UIDraw_Clean = 0x8401
[<AutoOpen>]
module Async
// Async extension to enable the direct use of Task<T> and Task
// in async {} blocs
open System
open System.Threading.Tasks
type Microsoft.FSharp.Control.Async with
@thinkbeforecoding
thinkbeforecoding / Server.fs
Created October 1, 2014 08:06
Http Server in F#
// This module implements AwaitTask for non generic Task
// It should be useless in F# 4 since it should be implemented in FSharp.Core
[<AutoOpen>]
module AsyncExtensions =
open System
open System.Threading
open System.Threading.Tasks
type Microsoft.FSharp.Control.Async with
static member Raise(ex) = Async.FromContinuations(fun (_,econt,_) -> econt ex)
@thinkbeforecoding
thinkbeforecoding / CodeHash.fs
Last active August 29, 2015 14:02
This creates a hash code of a F# Expr. The hash code changes when the code change
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open System.Reflection
let hashList f seed = List.fold (fun h v -> h * 37 + f v) seed
let (<+) x y = x * 37 + y
let (!<) f x y = x <+ f y
let rec hashC funcs =
@thinkbeforecoding
thinkbeforecoding / FsCluster.fs
Created May 20, 2014 12:14
EventStore cluster in a F# script !
(*
This gist runs a 3 in memory node EventStore cluster
and a client that send messages to the cluster
To use the web interface, copy EventStore web folders.
You can found them in the server distribution at http://geteventstore.com/downloads/.
Then connect to http://localhost:2113/
You can view the cluster status at:
http://localhost:2113/web/gossip.htm
@thinkbeforecoding
thinkbeforecoding / Actors.FSharp
Last active August 29, 2015 13:57
Fun with Akka.net
#r @"C:\Development\GitHub\Pigeon\src\Pigeon\bin\Release\Akka.dll"
#r @"C:\Development\GitHub\Pigeon\src\Pigeon.FSharp\bin\Release\Akka.FSharp.dll"
open Akka.FSharp
open Akka.Actor
type IO<'msg> = | Input
type Cont<'m,'v> =
@thinkbeforecoding
thinkbeforecoding / csharp.cs
Last active August 29, 2015 13:56 — forked from ToJans/csharp.cs
Other try without query expression. articles is now a map.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace TDDCoverage
{
public class Order
{
@thinkbeforecoding
thinkbeforecoding / csharp.cs
Last active August 29, 2015 13:56 — forked from ToJans/csharp.cs
Here is a cleaner, shorter version.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace TDDCoverage
{
public class Order
{
@thinkbeforecoding
thinkbeforecoding / Zip computation
Created January 20, 2014 23:30
This is an example of the Zip (applicative functor) experimental extension to Computation Expression. using for .. and ... do, sources are merges using the .Merge(xs,f) method. If Select is defined and the rest of the expression is a simple projections, the result is Select(Merge(xs,ys), projection) else it is Bind(Merge(xs,ys), rest of the expr…
open System
type ZipBuilder() =
member t.Zip(xs,ys) = List.zip xs ys
member t.For(xs,f) = List.collect f xs
member t.Yield x = [x]
member t.Select(xs,f) =
List.map f xs
member t.Zero() = []