Skip to content

Instantly share code, notes, and snippets.

@larskuhtz
larskuhtz / Main.hs
Last active February 17, 2023 17:56
Bug with the mod package And GHC 9.4.4 on Linux
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main (main) where
import Data.Mod (Mod)
import GHC.TypeNats (KnownNat)
import Numeric.Natural (Natural)
@larskuhtz
larskuhtz / .jq
Last active August 18, 2022 09:55
jq config file for working with Kadena chainweb payloads
# ############################################################################ #
# Base64 URL without padding
def base64dUrl: .
| gsub("(?<x>[-_])"; if .x == "-" then "+" else "/" end)
| "\(.)==="
| @base64d
;
def fromjson64: .
@larskuhtz
larskuhtz / Bench.hs
Last active November 21, 2021 22:24
JSON serialization benchmarks for Chainweb
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@larskuhtz
larskuhtz / README.md
Last active May 9, 2024 19:27
Chainweb Tx History

Chainweb Transfers

Query Chainweb transfer events within a block range for a given chain.

Usage example:

CHAIN=1 MINHEIGHT=1420000 MAXHEIGHT=14201000 bash ./tranfers.sh
@larskuhtz
larskuhtz / Events.hs
Last active January 7, 2020 06:04
Reproduce EventSource + HTTP/2 + TLS issue
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
-- |
-- To reproduce with curl, run mainTls (from ghci) and use
--
-- @
@larskuhtz
larskuhtz / README.md
Last active April 9, 2020 00:03
Chainweb Performance Numbers

Updated Results [2020-04-08]

transfers (tx/min) orphan rate (%) block time (s) pact validation (ms) cut processing (ms) pending tx CPU (cores) Mem (MB) Git Rev
12,000 5% 40 (target 30) 1500-2000 1500-2000 - - - -
15,000 6-7% 40 (target 30) 2000 1500-2000 - - - -

Results

@larskuhtz
larskuhtz / README.md
Last active December 4, 2018 23:05
Haskell Benchmarks for Concurrent Transactions with Many Shared Variables

Setup

This gist contains benchmarks for read-only concurrent transaction that involve many shared variables. The test data is a mutable single-linked list where individual list "cells" are linked via mutable shared variables. The goal is to measure the overhead of different transaction types and variables in read-only transactions when there are no concurrent writes.

The input to a benchmark run is a list of a of successive Int values. The benchmark code runs a number of concurrent threads that each fold over the list and each compute the sum of all entries. The list isn't mutated during the benchmarks.

@larskuhtz
larskuhtz / WrappedException.hs
Last active October 16, 2018 20:53
Safely Wrapping Exception in Haskell
{-# LANGUAGE ScopedTypeVariables #-}
module WrappedException
( main
) where
import Control.Concurrent
import Control.Exception (SomeAsyncException(..))
import Control.Monad.Catch
@larskuhtz
larskuhtz / script.sh
Created October 2, 2018 16:56
Demonstrate incompatibility of Haskell packages cryptonite and blake2
#!/bin/bash
# The Haskell packages cryptonite and blake2 both include a version
# of the C sources of the blake2 reference implementation. Linking
# both packages into the same Haskell binary can result in a broken
# binary that produces unsound results.
TDIR=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX")
trap "{ rm -rf "$TDIR"; }" EXIT
@larskuhtz
larskuhtz / Main.hs
Last active June 10, 2019 21:53
Microbenchmarks for comparing time and thyme packages
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UnicodeSyntax #-}
-- |
-- Module: Main
-- Copyright: Copyright © 2018 Kadena LLC.