Skip to content

Instantly share code, notes, and snippets.

@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() { }
@JeffreyZhao
JeffreyZhao / BoundUrl.cs
Created August 24, 2009 09:25
ParsedRoute
public class BoundUrl
{
private static PropertyAccessor s_urlAccessor;
static BoundUrl()
{
var type = typeof(Route).Assembly.GetType("System.Web.Routing.BoundUrl");
var property = type.GetProperty("Url", BindingFlags.Instance | BindingFlags.Public);
s_urlAccessor = new PropertyAccessor(property);
}
@JeffreyZhao
JeffreyZhao / DomainParser.cs
Created August 24, 2009 10:23
DomainParser
internal class DomainParser
{
public DomainParser(string pattern)
{
this.Pattern = pattern;
this.Segments = CaptureSegments(pattern);
string routePattern = pattern.Replace("://", "/").Replace('.', '/');
this.m_parsedRoute = RouteParser.Parse(routePattern);