Skip to content

Instantly share code, notes, and snippets.

View mivade's full-sized avatar
👋

Mike DePalatis mivade

👋
View GitHub Profile
@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 / #zmqcpp-raw-README.md
Last active April 12, 2017 01:33
Sending raw bytes over ZMQ sockets with C++

Demo of sending raw bytes over ZMQ sockets with C++.

This assumes you are using miniconda and have installed cppzmq:

conda install -c conda-forge cppzmq
@mivade
mivade / randport.py
Created May 12, 2017 17:49
Binding to random ports for IPC
"""Examples of how to bind a socket to a random port and have that port number
accessible to other processes. Useful for interprocess communications.
"""
import time
import socket
from socket import AF_INET, SOCK_STREAM
from multiprocessing import Process, Queue, Event
from contextlib import contextmanager
@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.

Keybase proof

I hereby claim:

  • I am mivade on github.
  • I am mivade (https://keybase.io/mivade) on keybase.
  • I have a public key ASCjifbgjSNGV_4F5Ge6JtJZBHGMNpi4miYvMDbZUbD1Fwo

To claim this, I am signing this object:

@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')
@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()
@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'])
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)
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)