Skip to content

Instantly share code, notes, and snippets.

View cdrnet's full-sized avatar

Christoph Ruegg cdrnet

View GitHub Profile
@ovatsus
ovatsus / Setup.fsx
Created March 17, 2012 17:07
Script to setup F# Interactive session, loading everything in the current solution
#r "System.Xml.Linq"
open System
open System.IO
open System.Xml.Linq
let script = seq {
//TODO: this currently loads fsproj's in alphabeticall order, we should instead
//build the dependencies graph of the fsproj's and load them in topological sort order
@MartinBodocky
MartinBodocky / asyncParallel
Last active August 29, 2015 13:58
Asynchronous and Parallel Programming in F#
// Creating new threads
open System
open System.Threading
//What will execute on each thread
let threadBody() =
for i in 1..5 do
//Wait 1/10 of a second
Thread.Sleep(100)
printfn "[Thread %d] %d ..."
@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 =
namespace Tsunami.Server
open System
open System.IO
open System.Linq
open System.Net
open System.Net.Sockets
open System.Text
open System.Threading
open System.Runtime.Serialization
// Original code: https://gist.github.com/taumuon/11302896
// This implementation optimized by Jack Pappas (https://github.com/jack-pappas)
open MathNet.Numerics.Distributions
open MathNet.Numerics.Statistics
open MathNet.Numerics.Random
open LanguagePrimitives
let inline callPayoff strike price =
max (price - strike) GenericZero
@ctaggart
ctaggart / 3.0 to 3.1.fsi
Created December 27, 2014 02:13
FSharp.Core Surface Area Diff (what is new)
[<AutoOpen>]
module Microsoft.FSharp.Reflection.FSharpReflectionExtensions
/// Creates an instance of a record type.
val MakeRecord : recordType:Type * values:obj [] * ?allowAccessToPrivateRepresentation:bool -> obj
/// Reads all the fields from a record value.
val GetRecordFields : record:obj * ?allowAccessToPrivateRepresentation:bool -> obj []
/// Precompute a function for reading all the fields from a record. The fields are returned in the
@dsyme
dsyme / gist:9b18608b78dccf92ba33
Last active November 1, 2022 18:11
Working self-contained getting-started sample for Suave Web Scripting
//==========================================
// Working fully self-contained getting-started example for Suave Web Server scripting
//
// Note you don't need to have _anything_ installed before starting with this script. Nothing
// but F# Interactive and this script.
//
// This script fetches the Paket.exe component which is referenced later in the script.
// Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
// downloaded by the user (by executing the first part of the script) the reference
// shows as resolved and can be used.
@TWith2Sugars
TWith2Sugars / build.fsx
Last active January 28, 2016 14:44
Conform all fsproj
#r @"packages/Paket.Core/lib/net45/Paket.Core.dll"
open Paket
open Paket.Xml
open System.Xml
let setProjectAttribute attribute innerText (propertyGroup:Xml.XmlNode) =
let nodes = propertyGroup.ChildNodes |> Seq.cast<XmlNode> |> Seq.filter(fun node -> node.Name = attribute )
nodes |> Seq.iter(propertyGroup.RemoveChild >> ignore)
let attribute = propertyGroup.OwnerDocument.CreateElement(attribute, Constants.ProjectDefaultNameSpace)
@AArnott
AArnott / NuGetPackageSources.ps1
Last active December 30, 2023 18:46
PowerShell cmdlets for publishing NuGet packages in a fast directory structure, and upgrading from an old flat directory listing of nupkg's to the faster one.
Function Create-NuPkgSha512File {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,Position=1)]
[string]$Path,
[Parameter()]
[string]$Sha512Path="$Path.sha512"
)
$sha512 = [Security.Cryptography.SHA512]::Create()
@kjnilsson
kjnilsson / handy.fs
Last active April 6, 2018 17:49
my current favourite handy fsharp helpers
//invaluable for all those Choice<'a, exn> flows
let exnf f = Printf.ksprintf (fun s -> exn s) f
//combine paths
let (</>) x y = System.IO.Path.Combine(x, y)
//allows you to pattern match on values in the current scope rather than just literals
let (|Eq|_|) expected value =
if expected = value then Some ()
else None