Skip to content

Instantly share code, notes, and snippets.

View mastoj's full-sized avatar

Tomas Jansson mastoj

View GitHub Profile
@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 / 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 / Program.fs
Created October 17, 2017 21:32
Proto.actor and F#
open System
open Proto
open System.Threading.Tasks
type Message = {Text: string}
type Message2 =
| Text of string
module Proto =
let createActor<'T> f =
@mastoj
mastoj / Program.cs
Last active October 10, 2024 21:40
Some plinq examples
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace ParallelTest
{
class Program
{
static void Main(string[] args)
type Connection = {
Start: unit -> unit
Stop: unit -> unit
}
type ActiveConnection = {
Stop: unit -> ConnectionWrapper
}
and InActiveConnection = {
Start: unit -> ConnectionWrapper
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MinimalDispatcher
{
public interface IHandle<TRequest, TResponse> {
Task<TResponse> Handle(TRequest request);
@mastoj
mastoj / Kubernetes.fs
Created December 23, 2020 23:13
Sample pulumi F# helpers
[<RequireQualifiedAccess>]
module Secret =
open Pulumi.Kubernetes.Core.V1
open Pulumi.Kubernetes.Types.Inputs.Core.V1
let base64Encode (str: string) =
let bytes = System.Text.Encoding.UTF8.GetBytes(str)
System.Convert.ToBase64String(bytes)
@mastoj
mastoj / CatchAllController.cs
Created November 12, 2021 08:45
Catch all sample controller
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace catchall.Controllers
{
@mastoj
mastoj / day05.fsx
Created December 5, 2021 20:52
Day 05
open System.IO
let path = "05-input.data"
let sample = """0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
@mastoj
mastoj / day19.fsx
Created December 20, 2021 23:36
Day 19 part 10 not working
open System.IO
type Beacon = {
X: int
Y: int
Z: int
}
type Scanner = {
Id: int
Beacons: Beacon Set