Skip to content

Instantly share code, notes, and snippets.

@nrolland
nrolland / display keyboard applescript
Created March 7, 2011 10:17
display keyboard applescript/lion et SL
set proc_ to "/System/Library/Input\\ Methods/KeyboardViewer.app/Contents/MacOS/KeyboardViewer"
set app_ to "KeyboardViewer"
try
do shell script "ps -axwww | grep" & space & proc_ & space & "| grep -v grep"
tell application app_ to quit
on error
do shell script proc_ & space & "> /dev/null 2>&1 &"
end try
@nrolland
nrolland / Setup.fsx
Created April 4, 2012 20:46 — forked from ovatsus/Setup.fsx
Script to setup F# Interactive session, loading everything in the current solution. works with many project with a bit of hand cleaning
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
open System
open System.IO
open System.Xml.Linq
open System.Text.RegularExpressions
#r "System.Web.Extensions"
let json = """
{ "FirstName":"Foo",
"LastName":"Bar",
"Hobbies":
[
{"Sport":"FootBall","Music":"Rock"}
]} """
@nrolland
nrolland / gist:3352821
Created August 14, 2012 20:46
Install your packages for a solution from its project's packages.config
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
open System
open System.IO
open System.Xml.Linq
open System.Text.RegularExpressions
@nrolland
nrolland / scriptSetup.fsx
Created August 18, 2012 15:19
Script for loading dependencies in fsx file from a solution/project
//This script generates
//a file named __project.fsx, for each proejct which can be #load "__project.fsx" in script intending to use the same dependency graph as the code in VS
//a file named __solmerged.fsx, at the solution root which can be #load "__solmerged.fsx" in script intending to use the same dependency graph as the code in VS
//In both cases, this enforce that a script compiling in VS should work from within FSI
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
@nrolland
nrolland / gist:3731548
Created September 16, 2012 08:19
a tree
type 'a Tree=
| Leaf
| Branch of 'a * 'a Tree * 'a Tree
@nrolland
nrolland / gist:3731642
Created September 16, 2012 08:47
insertbst
let rec insertBST x = function
| Leaf -> Branch(x , Leaf, Leaf)
| Branch(v, l, r) when x < v -> Branch(v, insertBST x l, r )
| Branch(v, l, r) as b when x > v -> Branch(v, l, insertBST x r )
| b -> b
@nrolland
nrolland / gist:3731734
Created September 16, 2012 09:23
zipper
type 'a Zipper = { focus:'a Tree; path: (TDirection * 'a * 'a Tree) list}
type ZDirection = Up | Left | Right
@nrolland
nrolland / gist:3731738
Created September 16, 2012 09:24
zipper module
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Zipper =
let up z = match z.path with
| (d,v,other)::ep -> match d with
| TDirection.Left -> {focus=Branch(v,z.focus,other); path=ep}
| TDirection.Right -> {focus=Branch(v,other,z.focus); path=ep}
| [] -> failwith "can't go up" // because ep only goes down and is empty
let rec top z = match z.path with [] -> z | _ -> top (up z)
@nrolland
nrolland / gist:3731883
Created September 16, 2012 10:20
zipper test
module test =
open Zipper
let t = Branch("a", Branch("b", Leaf, Branch("c", Leaf, Leaf)), Leaf)
let focus1 = t |> fromTree |> move [Left;Right]
let same1 = t |> fromTree |> move [Left;Right;Right;Up;Up;Up]
let same2 = t |> fromTree |> move [Left;Right;Right] |> Zipper.top
let xx = focus1 |> top
let newz = {(move [Left;Right;Right] xx) with focus = t} |> top