Skip to content

Instantly share code, notes, and snippets.

@anthonyjoeseph
anthonyjoeseph / unjailTest.ts
Created May 12, 2023 17:59
CosmJs Unjail Validator
import {
AminoConverters,
AminoMsgUnjail,
AminoTypes,
SigningStargateClient,
StargateClient,
createDefaultAminoConverters,
defaultRegistryTypes,
makeMultisignedTxBytes,
} from "@cosmjs/stargate";
@anthonyjoeseph
anthonyjoeseph / fireblocksCosmos.ts
Last active April 18, 2024 11:28
RAW signing via fireblocks API
import path from "path";
import fs from "fs";
import { coins, pubkeyToAddress } from "@cosmjs/amino";
import { fromHex, toBase64, toHex } from "@cosmjs/encoding";
import { StargateClient } from "@cosmjs/stargate";
import { encodePubkey, makeSignBytes } from "@cosmjs/proto-signing";
import { EncodeObject, Registry, makeAuthInfoBytes, makeSignDoc } from "@cosmjs/proto-signing";
import { sha256 } from "@cosmjs/crypto";
import { FireblocksSDK, TransactionOperation, TransactionStatus } from "fireblocks-sdk";
import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
@anthonyjoeseph
anthonyjoeseph / 3.9|package.json
Last active April 12, 2022 15:11
Test Multiple Typescript Versions Using TSC
{
"name": "Tests against TS v3.9",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"typescript": "^3.9.2"
}
}
@anthonyjoeseph
anthonyjoeseph / Struct.ts
Last active April 2, 2021 00:22
fp-ts Struct Module
/**
* @since 2.11.0
*/
import { URIS3, Kind3, URIS2, Kind2, URIS, Kind, URIS4, Kind4, HKT } from './HKT'
import * as R from './ReadonlyRecord'
import { Option, fromNullable, fromPredicate, some, Applicative as OptionApplicative } from './Option'
import { Either, right, left } from './Either'
import { Ord } from './Ord'
import { Ord as StringOrd } from './string'
import { Apply4, Apply3, Apply3C, Apply2, Apply2C, Apply1, Apply } from './Apply'
@anthonyjoeseph
anthonyjoeseph / tableColumns.tsx
Last active February 28, 2021 22:00
fp-ts-tree-utils
import { sum } from 'fp-ts-std/Array';
import * as A from 'fp-ts/Array';
import { pipe } from 'fp-ts/function';
import * as O from 'fp-ts/Option';
import * as T from 'fp-ts/Tree';
import React from 'react';
// npm package name: fp-ts-tree-contrib ?
export const isLeaf = <A,>(tree: T.Tree<A>): boolean => tree.forest.length === 0
@anthonyjoeseph
anthonyjoeseph / mapAll.ts
Created February 28, 2021 02:41
mapAll function
const mapAll = <A, B>(vals: {
[K in NonNullable<keyof A>]: (val: A[K]) => B
}) => (a: A): {
[K in NonNullable<keyof A>]: B
} => {
const keys = Object.keys(a) as (NonNullable<keyof A> & string)[]
const mapped = fromFoldableMap(
S.getLastSemigroup<B>(), RA.readonlyArray
)(
keys, (key) => [key, vals[key](a[key])]
@anthonyjoeseph
anthonyjoeseph / tabledemo.tsx
Last active February 28, 2021 08:21
Typesafe Table W/O React Table
import React from 'react'
import * as A from 'fp-ts/Array';
const Table2 = <A,>({
data, order, headerTitles, rowRenderer
}: {
data: A[]
order: NonNullable<keyof A>[]
headerTitles: {
[K in NonNullable<keyof A>]: string
@anthonyjoeseph
anthonyjoeseph / catchErrorExperiment.ts
Last active January 15, 2021 19:13
Catch Error Experiment
import { flow, pipe } from 'fp-ts/function';
import * as E from 'fp-ts/Either'
import * as r from 'rxjs'
import * as ro from 'rxjs/operators'
import * as OB from 'fp-ts-rxjs/lib/Observable'
export const tryCatch = <E, A>(
onErr: (e: unknown) => E
): r.OperatorFunction<A, E.Either<E, A>> => flow(
OB.map(E.right),
@anthonyjoeseph
anthonyjoeseph / FpReduxExample.tsx
Last active April 19, 2022 08:08
Should I Use redux-observable fp-ts Example
import { pipe } from 'fp-ts/pipeable'
import * as O from 'fp-ts/Option'
import * as Op from 'monocle-ts/lib/Optional'
import * as r from 'rxjs'
import * as ro from 'rxjs/operators'
import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import React from 'react';
import { Provider, useDispatch, useSelector } from 'react-redux';
import { makeADT, ofType, ADTType } from '@morphic-ts/adt'
@anthonyjoeseph
anthonyjoeseph / PromiseLikeAdverb.ts
Created October 3, 2020 20:25
Accidental PromiseLike
interface PrintAdverb<T> {
then: <TResult1>(o: ((value: T) => PrintAdverb<TResult1>)) => PrintAdverb<TResult1>;
absolutely?: string;
positively?: string;
veryvery?: string;
necessary?: string;
}
const pa: PrintAdverb<string> = {
then: <TResult1>(o: ((value: string) => PrintAdverb<TResult1>)) => o('3')
}