Skip to content

Instantly share code, notes, and snippets.

@carlosperate
carlosperate / micropython_timing.py
Last active September 3, 2021 12:25
Timing functions in MicroPython via decorator
import time
def timed_function(f, *args, **kwargs):
def new_func(*args, **kwargs):
t = time.ticks_us()
result = f(*args, **kwargs)
delta = time.ticks_diff(time.ticks_us(), t)
print("Function Time = {:6.3f}us".format(delta))
return result
@carlosperate
carlosperate / measure.py
Last active August 11, 2020 23:12
Mu Serial REPL benchmark
from original import FakePaneOriginal
from option_1 import FakePaneOne
from option_2 import FakePaneTwo
from option_3 import FakePaneThree
from option_4 import FakePaneFour
from option_5 import FakePaneFive
utf8_char_list = [
"°",
"🌈",
@carlosperate
carlosperate / get_releases.html
Last active January 24, 2017 15:48
GH REST API
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>gh3</title>
</head>
<body>
<h1>Test</h1>
<script>
@carlosperate
carlosperate / beatboxing.py
Created October 31, 2016 23:53
beatboxing
import speech
from microbit import sleep, button_a, button_b, display, Image
gap = 220 # How long a silence should be.
bass_drum = 'BUH' # Sound of a beat box bass drum
snare = 'CHIXIX' # Sound of a beat box snare
roll = 'DGDG' # Sound of a beat box drum roll
rest = '' # Represents a rest of "gap" duration
# Two sequences (lists) of beats. One beat per line.
@carlosperate
carlosperate / batch_pic_rename.py
Created September 20, 2016 16:34
Rename pictures with date and time.
import os
import sys
import glob
#from PIL import Image
#from PIL.ExifTags import TAGS
import time
def get_exif(file_name):
""" Extracts EXIF data. Does not check for file validity. """