This file contains hidden or 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 locks, threadpool, strutils | |
# compile with: | |
# nim c -r --threads:on -d:danger --threadanalysis:off --gc:arc | |
{.experimental: "parallel".} | |
var | |
lock: Lock | |
a: array[20, string] | |
ptra: ptr array[20, string] |
This file contains hidden or 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
'''This script goes along the blog post | |
"Building powerful image classification models using very little data" | |
from blog.keras.io. | |
It uses data that can be downloaded at: | |
https://www.kaggle.com/c/dogs-vs-cats/data | |
In our setup, we: | |
- created a data/ folder | |
- created train/ and validation/ subfolders inside data/ | |
- created cats/ and dogs/ subfolders inside train/ and validation/ | |
- put the cat pictures index 0-999 in data/train/cats |
This file contains hidden or 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
from time import sleep | |
from machine import Pin, ADC | |
Bank_1 = Pin(0, Pin.OUT) | |
Bank_2 = Pin(1, Pin.OUT) | |
Bank_3 = Pin(2, Pin.OUT) | |
dial = ADC({analog-to-digital-pin}) | |
# Reading a potentiometer on a board with a 10-bit DAC |
This file contains hidden or 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
from quart import Quart, request, session, render_template, render_template_string, redirect, url_for | |
from functools import wraps | |
import os | |
app = Quart(__name__) | |
app.secret_key = os.urandom(20) | |
# ~ | |
# Shared Funcs |
This file contains hidden or 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 strformat, asyncdispatch, random | |
randomize() | |
proc A(i: int): Future[string] {.async.} = | |
var ms = rand(1..1000) | |
await sleepAsync(ms) | |
var msg = fmt"hello from A({i}) (Slept for {ms} ms)" | |
echo msg | |
result = msg |
This file contains hidden or 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 threadpool, strformat | |
{.experimental: "parallel".} | |
proc A(i: int): string = | |
result = fmt"hello from thread {i}" | |
proc B(i: int): int = i | |
proc pa(): seq = | |
var s = newSeq[string](4) |
This file contains hidden or 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 threadpool, os, random, strformat | |
proc p(num: int) = | |
var seconds = rand(3..10) | |
sleep(seconds * 1000) | |
echo fmt"process: {num} slept {seconds} seconds." | |
when isMainModule: | |
randomize() |
This file contains hidden or 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 threadpool, os, random, strformat | |
var | |
seqResults {.global.}: seq[string] | |
# tSeqResults {.threadvar.}: seq[string] | |
proc p(num: int) = | |
var seconds = rand(0..10) | |
sleep(seconds * 1000) | |
var msg = fmt"process: {num} slept {seconds} seconds." |
This file contains hidden or 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
# Compute PI in an inefficient way | |
import strutils, math, threadpool | |
{.experimental: "parallel".} | |
proc term(k: float): float = 4 * math.pow(-1, k) / (2*k + 1) | |
proc pi(n: int): float = | |
var ch = newSeq[float](n+1) | |
parallel: | |
for k in 0..ch.high: |
This file contains hidden or 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 os, threadpool, strformat, strutils, sequtils | |
const | |
mkvmerge = r"d:\installer\mkvtoolnix\mkvmerge.exe" | |
proc remux(idx: int, filename: string) = | |
let | |
newcount = &"{idx:02}" | |
newname = newcount & ".mkv" | |
fonts = toseq(walkFiles("./" & newcount & "/*")) |