Skip to content

Instantly share code, notes, and snippets.

@osfameron
osfameron / foo.carp
Created November 16, 2020 09:25
testing Carp
https://blog.veitheller.de/Carp.html
(def x 1)
(+ x 1) ;; ???
x
(IO.println &(Int.str (+ x 10)))
(defn id [a] a)
(id x)
(deftype Point [x Int, y Int])
@osfameron
osfameron / tickers.u
Created September 26, 2020 09:24
Unison tickers sketch
type Counter a = { value : a,
tick : (a -> a) }
tock : (state -> Counter a)
-> (Counter a -> state -> state)
-> state
-> (a, state)
tock sc css s =
c = sc s
@osfameron
osfameron / effect.u
Last active September 23, 2020 20:38
Unison effect handling/testing sketch
-- basic algebraic effect with just 2 capabilities
ability Effect where
print : Text ->{Effect} ()
input : {Effect} Text
-- `run main` will run the code
main = 'handle !prog with IOHandler
-- this is the program
prog _ =
@osfameron
osfameron / JsonTest3.purs
Last active September 1, 2020 11:28
Better API for Json passthrough
module JsonTest where
import Prelude (bind, pure, ($), (=<<))
import Data.Argonaut.Core (Json, fromObject, stringify, toObject)
import Data.Argonaut.Decode (JsonDecodeError(..), decodeJson, parseJson)
import Data.Argonaut.Encode (encodeJson)
import Data.Either (Either, note)
import Foreign.Object as O
import Data.Tuple (Tuple(..))
@osfameron
osfameron / JsonTest2.purs
Created September 1, 2020 09:44
Simpler passthrough of un-codec'd fields
module JsonTest where
import Prelude (bind, pure, ($), (<<<))
import Data.Argonaut.Core (Json, fromObject, stringify, toObject)
import Data.Argonaut.Decode (JsonDecodeError(..), decodeJson, parseJson)
import Data.Argonaut.Encode (encodeJson)
import Data.Either (Either, note)
import Foreign.Object as O
import Data.Tuple (Tuple(..))
import Data.Maybe (Maybe, fromJust)
@osfameron
osfameron / JsonTest.purs
Last active September 1, 2020 07:31
Test of updating a partial object from a record. (Rather clumsy)
module JsonTest where
import Prelude (bind, pure, (#), ($), Unit)
import Data.Argonaut.Core (Json, caseJsonObject, fromNumber, fromObject, fromString)
import Data.Argonaut.Decode (JsonDecodeError, decodeJson, parseJson)
import Debug.Trace (spy)
import Effect
import Effect.Console (log)
import Data.Either (Either)
import Foreign.Object as O
@osfameron
osfameron / Main.purs
Last active August 29, 2020 15:38
chainl1 parser example in PureScript
-- attempt to port `chainl1` example from
-- https://hackage.haskell.org/package/parsec-3.1.14.0/docs/Text-Parsec-Combinator.html#v:chainl1
module Main where
import Prelude hiding (between)
import Text.Parsing.StringParser
import Text.Parsing.StringParser.Combinators
import Text.Parsing.StringParser.CodePoints
import Control.Alt
@osfameron
osfameron / CLIReporter.cs
Last active August 18, 2020 16:41
C# ApprovalTests - Custom reporter that outputs to command line and copies `cp` command to clipboard
using System.IO;
using ApprovalTests.Core;
using System;
using TextCopy;
namespace ApprovalTests.Reporters
{
/// Reporter class to work in `dotnet watch test` in VSCode
/// terminal window on Mac.
public class CLIReporter : IApprovalFailureReporter
@osfameron
osfameron / explain.py
Last active June 1, 2019 07:07
Sketch of explainshell like output, after discussion on work Slack
"""
Sketch of https://explainshell.com/ like output, in plain text
$ python explain.py
git diff-tree -M -r --name-status <commit>
└───┬───┘ ├┘ ├┘ └─────┬─────┘ └──┬───┘
┌───────┘ │ │ │ │
│┌────────────┘ │ │ │
││┌──────────────┘ │ │
@osfameron
osfameron / aoc5.clj
Created December 5, 2017 19:01
AoC day 5 sketch
(require '[clojure.zip :as zip])
(def s '(0 3 0 1 -3))
(defn step [z]
(let [v (zip/node z)
dir (if (pos? v) zip/right zip/left)]
(->> z
(#(zip/edit % inc))
(iterate dir)
(take (inc (Math/abs v)))