Skip to content

Instantly share code, notes, and snippets.

open System
open System.IO
let illegalPathChars =
let chars = Path.GetInvalidPathChars ()
chars
let checkPathForIllegalChars (path:string) =
@rojepp
rojepp / toNullable.fs
Last active August 29, 2015 14:17
toNullable
let toNullable x : System.Nullable<_> =
match x with
| Some v -> System.Nullable<_>(v)
| _ -> System.Nullable()
// Extension for use from F#
type Option<'t> with
member this.ToNullable () =
toNullable (box this |> unbox)
@rojepp
rojepp / keybase.md
Created February 9, 2015 08:49
keybase.md

Keybase proof

I hereby claim:

  • I am rojepp on github.
  • I am rojepp (https://keybase.io/rojepp) on keybase.
  • I have a public key whose fingerprint is 2F43 7281 95CC CDEE 64CA D69B B2FE AC41 C9E1 4019

To claim this, I am signing this object:

@rojepp
rojepp / Stack trace
Created November 17, 2013 12:42
EntryPointNotFoundException
A first chance exception of type 'System.EntryPointNotFoundException' occurred in mscorlib.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>ConsoleApplication1.exe</AppDomain><Exception><ExceptionType>System.EntryPointNotFoundException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Entry point was not found.</Message><StackTrace> at System.Collections.Generic.IEnumerable`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ConsoleApplication1.Program.Main(String[] args) in c:\Users\rojepp\Documents\Visual Studio 2012\Projects\ConsoleApplication7\ConsoleApplication1\Pr
@rojepp
rojepp / gist:7497743
Created November 16, 2013 08:46
Stack trace for exception that happens when running generated TP
System.NotSupportedException was unhandled
HResult=-2146233067
Message=Specified method is not supported.
Source=FSharp.Core
StackTrace:
at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[a](Result`1 res)
at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[a](CancellationToken token, FSharpAsync`1 computation, FSharpOption`1 timeout)
at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken)
at ConsoleApplication1.Program.Main(String[] args) in c:\Users\rojepp\Documents\Visual Studio 2012\Projects\ConsoleApplication7\ConsoleApplication1\Program.cs:line 26
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
@rojepp
rojepp / contiguousGroupBy.fs
Created February 26, 2013 10:06
contiguousGroupBy
let inline contiguousGroupBy (f:'a -> 'b) (xs:'a seq) : seq<'a list> = seq {
use e = xs.GetEnumerator()
let stop = ref (e.MoveNext() |> not)
while not !stop do
let lastval = ref (f e.Current)
let list =
[
while not !stop && !lastval = f e.Current do
let cur = e.Current
lastval := f cur
@rojepp
rojepp / gist:5030535
Last active December 14, 2015 04:48
#irc thingie
type A = | Correct | Incorrect
let answers = [1; 2; 3]
let correctanswers = [1; 2; 2]
answers
|> List.zip correctanswers
|> List.map (function | a,ca when a = ca -> Correct, a
| a,_ -> Incorrect, a)
// Just need a count? Use sumBy
@rojepp
rojepp / gist:3831846
Created October 4, 2012 06:40
Trying to reproduce @voyce's F# bug in C#.
using System;
namespace ConsoleApplication2
{
class Program
{
static DateTime compbugresult;
static void Main(string[] args)
{
compbugresult = compbug.result;
@rojepp
rojepp / gist:2405633
Created April 17, 2012 12:15
Levenshtein imp vs memo rec
let levenshteinm (s:string) (t:string) =
let c = new Dictionary<_,_>()
let rec memo i j =
match c.TryGetValue((i,j)) with
| true, x -> x
| _ ->
let r =
match (i,j) with
| (i,0) -> i
@rojepp
rojepp / FsVersion.fs
Created March 14, 2012 00:02
F# Translation for Miguel. I have no idea if this works, and it is pretty much a verbatim translation, only some F# flare added. I didn't dare to do too much refactoring without having a way to test properly. Original: https://github.com/xamarin/monotouch
namespace GLCameraRipple
open System
open System.Drawing
open System.Runtime.InteropServices
//open MonoTouch.CoreFoundation
open Microsoft.FSharp.NativeInterop
type RippleModel(screenSize : Size, meshFactor: int, touchRadius: int, textureSize: Size) =
do Console.WriteLine ("New RippleModel");
let poolWidth = screenSize.Width / meshFactor