Skip to content

Instantly share code, notes, and snippets.

View gradha's full-sized avatar

Grzegorz Adam Hankiewicz gradha

View GitHub Profile
@gradha
gradha / gist:6189439
Created August 8, 2013 22:33
Equality comparison for arrays in nimrod
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]
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?
type
TNode = object
id: int
child_l: PNode
child_r: PNode
PNode = ref TNode
var
counter = 0
@gradha
gradha / gist:7399445
Created November 10, 2013 15:23
Test to see if findifle on windows works with * in directory parts of the path
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"
@gradha
gradha / gist:7401114
Last active December 27, 2015 22:48
Nimrod cmp proc for sequences
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))
@gradha
gradha / gist:7402320
Created November 10, 2013 19:03
Attempt to sort seqs of tuples
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),
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.
@gradha
gradha / bit.nim
Created December 4, 2013 21:32
Infinite bitpuffins
const BitPuffin = "BitPuffin"
proc WAAAAAIT(a: string) =
echo "WAAAAAIT for ", a
while true: WAAAAAIT(BitPuffin)
@gradha
gradha / babel_tester.sh
Created December 4, 2013 22:39
Bash script to test compilation of babel packages
#!/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
@gradha
gradha / betterobjc.nim
Created December 10, 2013 00:18
Better objc nimrod integration
# horrible example of how to interface with GNUStep ...
import macros, strutils
{.passL: "-lobjc".}
{.passL: "-framework AppKit".}
{.emit: """
#include <Foundation/NSObject.h>
@interface Greeter: NSObject