Skip to content

Instantly share code, notes, and snippets.

@vietnt
vietnt / gist:1267895
Created October 6, 2011 16:40
session ?
[Authenticated]
public class SomePage
{
[Inject("CurrentUser")]
public User CurrentUser { get; set; }
....
}
@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 / 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: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 / 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 / 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.

let inline isPhom x y z =
let sx, sy, sz = x%13,y%13,z%13
if sx = sy && sy = sz then true
else
let tx, ty, tz = x/13, y/13, z/13
if tx = ty && ty = tz then
let a = max sx sy |> max sz
let c = min sx sy |> min sz
let b = (sx + sy + sz)/3
a = b + 1 && a = c + 2
public class UChecker:IDisposable
{
public int[,] CardSet;
public int[,] PhomMark;
private int _countNotPickedCard;
private int _countCardNotInPhom;
public int CountCardNotInPhom { get { return _countCardNotInPhom;} set{ _countCardNotInPhom = value;}}
private int _countEatenCardInHand;
//// See the 'F# Tutorial' project for more help.
//
open System
type Command =
| Block of string * TimeSpan
| Unblock of string
| IsBlocked of string
let maxTimeSpan = TimeSpan.FromDays (365*1000 |> float)
open System
open System.Drawing
open System.Drawing.Imaging
let perlinNoise width height persistence octaves zoom seed bias amplitudeBias handler =
let inline noise x y =
let n = x + y * 57;
let n = (n <<< 13) ^^^ n
1.0 - (float ((n * (n * n * 15731 + 789221) + 1376312589) &&& 0x7fffffff)) / 1073741824.0