Skip to content

Instantly share code, notes, and snippets.

@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);
public static class ImmutableListExtensions
{
public static ImmutableList<T> Filter<T>(this ImmutableList<T> source, Func<T, bool> predicate)
{
if (source == null) throw new ArgumentNullException("source");
if (predicate == null) throw new ArgumentNullException("predicate");
if (source.IsEmpty) return source;
return ImmutableList<T>.Create(source.Where(predicate));
}
public static class EventFactory
{
public static Event<T> Create<T>(Expression<Func<T>> eventExpr)
{
return new Event<T>(eventExpr);
}
}
public class Event<T>
{
public static class EventFactory
{
public static DelegateEvent<T> Create<T>(Expression<Func<T>> eventExpr)
{
return new DelegateEvent<T>(eventExpr);
}
}
public class DelegateEvent<TDelegate>
{
private static RAMDirectory IndexBenchmark(String target, int topN) throws Exception {
System.gc();
if (topN < 0) topN = Integer.MAX_VALUE;
RAMDirectory ramDir = new RAMDirectory();
IndexWriter ramWriter = new IndexWriter(ramDir, new StandardAnalyzer());
FileInputStream fstream = new FileInputStream("Content.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(fstream));
@JeffreyZhao
JeffreyZhao / PersistentSetBase.cs
Created October 11, 2009 03:13
Generic base to use custom set in NHibernate
namespace NHTest.Collections
{
using System.Reflection;
using Iesi.Collections.Generic;
using NHibernate.Collection.Generic;
using NHibernate.Engine;
public class PersistentSetBase<TItem, TAbstractSet> : PersistentGenericSet<TItem>
where TAbstractSet : ISet<TItem>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SimpleTest.Tdd
{
internal interface IConverter
{
object Convert(List<string> values);
namespace SimpleConsole
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main()
#light
module Token
let rec private readToken inQuote tokenChars restChars =
let chars2Token chars = new string(chars |> Array.ofList |> Array.rev)
if inQuote then
match restChars with
| '\'' :: [] -> (chars2Token tokenChars, [])
| '\'' :: '-' :: cs -> (chars2Token tokenChars, '-' :: cs)