Skip to content

Instantly share code, notes, and snippets.

@ptrelford
ptrelford / Links.csv
Last active January 11, 2024 09:35
Mystic Brew
@ptrelford
ptrelford / JsonParser.js
Created May 16, 2016 08:56
Custom Json Parser in vanilla JavaScript
JSON={
parse:function(str,options) {
this.str = str;
this.i = 0;
this.nfirstchars = '-0123456789.';
this.nchars = '-0123456789.eE';
this.n
return this.parseValue();
},
isWhiteSpace:function(c) {
@ptrelford
ptrelford / goget.go
Last active August 18, 2022 14:13
Go program to download and unzip the latest specified package from Nuget
package main
import "os"
import "io"
import "fmt"
import "path"
import "net/http"
import "archive/zip"
func downloadPackage(name string) {
@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 / JsonParser.fs
Last active May 7, 2018 14:05
JSON Parser
type json =
| Number of float
| String of string
| Boolean of bool
| Array of json list
| Object of (string * json) list
| Null
static member (?) (this,name:string) =
match this with
| Object xs -> xs |> List.find (fst >> (=) name) |> snd
using System;
using static Exceptions;
class MainClass
{
public static void Main(string[] args)
{
throw NRE;
}
}
using System;
using System.Xml;
class MainClass : Variables
{
public static void Main(string[] args)
{
new MainClass().StaticIsEvilForSure();
}
using System;
using System.Xml;
using static Variables;
class MainClass
{
public static void Main(string[] args)
{
for (i = 0; i < 10; i++)
{
@ptrelford
ptrelford / timeline.fs
Last active April 23, 2016 16:36
Generates a responsive timeline of F# meetups around the world
#r @"packages/FSharp.Data/lib/net40/FSharp.Data.dll"
#load "FsHtml.fs" // "paket-files/ptrelford/FsHtml/src/FsHtml.fs"
open System
open FSharp.Data
open FsHtml
type Events = JsonProvider<"https://api.meetup.com/fsharplondon/events?&sign=true&photo-host=public&page=200&status=past,upcoming">
let meetups = [
@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 =