Skip to content

Instantly share code, notes, and snippets.

View treeform's full-sized avatar

Andre von Houck treeform

View GitHub Profile
+---------+--------------------+-------+
| faction | avg | count |
+---------+--------------------+-------+
| MOD | 727.6 | 5 |
| AUTO | 614.6 | 20 |
| GBC | 593.6 | 5 |
| TKKA | 577.7368421052631 | 19 |
| CNCR | 517.7659574468086 | 47 |
| TOTO | 502.2 | 5 |
| STIX | 464.5 | 10 |
import macros
macro print*(n: varargs[typed]): untyped =
result = newNimNode(nnkStmtList, n)
for i in 0..n.len-1:
if n[i].kind == nnkStrLit:
# pure string literals are written diretly
result.add(newCall("write", newIdentNode("stdout"), n[i]))
else:
# other expressions are written in <expression>: <value> syntax
import json
import strutils
type
Mapping = object
generatedLine: int
generatedColumn: int
originalLine: int
originalColumn: int
source: string
import json, strutils, algorithm
type
Mapping* = object
## mapping object that represents the line
generatedLine: int
generatedColumn: int
originalLine: int
originalColumn: int
source: string
Should I do?
if (`b`.length > `a`.length) {
return -`b`[`a`.length];
}
vs
if (`b`.length > `a`.length) {
return -1;
#[
kiwi is a packed key value table/dictinary/associate-arrays like objects that is packed into a single buffer.
kiwis don't optimize key access, but its pretty fast to do a liner scan if your kiwi is less then 100 elements.
]#
type
Kiwi* = object
arr: seq[uint8]
proc pythonMod(n, M: int): int = ((n mod M) + M) mod M
assert pythonMod(1, -4) == -3
assert pythonMod(-1, 4) == 3
assert pythonMod(-1, -4) == -1
assert pythonMod(1, 4) == 1
import streams
when hostOS == "windows":
proc wgetch(): char {. header: "<conio.h>", importc: "getch" .}
proc wgetche(): char {. header: "<conio.h>", importc: "getche" .}
# stdout.write("\e[2J") # clear screen
const promt = "quicki >>> "
{.compile: "openwl/source/osx-cocoa/MainThreadExecutor.mm".}
{.compile: "openwl/source/osx-cocoa/WLAppDelegate.mm".}
{.compile: "openwl/source/osx-cocoa/WLContentView.mm".}
{.compile: "openwl/source/osx-cocoa/WLWindowObject.mm".}
{.compile: "openwl/source/osx-cocoa/globals.mm".}
{.compile: "openwl/source/osx-cocoa/keystuff.mm".}
{.compile: "openwl/source/osx-cocoa/miscutil.mm".}
{.compile: "openwl/source/osx-cocoa/openwl.mm".}
{.compile: "openwl/source/osx-cocoa/private_defs.mm".}
{.passL: "-framework Foundation" .}
import strutils
proc initDecodeTable*(): array[256, char] =
# computes a decode table at compile time
for i in 0 ..< 256:
let ch = char(i)
var code = 255
if ch >= 'A' and ch <= 'Z': code = i - 0x00000041
if ch >= 'a' and ch <= 'z': code = i - 0x00000047