Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / FoqReturns.fs
Created November 19, 2013 07:36
Foq cannot explicitly return an F# type as null
module ``Foq cannot explicitly return an F# type as null``
open System
open Foq
// Discriminated Unions
type TimeInForce = GoodTillCancel | GoodTillDate of DateTime
type IOrder =
@ptrelford
ptrelford / SmallSmallBasicParser.fsx
Created January 4, 2014 19:05
Small Small Basic Parser FParsec sample
// Type abbreviations
type label = string
type identifier = string
type index = int
type HashTable<'k,'v> = System.Collections.Generic.Dictionary<'k,'v>
/// Small Basic arithmetic operation
type arithmetic = Add | Subtract | Multiply | Divide
/// Small Basic comparison operaton
type comparison = Eq | Ne | Lt | Gt | Le | Ge
/// Small Basic logical operation
@ptrelford
ptrelford / SimplestBehaviorTree.fsx
Last active August 29, 2015 14:01
Simplest Behaviour Tree
type Result = Success | Failure | Running
type Behavior =
| Action of (unit -> Result)
| Selector of Behavior list
| Sequence of Behavior list
let rec behave = function
| Action f -> f ()
| Selector xs -> select xs
// Start in VS: View -> Other Windows -> F# Interactive
open System
// Turn on timing in F# interactive
#time
// Performance bottle kneck
let formatKey (a:string,b:string) =
String.Format("{0}:{1}", a, b)
@ptrelford
ptrelford / Yahoo.cs
Created July 17, 2014 13:03
Yahoo reade
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
namespace DashboardApp
{
public static class Yahoo
{
public static IEnumerable<object> GetPrices(string stock)
@ptrelford
ptrelford / TwitterDataScience.fsx
Last active August 29, 2015 14:06
FsiBot Data Science Prototype
#r "System.Windows.Forms.DataVisualization.dll"
#r @"..\packages\FSharp.Charting.0.90.7\lib\net40\FSharp.Charting.dll"
#r @"..\packages\FSharp.Data.2.0.14\lib\net40\FSharp.Data.dll"
open FSharp.Data
open FSharp.Charting
let wb = WorldBankData.GetDataContext()
type Indicator = Runtime.WorldBank.Indicator
type Indicators = WorldBankData.ServiceTypes.Indicators
@ptrelford
ptrelford / GoLangAST.fs
Created December 8, 2014 12:42
Go Lang AST (early draft)
// AST for GO lang
type packageName = string
type typeName = string
type name = string
type typ = string
type value =
| Bool of bool
| Int of int
| Float64 of double
| String of string