Skip to content

Instantly share code, notes, and snippets.

@blink1073
blink1073 / LICENSE
Last active April 9, 2024 06:57
Wrap an Asynchronous Class
Copyright (c) 2022 Steven Silvester
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@blink1073
blink1073 / phantom_3d.py
Last active November 6, 2023 01:38
3D Phantom
from __future__ import division
import numpy as np
def phantom3d(phantom='modified-shepp-logan', n=64):
"""Three-dimensional Shepp-Logan phantom
Can be used to test 3-D reconstruction algorithms.
Parameters
@blink1073
blink1073 / pymongo_greenlet.md
Created June 16, 2023 00:12
Async PyMongo with Greenlet

Async PyMongo with Greenlet

June 12, 2023

Proposal

Use greenletio to add asyncio support in PyMongo, with minimal changes to existing classes.

Background

The reason that Motor is not "truly asynchronous" is that we have blocking calls in PyMongo that do not enable cooperative multitasking. These include acquiring thread locks and socket i/o. Even if we were to use non-blocking versions of these, the event loop would still be blocked.

The previous proposal required rewriting the entirety of PyMongo to be asyncio-friendly, and gave a small performance hit for synchronous code, especially noticeable for small documents.

@blink1073
blink1073 / extension_types.py
Last active January 20, 2023 19:16
Pandas Extension Types for BSON
from __future__ import annotations
from bson import ObjectId, Decimal128, Binary
from pandas.api.extensions import ExtensionDtype, ExtensionArray, register_extension_dtype
from pandas._typing import type_t
import pyarrow as pa
from typing import Union, Any
import numpy as np
import pandas as pd
import numbers
"""Compare the dist file created by a migrated package to one created by the original."""
import argparse
import glob
import os
import shutil
import subprocess
import sys
import tarfile
import zipfile
@blink1073
blink1073 / xonsh_metakernel.py
Last active March 17, 2022 17:10
Xonsh Jupyter Metakernel
from __future__ import absolute_import
from metakernel import MetaKernel
from xonsh.shell import Shell
import builtins
from xonsh import imphooks
import re
__version__ = '0.0'
@blink1073
blink1073 / myqtgraph.py
Created May 8, 2015 20:21
PyQtGraph Simplified Gui Maker
import pickle
import pyqtgraph as pg
from pyqtgraph.parametertree import Parameter, ParameterTree
from pyqtgraph.parametertree.parameterTypes import (
WidgetParameterItem, registerParameterType)
from pyqtgraph.Qt import QtGui, QtCore
def tree(name, params):
@blink1073
blink1073 / Atom PyQtGraph Scatter3D Plot Example
Last active February 1, 2022 05:26
Demonstration of the pyqtgraph.opengl.GLScatterPlotItem in a pyqtgraph.opengl.GLViewWidget with Atom bindings. This is meant to be used as the basis of a point cloud GUI in Enaml.
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 20 14:27:48 2013
@author: silvester
Demonstration of Point Cloud tool using OpenGL bindings in PyQtGraph
Based on GLScatterPlotItem.py example from PyQtGraph
License: MIT
@blink1073
blink1073 / lab_tables.py
Last active December 22, 2021 01:45
Create LAB LUTs for skimage.color.colorconv based on OpenCV Method
import numpy as np
from scipy.interpolate import interp1d
from skimage import img_as_ubyte
def build_spline(x, y):
"""computes cubic spline coefficients for a function: (xi=i, yi=f[i]), i=0..n
Adapted rom OpenCV project.
"""
@blink1073
blink1073 / meta.yml
Last active December 20, 2021 18:39
prototype conda recipe for pymongoarrow
{% set name = "pymongoarrow" %}
{% set version = "0.2.0.dev0" %}
package:
name: {{ name|lower }}
version: {{ version }}
source:
url: file:///home/runner/work/mongo-arrow/mongo-arrow/bindings/python/dist/pymongoarrow-{{ version }}.tar.gz