Skip to content

Instantly share code, notes, and snippets.

proc get_password(): string =
echo "Enter password: "
result = ""
var ch = getch()
while ch != '\r':
result &= $ch
ch = getch()
when isMainModule:
let password = get_password()
import terminal
proc restoreOnInterrupt() {.noconv.} =
## called in `getPassword` if readLine is interrupted by SIGINT to remove the
## typed characters and restore the terminal to default settings.
# erase line, to remove the password
eraseLine()
# restore default terminal settings
showCursor()
resetAttributes()
import pylab
# taken from some random webpage several years ago. Sorry author :(
def fancy_plotting():
# set up some LaTeX plotting parameters
# still need to change parameters
# next line is for standard article document
# fig_width_pt = 478.00812#246.0 # Get this from LaTeX using \showthe\columnwidth
# next line is for thesis after Brock thesis guide
fig_width_pt = 451.58598
function draw_new_frame(fig, cb, image, frame, file)
image[:set_data](frame)
# get the filename written prev.
texts = fig[:texts]
for i in range(1, length(texts))
# and remove each
texts[1][:remove]()
end
# write new filename
# same as the Julia example, but in Python
# I hope I made no mistake (mistaking an attribute as a
# function or something like this while converting it
# from the Julia to Python. Didn't test it)
def draw_new_frame(fig, cb, image, frame, file)
image.set_data(frame)
# get the filename written prev.
texts = fig.texts
macro setTabFields[T: (float | int), N: int](tab: Table[string, seq[seq[T]]],
names: array[N, string],
chip: int,
obj: untyped): untyped =
## taking some table `tab` sets all fields of the table taken from an array `names` to the
## fields of the object `obj` of the same names as the names in the table
result = newStmtList()
let namesImpl = names.symbol.getImpl
for name in namesImpl:
let field = parseExpr(name.strVal)
proc compilerError*[T](x: seq[T], y = @[]) =
discard
proc linkerError*[T](x: seq[T], y: seq[T] = @[]) =
discard
when isMainModule:
let a = @[0, 1, 2]
#compilerError(a)
linkerError(a)
import sequtils
proc `[]`*[T](a: openArray[T], inds: seq[int]): seq[T] {.inline.} =
## given two openArrays, return a sequence of all elements whose indices
## are given in 'inds'
## inputs:
## a: seq[T] = the sequence from which we take values
## inds: openArray[int] = the array which contains the indices for the
## arrays, which we take from 'array'
## outputs:
## seq[T] = a sequence of all elements s.t. array[ind] in numpy indexing
import ../src/arraymancer, random
# This is an early minimum viable example of handwritten digits recognition.
# It uses convolutional neural networks to achieve high accuracy.
#
# Data files (MNIST) can be downloaded here http://yann.lecun.com/exdb/mnist/
# and must be decompressed in "./build/" (or change the path "build/..." below)
#
import macros
type
Container = object
field1: string
field2: string
fieldInt: int
macro setField(obj: untyped, name: string, val: untyped): untyped =
result = newStmtList()