This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc get_password(): string = | |
echo "Enter password: " | |
result = "" | |
var ch = getch() | |
while ch != '\r': | |
result &= $ch | |
ch = getch() | |
when isMainModule: | |
let password = get_password() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
type | |
Container = object | |
field1: string | |
field2: string | |
fieldInt: int | |
macro setField(obj: untyped, name: string, val: untyped): untyped = | |
result = newStmtList() |
OlderNewer