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
######..#######..#####.....####..#########......#####.....####.. | |
#.......#######..#####.....####..#########......###..........#.. | |
...........####..#######..#####.................##...........#.. | |
...........#..#...#....#......#.................##...######..#.. | |
..................#....#......#......#..######.......#.......### | |
...#####..........#....#......#..#......#....#.......#.......#.. | |
...#...#...#..##.......#................#....#..##...######..#.. | |
####......######.......#...###..........#.......###..........#.. | |
#.........######..#....##..#####.....####.......###..........#.. | |
#........#######..#######..#####.....####....#..####......#####. |
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
#define STB_HERRINGBONE_WANG_TILE_IMPLEMENTATION | |
#include "stb_herringbone_wang_tile.h" |
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 random, times, deques | |
type | |
DungeonKind {.pure.} = enum | |
Caves | |
CellKind {.pure.} = enum | |
Empty, Floor, Wall, Count | |
Cell = object |
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 season(month: range[1..12]): string = | |
case month | |
of 1, 2, 12: return "winter" | |
of 4, 5, 6: return "spring" | |
of 7, 8, 9: return "summer" | |
of 10, 11: return "autumn" | |
echo season(5) # in.nim(2, 3) Error: not all cases are covered |
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 season(month: range[1..12]): string = | |
case month | |
of 1, 2, 12: return "winter" | |
of 4, 5, 6: return "spring" | |
of 7, 8, 9: return "summer" | |
of 10, 11: return "autumn" | |
echo season(5) |
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 `[]`*[Idx, T](a: openarray[T], x: Slice[Idx]): seq[T] = | |
# https://github.com/nim-lang/Nim/tree/master/lib/system.nim#L3381 | |
var L = ord(x.b) - ord(x.a) + 1 | |
newSeq(result, L) | |
for i in 0.. <L: | |
result[i] = a[Idx(ord(x.a) + i)] |
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 options | |
import typetraits | |
template hasValue[T](o: Option[T]): bool = | |
proc default(): T = discard | |
let isSome = o.isSome() | |
(let `o` {.inject.} = (if isSome: o.get() else: default()); isSome) | |
let x = some(123) |
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
var the_sum = 0 | |
echo(the-sum) |
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 rst | |
echo repr parseRST("Hello World!") |
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 macros | |
proc getProcDef(fromProc: NimNode): NimNode = | |
let procDef = copyNimTree(fromProc) | |
# Strip proc of its "body", not sure if there is a better way to do this | |
var indexOfBody = 0 | |
for item in fromProc: | |
if item.kind() == nnkStmtList: break | |
indexOfBody += 1 |