Skip to content

Instantly share code, notes, and snippets.

View mastoj's full-sized avatar

Tomas Jansson mastoj

View GitHub Profile
@mastoj
mastoj / main.go
Created October 17, 2017 11:25
Example of lightweight railway oriented programming in go (but some typing is lost)
package main
import (
"fmt"
)
type Result struct {
Error error
Data interface{}
}
@mastoj
mastoj / getBQSchema.sh
Last active April 5, 2017 21:15
How to get the schema for a BigQuery query on the command line
bq query --format=json --dry_run=true --use_legacy_sql=false 'SELECT @a IS TRUE AS x, @b + 1 AS y, "foo" = @c AS z, ["tomas", "jansson"] as w, STRUCT("wat" as t, 69 as u) as v, [STRUCT(3, "allo" as g), STRUCT(5 as a, "yolo")] as u, STRUCT(["a"] as h) as t;'
@mastoj
mastoj / paket.dependencies
Created February 3, 2017 08:04
VS Code/ionide error
source https://nuget.org/api/v2
nuget FSharp.Data framework: net45
nuget MySql.Data framework: net45
type Time = int*int
type Day = int
type OpeningHour = Day*Time
type DayGroup =
{
Days: int list
Time: Time
}
let openingHour day startTime endTime = day,(startTime,endTime)
@mastoj
mastoj / Program.cs
Created September 9, 2016 09:42
Show the difference between multiple await and Task.WhenAll
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsyncDiff
{
@mastoj
mastoj / RouteParser.fsx
Last active August 14, 2016 19:27
Parser proof of concept for fable.
(*
Based on the excellent blog series by Scott Wlaschin: http://fsharpforfunandprofit.com/posts/understanding-parser-combinators/
Inspired by Elm Route Parser: http://package.elm-lang.org/packages/etaque/elm-route-parser/2.2.1/
*)
[<AutoOpen>]
module Parsing =
open System
open Microsoft.FSharp.Reflection
module MA =
type A = { AStr: string}
type B = { BInt: int}
type private DU =
| A of A
| B of B
@mastoj
mastoj / README
Last active March 8, 2016 23:02
FAKE build script with spawn, run, stop and attach
Copy `build.fsx` manually to root as a starting point for your build file.
#r "packages/Suave/lib/net40/Suave.dll"
open System
open Suave
open Suave.Filters
open Suave.Successful
open Suave.RequestErrors
open System.Text.RegularExpressions
[<AutoOpen>]
/// Discriminated union representing two messages - one for sending
/// numbers to the agent and one for resetting the state of the agent
type CounterMessage =
| Update of float
| Reset
// Simple agent that calculates average and can be reset
let counter = MailboxProcessor.Start(fun agent ->
let rec loop sum count = async {