Skip to content

Instantly share code, notes, and snippets.

View hkdf.nim
import nimcrypto, math, byteutils
proc hkdf*(HashType: typedesc, secret, salt, info: openarray[byte], output: var openarray[byte]) =
var ctx: HMAC[HashType]
let prk = ctx.finish().data
const hashLen = HashType.bits div 8
var t: MDigest[HashType.bits]
yglukhov / wrc20.wat
Last active December 11, 2018 09:33
View wrc20.wat
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32 i32)))
(type (;2;) (func (param i32 i32 i32)))
(type (;3;) (func (param i32)))
(type (;4;) (func))
(import "ethereum" "getCallDataSize" (func (;0;) (type 0)))
(import "ethereum" "finish" (func (;1;) (type 1)))
(import "ethereum" "revert" (func (;2;) (type 1)))
(import "ethereum" "callDataCopy" (func (;3;) (type 2)))
View NIP_rlpx.nim
# This gist should explain the rlpx.nim improvements
# Main points
# Rlpx is an entity which is responsible only for rlpx messaging. The rlpx
# subsystem doesn't know anything about Ethereum or even Peer.
# Subprotocol functions are "namespaced" to corresponding protocol types.
# This provides an option to have multiple equally named functions belonging
# to different protocols/versions.
# A protocol of specific type can be queried from an Rlpx object
# The rlpxProtocol macro is used to help generate a new Protocol type.
# An object of a protocol type is capable of
View gist.nim
# Nim's Runtime Library
# (c) Copyright 2015 Andreas Rumpf
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
View new_ranges.nim
const rangesGCHoldEnabled = not defined(rangesDisableGCHold)
const unsafeAPIEnabled = defined(rangesEnableUnsafeAPI)
Bytes* = seq[byte]
# A view into immutable array
yglukhov / test.nim
Created March 19, 2018 15:10
keys mismatch
View test.nim
import eth_keys
let privKey = initPrivateKey("a2b50376a79b1a8c8a3296485572bdfbf54708bb46d3c25d73d2723aaaf6a617")
echo "priv: ", privKey.raw_key.toHex()
echo "pub: ", privKey.public_key.raw_key.toHex()
# priv: a2b50376a79b1a8c8a3296485572bdfbf54708bb46d3c25d73d2723aaaf6a617
# pub: c58a9e3bcea19d6284a1a5b7da269ef100f8f48fef1e165ab1c625dade34cd717400e3d43682e6061472007fbb303c3896c48926912a6e57d7c024087fd45c40
yglukhov / rest.nim
Last active November 16, 2017 11:25
View rest.nim
# protocol.nim
import super_rest_lib
type Foo = object
a: int
restInterface myInterface:
proc bar(arg1, arg2: Foo)
proc someOtherBar(arg1: string): string
proc someOtherBar2(arg1, arg2: string)
View nimx_layout_tests.nim
import nimx / [ window, button, text_field, layout, split_view, context, scroll_view2 ]
type Label = ref object of TextField
method init*(v: Label, r: Rect) =
procCall v.TextField.init(r)
v.editable = false
v.selectable = false
type TestView = ref object of View
View nimx_layout_test.nim
proc createLayout4(w: Window) =
- SplitView sv:
vertical: true # Comment this line to make me horizontal
backgroundColor: blue
top == super
bottom == super
leading == super
trailing == super
View threadpools.nim
import macros, cpuinfo
when not compileOption("threads"):
{.error: "ThreadPool requires --threads:on compiler option".}
ThreadPool* = ref object
chanTo: ChannelTo # Tasks are added to this channel
chanFrom: ChannelFrom # Results are read from this channel
threads: seq[ThreadType]