Skip to content

Instantly share code, notes, and snippets.

@liammclennan
liammclennan / gist:9455524
Created March 9, 2014 22:10
React mixin that warns if a propTypes key is missing
define('validation', [], function() {
return {
allPropsSpecifiedMixing: {
componentDidMount: function() {
var unspecifiedPropKeys = _.difference(
_.keys(this.props),
_.keys(this.type.propTypes || {}).concat('ref'));
if (unspecifiedPropKeys.length) {
console.warn('Component ' +
void Main()
{
var environment = new Environment(30);
var composed = DoSomeStuff();
var extracted = composed.RunReader(environment);
Console.WriteLine(extracted);
}
public class Environment {
public int Count {get; private set;}
@liammclennan
liammclennan / gist:9925787
Created April 2, 2014 00:24
Problem using F# match
// this works
let makeImage bytes =
match Array.length bytes with
| 784 -> Image bytes |> Some
| _ -> None
// but this does not. The none branch is never used.
@liammclennan
liammclennan / gist:10521441
Last active August 29, 2015 13:59
Reverse Polish notation
let solveRPN expression =
let foldingFunction stack item =
match (stack,item) with
| (x::y::xs,"*") -> x * y :: xs
| (x::y::xs,"+") -> x + y :: xs
| (x::y::xs,"-") -> y - x :: xs
| (s,o) -> int o :: s
let words (i:string) = i.Split(' ') |> List.ofArray
words expression
|> List.fold foldingFunction []
@liammclennan
liammclennan / gist:11100906
Last active August 29, 2015 14:00
F# postgresql document database WIP
type Person =
{ _id: System.Guid; age: int; name: string }
interface IDocument with
member x.tableName() = "People"
member x.id() = x._id
[<Fact>]
let ``insert, read, update, delete a document`` () =
// insert
let id = System.Guid.NewGuid()
@liammclennan
liammclennan / gist:1014fffd40371cb8286f
Created June 1, 2014 09:14
React with design with Routing
euclid.start([{
title: 'Dashboard',
route: '/dashboard/:date'
entry: function (date) {
return [pageComponent, initialProps];
},
exit: function () {},
actions: {
showDetail: function (itemId) {
return updatedProps;
module Library1
open NUnit.Framework
open FsUnit
type IHaveAnAge =
abstract age: int
type Person =
{ name: string; age: int }
interface IHaveAnAge with
@liammclennan
liammclennan / gist:56466b18014aeb2e530a
Last active August 29, 2015 14:06
Typescript game of life
// start of a port of Ristretto/Coffeescript game of life to typescript
// http://withouttheloop.com/articles/2013-08-11-coffeescript-gameoflife-ristretto/
class Cell {
constructor(public x: number, public y:number) {}
}
function isNeighbour(c:Cell, x:number, y:number): boolean {
return Math.abs(x-c.x) < 2
&& Math.abs(y-c.y) < 2
* A brief history of time
* Black Swan
* Godel Escher Bach
* How not to be wrong
* Men of mathematics
class Showable a where
shw :: a -> String
data A = A String
data B = B Int
instance Showable A where
shw (A s) = s
instance Showable B where