Skip to content

Instantly share code, notes, and snippets.

iffy / nbody.nim
Created Oct 26, 2022
I wanted to see how Nim compared (readability and speedwise) with what's reported here:
View nbody.nim
## Compile for speed with `nim c -d:danger nbody.nim`
## Run `./nbody 10000000`
import std/os
import std/sequtils
import std/strformat
import std/strutils
import std/tables
from std/math import pow
iffy /
Created Mar 30, 2021
Idea for making Nim's `staticExec`/`staticRead` auditable

I agree that it's impossible for Nim to protect you if you're willing to compile other people's code.

However, it could be good if Nim provided a means for auditing calls to staticExec/staticRead. Or at least provided means for someone else to write an auditing library. I imagine something like the following could work and not be onerous either to the user or the compiler:

  1. nim c --strictStatic myfile.nim

This would fail on all instances of staticExec with a message like:

ERROR: Prevented execution of myfile.nim:staticExec("/bin/echo foo") Pass --allowStatic:'myfile.nim:staticExec("/bin/echo foo")' to allow it

iffy / equalproc.nim
Last active May 7, 2019
How to make proc `==`(a,b: Thing):bool for a variant object.
View equalproc.nim
import sequtils
import strutils
import macros
import sugar
export macros
proc replaceNodes*(ast: NimNode): NimNode =
## Replace NimIdent and NimSym by a fresh ident node
## Use with the results of ``quote do: ...`` to get
iffy / dumpMem.nim
Last active Feb 13, 2019
Print out memory in Nim
View dumpMem.nim
import strutils
import terminal
template lowerHex(x:untyped):untyped =
proc charRepr(x:byte):char =
case x
of 32..126: result = chr(x)
else: result = '.'
iffy / results.txt
Created Nov 5, 2018
Small, probably non-representative benchmark of JSON Changelog with SQLite
View results.txt
python 10000 :memory: 0
6.65568494797 seconds to do 10000 records db=:memory:, triggers=False
6.66251087189 seconds to do 10000 records db=:memory:, triggers=False
6.69321203232 seconds to do 10000 records db=:memory:, triggers=False
python 10000 :memory: 1
6.76699709892 seconds to do 10000 records db=:memory:, triggers=True
6.82708096504 seconds to do 10000 records db=:memory:, triggers=True
6.82913088799 seconds to do 10000 records db=:memory:, triggers=True


$ nim objc -r v1_manual.nim 
Hint: used config file '/Users/matt/lib/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: v1_manual [Processing]
CC: v1_manual
CC: stdlib_system
Error: execution of an external compiler program 'clang -c -w -I/Users/matt/lib/Nim/lib -o /Users/matt/.cache/nim/v1_manual_d/v1_manual.m.o /Users/matt/.cache/nim/v1_manual_d/v1_manual.m' failed with exit code: 1
View change.diff
--- /tmp/orig.nim 2018-10-24 09:01:22.000000000 -0600
+++ /tmp/frommanual.nim 2018-10-24 09:00:51.000000000 -0600
@@ -1,7 +1,6 @@
-{.passL: "-lobjc".}
{.emit: """
-#include <objc/Object.h>
-@interface Greeter:Object
+#include <Cocoa/Cocoa.h>
+@interface Greeter:NSObject
iffy / .gitignore
Last active Sep 21, 2018
Comparing line-reading in Python/Nim/Node
View .gitignore
iffy /
Created Jun 15, 2017
Is "Account" a reserved name?
set -x
tsc okay.ts
tsc fails.ts
iffy / package.json
Created Jun 12, 2017
Cannot find module '../package' from 'node-pre-gyp.js'
View package.json
"dependencies": {
"jest": "20.0.4",
"sqlite3": "3.1.8"