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:4533999
Created January 14, 2013 22:12
Python test case for parsing a big json
#!/usr/bin/env python
import json
import time
print "Loading and parsing json"
t1 = time.time()
j = json.load(open("nimrod_performance.json", "rt"))
print j["pak_filename"]
t2 = time.time()
@gradha
gradha / nimparse.nim
Created January 14, 2013 22:13
Nimrod test case for parsing a big json
import json, times, strutils
when isMainModule:
echo "Loading and parsing json"
let t1 = epochTime()
let j = parseFile("nimrod_performance.json")
assert (j.kind == JObject)
let t2 = epochTime()
echo "Took ", formatFloat(t2 - t1, ffDecimal, 2)
@gradha
gradha / nimepakoo.nim
Created January 20, 2013 21:39
The docstring for open_chunk contains a single ` which causes "nimepakoo.nim(153, 2) Error: '`' expected", but line 153 is in the getc proc, much later.
## Convenience wrapper around raw `nimepak <nimepak.html>`_ module.
##
## The usual operation with these procs is to create a Tepak var and call
## init() on it to use it. You can call is_valid() at any time on a Tepak to
## check its validity.
import nimepak
export nimepak.F_BUF_SIZE
export nimepak.F_PACK_MAGIC
@gradha
gradha / docstrings.nim
Created January 21, 2013 11:31
(25, 18) Error: '*' expected Error: unhandled exception: (25, 18) Error: '*' expected [ERecoverableError]
proc doc1*(text: string) =
## Blah blah blah the blah
##
## Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
## blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
## blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
## blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
## blah blah blah blah blah blah blah blah blah blah blah blah
##
## Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
@gradha
gradha / except.nim
Created January 21, 2013 23:03
What echos do you get?
proc test1() =
raise newException(E_base, "Hey ho")
proc tester() =
except: echo "2. except block"
finally: echo "3. Finally block"
echo "1. Pre exception"
test1()
echo "NaN. Post exception"
@gradha
gradha / weird.nim
Created February 2, 2013 20:02
weird.nim(12, 9) Error: undeclared field: 'PK_INT'
type
TNodeKind = enum PK_EMPTY, PK_INT, PK_STRING
TNode = object
case kind: TNodeKind
of PK_EMPTY: nil
of PK_INT: int_val: int
of PK_STRING: str_val: string
template new_node(kind: TNodeKind, expr): TNode {.immediate.} =
@gradha
gradha / idetools.nim
Created February 3, 2013 17:07
Unexpected nimrod idetools behaviour on $data.str_val
type
Tparam_kind* = enum PK_EMPTY, PK_STRING
Tparsed_parameter* = object
case kind*: Tparam_kind
of PK_EMPTY: nil
of PK_STRING: str_val*: string
proc `$`*(data: Tparsed_parameter): string {.procvar.} =
case data.kind:
proc parse*(expected: seq[string] = @[],
bad_prefixes = @["-", "--"], end_of_parameters = "--",
quit_on_failure = true) =
nil
template tp(expected: seq[string] = @[],
bad_prefixes, end_of_parameters): expr =
parse(expected,
quit_on_failure = false, bad_prefixes = bad_prefixes,
type
TKind1 = enum TK1A, TK1B
TKind2 = enum TK2A, TK2B
TKind3 = enum TK3A, TK3B
TK2 = object
case kind: TKind2
of TK2A: tk2_int: int
of TK2B: tk2_string: string
#import "test.h"
#import "RestKit/RestKit.h"
@interface Root : NSObject
@property (nonatomic, strong) NSArray *users;
@property (nonatomic, strong) NSString *text;
@end
@implementation Root
- (NSString*)description {