Skip to content

Instantly share code, notes, and snippets.

View AlexCuse's full-sized avatar

Alex Ullrich AlexCuse

View GitHub Profile
@AlexCuse
AlexCuse / gist:1056072
Created June 30, 2011 11:46
subscriber usage
let Run<'T when 'T: not struct and 'T:null and 'T:equality> (errorCallback, ct:CancellationToken, finished:ManualResetEvent) =
let sub = new Subscriber<'T>()
sub.ReceivedMessages(ct)
|> Seq.iter (fun msg ->
try
write msg
with | ex ->
sub.Return msg
errorCallback ex)
finished.Set() |> ignore
@AlexCuse
AlexCuse / gist:1055462
Created June 30, 2011 01:41
F# subscription
namespace BrewTelligence.Search.IndexingService
#light
open System.Threading
open System.Configuration
open RabbitMQ.Client
open RabbitMQ.Client.MessagePatterns
//TODO: single connection / channel for lifetime?
@AlexCuse
AlexCuse / gist:1055416
Created June 30, 2011 01:03
rabbitmq subscription?
//I think this is more or less how it'd work
public IEnumerable<T> Stuffs () {
bool noAck = false;
using (var connection = connectionFactory.CreateConnection ())
using (var channel = SetupChannel (connection)) {
var sub = new Subscription (channel, queueName, noAck);
while (true) {
var result = sub.Next ();
if (result != null) {
@AlexCuse
AlexCuse / gist:1055202
Created June 29, 2011 22:53
looping indexer
let Run<'T when 'T: not struct and 'T:null and 'T:equality> (errorCallback, ct:CancellationToken, finished:ManualResetEvent) =
let p = QueueProvider<'T>.Create()
try
while not (ct.IsCancellationRequested) do
match p.Dequeue() with
| null -> Thread.Sleep 1000
| _ as obj ->
try
write obj
with | ex ->
type Service = //snip
member this.Run() =
let mutable retryCount = 0
while retryCount < 10 do
//what to do on mono? Maybe setting up local log better
let errorCallback =
function(ex:System.Exception) -> this.EventLog.WriteEntry("error in BrewTelligence Indexing Service:\n\n" + ex.Message + "\n\n" + ex.StackTrace)
try
@AlexCuse
AlexCuse / gist:1013392
Created June 7, 2011 23:00
parallel still not working for some reason
module Program
#light
open System.Threading
open StructureMap
open BrewTelligence.Domain
open BrewTelligence.Search.Indexing
open BrewTelligence.ApplicationServices
open BrewTelligence.ApplicationServices.Messaging
@AlexCuse
AlexCuse / gist:1012647
Created June 7, 2011 16:51
Seq option merge
#light
open System
module Seq =
let merge (s1:seq<option<'a>>) (s2:seq<option<'a>>) =
let rec innerMerge s1 s2 =
seq {
match s1, s2 with
| LazyList.Cons(h1, t1), LazyList.Cons(h2, t2) ->
yield h1
module Seq
#light
let merge (s1:seq<'a>) (s2:seq<'a>) =
let rec innerMerge s1 s2 =
seq {
match s1, s2 with
| LazyList.Cons(h1, t1), LazyList.Cons(h2, t2) ->
yield h1
@AlexCuse
AlexCuse / gist:1011592
Created June 7, 2011 02:40
Attempting Sequence 'merge' - look at LazyList in F# power pack for other possibilities
module Seq
#light
let rec merge s1 s2 =
seq {
yield s1 |> Seq.head
yield s2 |> Seq.head
yield! merge s1 s2
}
@AlexCuse
AlexCuse / gist:1009694
Created June 6, 2011 03:33
may need some stability improvements but this seems like a step in the right direction
ObjectFactory.Initialize(fun x -> x.AddRegistry (new SearchRegistry()))
let write<'T> item =
ObjectFactory.GetAllInstances<Indexer<'T>>()
|> Seq.iter (fun idxr -> idxr.Index item)
let itemsToIndex<'T when 'T:null and 'T:not struct and 'T:equality> =
let p = QueueProvider<'T>.Create()
seq {
while true do