Skip to content

Instantly share code, notes, and snippets.

View UNIcodeX's full-sized avatar

Jared Fields UNIcodeX

View GitHub Profile
@UNIcodeX
UNIcodeX / parallelProcessingGlobalVarWithExplicitPointer.nim
Last active April 13, 2020 16:26
Example of using an explicitly defined pointer with parallel processing in Nim.
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 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
@UNIcodeX
UNIcodeX / rotate_lights.py
Last active November 13, 2019 20:55
mock up code for Seth's LED light wagon wheel project
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
@UNIcodeX
UNIcodeX / testQuart.py
Created October 30, 2019 04:41
Quart Web App - Minimal example. calling
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
@UNIcodeX
UNIcodeX / example_nim_async.nim
Created October 21, 2019 19:52
Nim async example
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
@UNIcodeX
UNIcodeX / threading_why.nim
Created October 21, 2019 19:25
Nim threading questions....
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)
@UNIcodeX
UNIcodeX / threaded_echo.nim
Created October 20, 2019 05:16
Nim Threaded Echo
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()
@UNIcodeX
UNIcodeX / threaded_global.nim
Created October 20, 2019 05:16
Nim Threaded Change Global
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."
@UNIcodeX
UNIcodeX / threaded_pi.nim
Created October 20, 2019 05:15
Nim Threaded Pi
# 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:
@UNIcodeX
UNIcodeX / Nim threading example.nim
Created October 19, 2019 16:25
Rahmatullah's threading example
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 & "/*"))