This file contains hidden or 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 math | |
| func genCache(): array[10, int32] = | |
| for i in 1 .. 9: | |
| result[i] = int32(i ^ i) | |
| const | |
| MAX = 440_000_000.int32 | |
| cache = genCache() |
This file contains hidden or 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 fidget, flippy, chroma | |
| var f = newImage(400, 400, 4) | |
| for x in 0 ..< 400: | |
| for y in 0 ..< 400: | |
| f.putRgba(x, y, hsl(x.float/400*360, y.float/400*100, 75).color.rgba) | |
| f.save("data/generated.png") | |
| setTitle("Image viewer") | |
| proc drawMain() = |
This file contains hidden or 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 str = newString(1001*3 + 1001*801*3 + 1001*801*501*3) | |
| var i = 0 | |
| for foo in 0..100: | |
| str[i] = 'f' | |
| inc i | |
| str[i] = 'o' | |
| inc i | |
| str[i] = 'o' |
This file contains hidden or 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 chroma | |
| template fill(s: string) = | |
| echo "parsed", s | |
| let color = parseHtmlColor(s) | |
| echo color | |
| template fill(s: static string) = | |
| const color = parseHtmlColor(s) | |
| echo color |
This file contains hidden or 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
| ## Radix sort in O(n) unlike other sorting methods that can be way worse. | |
| ## But radix sort needs the bits to operate on, which makes it different then | |
| ## other sorting algorithms. | |
| proc getMax(arr: seq[SomeInteger]): SomeInteger = | |
| for i, e in arr: | |
| if i == 0: | |
| result = e | |
| elif e > result: | |
| result = e |
This file contains hidden or 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 sdl2 | |
| import math | |
| # ------ SDL2 CONF ------ | |
| discard sdl2.init(INIT_EVERYTHING) | |
| var | |
| window : WindowPtr | |
| render : RendererPtr |
This file contains hidden or 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 | |
| OpType = enum Inc, Move, Loop, Print | |
| Ops = seq[Op] | |
| Op = object | |
| case op: OpType | |
| of Inc, Move: val: int | |
| of Loop: loop: Ops | |
| else: discard | |
| StringIterator = iterator(): char |
This file contains hidden or 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 FooThread = ref object | |
| thread: Thread[void] | |
| var fooThreads: seq[FooThread] | |
| for i in 0 ..< 5: | |
| var t = FooThread() | |
| createThread(t.thread, threadFunc) | |
| fooThreads.add t | |
| for t in fooThreads: | |
| joinThread(t.thread) |
This file contains hidden or 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
| # createThread then .add -> crash | |
| # .add then createThread -> some threads dont run | |
| # pre .add all threads -> works 100% | |
| import locks | |
| var | |
| thr: seq[Thread[void]] | |
| L: Lock |
This file contains hidden or 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
| spawn: | |
| var socket = newSocket() | |
| print "1" | |
| socket.connectFi("localhost", Port(12321)) | |
| print "2" | |
| socket.sendFi("spawn #1\c\L") | |
| print "4" | |
| echo socket.recvFi() | |
| socket.close() | |
| print "5" |