Skip to content

Instantly share code, notes, and snippets.

@mratsim
mratsim / call_cuda.nim
Last active September 16, 2017 09:26
Calling CUDA kernels from Nim
import nimcuda/[cuda_runtime_api, driver_types, nimcuda]
import sequtils, future
type GpuArray[T: SomeReal] = object
data: ref[ptr T]
len: int
{.compile: "./square.cu".}
proc cuda_square(bpg, tpb: cint, y: ptr cfloat, x: ptr cfloat) {.importc, header:"../square.cuh".}
#../square.cuh is a workaround because header is not copied to nimcache
import macros, times, strutils, tables
type
Data* = object
value*: int
fvalue*: float
tvalue*: Time
Container* = object
desc*: string

Basic idea: A Nim DSL that describes the game model declaratively

There is a raw list/sequence of the data for fast iteration over all elements. The implementation should be either based on an ordinary contiguous sequence or something like: http://plflib.org/colony.htm which is essentially a linked list of growing arrays so that no reallocations are required.

In addition to the contiguous storage there can be multiple indexes into the data. The indexes can be hash based or based on a BTree depending on whether ranges queries need to be supported. There is always a primary key of type integer that can be used to index the contiguous array.

An example:

@mikroskeem
mikroskeem / get_shell.c
Last active August 30, 2018 16:03
A script to get Arch Linux ARM rootfs running in proot on Android (Termux)
/*
* clang -static -O2 get_shell.c get_shell
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
int main(int argc, char *argv[]) {
const
intrin = "<x86intrin.h>"
{.localPassC: "-msse4.2".}
type
M128i {.importc: "__m128i", header: intrin, bycopy.} = object
const
SIDD_CMP_RANGES = 0b0000_0100'i32
SIDD_NEGATIVE_POLARITY = 0b0001_0000'i32
@genotrance
genotrance / sciter.nim
Last active July 13, 2020 03:38
Nim wrapper for sciter using nimterop
import nimterop/[cimport]
cIncludeDir(@[
"/usr/include/gtk-3.0",
"/usr/include/glib-2.0",
"/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"/usr/include/pango-1.0",
"/usr/include/cairo",
"/usr/include/gdk-pixbuf-2.0",
"/usr/include/atk-1.0"

First suggestion:

src/
  <pkgname>.nim
tests/
docs/
<pkgname>.nimble # with srcDir = "src"

library with single module

@obscurerichard
obscurerichard / pull-request-poetry.md
Last active March 26, 2021 15:19
pull-request-poetry.md

Pull request poetry

by Richard Bullington-McGuire richard@obscure.org @obscurerichard on GitHub and Twitter

Use these as comments in pull requests in order to charm the project owner into taking action on the pull request.

Initial ticklers

lonely pull request
the completist in me pines
for its prompt closure
@fujin
fujin / gettimeofday.cpp
Created April 1, 2015 01:41
LD_PRELOAD gettimeofday linux speedhack
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <dlfcn.h>
#include <stdio.h>
static timeval * timezero = 0;
typedef int (*go)(timeval *tv, timezone *tz);
@fstab
fstab / MATRIX.md
Last active January 5, 2022 12:31
How to use matrix.org and vector.im as an IRC client

How to use matrix.org and vector.im as an IRC client

How to Join an IRC Channel on matrix.org

Join the room #freenode_<#channel>:matrix.org, replacing <#channel> with the name of the IRC channel. For example, in order to join the #prometheus IRC channel, join the room #freenode_#prometheus:matrix.org on matrix.org.

In vector.im, rooms can be joined with the directory symbol on the bottom left.