Skip to content

Instantly share code, notes, and snippets.

View hiway's full-sized avatar

Harshad Sharma hiway

View GitHub Profile
@hiway
hiway / micropython_http_bootstrap.py
Created December 13, 2016 08:27
Micropython (ESP8266): Download files from a known server to populate the filesystem with necessary files.
import ujson as json
import uos as os
import usocket as socket
# todo: https
def http_get_async(url):
_, _, host, path = url.split('/', 3)
if ':' in host:
@hiway
hiway / pyqt5_macos_systray.py
Last active September 26, 2023 07:56
PyQt5 (Python3/ MacOS) System Tray application with KeyboardInterrupt (Ctrl+C) on terminal wired to Application > Quit.
import logging
import signal
import sys
from PyQt5 import QtGui, QtWidgets
logger = logging.getLogger(__name__)
def refresh(*args):
@hiway
hiway / README.md
Last active December 1, 2016 23:43
link-and-move: move a file or directory to another location and symlink back to original

lmv: Link and Move

A tiny utility that will move a file and put a symlink back in the original location to ensure others looking for the file will find it.

Download the files into a directory cd into the directory run pip install -e . (don't forget the .)

@hiway
hiway / commands.sh
Created November 27, 2016 08:22
Use T* and Python to make users with zero tweets (generally bots) unfollow you (block and unblock) (* https://github.com/sferik/t)
t followers --csv -l > followers.csv
python zero_tweets.py | xargs t block
python zero_tweets.py | xargs t delete block
@hiway
hiway / asyncsrv.py
Last active October 2, 2016 05:40 — forked from felipecruz/asyncsrv.py
python zmq async server example
"""
ZMQ with Threaded Workers on Python 3
Python 3 compatible port of: https://gist.github.com/felipecruz/883983
"""
import zmq
import threading
import time
from random import choice
@hiway
hiway / curiozmq.py
Last active October 2, 2016 07:23
async ZeroMQ in curio: attempt 1
import attr
import time
import zmq as _zmq
from curio import sleep
ROUTER = _zmq.ROUTER
DEALER = _zmq.DEALER
PUB = _zmq.PUB
SUB = _zmq.SUB
XPUB = _zmq.XPUB
@hiway
hiway / pybble.py
Last active June 29, 2023 23:46
Python on Pebble. Yes. It works, with a bit of space to write a decent app and some heap memory to spare. AJAX works, as shown in code.
"""
pybble.py
Yup, you can run Python on your Pebble too! Go thank the good folks who
made Transcrypt, a dead-simple way to take your Python code and translate
it to *very* lean Javascript. In our case, instead of browser, we run it
on Pebble using their equally dead-simple Online IDE and Pebble.js library.
Here's a working example, it runs on a real Pebble Classic.
@hiway
hiway / micropython-esp8266-scheduler.py
Created July 5, 2016 23:42
First draft of a rudimentary async/ await based scheduler that can run coroutines that share time by sleeping and handing over control.
import gc
import time
CLOCK_PERIOD = 0x3fffffff # ACTUAL: overflows at 1073741823 microseconds (1073.74 seconds)
# CLOCK_PERIOD = 0x3ffffff # TESTING: overflow at: 67108863 (67.10 seconds)
# CLOCK_PERIOD = 0x3fffff # IMPATIENT TESTING: overflow at: 4194303 (4.19 seconds)
MAX_TIMEOUT = CLOCK_PERIOD // 2
MAX_SECONDS = MAX_TIMEOUT // (10 ** 6) # 536.87 seconds
PLATFORM_ESP = 1
@hiway
hiway / .bash_profile
Last active May 27, 2016 15:14
.bash_profile for python virtualenvwrapper using brew python (MaxOSX El Capitan)
export WORKON_HOME=$HOME/virtualenvs
export PROJECT_HOME=$HOME/Source
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
source /usr/local/bin/virtualenvwrapper_lazy.sh