Skip to content

Instantly share code, notes, and snippets.

type RgbColor = {r:int;g:int;b:int} with
static member create r g b = {r=r;g=g;b=b}
static member fmap f left right = {r=f left.r right.r;g=f left.g left.b; b = f left.b right.b }
static member (-) (l,r) = RgbColor.fmap (-) l r
static member (*) (l,r) = RgbColor.fmap (*) l r
member left.squaredDistance right =
let diffColor = (left - right)
let squaredColor = diffColor * diffColor
diffColor.r + diffColor.g + diffColor.b
@ToJans
ToJans / OOvsFP.md
Last active August 29, 2015 14:02
OO vs FP

Today I was having a discussion on twitter, and after re-reading my timeline and seeing this tweet, I decided to blog about it.

This is the gist of it

Abstraction
Encapsulation
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Pauwels.AspNet
@ToJans
ToJans / mquery.js
Created October 9, 2014 23:36
mquery - a minimalistic version of jquery
function $(selector) {
if (typeof (selector) == "function") {
document.addEventListener('DOMContentLoaded', selector)
} else {
return [].reduce.call(document.querySelectorAll(selector), function (acc, element) {
return acc.concat([element]);
}, [])
}
}
@ToJans
ToJans / Tesla model S.txt
Created October 10, 2014 09:13
Tab from a song by yours truly "Tesla Model S" - inspired by Janis Joplin's "Mercedes Benz"
TAB "Tesla Model S" – Tom Janssens
D = x-x-0-2-3-2
D7 = x-x-0-2-1-2
A = x-0-2-2-2-0
G = 3-2-0-0-0-3
D
Oh Lord, won’t you buy me a Tesla Model S?
A
@ToJans
ToJans / Matrix.fs
Last active August 29, 2015 14:11
fugly
type Matrix =
| Matrix of decimal list list
static member create l = Matrix l
static member unit n =
seq {
for r in 1..n do
yield seq {
for c in 1..n do
yield if r = c then 1M
@ToJans
ToJans / Better.fs
Created December 17, 2014 15:27
Better matrix - but it crashes the pretty printer in FSI
type Matrix =
| Matrix of decimal [,]
static member create l = Matrix l
member this.elements =
match this with
| Matrix l -> l
member this.rowcount = this.elements |> Array2D.length1
member this.columncount = this.elements |> Array2D.length2
@ToJans
ToJans / how_to_install_idris.md
Created December 24, 2014 10:00
How I installed idris on ubuntu

Disclaimer: I'm a linux noob

apt-get update
apt-get install haskell-platform libcurses5
cabal update
cabal install cabal-install
cd /tmp
cabal unpack idris
cd idris-0.9.15.1
@ToJans
ToJans / firstattempt.idr
Last active August 29, 2015 14:12
First attempt at the bowling kata in idris
%default total
||| First pins down range is limited from 0 to 9 or a `Strike`
data FirstThrow = FirstPinsDown (Fin 10) | Strike
-- ||| Second pins down range should be limited by FirstThrowPinsdown count - 9 or a `Spare`
-- ||| This currently isn't; up next: figuring out how to do this; ignore the Spare for now!
-- data SecondThrow = Second FirstThrowPinsDown | Spare
data SecondThrow = SecondPinsDown (Fin 10) | Spare
@ToJans
ToJans / matrix.fs
Created December 30, 2014 12:02
I love the sheer elegance of F#
module Math
type Matrix =
| Matrix of decimal [,]
static member create l = Matrix l
member this.elements =
match this with
| Matrix l -> l
member this.rowcount = this.elements |> Array2D.length1