Skip to content

Instantly share code, notes, and snippets.

from tables import TTable, initTable
proc f(n: int): TTable[int, seq[int]] =
result = initTable[int, seq[int]]()
var t = f(10)
@def-
def- / helloflops.c
Created December 20, 2014 21:06
Helloflops on Xeon Phi
/* Generated by Nim Compiler v0.10.1 */
/* (c) 2014 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, amd64, gcc */
/* Command for C compiler:
icc -c -w -vec-report=5 -O3 -mmic -fopenmp -O3 -fno-strict-aliasing -I/amd.home/home/felsing/nim/lib -o /amd.home/home/felsing/test/nimcache/helloflops.o /amd.home/home/felsing/test/nimcache/helloflops.c */
#define NIM_INTBITS 64
#include "nimbase.h"
#include <stdio.h>
@def-
def- / asynchttpserver_hello.nim
Last active August 29, 2015 14:12
Jester Performance
import asynchttpserver, asyncdispatch
var server = newAsyncHttpServer()
proc cb(req: Request) {.async.} =
await req.respond(Http200, "{ \"message\": \"Hello, World!\"}")
asyncCheck server.serve(Port(8000), cb)
runForever()
@def-
def- / min.nim
Created December 31, 2014 16:52
Iterators with shallowCopy
type TaskFn = iterator (): float
iterator a1(): float {.closure.} =
var k = 10
while k > 0:
echo "a1 ", k
dec k
yield 1.0
@def-
def- / lc.nim
Created January 1, 2015 23:45
list comprehensions with consts
let foo = (proc: seq[int] =
result = @[]
for a in 1..10:
for v in 1..10:
result.add(a+v)
)()
echo foo
@def-
def- / objectinheritance.nim
Created January 2, 2015 16:01
Object Inheritance
type # Fine with ref object
T = object of RootObj
myValue: string
S1 = object of T
S2 = object of T
method speak(x: T) = echo "T Hello ", x.myValue
method speak(x: S1) = echo "S1 Meow ", x.myValue
method speak(x: S2) = echo "S2 Woof ", x.myValue
cmake .
CMake Error at src/SFML/CMakeLists.txt:27 (find_package):
By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.
Could not find a package configuration file provided by "SFML" (requested
version 2.0) with any of the following names:
SFMLConfig.cmake
@def-
def- / gist:d86c40de803819d7d535
Created January 6, 2015 02:39
NAN in C compilers
#include<math.h>
#include<stdio.h>
// clang: HERE2
// gcc: HERE2
// tcc: NO OUTPUT
int main()
{
if (0.0 <= NAN)
puts("HERE1");
if (!(0.0 <= NAN))
@def-
def- / raytracer.nim
Last active August 29, 2015 14:13
Raytracer
import math
import sequtils
import sdl
const
width = 1280
height = 720
fov = 45.0
max_depth = 6
@def-
def- / crc32.nim
Last active August 29, 2015 14:13
map download updater script
import unsigned, strutils
type TCrc32* = uint32
const InitCrc32* = TCrc32(-1)
proc createCrcTable(): array[0..255, TCrc32] =
for i in 0..255:
var rem = TCrc32(i)
for j in 0..7:
if (rem and 1) > 0: rem = (rem shr 1) xor TCrc32(0xedb88320)