Skip to content

Instantly share code, notes, and snippets.

@vietnt
vietnt / rules.md
Created February 15, 2013 03:48 — forked from henrik/rules.md
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done.

You can break these rules if you can talk your pair into agreeing with you.

@vietnt
vietnt / gist:2976707
Created June 23, 2012 03:37
transaction_specs
post.View = 0
using (var t = root.NewTransaction())
{
post.View++;
Assert.AreEqual (1, post.View);
}
Assert.AreEqual(0, post.View);
@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);
}