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
func findMatching(s: string; first, last: Natural; a, b: static char; d: static int): int {.raises: [ValueError].} = | |
var i = first.int | |
var level = 0 | |
while true: | |
if s[i] == a: | |
inc level | |
elif s[i] == b: | |
dec level | |
if level == 0: | |
return i |
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
iterator walkDirRecEx*(dir: string; yieldFilter = {pcFile}; followFilter = {pcDir}; relative = false; checkDir = false; depth = -1): string {.raises: [OSError].} = | |
## Same as std/os.walkDirRec but with added `depth` parameter. `depth < 0` | |
## means no depth limit. | |
if depth != 0: | |
var stack = @[("", 1)] | |
var checkDir = checkDir | |
while stack.len > 0: | |
let (subDir, subDepth) = stack.pop() | |
for kind, path in walkDir(dir / subDir, relative = true, checkDir = checkDir): | |
let rel = subDir / path |
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 std/asyncdispatch | |
proc asyncThread*[T](worker: proc (arg: T) {.thread.}; arg: T): Future[void] {.async.} = | |
## Starts a thread that runs `worker` and completes the Future when the thread exits. | |
var fut = newFuture[void]("asyncThread") | |
let ev = newAsyncEvent() | |
addEvent(ev) do (_: AsyncFD) -> bool: | |
fut.complete() | |
true |
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
type | |
Either*[A, B] = object | |
case isA: bool | |
of true: | |
a: A | |
of false: | |
b: B | |
template isB(e: Either): bool = | |
not e.isA |
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
#!/bin/sh | |
git show-branch -a 2>/dev/null \ | |
| grep '\*' \ | |
| grep -v `git rev-parse --abbrev-ref HEAD` \ | |
| head -n1 \ | |
| perl -pe 's/.*?\[(.*?)\].*/\1/' \ | |
| sed 's/[\^~].*//' | |
# How it works: |
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
function aliasexpand { # $* command | |
ALIASRET=$(alias $1 2>/dev/null) | |
if [[ $? -ne 0 ]]; then | |
# not an alias | |
ALIAS=$1 | |
else | |
ALIASLAYER=$(echo "$ALIASRET" | cut -d '=' -f2 | sed "s/^'//" | sed "s/'$//") | |
ALIAS=$(aliasexpand $ALIASLAYER) | |
fi | |
shift |
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 std/strutils | |
import std/tables | |
import std/sugar | |
import std/options | |
import std/sequtils | |
when defined(js): | |
import std/dom | |
type | |
Response = tuple[text: string, asterisk: bool] |
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
Nim 11m βββββββββββββββββββββ 100.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 | |
template constDecl(n, t, v): untyped = | |
const n: t = v | |
macro cenum*(t, body: untyped): untyped = | |
var | |
i: BiggestInt = 0 | |
curBaseExpr = newIntLitNode(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
const MODE_NONE = 0, | |
MODE_BYTESTRING = 1, | |
MODE_INT = 2, | |
MODE_LIST = 3, | |
MODE_DICT = 4; | |
function getInt(buf) { | |
let n = 0; | |
for (let i = 0; i < buf.length; ++i) { | |
n += (buf[buf.length - 1 - i] - 48) * 10 ** i; |
NewerOlder