Skip to content

Instantly share code, notes, and snippets.

View UNIcodeX's full-sized avatar

Jared Fields UNIcodeX

View GitHub Profile
import hashlib
import os
import imghdr
import datetime
import re
import shutil
import sys
import optparse
import time

Keybase proof

I hereby claim:

  • I am unicodex on github.
  • I am jared_fields (https://keybase.io/jared_fields) on keybase.
  • I have a public key ASDzWwMMAL1fy055FqazbMsftKK66OoUG7oQzzLqNrfGcAo

To claim this, I am signing this object:

@UNIcodeX
UNIcodeX / FadeInAndOut.py
Last active March 1, 2018 04:23
Intended to cycle the brightness of an LED on an ESP8266 board from the lowest to the brightest duty cycle and then back down again.
import machine
import time
p14 = machine.Pin(14, machine.Pin.OUT)
p2 = machine.Pin(2, machine.Pin.OUT)
direction = 'forward'
forward = [i for i in range(2, 1024)]
backward = [i for i in reversed(forward)]
def setPWM(OBJ=None, FREQ=1000, DUTY=1023):
@UNIcodeX
UNIcodeX / async_progress.py
Last active March 13, 2018 21:00
Do some work asynchronously, reporting the progress when it changes
import asyncio
import random
import sys
processed = int()
lastProcessed = int()
async def some_work():
global processed, length_of_work
print('some_work() has started.')
@UNIcodeX
UNIcodeX / async_server_echo.py
Last active March 13, 2018 21:00
Asynchronous server example from Python documentation
import asyncio
async def echo_server():
print('Serving on localhost:8000')
await asyncio.start_server(handle_connection,
'localhost', 8000)
async def handle_connection(reader, writer):
@UNIcodeX
UNIcodeX / sanic_work_progress.py
Last active March 13, 2018 21:09
An exercise in initializing some work to be done, while also being able to poll its progress, using asynchronous IO, via Sanic.
import asyncio # to get access to the asyncio.sleep function. Not sure if or where this is available in Sanic.
import random
from sanic import Sanic, request, response
from sanic_session import InMemorySessionInterface
app = Sanic(__name__)
session_interface = InMemorySessionInterface()
@app.middleware('request')
async def add_session_to_request(request):
@UNIcodeX
UNIcodeX / sanic_work_progress_sessionized.py
Created March 8, 2018 22:44
A version of sanic_work_progress.py that uses a session variable to store and retrieve the data.
import asyncio # to get access to the asyncio.sleep function. Not sure if or where this is available in Sanic.
import random
from sanic import Sanic, request, response
from sanic_session import InMemorySessionInterface
app = Sanic(__name__)
session_interface = InMemorySessionInterface()
session = None
@UNIcodeX
UNIcodeX / async-send_email-Flask.py
Last active December 1, 2019 22:08
An example of how to perform asynchronous work within a synchronous program, this example using Flask. Code adapted from "Example #1" at https://hackernoon.com/threaded-asynchronous-magic-and-how-to-wield-it-bba9ed602c32
import asyncio
import smtplib
from threading import Thread
from flask import Flask
from email.mime.text import MIMEText
app = Flask(__name__)
def send_notification(sender, recipient, subject, body, server):
"""Stuff to parse WAVE files.
Usage.
Reading WAVE files:
f = wave.open(file, 'r')
where file is either the name of a file or an open file pointer.
The open file pointer must have methods read(), seek(), and close().
When the setpos() and rewind() methods are not used, the seek()
method is not necessary.
"""Simple class to read IFF chunks.
An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File
Format)) has the following structure:
+----------------+
| ID (4 bytes) |
+----------------+
| size (4 bytes) |
+----------------+