Skip to content

Instantly share code, notes, and snippets.

(*
ParserLibrary.fsx
Final version of a parser library.
Related blog post: http://fsharpforfunandprofit.com/posts/understanding-parser-combinators-3/
*)
module ParserLibrary
(*
JsonParser.fsx
A JSON parser built from scratch using a combinator library.
Related blog post: http://fsharpforfunandprofit.com/posts/understanding-parser-combinators-4/
*)
module JsonParser
function maybe(value) {
const isEmpty = () => value === undefined || value === null;
const nonEmpty = () => !isEmpty();
return {
map(f) { return isEmpty() ? this : maybe(f(value)) },
getOrElse(n) { return isEmpty() ? n : value },
isEmpty: isEmpty,
nonEmpty: nonEmpty
}
}
@toburger
toburger / file.php
Last active September 28, 2015 10:09
PHP: Computes the difference of two arrays by value, not by key (like array_diff_ukey)
<?php
function diff($array1, $array2, $compare_func) {
return array_diff_ukey($array1, $array2, function($key1, $key2) use ($array1, $array2, $compare_func) {
if (!isset($array1[$key1])) return 1;
if (!isset($array2[$key2])) return -1;
return $compare_func($array1[$key1], $array2[$key2]);
});
}
@toburger
toburger / reflector.fsx
Last active August 29, 2015 14:25
Cool new F# 4.0 feature
module Reflection =
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open System.Reflection
let private (|Name|) (info: MemberInfo) = info.Name
let private (|PropertyName|_|) = function
| PropertyGet (_, Name name, _) -> Some name
| _ -> None
#r "System.Speech"
open System.Speech.Synthesis
let synt = new SpeechSynthesizer()
// synt.Rate <- 5 // schneller mochn!
let say s = synt.Speak(s: string)
[1 .. 100]
|> List.map (fun n ->
match n%3, n%5 with
param ([string[]]$Computer = ".")
@($Computer) | % {
$c = $_
if ($c -eq '.') { $c = $env:COMPUTERNAME }
$os = get-wmiobject Win32_OperatingSystem -Computer $_
$physical = Get-WmiObject CIM_PhysicalMemory -Computer $_
$free = $os.FreePhysicalMemory
@toburger
toburger / functional_unity3d.fsx
Last active August 29, 2015 14:07
An experiment if Unity3D and (kind of) idiomatic F# can play nicely together.
#r @"C:\Users\TBurger\Downloads\UnityEngine.dll"
open UnityEngine
module Unity =
[<AutoOpen>]
module Log =
let inline uprintfn fmt =
Printf.kprintf Debug.Log fmt
@toburger
toburger / Pretzel.SassTransformer.fsx
Created October 9, 2014 10:00
Simple pretzel extension to transform SASS files into CSS
#r "System.ComponentModel.Composition"
#if INTERACTIVE
#r "../Pretzel.exe"
#r "LibSass.x86.dll"
#r "libsassnet.dll"
#endif
open System.ComponentModel.Composition
open Pretzel.Logic.Extensibility
open Pretzel.Logic.Templating.Context
#if INTERACTIVE
#r "System.Net.Http"
#endif
module MimeTip
open System.IO
open System.Net.Http
open System.Runtime.InteropServices