Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
@Varriount
Varriount / winPragma.nim
Created January 19, 2014 04:30
A nimrod pragma macro which generates helper procs
import macros
from winlean import useWinUnicode
when useWinUnicode:
type winString = WideCString
let apiPrefix = "W"
else:
type winString = CString
let apiPrefix = "A"
macro WinImport*(baseProc: stmt): stmt {.immediate.} =
@Varriount
Varriount / splitText.nim
Created January 19, 2014 04:39
A split procedure that accepts strings
import strutils
iterator split*(s, sep: string): string =
var remainder = s # What string contents is left
var pos = find(remainder, sep)
while pos != -1:
let
start = pos-1
middle = pos+sep.len
ending = remainder.len-1
@Varriount
Varriount / testdiff.txt
Created January 19, 2014 18:12
Test differences (Keep in mind that I might have made some mistakes or left out some things accidentally)
Succeeded on x86-64 (64 bit), failed on x86 (32 bit)
t99bott.nim
tbind2.nim
teffects1.nim
tenummix.nim
tnot.nim
twrongconst.nim
twrongiter.nim
tbindtypedesc.nim
tthreadgeneric
# This
proc findFirstFileW*(lpFileName: WinString,
lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", winApi.}
# Becomes this when using the Unicode Windows API
proc findFirstFile*(lpFileName: WinString, lpFindFileData: var TWIN32_FIND_DATA): THandle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileW".}
@Varriount
Varriount / crash.txt
Created January 20, 2014 02:23
Generic Case Crash
C:\64\Nimrod>nimrod c test.nim
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\windows-1.0' [Path]
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\babel-0.1.0' [Path]
config\nimrod.cfg(37, 2) Hint: added path: 'C:\Users\Clay\.babel\pkgs\' [Path]
Hint: used config file 'C:\64\nimrod\config\nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: tables [Processing]
Hint: hashes [Processing]
Hint: strutils [Processing]
# Implementation
iterator split*(s, sub: string): string =
## Replaces `sub` in `s` by the string `by`.
var a {.noinit.}: TSkipTable
preprocessSub(sub, a)
var i, j = 0
let z = s.len()
while true:
j = findAux(s, sub, i, a)
if j < 0: break
import strutils
type charContainer = generic c
c.contains(char) is bool
iterator split*(s: string, seps: charContainer = Whitespace): string =
## Splits the string `s` into substrings using a group of separators.
##
## Substrings are separated by a substring containing only `seps`. Note
## that whole sequences of characters found in ``seps`` will be counted as
import strutils
when isMainModule:
doAssert split("Hello<world<!!", '<') == @["Hello", "world", "!!"]
doAssert split("Hello<world<", '<') == @["Hello", "world", ""]
doAssert split("<Hello<world<", '<') == @["", "Hello", "world", ""]
doAssert split("Hello<world<!!", {'<'}) == @["Hello", "world", "!!"]
doAssert split("Hello<world<", {'<'}) == @["Hello", "world"]
doAssert split("<Hello<world<", {'<'}) == @["Hello", "world"]
proc setControlCHook(hook: proc () {.noconv.}) =
# ugly cast, but should work on all architectures:
type TSignalHandler = proc (sig: cint) {.noconv.}
c_signal(SIGINT, cast[TSignalHandler](hook))
type
TTest = tuple[x: range[0..80], y: range[0..25]]
let x: TTest = (2, 23)
echo(x)