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 asyncio | |
import time | |
def sync_func(): | |
time.sleep(10) | |
return 'sync_func() - Synchronous function data' | |
async def async_func(): | |
while True: |
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 asyncio # to get access to the asyncio.sleep function. Not sure if or where this is available in Sanic. | |
import random | |
import aioredis | |
import redis | |
from sanic import Sanic, request, response | |
app = Sanic(__name__) | |
sr = redis.StrictRedis(host='localhost', port=6379) | |
sr.execute_command('FLUSHDB') |
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 asyncio | |
import random | |
import aioredis | |
import redis | |
from quart import Quart, request, url_for, jsonify | |
app = Quart(__name__) | |
sr = redis.StrictRedis(host='localhost', port=6379) | |
sr.execute_command('FLUSHDB') |
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
1) create a jail | |
2) chroot to the jail | |
3) pkg update | |
4) pkg install python36-3.6.5 (or latest) | |
5) pkg install python py36-pip-9.0.3 (or latest) | |
6) pkg install bash | |
7) pip install --upgrade pip | |
8) pip install twisted | |
9) pkg install py27-supervisor-3.3.3,1 (or latest) | |
10) pkg install wget |
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 multiprocessing | |
from tqdm import tqdm | |
import time | |
import sys | |
def worker(i): | |
time.sleep(.1) | |
return i*8 |
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 times | |
let time_begin = times.cpuTime() | |
proc primes(n: int): seq[int] = | |
result = seq[int] | |
if n == 2: | |
result.add(2) | |
elif n < 2: | |
result.add(0) |
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
""" | |
1) Dont use * or ** args | |
2) Short variable names | |
3) Functions to avoid global variables (local over global) | |
4) "mpy-cross" to pre-compile code so that the microcontroller doesnt have to use as many resources to compile and load / import | |
5) freeze modules | |
""" | |
# HARDWARE CONTROL EXAMPLES (BLINK LED) | |
# ===================================== |
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
# Python 2x only. Python 3x does not work with this. | |
import time | |
def primes(n): | |
if n == 2: return [2] | |
elif n < 2: return [] | |
s = range(3, n + 1, 2) | |
mroot = n ** 0.5 | |
half = (n + 1) / 2 - 1 | |
i = 0 |
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 & "/*")) |
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: |