Skip to content

Instantly share code, notes, and snippets.

import strutils
proc parseFile(filename: string): int =
result = filename.staticRead.strip.parseInt
# define the brightness file
const file = "/sys/class/backlight/intel_backlight/brightness"
# define thresholds for on and off
const brightnessOff = 0

General remarks

I personally just implement the features when I need them, as I go (as far as I’m able anyways). I think with a few people pushing we could get most of the important functionality of numpy and scipy built on top of arraymancer in a reasonable time.

In principle using Python where needed (but still accelerating it with Nim!) is pretty straight forward nowadays thanks to the advances in nimpy. I’ll show an example below. One major thing for this is still missing in nimpy, which makes it slightly more complicated than needed.

import macros
macro enumExt(e: typed, nums: varargs[untyped]): untyped =
# get type to access nodes of given enum
let t = e.getType
# seq to store syms to add to new enum
var toAdd = newSeq[NimNode]()
for x in t[1]:
case x.kind
of nnkSym:
if data =~ reg:
echo matches
let s = findAll(data, reg)
echo s
# ["Teil \nII<o:p></o:p>", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
# @["<P class=MsoNormal \nstyle=\"MARGIN-BOTTOM: 0pt; LINE-HEIGHT: normal; TEXT-AUTOSPACE: ; mso-pagination: none; mso-layout-grid-align: none\"><B><SPAN \nlang=de \nstyle=\'FONT-SIZE: 33pt; FONT-FAMILY: \"TimesNewRoman,Bold\",\"serif\"; mso-bidi-font-family: \"TimesNewRoman,Bold\"; mso-ansi-language: #0007\'>Teil \nII<o:p></o:p></SPAN></B></P>"]
import strutils
import os
import osproc
import streams
import regex
import docopt
const doc = """
Compile your TeX file with pdflatex --shell-escape and install missing
packages automatically!
#!/usr/bin/env python
import os
import numpy as np
import re
def parseFile(filename):
lines = open(filename).readlines()
x = []
y = []
when defined(EAPI):
when defined(WIN32):
when defined(BUILDING_DLL):
const
EAPI* = __declspec(dllexport)
else:
const
EAPI* = __declspec(dllimport)
else:
when defined(__GNUC__):
#ifndef __IMLIB_API_H
#define __IMLIB_API_H 1
#ifdef EAPI
#undef EAPI
#endif
#ifdef WIN32
#ifdef BUILDING_DLL
#define EAPI __declspec(dllexport)
#else
type
Func1 = proc (p: seq[float])
Func2[T] = proc (p: seq[float], d: T)
proc f1(p: seq[float]) = discard
proc f2(p: seq[float], d: float) = discard
echo "f1 is ", f1 is Func1 # returns false
echo "f2 is ", f2 is Func2 # returns true
type
BitArray[T: static[int]] = array[T, '0'..'1']
proc `[]=`(b: var BitArray, ind: int, val: int) =
b[ind] = if val == 1: '1' else: '0'
proc createBitarray(size: static[int]): BitArray[size] =
for i in 0 ..< size:
result[i] = '0'