Skip to content

Instantly share code, notes, and snippets.

@zah
zah / keybase.md
Created November 29, 2022 23:34
keybase.md

Keybase proof

I hereby claim:

  • I am zah on github.
  • I am zahary (https://keybase.io/zahary) on keybase.
  • I have a public key ASB3c8AUGb_cjAv7wosU_183YlSZimg7ZYG9rV2H3tdSdwo

To claim this, I am signing this object:

import
sequtils, random,
stew/shims/macros,
stew/objects
type
A = object
s: string
i: int
b: B

0x05556c26c5d722da32f57ca29a0f9f049525d2718961d1d875723795a6eb7ecf

Chunked responses

The chunked responses were originally suggested and discussed in the first network spec PR: ethereum/consensus-specs#1158

Here are the relavant bits from a possible spec:

Response -- After receiving a request, the responding party MUST reply on the same stream within 10 seconds with a response code, followed by the contents of the response.

import
sets
type
AlwaysMatch = object
proc match(val: string, values: HashSet[string]): bool =
val in values
proc match(val: string, predicate: proc(x: string): bool): bool =
import macros
template generateCode(body: untyped) =
iterator yields: NimNode = body
macro payload: untyped =
result = newStmtList()
for node in yields():
result.add node
@zah
zah / beacon_sync.nim
Created March 26, 2019 10:06
beacon_node RLPx protocols
type
BeaconSync* = object
template NetworkState*(P1822062: type BeaconSync): type =
ref[BeaconSyncState:ObjectType]
type
statusObj* = object
networkId*: uint64
latestFinalizedRoot*: Eth2Digest
latestFinalizedEpoch*: Epoch

Here's the canonical TOML example from the TOML README, and a YAML version of the same. Which looks nicer?

title = "TOML Example"

[owner] name = "Tom Preston-Werner"

# These two are semantically equivalent:
proc makeIterator(x, y: int): Irerator[int] =
result = iterator(): int {.closure.} =
yield 1
yield 2
iterator makeIterator(x, y): int =
yield 1
yield 2
@zah
zah / ImportNim.cs
Last active October 22, 2017 12:32
Importing Nim modules from C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace nim_sharp
{
[StructLayout(LayoutKind.Sequential)]