Skip to content

Instantly share code, notes, and snippets.

View bjartwolf's full-sized avatar

Bjørn Einar Bjartnes bjartwolf

View GitHub Profile
type EnumerableFromEnumerator(input: IEnumerator<byte> ) =
interface IEnumerable<byte> with
member this.GetEnumerator() = input
interface System.Collections.IEnumerable with
member this.GetEnumerator() = input :> System.Collections.IEnumerator
let takeSkip (sequence: IEnumerable<byte>) (n: int) : (byte[] * IEnumerable<byte>) =
let enumerator = sequence.GetEnumerator()
let data = Array.zeroCreate(n)
let rec readSequence i =
let takeSkip2 (s: IEnumerable<byte>) (n: int) : (byte[] * IEnumerable<byte>) =
let c = Seq.cache s
(c |> Seq.truncate n |> Seq.toArray, c |> Seq.skip n)
@bjartwolf
bjartwolf / generators.fs
Created September 29, 2015 14:01
generators.fs
module ProgramSpillerGenerators
open System
open FsCheck
type ProgramId = string
type ConstrainedDate = DateTime
type Tolker = None | Tolk | Syns
type ProgramSpillerGenerators =
static member DateTimeInRange() =
open System
open System.Collections.Generic
open System.IO
open System.Linq
open NAudio.Wave
open FSharp.Charting
let samplesPerSecond = 44100
let duration = 10*1000
let msDuration = duration*1000
#r "tools/FAKE/tools/FakeLib.dll"
open Fake
open Fake.Testing
open Fake.MSTest
open Fake.DotCover
open Fake.TeamCityHelper
open Fake.ZipHelper
open Fake.MSBuildHelper
"../.nuget/packages.config" |> RestorePackage (fun p -> { p with OutputPath = "tools"
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.7735971
RestoreNugetPackages 00:00:16.9486360
Build 00:00:09.0179679
BuildTest 00:00:57.5668270
CoverXUnit2 00:00:23.2599174
public bool Start(HostControl host)
{
// exceptions to be thrown on min thread
_mainTask.ContinueWith(x =>
{
throw x.Exception;
}, TaskContinuationOptions.OnlyOnFaulted);
_mainTask.Start();
return true;
}
SELECT p.UpdatedUtc, p.LastReadTimeStampUtc, p.LastReadMeterValue, p.Unit, p.MeterPointId
FROM (SELECT UpdatedUtc,
LastReadTimeStampUtc,
LastReadMeterValue,
Unit,
MeterPointId,
rn = ROW_NUMBER() OVER (PARTITION BY MeterPointId ORDER BY UpdatedUtc DESC)
FROM AbsoluteMeterReadings
WHERE UpdatedUtc <= @until )as p
WHERE rn=1
// http://www.cdn.geeksforgeeks.org/merging-intervals/
type OpenInterval = {Start: int; End: int }
let test = [{Start = 10; End = 19};
{Start = 11; End = 19};
{Start = 0; End = 8}]
// Assumes sorted intervals...
let overLap i i' = i.End + 1 >= i'.Start
type OpenInterval = {Start: int; End: int }
let sorted = [{Start = 10; End = 19};
{Start = 11; End = 19};
{Start = 0; End = 8}] |> Seq.sortBy (fun f -> f.Start)
let stack = new Stack<OpenInterval>()
stack.Push (Seq.head sorted)
for interval in Seq.tail sorted do