Skip to content

Instantly share code, notes, and snippets.

View mivade's full-sized avatar
👋

Mike DePalatis mivade

👋
View GitHub Profile
@mivade
mivade / schedule_coroutines.py
Created May 7, 2018 12:52
Running coroutines without explicitly awaiting
import asyncio
from threading import Event, Thread
class EventLoopThread(Thread):
def __init__(self):
super().__init__()
self.loop = None
self.ready = Event()
"""Example of how to use webargs with Tornado to read form data which includes file uploads."""
from dataclasses import dataclass, field
from typing import List, Optional
from marshmallow_dataclass import class_schema
from marshmallow.fields import Raw
from tornado.ioloop import IOLoop
from tornado.web import Application, RequestHandler
@mivade
mivade / benchmark.ipynb
Last active February 25, 2021 02:52
Sharing memory between processes with various methods
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mivade
mivade / tornadobg.py
Last active March 17, 2020 02:07
Background tasks with tornado and concurrent.futures
"""A simple demonstration of running background tasks with Tornado.
Here I am using a basic TCP server which handles streams and keeps
them open while asynchronously performing a fake task in the
background. In order to test it, simply telnet to localhost port 8080
and start typing things to see that the server receives the messages.
The advantage to running on an executor instead of conventional
threads is that we can more easily shut it down by stopping the
tornado IO loop.
@mivade
mivade / #tornado-websocket-pubsub.rst
Last active July 5, 2019 05:48
Using Tornado websockets for the publish/subscribe pattern
@mivade
mivade / hg_importing.md
Last active March 6, 2019 20:00
How to import history from one Mercurial repository into another

Importing a Mercurial repository's full history into another repository

Convert the soon-to-be child repository

With the Mercurial convert extention, you can rename branches, move, and filter files. As an example, say we have a repo with only the default branch which is to be imported into a super-repository.

For starters, we will want all our files in the child repo to be in a subdirectory of the parent repo and not include the child's

Testing using Pygal to render plots server-side and embed them in a web page via a <canvas>.

import codecs
import json
from typing import Union
import h5py
import numpy as np
import pandas as pd
vlen = np.vectorize(len)
vencode = np.vectorize(codecs.encode)
@mivade
mivade / admonitions.js
Created December 7, 2014 14:29
Colored admonitions in Pelican with pelican-bootstrap3
/*
Simple jQuery calls to replace RST admonitions with Bootstrap
alerts.
This is intended to work with the pelican-bootstrap3 Pelican theme,
but may also work with others.
This script is public domain.
*/
@mivade
mivade / multiline_lambdas.py
Last active January 15, 2018 16:54
Multiline lambdas and why you'd want to use them
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class MainWindow(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle('Multiline lambdas')