Skip to content

Instantly share code, notes, and snippets.

@ptrelford
ptrelford / Bullets.feature
Created October 8, 2013 06:47
TickSpec bullet points example with Active Pattern to convert string array to points
Feature: As a writer I like to use bullet points
Scenario: Writing lists with bullets
Given a list of bullet points:
* 1,2
* 2,3
* 3,4
@ptrelford
ptrelford / Balls.fsx
Last active December 21, 2015 17:29
Ball collision detection script runs in Tsunami Cloud IDE
/// Processing style vector type
/// See http://processing.org/reference/PVector.html
type PVector(x:float,y:float) =
new(x:int,y:int) = PVector(float x,float y)
member val X = x with get,set
member val Y = y with get,set
member vector.Mag() : float =
sqrt(x * x + y * y)
member vector.Normalize() : unit =
let length = vector.Mag()
@ptrelford
ptrelford / TuringDrawing.fsx
Created July 27, 2013 19:39
Turing drawing Cloud Tsunami script based on https://github.com/maximecb/Turing-Drawings
[<AutoOpen>]
module Utils =
/// Generate a random integer within [a, b]
let randomInt =
let rand = System.Random()
fun (a,b) -> a + rand.Next(b-a+1)
type Action = Left = 0 | Right = 1 | Up = 2 | Down = 3
type Program(numStates, numSymbols, mapWidth, mapHeight) =
@ptrelford
ptrelford / PacmanMaze.fsx
Last active December 20, 2015 04:09
Pacman maze runnable in Tsunami Cloud IDE
#r "System.Windows.dll"
#r "Tsunami.IDESilverlight.dll"
#r "Telerik.Windows.Controls.dll"
#r "Telerik.Windows.Controls.Docking.dll"
#r "Telerik.Windows.Controls.Navigation.dll"
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Media
@ptrelford
ptrelford / Links.fs
Last active December 20, 2015 01:08
Morning Dew
@ptrelford
ptrelford / DecisionTree.fs
Created July 13, 2013 19:49
Titanic: Machine Learning from Disaster guided F# script for the Kaggle predictive modelling competition of the same name.
module DecisionTree
open System.Collections.Generic
module internal Tuple =
open Microsoft.FSharp.Reflection
let toArray = FSharpValue.GetTupleFields
module internal Array =
let removeAt i (xs:'a[]) = [|yield! xs.[..i-1];yield! xs.[i+1..]|]
@ptrelford
ptrelford / DecisionTree.fsx
Last active December 19, 2015 11:19
Decision Trees - port of Machine Learning in Action from Python to F#
open System.Collections.Generic
module internal Tuple =
open Microsoft.FSharp.Reflection
let toArray = FSharpValue.GetTupleFields
module internal Array =
let removeAt i (xs:'a[]) = [|yield! xs.[..i-1];yield! xs.[i+1..]|]
let splitDataSet(dataSet:obj[][], axis, value) = [|
@ptrelford
ptrelford / gist:5641811
Created May 24, 2013 07:15
Survey CSV exercise
open Microsoft.FSharp.Reflection
open System.Collections.Generic
type ProgrammingLanguage =
| CSharp
| FSharp
| Haskell
| Ruby
| JavaScript

Survey CSV exercise

Background

We are surveying developers at a number of sites to find their favourite programming language. Each response from a site is stored in a type that contains the site name, and a map/dictionary of programming languages and the number of votes they received. In C# this could look something like this:

class SurveyResponse {
    public string Site;
 public Dictionary Results;
@ptrelford
ptrelford / SnowflakesMono.fsx
Created December 15, 2015 22:40
Snowflakes falling using MonoGame
#r "System.Drawing.dll"
#r "System.Windows.Forms.dll"
#r @"./packages/MonoGame.Framework.WindowsDX.3.4.0.459/lib/net40/MonoGame.Framework.dll"
open Microsoft.Xna.Framework
open Microsoft.Xna.Framework.Graphics
open Microsoft.Xna.Framework.Input
module Text =
open System.IO