Skip to content

Instantly share code, notes, and snippets.

@JohnNilsson
JohnNilsson / gist:10623861
Created April 14, 2014 07:21
Reading Push Pull FRP in C#
public static class ComparableExtensions
{
public static bool IsAfter<T>(this T c1, T c2) where T:IComparable<T>
{
return Comparer<T>.Default.Compare(c1,c2) > 0;
}
public static T Min<T>(this T c1, T c2) where T:IComparable<T>
{
return (c1.CompareTo(c2) < 0) ? c1 : c2;
@JohnNilsson
JohnNilsson / plist2xml.xsl
Created October 5, 2013 19:23
XSLT to transform PList XML to something almost XML-like
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" />
<xsl:template match="/plist">
<xsl:element name="theme">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
@JohnNilsson
JohnNilsson / Actor.cs
Created May 6, 2012 22:17 — forked from viktorklang/Actor.java
Minimalist C# Actors
// Inspired by https://gist.github.com/2557678
// and http://dspace.mit.edu/bitstream/handle/1721.1/6935/AITR-633.pdf
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks.Dataflow;
using Message = System.Object;
namespace Actors
{
public interface Behavior { Behavior OnArrival(Message message); }
@JohnNilsson
JohnNilsson / gist:1227786
Created September 19, 2011 22:28
Further understanding scala.Option by Tony Morris
/*
Below are 15 exercises. The task is to emulate the scala.Option API
without using Some/None subtypes, but instead using a fold (called a
catamorphism).
A couple of functions are already done (map, get)
to be used as an example. ScalaCheck tests are given below to
verify the work. The desired result is to have all tests passing.
@JohnNilsson
JohnNilsson / gist:1227708
Created September 19, 2011 21:46
20 Intermediate Scala Exercises by Tony Morris
trait PartialType[T[_, _], A] {
type Apply[B] = T[A, B]
type Flip[B] = T[B, A]
}
trait Fluffy[F[_]] {
def furry[A, B](f: A => B, fa: F[A]): F[B]
}
object Fluffy {
@JohnNilsson
JohnNilsson / zmqsegfault.c
Created June 5, 2011 22:06
zmq example with weird bahavior
#include <zmq.h>
void recv() //This name overrides something in libzmq causing things to break.
{
//NOOP
}
int main()
{
void* ctx = zmq_init(1);
class Calc extends PackratParsers {
type Elem = Char
val vars = mutable.Map[Char,Int]()
def parse(input:CharSequence) = doIt(new PackratReader(new CharSequenceReader(input)))
val spaces: Parser[Seq[Char]] = elem("Whitespace", _.isWhitespace)*
val digit: Parser[Char] = elem("Digit", _.isDigit)
val letter: Parser[Char] = elem("Letter", _.isLetter)
When discussing a particular subset of a system one can usually produce some light and useful UMLish diagrams of the topic on a whiteboard.
Displaying the true system model of the related components would be overwhelming and not usefull at all though.
I'm thinking that these ephermal aspects should be our true representation of the system implementation.
Instead of producing files with classes containing all related functionality ever thought of for that part of the model we should produce small snippets of design aspects relevant to the design session that created them.