Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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]);
}, [])
}
}
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 / 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
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 / Fpexplained2.cs
Last active August 29, 2015 14:02
This is a C# implementation showing what functors, applicatives and monads look like.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
namespace FPExplainedV2
{
// another implementation to test category theory; this time I implement a list...
public class FList<TObject>
@ToJans
ToJans / fzip.fs
Last active August 29, 2015 14:02
Does something like "fzip" even exist? Or did I just invent a wacko name to do this stuff?
open System.Runtime.Serialization
[<DataContract>]
type Vector3D = {
[<DataMember>] x: decimal
[<DataMember>] y: decimal
[<DataMember>] z: decimal
} with
member this.width = this.x
member this.height = this.y