Skip to content

Instantly share code, notes, and snippets.

public class Point
{
public double X;
public double Y;
public double Z;
}
// inspired by stylus: http://learnboost.github.com/stylus/
// constant
transparent = 0.8
fonts = Segoe UI, Arial
// function
border-radius()
-moz-border-radius arguments
-webkit-border-radius arguments
@vietnt
vietnt / gist:1103568
Created July 25, 2011 04:39
template_engine
// inspired by python, razor
ul
@foreach (var item in menus)
li
a [href='@item.Link']
@item.Text
p
Sum: @x + @y = @(x + y)
@vietnt
vietnt / gist:1165535
Created August 23, 2011 15:48
new language
int Sum(int[] list)
<- 0 += x in list
int Max(int[] list)
<- max = x
if x > max
x in list
max = int.MinValue
QSort(int[] list, int lo, int hi)
@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"}
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)
{
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);
}
@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>()
@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>(
interface INumber =
(+) (x : INumber) : INumber
(-) (y : INumber) : INumber
(*) (x : INumber) : INumber
(++) : INumber
(--) : INumber