Skip to content

Instantly share code, notes, and snippets.

@ToJans
ToJans / index.html
Created April 6, 2015 15:16
I don't understand why something this simple doesn't work (I get back undefined is not a function)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Editor</title>
<script src="bower_components/webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="elements/user-gravatar.html" />
</head>
<body>
<user-gravatar email="[email protected]"/>
@ToJans
ToJans / 99bottles.js
Last active August 29, 2015 14:14
99 bottles of beer as short as possible in ECMAScript 6 - currently 142 characters
x=""
b=r=>`${c||"No more"} bottle${c-1?"s":""} of beer${r&&c--||" on the wall"}
`
for(c=99;c;)x+=b()+b(1)+`Take one down, pass it around
`+b()
@ToJans
ToJans / maybethis.fs
Last active August 29, 2015 14:13
my ideal F# web framework; a brain dump
// these series of types define the api of the app
type Command =
| Add of CreateNewTodo
| Clear
| Delete of Guid
| Update of Guid * PatchTodo
}
and Query =
| Get of Guid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
@ToJans
ToJans / current.fs
Last active August 29, 2015 14:13
A proposition to make f# docs a lot easier and testable, like in @elixirlang : http://elixir-lang.org/docs/stable/ex_unit/ExUnit.DocTest.html
(**
### Evaluation demo
The following is a simple calculation: *)
let test = 40 + 2
(** We can print it as follows: *)
(*** define-output:test ***)
printf "Result is: %d" test
(** The result of the previous snippet is: *)
@ToJans
ToJans / list.cs
Created January 8, 2015 10:32
A C# implementation of the Haskell List
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Pauwels.AspNet.Controllers
{
public abstract class FList<T> {
public abstract FList<T> Tail();
public abstract T Head();
@ToJans
ToJans / migrate.fsi
Created January 5, 2015 13:22
Fsharp script used to migrate from octopress to hugo
open System.IO
let oldpath = @"D:\dev\oldblog\source\_posts"
let newpath = @"D:\dev\blog\tojans.me\content\blog"
let migrate (fname:string) =
let (date,name) = fname.Substring(0,10),fname.Substring(11).ToLower()
let slug = name.Substring(0,name.Length - ".markdown".Length).ToLower()
let isNonDateLine (x:string) = x.StartsWith("date:") = false
let isNonAddThisLine (x:string) =
@ToJans
ToJans / Nat.cs
Last active August 29, 2015 14:12
Natural numbers and vectors in C# , the Idris way
// Data Nat = Z | S Nat
//
// plus : Nat -> Nat -> Nat
// plus Z y = y
// plus (S k) y = S (plus k y)
abstract class Nat {
}
class Zero : Nat {
@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
@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