Skip to content

Instantly share code, notes, and snippets.

@vietnt
vietnt / gist:1979169
Created March 5, 2012 16:36
linq_functions
public class LinqQuery<T>
{
Action<Action<T>> _source;
public LinqQuery(Action<Action<T>> source)
{
_source = source;
}
public LinqQuery(T[] array)
@vietnt
vietnt / the_future_is_near.cs
Created February 2, 2012 19:29
alt future ? = ]
interface IProductService
{
Future<int> GetPrice(string id);
Future<double> GetDiscount (int qty);
}
Future<int> GetQuote(string id, int qty)
{
var service = _activator.Get<IProductService>();
@vietnt
vietnt / gist:1700125
Created January 29, 2012 18:53
simple async wflow
.On<QuoteRequest, QuoteRequest>(m => m)
.Request<int>(
state => new PriceRequest
{
Id = state.Id
})
.Request<double>(
state => new DiscountRequest
{
Qty = state.Qty
@vietnt
vietnt / gist:1267895
Created October 6, 2011 16:40
session ?
[Authenticated]
public class SomePage
{
[Inject("CurrentUser")]
public User CurrentUser { get; set; }
....
}
interface INumber =
(+) (x : INumber) : INumber
(-) (y : INumber) : INumber
(*) (x : INumber) : INumber
(++) : INumber
(--) : INumber
@vietnt
vietnt / gist:1215014
Created September 13, 2011 20:15
c# is so .. verbose
public IPipeline<TResult,TState> Combine<T1,T2,T3,TResult>(
IPipeline<T1,TState> a,
IPipeline<T2,TState> b,
IPipeline<T3,TState> c,
IPipeline<TResult,TState> d)
{
return a.Then(b).Then(c).Then(d);
}
public IPipeline<TResult, TState> Combine<T1, T2, TResult>(
@vietnt
vietnt / gist:1196575
Created September 6, 2011 04:22
simple ioc
open System
open System.Linq
open System.Collections.Generic
open System.Collections.Concurrent
open Microsoft.FSharp.Collections
open System.Reflection
type Container() =
let _map = new HashMultiMap<Type,Type>(HashIdentity.Structural)
let _activated = new ConcurrentDictionary<Type, obj>()
public Slice Get(Slice key, int transactionId = -1)
{
var record = UseTransaction (transactionId, tr=>tr.Records.FindLast (r=> r.Key == key));
if (record != null) return record.Value;
var r = log.Get(key);
if (v != null) return v;
return InternalGet(key);
}
ITemplate Compile(string assemblyPath, string templateId, string input, List<string> usings)
{
var providerOptions = new Dictionary<string, string>();
providerOptions.Add("CompilerVersion", "v4.0");
ITemplate _template = null;
var usingBuilder = new StringBuilder();
foreach (var @using in _usings)
{
@vietnt
vietnt / gist:1170434
Created August 25, 2011 10:58
_new real-code
ITemplate Compile (string path, string id, string input, List<string> usings)
<- assembly.CreateInstance (typeName)
typeName = "Templates_Template_{0}_{1}".FormatWith (id, DateTime.Now.Ticks)
assembly = results.CompiledAssembly
results = provider.CompileAssemblyFromSource (options, code)
provider = new CSharpProvider
<- new Dictionary<string, string>
<- {"CompilerVersion", "v4.0"}