Skip to content

Instantly share code, notes, and snippets.

@iffy
iffy / proposal.md
Created Mar 30, 2021
Idea for making Nim's `staticExec`/`staticRead` auditable
View proposal.md

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
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
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 =
toHex(x).toLower()
proc charRepr(x:byte):char =
case x
of 32..126: result = chr(x)
else: result = '.'
@iffy
iffy / results.txt
Created Nov 5, 2018
Small, probably non-representative benchmark of JSON Changelog with SQLite https://blog.budgetwithbuckets.com/2018/08/27/sqlite-changelog.html
View results.txt
python testsqlite.py 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 testsqlite.py 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
View aoutput.md

v1

$ 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
iffy / .gitignore
Last active Sep 21, 2018
Comparing line-reading in Python/Nim/Node
View .gitignore
hugefile.txt
myreader
builtinreader
hugebin.txt
hugestr.txt
@iffy
iffy / compile.sh
Created Jun 15, 2017
Is "Account" a reserved name?
View compile.sh
set -x
tsc okay.ts
tsc fails.ts
@iffy
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"
}
}
@iffy
iffy / .gitignore
Last active Apr 15, 2021
Example using electron-updater with `generic` provider.
View .gitignore
node_modules
dist/
yarn.lock
wwwroot