Skip to content

Instantly share code, notes, and snippets.

View bkase's full-sized avatar

Brandon Kase bkase

View GitHub Profile
@bkase
bkase / fold.ml
Created January 24, 2022 21:42
Haskell-style applicative Fold in OCaml
module Fold = struct
module T = struct
type ('a, 'e) t = Fold : ('x -> 'e -> 'x) * 'x * ('x -> 'a) -> ('a, 'e) t
let make ~step ~init ~finish = Fold (step, init, finish)
let map =
`Custom
(fun (Fold (step, init, finish)) ~f ->
Fold (step, init, fun x -> finish x |> f))
@bkase
bkase / README.md
Last active June 7, 2021 23:20
Generating an offline transaction for mina-generate-keypair keys (v2 -- no docker dependency)

Generating an offline transaction v2

Before there is an official tool to directly generate an offline transaction with the standard mina-generate-keypair generated private key, we can instead convert the key to the client-sdk compatible format and then use the client-sdk to generate the transaction.

A while ago I shared this idea with @nholland94, who in turn made a script that I then tweaked to use Docker and created this one. Thanks @nholland94 !

@nholland94's script minimizes the time that the private key is unencrypted by immediately creating the transaction as soon as the key is dumped.

Version 2 of this script replaces the key loading functionality from relying on the mina daemon via docker to doing everything through NodeJS -- thanks to Auro wallet ( https://github.com/bitcat365/auro-wallet-browser-extension/blob/0888a71dc6abde41ad72889c1826a722c3954553/src/background/accountService.js#L58 ) for the routine of loading the libsodium-encrypted wallet files.

@bkase
bkase / README.md
Last active June 9, 2021 12:26
Generating an offline transaction for mina-generate-keypair keys

Generating an offline transaction

Before there is an official tool to directly generate an offline transaction with the standard mina-generate-keypair generated private key, we can instead convert the key to the client-sdk compatible format and then use the client-sdk to generate the transaction.

A while ago I shared this idea with @nholland94, who in turn made a script that I then tweaked to use Docker and created this one. Thanks @nholland94 !

@nholland94's script minimizes the time that the private key is unencrypted by immediately creating the transaction as soon as the key is dumped.

How to use

@bkase
bkase / gpt-data-abstraction.md
Last active July 22, 2020 07:21
GPT3 was fed the first paragraph only (taken from https://bkase.dev/posts/data-abstraction )

One of the greatest tools to tame complexity in a growing codebase, growing either via lines of code or via people, is through strategic information hiding — you may know this as encapsulation, modularization, or data abstraction. In this post, we'll explore data abstraction's definition and capabilities from a formal perspective and show to what extent we can achieve the ideal through Swift, TypeScript, OCaml, ReasonML, Rust, and Haskell. Knowing how to use data abstraction in your language of choice is important in the short term, but understanding and naming the general concepts equips you to understand these tools as our languages evolve and change.

Data abstraction is about abstracting away the details of data structures and manipulating them at will, so that you don't have to worry about their internals anymore. It's not just about avoiding memory leaks, it's also about avoiding having to think about the underlying representation of those values in the first place. This allows for more flexibility when

@bkase
bkase / WordGuess.scr
Created June 6, 2020 09:15
The Scribble Multiparty Session model for a WordGuess game
module WordGuess;
// This is an attempt to model a game of "word guess"
// All communication flows through board (maybe that makes this whole thing
// trivial)
// There are 4 players, 2 on red team and 2 on blue team
//
// Roughly, there is a leader selected in a round-robin fashion, the leader sees
// a full board of words and shouts a word+#. The player on that team uses the
// word as a hint and can make up to # of guesses unless they get one wrong.
@bkase
bkase / Component.swift
Created November 2, 2019 23:28
Comonadic UIs in SwiftUI with Bow
import Bow
import SwiftUI
public typealias Component<W: Comonad, V: View> =
Kind<W, SwiftUIBackendOf<CoOf<W, ()>, V>>
func const<A,B>(_ x: A) -> (B) -> A { return { _ in x } }
public final class ComponentView<W: Comonad, V: View>: View {
private var component: Component<W, V>
@bkase
bkase / Co.swift
Last active December 6, 2019 00:27
Co.swift seems to work. Read NaturalSubclass.swift for what doesn't work, Natural.swift for what seems to work, and Co_old.swift for where it breaks down
import Bow
// This version of Co seems to work even thoug it's a bit gross to deal with Any
// Think of this as an example of how to deal with rank2 type polymorphism -- you only
// deal with Any in the constructor, even `runCo` has a generic interface.
// newtype Co w a = Co (forall r. w (a -> r) -> r)
public final class ForCo {}
public final class CoPartial<W: Comonad>: Kind<ForCo, W> {}
public typealias CoOf<W: Comonad, A> = Kind<CoPartial<W>, A>
@bkase
bkase / not-really-gadts-protocol.swift
Created January 12, 2018 09:32
"Gadts" with a base protocol
protocol Expr {
associatedtype A
func eval() -> A
}
struct Const<T>: Expr {
typealias A = T
let value: A
func eval() -> A {
return value
@bkase
bkase / unary-indexed-collection.swift
Created January 5, 2018 06:10
Unary-indexed Collection (ported from Swift Sandbox)
// Write some awesome Swift code, or import libraries like "Foundation",
// "Dispatch", or "Glibc"
import Foundation
struct SampleCollection: LazyCollectionProtocol, RandomAccessCollection {
typealias Indices = DefaultRandomAccessIndices<SampleCollection>
let xs = ["a", "b", "c"]
@bkase
bkase / monoidal-cancellation.swift
Created January 5, 2018 06:08
Monoidal Cancellations (ported from Swift Sandbox)
// Write some awesome Swift code, or import libraries like "Foundation",
// "Dispatch", or "Glibc"
struct Monoid<T> {
let empty: T
let append: (T, T) -> T
func fold(_ arr: [T]) -> T {
return arr.reduce(empty, append)
}