Skip to content

Instantly share code, notes, and snippets.

@Vindaar
Vindaar / ggplotnim_on_windows.org
Last active February 15, 2021 09:54
Notes on getting =ggplotnim= to work on Windows

Getting ggplotnim to work on Windows

I’ll note down my steps to get ggplotnim to work on Windows starting from a default Windows 10 installation without any development tools.

For me the first steps to get set up my development environment is to:

  1. install git
  2. install emacs and clone my settings
  3. and then set up additional tools, in this case nim and ggplotnim.
Plots.
@Vindaar
Vindaar / aNimKissFFT.org
Last active March 3, 2020 21:08
An example on how to use Kiss FFT in Nim

Another attempt of using kissFFT in Nim

I decided to look at what I did a couple of years ago with kiss FFT and Nim.

My original use case involved FADC (flash ADC; ADC with a sampling frequency of 1 GHz) events from my PhD work, which randomly contained a lot of noise (probably due to EMI).

The FADC has a cyclic register with 2560 elements. My idea was to

import strformat
import karax / [karaxdsl, vdom]
# want to use this like so
# linkItem:
# a(href="/"): text "Main Page"
template linkItem(body: untyped): VNode =
buildHtml(li(class="hover:underline text-center")):
h4:
li: body

fast code + fast code = slow code

Apparently.

So after finishing with the major refactoring of the scale filling in ggplotnim I re-ran the chapter2 examples file.

Before the refactor that file ran in:

basti at void in ~/CastData/ExternCode/ggplotnim/bookPlots ツ nim c chapter2.nim
basti at void in ~/CastData/ExternCode/ggplotnim/bookPlots ツ time ./chapter2
proc handleSetSeq(oId: NimNode, pnId: NimNode, sId: NimNode, name: string, dtype: NimNode): NimNode =
let
seqKind = dtype.nodeToVal().strVal
fieldName = ident(name)
eceId = ident"e"
bnId = ident"b"
var forBody = newStmtList()
case seqKind
of "floatVal":
# a super simple RPN calculator, which can evaluate input at compile time
# and creates the case statement for each supported operator automatically.
# inspired by D lang "Tiny RPN calculator" example: https://dlang.org/
import macros, strutils, deques
proc recurseReplace(n: NimNode, cond: NimNode, replace: NimNode): NimNode =
## a helper proc to replace a NimNode `cond` by `replace`
if n == cond:
result = n
else:
@Vindaar
Vindaar / callNimFromR.org
Created March 11, 2019 09:45
How to call Nim code from R using `.C` interface

Calling Nim from R

A super short introduction how to call Nim code from R using the .C interface. I’m not an R user normally, so I googled and used this post as a reference: https://www.r-bloggers.com/three-ways-to-call-cc-from-r/

Writing our Nim procedure

Let’s define a simple procedure, which we want Nim to do:

# 'overload' by name
proc foo_int(): int =
result = 1
proc foo_string(): string =
result = "1"
# use a generic
proc foo[T](): T =
when T is string:
import macros, typetraits
macro `&*`[T; N: static[int]](a: array[N, T], x: static[int]): untyped =
result = nnkBracket.newTree()
for i in 0 ..< x:
for j in 0 ..< N:
result.add a[j]
let key = [0] &* 10
echo name(type(key))