Skip to content

Instantly share code, notes, and snippets.

View mivade's full-sized avatar
👋

Mike DePalatis mivade

👋
View GitHub Profile
@mivade
mivade / aiowatch.py
Created October 26, 2018 17:00
Using watchdog with asyncio
import asyncio
from pathlib import Path
from typing import Optional
from watchdog.events import FileSystemEvent, FileSystemEventHandler
from watchdog.observers import Observer
class _EventHandler(FileSystemEventHandler):
def __init__(self, queue: asyncio.Queue, loop: asyncio.BaseEventLoop,
@mivade
mivade / tornadosse.py
Last active February 8, 2024 02:17
Tornado server-sent events
"""Demonstration of server-sent events with Tornado. To see the
stream, you can either point your browser to ``http://localhost:8080``
or use ``curl`` like so::
$ curl http://localhost:8080/events
"""
import signal
from tornado import web, gen
@mivade
mivade / cli.py
Last active January 18, 2024 07:51
Using a decorator to simplify subcommand creation with argparse
"""This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@mivade
mivade / zmq_auth.py
Last active December 30, 2023 12:57
ZeroMQ Curve authentication demo
"""Simple demonstration of using ZMQ's Curve authentication.
This demo is adapted from the examples given in the `PyZMQ repository`__. Key
differences include:
* Using ``setsockopt`` to set Curve parameters instead of setting attributes
directly (help out your IDE!)
* Integration with ``asyncio``
__ https://github.com/zeromq/pyzmq/tree/master/examples
@mivade
mivade / docker-wsl-ubuntu.md
Created May 4, 2023 14:53
Installing Docker in Ubuntu on WSL

Installing Docker in Ubuntu on WSL

Install upstream Docker

Follow the instructions here

Start the service and troubleshoot problems

sudo service docker start
@mivade
mivade / app.py
Last active May 4, 2023 16:51
Websockets with Flask via aiohttp
"""Simple demo of using Flask with aiohttp via aiohttp-wsgi's
WSGIHandler.
"""
import asyncio
from aiohttp import web
from aiohttp_wsgi import WSGIHandler
from flask import Flask, render_template
@mivade
mivade / Set-Up-PowerShell-for-Python.md
Last active October 10, 2022 17:02 — forked from andrew-rietz/Set-Up-PowerShell-for-Python.md
Set Up PowerShell for Python

1. Install Scoop
Scoop is a command-line installer for Windows -- it's like Homebrew for Windows. It installs programs from the command line with a minimal amount of friction. More info about scoop is available here: https://gist.github.com/andrew-rietz/66e4ebcf96f85b6618b078ebe00104b1
To install, open PowerShell and execute the following command:

iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

2. Use Scoop to install some awesome helper applications
We'll use Scoop to install a couple applications: posh-git and starship. Posh-git adds a lot of the convenience features you get in git bash directly into PowerShell (autocompletion, etc.). We'll also install starship.rs: a customizeable prompt for many of the common shells (Bash, Fish, Zsh, PowerShell).

@mivade
mivade / .gitignore
Last active February 5, 2022 15:11
Distributed Monte Carlo calculation of pi using Celery
__pycache__
*.pyc
*.ipynb
.ipynb_checkpoints
*.json
*~
class Manager(object):
classes = set()
class Meta(type):
def __new__(cls, name, bases, d):
print("name:", name, "\nbases:", bases, "\ndict: ", d)
if name is not "Base":
Manager.classes.add(d['data'])
return type.__new__(cls, name, bases, d)
@mivade
mivade / ipc_compare.py
Last active January 15, 2022 21:14
Interprocess communication speed comparisons
from multiprocessing import Event, Process, Queue
import time
import zmq
class BaseActor(Process):
ready = Event()
def handle(self, msg):
print("dt =", time.time() - msg['timestamp'])