Skip to content

Instantly share code, notes, and snippets.

@JeffreyZhao
JeffreyZhao / SelectiveReceive.fs
Created July 15, 2009 11:24
Selective Receive with F# MailboxProcessor
#light
open Microsoft.FSharp.Control
let counter =
MailboxProcessor.Start(fun inbox ->
let rec loop() =
async {
let! msg = inbox.Scan(fun x ->
match x with
@JeffreyZhao
JeffreyZhao / Crawler.cs
Created July 15, 2009 16:47
A simple web crawler based on ActorLite
namespace Crawling
{
public class Crawler : Actor<Message>, ICrawlingHandler
{
protected override void Receive(Message message)
{
message(this);
}
public Crawler(Monitor monitor)
@JeffreyZhao
JeffreyZhao / Program.cs
Created July 16, 2009 15:10
Strong Type Message with ActorLite
namespace Strong
{
using System;
using ActorLite;
static class Program
{
static void Main(string[] args)
{
new Ping(5).Start(new Pong());
namespace StrongCrawling
{
using System;
using System.Collections.Generic;
using System.Net;
using ActorLite;
public interface ICrawlRequestHandler
{
void Crawl(Monitor monitor, string url);
namespace Test
{
using System;
using System.Collections.Generic;
using ActorLite;
public interface IPersonHandler
{
void Chat(Person another, Topic topic);
void Eat(Restaurant restaurant);
@JeffreyZhao
JeffreyZhao / Program.cs
Created July 25, 2009 15:00
Action-based message with ActorLite
namespace StrongCrawling
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using ActorLite;
public interface ICrawlRequestHandler
namespace Crawling
{
using System;
using System.Linq;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using ActorLite;
@JeffreyZhao
JeffreyZhao / gist:162592
Created August 5, 2009 08:31
Convert inline <pre /> to <br />
static string DoPre(string content)
{
return Regex.Replace(content, @"(<pre[^>]*>)([\s\S]*?)(</pre>)", match =>
{
return
match.Groups[1].Value +
String.Join("<br />", match.Groups[2].Value.Split('\n').Select(p => p.Replace(" ", "&nbsp;").Trim()).ToArray()) +
match.Groups[3].Value;
});
}
@JeffreyZhao
JeffreyZhao / AreaControllerFactory.cs
Created August 20, 2009 03:24
AreaControllerFactory
public class AreaControllerFactory : IControllerFactory
{
private Dictionary<string, string> m_areaPartMapping = new Dictionary<string, string>();
private ReaderWriterLockSlim m_rwLock = new ReaderWriterLockSlim();
private Dictionary<string, Type> m_controllerTypes = new Dictionary<string, Type>();
public string NamespaceBase { get; private set; }
public AreaControllerFactory(string namespaceBase)
: this(namespaceBase, null)
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
public class AttachDataAttribute : Attribute
{
public AttachDataAttribute(object key, object value)
{
this.Key = key;
this.Value = value;
}
public AttachDataAttribute() { }