Skip to content

Instantly share code, notes, and snippets.

@mauicv
mauicv / thread_controller.py
Last active April 20, 2020 23:36
[thread-controller] #contoller #threads
import asyncio
from threading import Thread, Timer
import logging
import sys
logging.basicConfig(
level=logging.INFO,
format='%(threadName)10s %(name)18s: %(message)s',
@mauicv
mauicv / utils.py
Created June 4, 2020 17:17
[useful functions] #list_get #pairwise_iterator
from functools import reduce
import operator
from itertools import tee
def list_get(dictionary, list):
return reduce(operator.getitem, list, dictionary)
def pairwise(iterable):
@mauicv
mauicv / JSLangInterface.js
Created August 12, 2020 12:12
[Javascript Language Interface] Run with node can be spawned as a subprocess from another language and acts as a wrapper for js code. #interface
var state = {
prop: undefined
doSomething: (envName) => {},
doSomethingElse: (_) => {},
setProp: (v) => {
this.prop = v
},
}
process.stdin.setEncoding('utf-8')
@mauicv
mauicv / manageSubprocess.py
Last active August 12, 2020 12:17
[Python Subprocess Manager] Class for spawning nodejs subprocess and passing cmd, arg pairs to it and parsing the responses #py-to-js #interface
from subprocess import Popen, PIPE
import json
class Manager:
def __init__(self, name):
self.ps = Popen(
['nodejs', 'src/js/index.js'],
stdin=PIPE, stdout=PIPE)
self.name = name
@mauicv
mauicv / batch_job.py
Last active April 11, 2021 10:31
[batch function] Turns single argument functions into batched functions #batch #parallelism
"""
Simple wrapper to compute a parrallelize a function.
given a function f that takes a single argument, `arg`, the batch_job decorator
turns f into a function that takes a list of args and computes each result in
a seperate process. It then returns the results as a list.
___
use:
@mauicv
mauicv / class_instance_validator.py
Created March 6, 2021 15:28
[class instance validator] Validates class on instance change for testing purposes #validation #testing
"""Functions that can be used as decorators to check the state of class datastructures are sound.
The class_validator function adds a validation step to each method in the decorated class if the environment is
in TESTING mode. This is used primarily for testing in order to catch cases where class instances enter states
they shouldn't.
Example:
```
def simple_validator(self, *args, **kwargs):
@mauicv
mauicv / redirect_stream.py
Created March 28, 2021 00:43
[RedirectStream] Supress unwanted stdout or stderr output from external librarys #hack #stdout #stderr
# taken from https://github.com/bulletphysics/bullet3/issues/3131
import ctypes
import sys
import os
class RedirectStream(object):
@staticmethod
def _flush_c_stream(stream):
@mauicv
mauicv / mnist-tensorflow-similarity-example.ipynb
Last active April 26, 2022 16:45
MNIST-tensorflow-similarity-example.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mauicv
mauicv / mnist-torch-similarity-explainer-example.ipynb
Last active April 26, 2022 16:45
MNIST-torch-similarity-explainer-example.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mauicv
mauicv / recursive-config-example.ipynb
Created March 7, 2022 09:48
recursive-config-example.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.