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 `==` *[I, T](x, y: array[I, T]): bool = | |
for f in low(x)..high(x): | |
if x[f] != y[f]: | |
return | |
result = true | |
when isMainModule: | |
let | |
t1: array[4, int8] = [int8(0x73), 0x6C, 0x68, 0x2B] | |
t2: array[4, int8] = [int8(0x73), 0x6b, 0x68, 0x2B] |
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
var F = open(app_filename, fm_read) | |
F.set_file_pos(FILE_SIZE - DATA_SIZE) | |
var BUF = new_string(payload_len) | |
let read_len = F.read_buffer(addr(BUF), payload_len) | |
echo "Did read " & $read_len | |
F.close() # <-- crashes with sigsev nil access? |
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 | |
TNode = object | |
id: int | |
child_l: PNode | |
child_r: PNode | |
PNode = ref TNode | |
var | |
counter = 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 os | |
var count = 0 | |
let path = "C:" / "*" / "*.exe" | |
echo "Looking for '", $path, "'" | |
for file in path.walkFiles: | |
echo "Found ", file | |
count += 1 | |
echo "Found ", $count, " files" |
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 cmpSeq*[T](x, y: seq[T]): int = | |
# Compare only the minimum amount of elements necessary | |
let maxIterations = min(len(x), len(y)) | |
for i in 0..maxIterations-1: | |
result = cmp(x[i], y[i]) | |
if result != 0: | |
return | |
# Well, if we exhausted the comparison, resort to system.cmp implementation. | |
result = cmp(len(x), len(y)) |
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
echo "Tuples" | |
proc cmp(x, y: tuple): int = | |
return -1 | |
type tup = tuple[name: string, age: int] | |
var | |
tits: seq[tup] = @[(name: "AA", age: 30), | |
(name: "AA", age: 40), | |
(name: "A2", age: 30), |
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, strutils | |
macro declare(s: string): stmt = | |
# First split all the input into separate lines. | |
var | |
rawLines = split(s.strVal, {char(0x0A), char(0x0D)}) | |
buf = "" | |
for rawLine in rawLines: | |
# Split the input line into three columns, stripped, and parse. |
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 BitPuffin = "BitPuffin" | |
proc WAAAAAIT(a: string) = | |
echo "WAAAAAIT for ", a | |
while true: WAAAAAIT(BitPuffin) | |
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 | |
for f in `babel list|grep -E "^\w+[^:]"`; do | |
N="${f%:}" | |
#echo "Testing $N" | |
babel install -y "${N}" 2>&1 > /dev/null | |
if [[ $? != 0 ]]; then | |
echo "Failed building ${N}" | |
#exit 1 | |
fi |
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
# horrible example of how to interface with GNUStep ... | |
import macros, strutils | |
{.passL: "-lobjc".} | |
{.passL: "-framework AppKit".} | |
{.emit: """ | |
#include <Foundation/NSObject.h> | |
@interface Greeter: NSObject |