Skip to content

Instantly share code, notes, and snippets.

@ToJans
ToJans / main.hs
Last active January 4, 2016 19:50
Zalora task
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Network.Wai.Middleware.RequestLogger(logStdoutDev)
import Data.Aeson ( (.:),(.:?),decode,FromJSON(..),Value(..))
import Data.Text.Lazy (pack)
import Control.Applicative ((<$>), (<*>))
import qualified Data.ByteString.Lazy.Char8 as BS
@ToJans
ToJans / example.ex
Last active August 29, 2015 13:56
Statistics usable for data series
Stream.repeatedly(&:random.uniform/0)
|> Enum.take(10000)
|> Stats.all
|> IO.inspect
@ToJans
ToJans / csharp.cs
Last active August 29, 2015 13:56
Trying to convert a simple C# app to eloquent F#; failing so far; to verbose IMO
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
namespace TDDCoverage
{
public class Order
{
@ToJans
ToJans / FullCoverage.cs
Last active August 29, 2015 13:56
100 Percent test coverage means nothing
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TDDCoverage
{
public enum Gender { Unknown, Male, Female }
public class Customer
{
public Gender Gender = Gender.Unknown;
@ToJans
ToJans / threes.exs
Last active August 29, 2015 13:57
An implementation in Elixir for Threes (http://asherv.com/threes/). Started out of curiosity after seeing a tweet by GraemeF(https://twitter.com/GraemeF/status/442580143140134912)
defmodule Threes do
def right(board) do
board
|> Enum.map(&pack/1)
end
def left(board) do
board
|> Enum.map(&reverse_pack/1)
@ToJans
ToJans / Models.fs
Last active August 29, 2015 13:57
Try describing this in C#
namespace Arealities.Models
type Size = Size of decimal * decimal * decimal
type Position = Position of decimal * decimal * decimal
type Rotation = Rotation of decimal * decimal * decimal
type Direction = Direction of decimal * decimal * decimal
type LightIntensity = float
type Material = Ground | Floor | ShinyStuff | Wall
type Geometry = CubeGeometry of Size
@ToJans
ToJans / error.txt
Last active August 29, 2015 13:57
Odd error: pilar is a Mesh, and I want to change some fields, so I use the with-syntax. On the last line I get this error:
Error 1 This expression was expected to have type
unit
but here has type
Mesh C:\dev\.Net\arealities\Arealities.Models\Veranda.fs 17 11 Arealities.Models
@ToJans
ToJans / types.fs
Last active August 29, 2015 13:57
I am probably overdoing it regarding types ATM
namespace Arealities.Models
type [<Measure>] mm; // milimeter
type [<Measure>] degrees; // degrees
type [<Measure>] intensity; // unit = 1
type Vector3D<'a> = {x: 'a; y: 'a; z: 'a}
type Placement = Placement of position: decimal<mm> Vector3D *
rotation: decimal<degrees> Vector3D
@ToJans
ToJans / povify.fs
Created March 30, 2014 09:16
What is the best way to do this in F#?
let povify model =
match model with
| (v:Vector3D<decimal>) -> sprintf "<%M,%M,%M>" (v.x/1M) (v.y/1M) (v.z/1M)
| CubeGeometry c ->
let half = c.size/2M
sprintf "box {%s %s} " (povify half) (povify vec3D0-half)
@ToJans
ToJans / ranges.fs
Created April 1, 2014 10:52
This should do it for ranges
type Range(min: decimal,max: decimal) =
member this.min = min
member this.max = max
static member (*) (r: Range, d: decimal) = Range(r.min * d,r.max * d)
static member (*) (d: decimal, r: Range) = r*d
static member (/) (r: Range, d: decimal) = Range(r.min / d,r.max / d)
static member (/) (d: decimal, r: Range) = r/d
static member (+) (r: Range, d: decimal) = Range(r.min + d,r.max + d)
static member (+) (d: decimal, r: Range) = r+d
static member (-) (r: Range, d: decimal) = Range(r.min - d,r.max - d)