Skip to content

Instantly share code, notes, and snippets.

@rojepp
rojepp / FindTF
Created October 19, 2010 19:32
Love the elegance of F#. This code looks for the TFS Command line tool and returns Some(path) or None
let findtfpath =
let VS_REGPATHS = [
@"Software\Wow6432Node\Microsoft\VisualStudio\10.0";
@"Software\Microsoft\VisualStudio\10.0";
@"Software\Wow6432Node\Microsoft\VisualStudio\9.0";
@"Software\Microsoft\VisualStudio\9.0";
@"Software\Wow6432Node\Microsoft\VisualStudio\8.0";
@"Software\Microsoft\VisualStudio\8.0"
]
let INSTALLDIR = "InstallDir";
@rojepp
rojepp / Delegates.cs
Created October 26, 2010 11:49
Show how delegate definition matters, the following sample will rightfully not compile
class Program
{
delegate bool delA(string item);
delegate bool delB(string item);
static void Main(string[] args)
{
delA del = s => true;
callA(del);
callB(del);
@rojepp
rojepp / gist:1122319
Created August 3, 2011 10:08
Test snippet
(* Test embedding in blogger... *)
let add x y = x + y
let add1 = add 1
let result = add1 2
printfn "%d" result
@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
@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 / 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: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 / 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: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 / 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