Skip to content

Instantly share code, notes, and snippets.

View dgfitch's full-sized avatar

Dan Fitch dgfitch

View GitHub Profile
@dgfitch
dgfitch / visitor.fs
Created November 15, 2010 22:11
visitor again
let rec visitor dir =
seq {
for subdir in listOfFolders dir do
yield subdir
yield! visitor subdir
}
@dgfitch
dgfitch / visitor.fs
Created November 15, 2010 16:54
visitor.fs
let rec visitor dir =
seq { yield!
( try Directory.GetFiles(dir)
with ex ->
(* actually do something *)
Array.empty )
for subdir in Directory.GetDirectories(dir) do yield! visitor subdir}
@dgfitch
dgfitch / simple_wcf.fs
Created November 3, 2010 20:31
A sample WCF host and client in F#, extremely simple but a starting point
open System
open System.ServiceModel
open System.ServiceModel.Description
[<ServiceContract(ConfigurationName = "PublishService", Namespace = "http://xyz.gov/PublishService")>]
[<ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)>]
type IPublishService =
[<OperationContract(Name="TestMethod")>]
abstract member TestMethod : name:string -> string
@dgfitch
dgfitch / splitList.fs
Created November 3, 2010 15:50
F# splitting a list into a list of lists
// there have got to be better ways to do this?
let splitList (f:'a -> bool) (list:'a list) =
let op (nested:'a list list) (thing: 'a) =
if f thing then
[] :: nested
else
match nested with
| [] -> [[thing]]
| headlist::rest -> (thing :: headlist) :: rest
-- givens and exercises from Ch 2 of Haskell School of Expression
--
module Shape (Shape (Rectangle, Ellipse, RightTriangle, Polygon),
Radius, Side, Vertex,
square, circle, distBetween, area
) where
data Shape = Rectangle Side Side
| Ellipse Radius Radius
Building Doctypes...
Testing Doctypes...
47 run, 46 passed, 1 failed, 0 inconclusive, 1 skipped (1 ignored)
Slowest: seq
[("DTC.Doctypes/TestLanguage/Include only these folders", 677.0);
("DTC.Doctypes/TestStatutes/Has children", 595.0);
("DTC.Doctypes/SharedLaw/Plain to separated", 513.0);
("DTC.Doctypes/TestSharedLawReferences/Paragraph nested in subsection only",
428.0); ...]
Loading up 'DTC.Doctypes/TestSharedLawReferences/Paragraph nested in subsection only' for fixage
(*
autotest.fsx
20100826 - dgfitch@gmail.com
Inspired by ruby autotest.
Tracks a set of projects, building and testing them automatically with Gallio
as they are modified.
Should work with xUnit.Net, MbUnit, NUnit, MsTest, or whatever other framework
(* Simple Gallio test runner, usable from FSI *)
#r "Gallio.dll"
open Gallio.Runner
open Gallio.Runtime.Logging
let launcher = new TestLauncher()
let setup = new Gallio.Runtime.RuntimeSetup()
setup.AddPluginDirectory @"C:\Program Files\Gallio\bin"
setup.RuntimePath <- @"C:\Program Files\Gallio\bin"
(* Sample F# active pattern for comparison *)
let (|LessThan|_|) x y = if y <= x then Some() else None
match 4 with
| LessThan 2 -> "uhh something is wrong"
| _ -> "yay math"
Get-ChildItem -Recurse |
Where-Object { !$_.PSIsContainer } |
Foreach-Object {
Write-Host("<p><a href='{0}'>{1}</a></p>" -f ($_.FullName.Replace($pwd, "").Trim('\')), $_.Name)
}