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 | |
Serial = object | |
prefix: array[0..2, range['A'..'Z']] | |
digits: array[0..4, range[0..9]] | |
var x = Serial(prefix: [range['A'..'Z']('A'), 'B', 'X'], digits: [range[0..9](1), 1, 1, 2, 3]) | |
echo x |
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 <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
char len; | |
char cap; | |
char data[]; | |
} MySeq; | |
void dump (MySeq *seq) { |
We can make this file beautiful and searchable if this error is corrected: It looks like row 3 should actually have 1 column, instead of 2. in line 2.
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
206 deu Theoretisch mache ich gerade Mathe. kroko \N 2010-10-14 14:36:23 | |
207 deu Was passierte? kroko \N 2016-06-17 22:16:22 | |
208 deu Wenn du mich nicht so gekannt hast, dann hast du mich einfach gar nicht gekannt. sugisaki 2008-05-14 18:36:22 2010-06-26 18:57:16 | |
209 deu Es hat mir fast Angst gemacht, dich einen ganzen Tag nicht online zu sehen. kroko \N 2010-10-14 14:37:47 | |
210 deu Ich weiß nicht, was du meinst. kroko \N 2011-04-26 18:39:53 |
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 parsecsv | |
import os | |
var p: CsvParser | |
p.open("file.csv", separator='\t') | |
while p.readRow(): | |
echo "new row: " | |
for val in items(p.row): | |
echo "##", val | |
p.close() |
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, npeg | |
proc linecount(str: string): int = | |
var count: int | |
let parser = peg "lines": | |
lines <- *line * !1 | trailing | |
trailing <- 1: | |
inc count | |
line <- *(1 - '\n') * '\n': | |
inc count |
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 sequtils | |
import strutils | |
import macros | |
import sugar | |
export macros | |
proc replaceNodes*(ast: NimNode): NimNode = | |
## Replace NimIdent and NimSym by a fresh ident node | |
## | |
## Use with the results of ``quote do: ...`` to get |
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 abc: int = | |
defer: | |
echo "abc cleanup" | |
yield 1 | |
yield 2 | |
yield 3 | |
for x in abc(): | |
echo x | |
if x == 2: |
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 addinto[T](x, y: openArray[T], z: var openArray[T]) = | |
var j = z.low | |
for i in x.low .. x.high: | |
z[j] = x[i] | |
inc j | |
for i in y.low .. y.high: | |
z[j] = y[i] | |
inc j | |
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 getline(lineptr: ptr cstring, n: ptr cint, stream: File): cint {.importc, header: "<stdio.h>".} | |
proc free(s: cstring) {.importc: "free", header: "<stdlib.h>".} | |
iterator getlines(filename: string): string = | |
var | |
getline_line: cstring | |
getline_len: cint | |
ret: int | |
file = open(filename, bufSize=4096 * 2) | |
defer: | |
close(file) |
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 `$`*(act: Action): string = | |
template `-->`(str: typed, field: untyped): untyped = | |
str & ':' & maybeQuote($field) | |
macro `---`(s: untyped): untyped = | |
s.expectKind nnkIdent | |
infix(newLit(s.repr), "-->", newDotExpr(ident("act"), ident(s.repr))) | |
case act.kind | |
of Accuracy: "accuracy" --> act.acc | |
of Maturity: --- maturity |