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 db_sqlite | |
var db = Open(connection="foo.db", user="rumpf", password="fpmur", database="mydb") | |
proc getFromWhere*(id, row, table: string): TRow = | |
result = db.getRow(sql"select 1 from ? where ? = ?", table, row, id) | |
template getFrom*(id, table: string): expr = | |
getFromWhere(id, "id", table) | |
# foo! this line causes error |
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 genRandomSalt(len: int): string = | |
randomize() | |
result = "" | |
for i in 0..<len: | |
result = char(random()) |
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
sql""" | |
select exists (select 1 from groups where | |
user_id = (select users.id from users where username=?) and | |
group_id = (select group.id from groups where name='admin'))""", id)[0] == "t" |
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 rotate(axis: TVector, angle: float): TMat4 = | |
let cosine = cos(angle).float32 | |
let sine = sin(angle).float32 | |
let oneminuscos = 1 - cosine | |
let xsquared = axis[0].pow(2.0) | |
let ysquared = axis[1].pow(2.0) | |
let zsquared = axis[2].pow(2.0) | |
result = [[cosine + oneminuscos*xsquared, oneminuscos*axis[0]*axis[1] - axis[2]*sine, oneminuscos*axis[0]*axis[2] + axis[1]*sine, 0], | |
[oneminuscos*axis[0]*axis[1] + axis[2]*sine, cosine + oneminuscos*ysquared, oneminuscos*axis[1]*axis[2] - axis[0]*sine, 0], | |
[oneminuscos*axis[0]*axis[2] - axis[1]*sine, oneminuscos*axis[1]*axis[2] + axis[0]*sine, cosine + oneminuscos*zsquared, 0], |
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 rotate(axis: TVector, angle: float): TMat4 = | |
result = [[cos(angle) + (1 - cos(angle))*axis[0].pow(2.0), (1 - cos(angle))*axis[0]*axis[1] - axis[2]*sin(angle), (1 - cos(angle))*axis[0]*axis[2] + axis[1]*sin(angle), 0], | |
[(1 - cos(angle))*axis[0]*axis[1] + axis[2]*sin(angle), cos(angle) + (1 - cos(angle))*axis[1].pow(2.0), (1 - cos(angle))*axis[1]*axis[2] - axis[0]*sin(angle), 0], | |
[(1 - cos(angle))*axis[0]*axis[2] - axis[1]*sin(angle), (1 - cos(angle))*axis[1]*axis[2] + axis[0]*sin(angle), cos(angle) + (1 - cos(angle))*axis[2].pow(2.0), 0], | |
[0f32, 0f32, 0f32, 1f32]] |
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 identity[T; N](): TMatrix[T, N, N] {.noSideEffect.} = | |
## Returns the identity matrix given the specified params | |
## This proc is unnecessarily inefficient for now because of | |
## the compiler | |
for i in N.low..N.high(): | |
for j in N.low..N.high(): | |
if i == j: | |
result[i][j] = 1.T | |
else: | |
result[i][j] = 0.T |
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
template identity(m: typedesc[TMatrix]): expr = | |
when m.R != m.C: | |
{.fatal: "Identity is only defined for square matrices".} | |
result = identity[m.T, m.R]() | |
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
echo(identity[float32, range[0..2]]()) | |
[1.0000000000000000e+00, 4.5671119549274438e-41, -7.7153667807579041e-03] | |
[4.5671119549274438e-41, 1.0000000000000000e+00, 4.5916346780531281e-41] | |
[-7.4024423956871033e-03, 4.5671119549274438e-41, 1.0000000000000000e+00] |
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 identity[T; N](): TMatrix[T, N, N] {.noSideEffect.} = | |
for i in N.low..N.high(): | |
result[i][i] = 1 | |
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
nimrod c graphics/terrain.nim | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/nim-glfw-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/linagl-0.1.1' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/nim-ao-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/nim-portaudio-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/nim-vorbis-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/opengl-1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/jester-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/nim-ogg-0.1.0' [Path] | |
config/nimrod.cfg(36, 2) Hint: added path: '/home/isak/.babel/pkgs/fowltek-0.9.3' [Path] |