This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include prelude | |
type | |
Node {.acyclic.} = ref object | |
le, ri: owned Node | |
proc checkTree(n: Node): int = | |
if n.le == nil: 1 | |
else: 1 + checkTree(n.le) + checkTree(n.ri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
discard """ | |
cmd: "nim c --gc:orc $file" | |
output: ''' | |
{"age": 12, "bio": "Я Cletus", "blob": [65, 66, 67, 128], "name": "Cletus"} | |
true | |
true | |
alpha 100 | |
omega 200 | |
0''' | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asynchttpserver, asyncdispatch, strutils, json, tables, streams | |
# about 130 MB of alive data: | |
var sessions: Table[string, JsonNode] | |
for i in 0..<10: | |
sessions[$i] = parseJson(newFileStream("1.json", fmRead), "1.json") | |
var served = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
macro awaitE(call: typed, r: untyped): untyped = | |
let x = call[0] | |
let tx = x.getType() | |
expectKind tx, nnkBracketExpr | |
var t = newTree(nnkProcTy) | |
var p = newTree(nnkFormalParams, tx[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import strutils, os | |
type Target = tuple[repo, package, ext: string] | |
proc newTarget*(path: string): Target = | |
let splat = path.splitFile | |
result = (repo: splat.dir, package: splat.name, ext: splat.ext) | |
let mem = getOccupiedMem() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
intrin = "<x86intrin.h>" | |
{.localPassC: "-msse4.2".} | |
type | |
M128i {.importc: "__m128i", header: intrin, bycopy.} = object | |
const | |
SIDD_CMP_RANGES = 0b0000_0100'i32 | |
SIDD_NEGATIVE_POLARITY = 0b0001_0000'i32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc complement(s: set[char]): string = | |
var last = '\0' | |
result = "" | |
for elem in '\0'..'\255': | |
if elem notin s: | |
if result.len == 0: | |
result.add elem | |
result.add elem | |
elif pred(elem) == last: | |
result[^1] = elem # patch last interval |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{.push staticBoundChecks: on.} | |
proc takeNat(n: Natural) = | |
discard | |
proc p(a: openArray[int]) = | |
if a.len > 0: | |
echo a[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include prelude | |
type | |
Node {.acyclic.} = ref object | |
le, ri: Node | |
proc checkTree(n: Node): int = | |
if n.le == nil: 1 | |
else: 1 + checkTree(n.le) + checkTree(n.ri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compile and run with 'nim c -r -d:useRealtimeGC -d:release main.nim' | |
import strutils | |
#import times | |
include "lib/system/timers" | |
const | |
windowSize = 200000 | |
msgCount = 1000000 |
NewerOlder