Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
import posix, strformat, typetraits
proc duplicate*(oldHandle, newHandle: FileHandle) =
if dup2(oldHandle, newHandle) < 0:
raise newException(
ValueError,
fmt"Unable to duplicate file handle {oldHandle}."
)
import pegs, strformat, strutils, unicode
let grammer = peg"""
# Node Expressions
commandline <- seperated_cmd / simple_cmd
seperated_cmd <- simple_cmd WS SEPERATOR WS simple_cmd
simple_cmd <- ATOM ( WS ATOM )+ ( WS redirection )?
redirection <- REDIRECTOR ( ATOM )
# Token expressions
import parseutils, strutils
template emitErrorIf(condition, errorString) =
if condition:
echo(errorString)
return 1
proc execDefine(input: string): int =
var position, newPosition = 0
proc sequenceAssign[T](to: var seq[T], from: seq[T]) =
to = newSeq(len(from))
for index in 0..high(to):
memcopy(addr to[index], addr from[index], sizeof(T))
import tables, regex, osproc, os, strformat, sequtils, streams, posix
import lexer, parser, treeutils
# Low-level Constants/Procedures
when defined(windows):
proc c_fileno(f: FileHandle): cint {.
importc: "_fileno", header: "<stdio.h>".}
else:
proc c_fileno(f: File): cint {.
{.push, stdcall, dynlib: "Advapi32.dll".}
proc CryptReleaseContext*(
hProv: HCRYPTPROV;
dwFlags: culong
): cint {.importc: "CryptReleaseContext".}
proc CryptAcquireContextA*(
phProv: ptr HCRYPTPROV;
szContainer: cstring;
szProvider: cstring;
proc newAddress*(key: string): string =
#ase58 encoded version of the first 80 characters, and append the checksum of the key.
var keyHash = $digest(sha512, key)
keyhash.setLen(80)
result = Base58.convert(Hex.revert(keyhash))
result.add(generateChecksum(key))
while result.len < 57:
result.insert("0", 0)
type
RawSecp256k1Context* = distinct pointer
RawSecp256k1ScratchSpace* = distinct pointer
Secp256k1Context* = ref object
raw*: RawSecp256k1Context
Secp256k1ScratchSpace* = ref object
raw*: RawSecp256k1ScratchSpace
// #ifdef __cplusplus
// extern "C" {
// #endif
// #ifndef MAXMINDDB_H
// #define MAXMINDDB_H
/* Request POSIX.1-2008. However, we want to remain compatible with
* POSIX.1-2001 (since we have been historically and see no reason to drop
* compatibility). By requesting POSIX.1-2008, we can conditionally use
# This...
let nums = {
"0": "₀",
"1": "₁",
"2": "₂",
"3": "₃",
"4": "₄",
"5": "₅",
"6": "₆",
"7": "₇",