Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
hodzanassredin / Iteratee.cs
Created November 6, 2012 15:42
iteratees in csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//http://jazzy.id.au/default/2012/11/06/iteratees_for_imperative_programmers.html
namespace Iteratee
{
class Program
{
@hodzanassredin
hodzanassredin / Prop.cs
Created October 26, 2012 15:09
first class properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FirstClassProperties
{
class Property<T, CONTAINERT>
{
T _val;
@hodzanassredin
hodzanassredin / ExpressionThread.cs
Created October 23, 2012 15:36
ExpressionThread from clojure to c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class ThreadExpression
{
public static T Thread<T>(this T obj, params Action<T>[] argsRest)
{
foreach (var item in argsRest)
@hodzanassredin
hodzanassredin / Phantom.cs
Created October 22, 2012 15:32
phantoms types and logic proving at compile time in c# v2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
var lst = SafeListMethods.Create<String>();
@hodzanassredin
hodzanassredin / mvvm.cs
Created October 15, 2012 21:16
clojure like mvvm in c#
public partial class Form1 : Form
{
private Model m = new Model();
public Form1()
{
InitializeComponent();
m.AllowedToReset.AddWatcher(x => button1.Enabled = x);
m.Count.AddWatcher(x => textBox1.Text = x.ToString());
m.Init();
}
@hodzanassredin
hodzanassredin / MessagePassing.fs
Created October 11, 2012 09:55
MessagePassing in fsharp
// Learn more about F# at http://fsharp.net
// See the 'F# Tutorial' project for more help.
type MyObjectMessage =
| PrintState
| Set of int;;
let MyObject() =
let refVar = ref 0
let dispatcher = fun message ->
@hodzanassredin
hodzanassredin / reducers.cs
Created October 11, 2012 09:23
trying to reproduce clojure reducers in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Reducable
{
//https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/reducers.clj
public static class ReduceExts1
{
@hodzanassredin
hodzanassredin / dataflow.fsx
Created September 30, 2012 21:07
abstraction over pull and push sources
type 'a Source =
| Push of (('a Option -> Unit) -> Unit)
| Pull of (Unit -> 'a Option)
type 'a Destination =
| Destination of ('a Option -> Unit)
type Converter<'a,'b> =
| Converter of ('a Option -> 'b Option)
@hodzanassredin
hodzanassredin / lisp.fs
Created September 10, 2012 21:43
lisp dsl in fsharp
type Expr = | ListOfExpr of list<Expr>
| Func of (list<Expr> -> Expr)
| Macro of (list<Expr> -> list<Expr>)
| Int of int
| Void;;
let rec evalArgs l =
@hodzanassredin
hodzanassredin / tweetspersecondwindow.fs
Created September 6, 2012 10:53
hw to split seq by date
windowBySecond (tweetsSq: seq<Tweet>) =
let tweet = Seq.head tweetsSq
let currSec = (toDateTime tweet.DateStr).Second
let tweetsForSecond = Seq.takeWhile (fun elem -> (toDateTime elem.DateStr).Second = currSec) tweetsSq |> Seq.toList
Some(Some(tweetsForSecond.Length), tweetsSq)
let tweetsPerMSecond tracking =
//|> Seq.map (fun t -> (toDateTime t.DateStr))