Skip to content

Instantly share code, notes, and snippets.

Avatar

Ruurd Moelker RRMoelker

View GitHub Profile
@RRMoelker
RRMoelker / asyncio_pipeline_wait.py
Last active Jul 24, 2019
Dead simple asyncio pipeline with random waiting
View asyncio_pipeline_wait.py
"""
Example program for asyncio pipeline with varying stage times.
Program takes string as input and converts it to upper case.
"""
import asyncio
import random
from dataclasses import dataclass
@RRMoelker
RRMoelker / asyncio_pipeline_basic.py
Last active Nov 12, 2021
Dead simple asyncio pipeline
View asyncio_pipeline_basic.py
"""
Example program for basic asyncio pipeline.
Program takes string as input and converts it to upper case.
For sake of simplicity missing some "features", most notably error handling is absent.
Errors will silenty prevent program completion in many cases.
"""
import asyncio
from dataclasses import dataclass
View gist:af11d53ab85ce361019f14504856bb30
(function(){
const knownTags = ['address', 'article', 'aside', 'footer', 'h1','h2','h3','h4','h5','h6', 'header', 'hgroup', 'nav', 'section', 'dd', 'div', 'dl', 'dt', 'figcaption', 'figure', 'hr', 'li', 'main', 'ol', 'p', 'pre', 'ul', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', 'q', 'rp', 'rt', 'rtc', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr','caption', 'col', 'colgroup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'button', 'datalist', 'fieldset', 'form', 'input', 'label', 'legend', 'meter', 'optgroup', 'option', 'output', 'progress', 'select', 'textarea' ];
const notCss = knownTags.map(tag => `:not( ${ tag } )`).join('');
const nodes = document.querySelectorAll(`body ${ notCss }`);
const nodesArray = Array.prototype.slice.call(nodes);
nodesArray.map( node => {
const outer = document.createElement('div');
@RRMoelker
RRMoelker / main.py
Created Jul 14, 2016
Food dispenser WiPy food cycle with stuttering motion
View main.py
# coding=utf-8
#
# Loop through food delivery cycle
#
import time
from machine import Pin
from servo import Servo
led = Pin('GP25', mode=Pin.OUT)
@RRMoelker
RRMoelker / upload.sh
Created Jul 14, 2016
WiPy hello servo using servo lib lftp upload shell script
View upload.sh
#!/bin/bash
# first argument is WiPy ip
lftp -u micro,python $1 << EOF
cd /flash
put main.py
put WiPy-servo/servo.py
View main.py
# coding=utf-8
#
# Rotate servo over full rotational range
#
import time
from machine import Pin
from servo import Servo
# Configuration
@RRMoelker
RRMoelker / main.py
Created Jul 14, 2016
Hello servo WiPy
View main.py
#
# Rotate servo over full rotational range
#
import time
from machine import Pin, Timer
# Servo specific constants
PULSE_MIN = 900 # in us, actually bit higher than specs indicate
PULSE_MAX = 2100 # in us
FREQUENCY = 50 # Hz
@RRMoelker
RRMoelker / main.py
Created Jul 13, 2016
WiPy hello world blink Heartbeat LED using pin 25
View main.py
import time
from machine import Pin
led = Pin('GP25', mode=Pin.OUT)
while True:
led(0) # turn off the heartbeat LED
time.sleep_ms(100)
led(1) # turn on the heartbeat LED
time.sleep_ms(100)
@RRMoelker
RRMoelker / main.py
Created Jul 13, 2016
WiPy hello world blink Heartbeat LED
View main.py
import time
import wipy
while True:
wipy.heartbeat(False) # disable the heartbeat
time.sleep_ms(100)
wipy.heartbeat(True) # enable the heartbeat
time.sleep_ms(100)
@RRMoelker
RRMoelker / boot.py
Created Jul 13, 2016
WiPy connect WiFi network on boot
View boot.py
# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
#
# WiPy WiFi setup, augmented code from:
# http://micropython.org/resources/docs/en/latest/wipy/wipy/tutorial/wlan.html#assigning-a-static-ip-address-when-booting
import machine
from network import WLAN
IP = '192.168.1.42'