Skip to content

Instantly share code, notes, and snippets.

@demotomohiro
demotomohiro / raytracingcamp7 AWS
Created September 4, 2019 04:25
レイトレ合宿7のAWSでインスタンス立ち上げ時に実行するスクリプト
c5n.18xlarge Windows Server
<powershell>
(New-Object System.Net.WebClient).DownloadFile("https://aka.ms/vs/16/release/vc_redist.x64.exe", "$home/vc_redist.x64.exe")
& "$home/vc_redist.x64.exe" /install /quiet
iwr -useb get.scoop.sh | iex
scoop install python git
git clone https://github.com/demotomohiro/rcauto.git $home/rcauto
mkdir $home/rctest
</powershell>
@demotomohiro
demotomohiro / testroot.nim
Created October 1, 2019 13:03
Test PathIsSameRootW and PathIsSameRootA Windows API in Nim language.
import winlean, macros
when useWinUnicode:
proc PathIsSameRootW(pszPath1: WideCString,
pszPath2: WideCString): WINBOOL {.
stdcall, dynlib: "Shlwapi", importc: "PathIsSameRootW".}
else:
proc PathIsSameRootA(pszPath1: cstring,
pszPath2: cstring): WINBOOL {.
stdcall, dynlib: "Shlwapi", importc: "PathIsSameRootA".}
@demotomohiro
demotomohiro / objectDef.nim
Created November 20, 2019 05:40
Macro that automatically generate object type definition from constructor.
import macros, strutils
# Some string that no one use for variable name.
# It was generated with following command:
# openssl rand -base64 16
const fieldMarker = "Ew55GZ4wPFop9pbAYp9RQ"
macro fields*(stmts: untyped): untyped =
stmts.expectKind nnkStmtList
result = newTree(
@demotomohiro
demotomohiro / objectDef.nim
Last active December 23, 2019 18:10
Macro that automatically generate object type definition from constructor.
import macros
macro tupleCtorToObjectDef(name: static[string];
isExported: static[bool];
isRef: static[bool];
procDef: typed{nkProcDef}): untyped =
func getObjType(name: string; isExported: bool; isRef: bool; node: NimNode): NimNode =
if node.kind == nnkAsgn and node[0].strVal == "result":
node[1].expectKind nnkTupleConstr
var recList = newNimNode(nnkRecList)
@demotomohiro
demotomohiro / Hotcodereloading_with_glfw_ sample.md
Created February 4, 2020 16:17
Nim's hot code reloading with GLFW sample

Tested this sample with Nim 1.0.6 on Windows 8.1

  1. Install Nim Game Library
nimble install nimgl
  1. Get glfw3.dll Go to GLFW web site, go to Download page and download Windows pre-compiled binaries. Unzip it and copy glfw3.dll to where you run sample program.
Install [Meson and ninja](https://mesonbuild.com/Getting-meson.html).
Build cairo
Disable some options to avoid compile/link errors
```
git clone --depth 1 https://gitlab.freedesktop.org/cairo/cairo.git
meson --prefix=c:\path\to\install --buildtype release -D tests=disabled -D gl-backend=disabled cairo_builddir cairo
meson compile -C cairo_builddir
meson install -C cairo_builddir
```
@demotomohiro
demotomohiro / printoffsets.c
Created October 8, 2020 05:23
Print offsets of object field in Nim
#include <stdio.h>
#include <stddef.h>
#define PRINTOFFSET(typ, field) printf("%s(%ld): %ld\n", #field, sizeof(((typ*)0)->field), offsetof(typ, field))
typedef struct {
char a;
int b;
short c;
double d;
@demotomohiro
demotomohiro / gintro_test.ipynb
Created October 9, 2020 22:12
Test gintro in google colab
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@demotomohiro
demotomohiro / libnice_simple_example.nim
Last active October 31, 2020 13:38
Nim version of libnice example code
# Nim version of example code of libnice:
# https://libnice.freedesktop.org
#
# Refer libnice/examples/simple-example.c
# Push enter key at same time as possible when you enter remote data.
#
# Public STUN server list:
# https://gist.github.com/mondain/b0ec1cf5f60ae726202e
import gintro/[nice, gio, glib, gobject]
@demotomohiro
demotomohiro / build_libnice.nims
Created October 10, 2020 01:24
Build & Install libnice 0.1.17 on gentoo linux
import os
proc execQuote(args: varargs[string]) =
args.quoteShellCommand.exec
proc download(url, dist: string) =
mkDir dist.parentDir
execQuote "wget", url, "-O", dist
proc untar(src, dist: string) =