Skip to content

Instantly share code, notes, and snippets.

@robkuz
robkuz / gist:f2ecb2b95a4f3815327eb4c8a584b795
Created March 18, 2024 19:32
Nestjs/schedule error on npm i
am hitting the following error while installing `@nestjs/schedule`
```
❯ npm i --verbose
npm verb cli /opt/homebrew/Cellar/node/21.6.1/bin/node /opt/homebrew/bin/npm
npm info using npm@10.2.4
npm info using node@v21.6.1
npm verb title npm i
npm verb argv "i" "--loglevel" "verbose"
@robkuz
robkuz / lookup.ts
Last active November 19, 2021 19:19
Building a typesafe Lookup with Constant Objects
//I find typescripts enums a bit lacking.
//This is a way to havevery strongly typed bidirectional lookup table
//first we start with a helper type to reverse a record with unique literal value types as property types
type UniqueReverser<T extends Record<keyof T, PropertyKey>> = unknown extends {
[K in keyof T]-?: T[K] extends Omit<T, K>[Exclude<keyof T, K>] ? unknown : never
}[keyof T] ? never : { [P in keyof T as T[P]]: P }
//this will allow to convert an object in this shape and type
const SOURCE = {
@robkuz
robkuz / keybase.md
Created July 26, 2019 19:34
Keybase md

Keybase proof

I hereby claim:

  • I am robkuz on github.
  • I am robkuz (https://keybase.io/robkuz) on keybase.
  • I have a public key ASAMZndFj-jdg8qESBMKO7DN7lBUZd4guVtM26w_4WkAdwo

To claim this, I am signing this object:

@robkuz
robkuz / JsonTest.fs
Last active October 11, 2018 15:44
Json Testing Lib in F#
open System
open Newtonsoft.Json.Linq
module JsonTest =
let tokenType2String tt =
match tt with
| JTokenType.None -> "None"
| JTokenType.Object -> "Object"
| JTokenType.Array -> "Array"
| JTokenType.Constructor -> "Constructor"
@robkuz
robkuz / codepuzzle.fs
Created December 12, 2017 15:58
Some Code puzzle
Given the following definitions
|>> : map/fmap
v: NonEmptyList<SomeRecord>
SomeRecord: {foo: Option<_>; bar: Option<_>; baz: Option<_>}
isSomeList: SomeRecord -> List<bool, string>
//string: the name of the field
//bool: if Some then true else false
What does this code do?
@robkuz
robkuz / checkDUOrder.fs
Created September 23, 2016 13:32
Checking if DU Value constructors are "reflected" in the same order of definition
//I'd like to see if the test below is true on different execution environments and compilers
//so if you could please run this code and report back to me at @kuzrob. Thanks
open Microsoft.FSharp.Reflection
type SomeDU<'a,'b, 'c> =
| One of 'a
| Two of 'a * 'b
| Three of 'a * 'b * 'c
@robkuz
robkuz / nested_tuple.fs
Created July 21, 2016 16:35
F# inferrer on nested tuples
type FooProtocol =
abstract member foo: unit -> string
type Foo = Foo of string with
interface FooProtocol with
member this.foo () = "foo"
let bar (foo: FooProtocol, _) = ()
let barnested ((foo: FooProtocol, _), y) = ()
let barnestedrev (y, (foo: FooProtocol, _)) = ()
@robkuz
robkuz / polymorphic.md
Last active June 16, 2016 15:24
Emulating Haskell Type classes in F# and creating a bind (>>=) function

Here is someway to support method overloading with F# and to create a bind function.

first create an inline operator

    let inline (>>=) (f: ^U -> ^T) (t:^T)  = 
        let bind' = (^T : (member bind : (^U -> ^T) -> ^T) (t, f))
        bind'
@robkuz
robkuz / error-handling-refactoring.purs
Created May 25, 2016 12:12
refactoring some convoluted error handling code
initial code with some really convoluted error handling.
The problem on this is that it must check for 2 different error cases and also return a different result in those error cases
dot :: Matrix -> Matrix -> Either MatrixError Number
dot (Matrix a sa) (Matrix b sb) = if areSimilarVectors sa sb then Right $ dot' a b else failed sa sb
where
areSimilarVectors s1 s2 = isVector s1 s2 && isSameSize s1 s2
dot' a b = _dot (join a) (join b)
isVector sa sb = fst sa == 1 && fst sb == 1
isSameSize sa sb = snd sa == snd sb
@robkuz
robkuz / api_design.md
Last active May 12, 2016 11:30
API design howto

I am wrapping some matrix library from javascript into Purescript. And I am thinking which signatures my two creation functions for a matrix should have. Their main difference is that in one case you just give a Vector (JS Array) and in the other case you give a 2D Array. In the first case I can easily construct my Matrix. But in the second case I have a error condition to check as the array elemements of of the 2D array (themselves being arrays) all need to be of the same lenght.

data Matrix = Matrix (Array (Array Number))
data Err = Err -- just some error, really not import what kind

make :: (Array (Array Number)) -> Either Err Matrix