Skip to content

Instantly share code, notes, and snippets.

@caindy
caindy / README.md
Created January 17, 2024 03:17 — forked from noelbundick/README.md
WSL2 container development with Moby

WSL2 container development with Moby

Building, pulling, pushing, and running containers is something many developers do often without even thinking. Most of my development over the past couple of years has been exclusively in a Linux environment, specifically WSL2.

Even prior to the recent licensing changes to Docker Desktop, I found myself increasingly as an engineer whose workflow didn't line up with my tools. I never used the GUI features. I never built Windows containers. I used kind or k3d instead of the Docker Kubernetes functionality. I never mounted the Windows filesystem into my containers. And I certainly didn't enjoy frequent downtime caused by updates for those features that I wasn't using. I wanted the container experience in my dev environment to match what I got on a server - just the runtime & tools.

That said, I still like shiny new (or not-so-new but I never see anyone use them

@caindy
caindy / xmasGreetings.fsx
Created December 5, 2015 20:46
an example of using an active pattern as a function argument
open System
let xmas = DateTime.Parse("December 25")
let (|ChristmasEve|ChristmasDay|Twelvetide|NearlyThere|TisTheSeason|NotChristmas|) (d : DateTime) =
match (d - xmas).Days with
| 0 -> ChristmasDay d.Year
| -1 -> ChristmasEve d.Year
| t when t > 0 && t < 12 -> Twelvetide t
| t when t > -7 && t < 0 -> NearlyThere
| t when t > -25 && t < 0 -> TisTheSeason
| _ -> NotChristmas
@caindy
caindy / jsonParse.fsx
Created December 5, 2015 18:13
Using the special (?) F# operator to streamline the Fleece monadic syntax
(*
let shareMsgParser = fun j -> jsonParse {
let! shareWith = j?users
return Share shareWith }
*)
let inline (?) (j : JsonValue) (k : string) =
match j with
| JObject props -> jget props k
| _ -> Failure <| sprintf "%s not found in %A" k j
@caindy
caindy / tryParse.fsx
Last active December 6, 2016 01:53
Using statically resolved types to remove a little boilerplate
// this works...
let n =
match System.Int32.TryParse("10") with
| (true,n) -> Some n | _ -> None
// but this is...
let inline tryParse (s : string) : ^o option =
let mutable o = Unchecked.defaultof<(^o)>
if (^o : (static member TryParse: string * ^o byref -> bool) (s, &o)) then Some o else None
@caindy
caindy / cooking.fsx
Created October 30, 2015 18:31 — forked from MartinBodocky/cooking.fsx
Prototyping for What's Cooking Kaggle competition
// link to competition: https://www.kaggle.com/c/whats-cooking/
//reference deelde with fsharp charting
#r "../packages/Deedle.1.2.4/lib/net40/Deedle.dll"
#r "../packages/FSharp.Charting.0.90.12/lib/net40/FSharp.Charting.dll"
#I "../packages/FSharp.Charting.0.90.12"
#load "FSharp.Charting.fsx"
#r "../packages/Newtonsoft.Json.7.0.1/lib/net45/Newtonsoft.Json.dll"
open System
A comparison of Collection+JSON, HAL, JSON-LD and SIREN media types.
Discussion at
http://sookocheff.com/posts/2014-03-11-on-choosing-a-hypermedia-format/

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@caindy
caindy / getOperator.fs
Last active August 29, 2015 14:11
The lines that use the (?) operator are compiler errors. I suspect this fails for the same reason that you cannot add operators in type extensions. I just don't know what that reason is...
[<AutoOpen>]
module Auto =
type Result<'s, 'f> =
| Success of 's
| Failure of 'f
open System
open System.Runtime.CompilerServices
open System.Collections.Generic
open Newtonsoft.Json.Linq
@caindy
caindy / bootstrapCanopyOSX.sh
Created September 8, 2014 13:12
bash script to bootstrap canopy on OSX
#! /bin/bash
if hash brew 2>/dev/null; then
echo "Found Homebrew"
else
echo >&2 "Please install Homebrew"
exit 1
fi
if hash fsharpi 2>/dev/null; then
@caindy
caindy / actpat.fsx
Created August 3, 2014 18:40
highlighting the expressiveness of total single-case active pattern
open System.Numerics
let (|Rect|) (x: Complex) = (x.Real, x.Imaginary)
let (|Polar|) (x: Complex) = (x.Magnitude, x.Phase)
//conversion functions easily expressed in terms of active patterns
let toRect = function | Rect(r, i) -> (r, i)
let toPolar = function | Polar(m, p) -> (m, p)
//following two functions are equivalent, but the former reads better IMO