Skip to content

Instantly share code, notes, and snippets.

View maartenbreddels's full-sized avatar

Maarten Breddels maartenbreddels

View GitHub Profile
@maartenbreddels
maartenbreddels / gist:82a3778c9a79b7ef048e
Last active June 19, 2022 22:26
simple example on how to combine python and numpy with some fast c function using a c++ template function
#include <Python.h>
#include <math.h>
#include <stdexcept>
#include <cstdio>
#include <numpy/arrayobject.h>
template<typename T>
void object_to_numpy1d_nocopy(T* &ptr, PyObject* obj, long long &count, int& stride=stride_default, int type=NPY_DOUBLE) {
if(obj == NULL)
@maartenbreddels
maartenbreddels / qt_and_tornado.py
Created October 1, 2015 10:57
Combining Qt and tornado, both which want to have their own event loop.
__author__ = 'breddels'
"""
Demonstrates combining Qt and tornado, both which want to have their own event loop.
The solution is to run tornado in a thread, the issue is that callbacks will then also be executed in this thread, and Qt doesn't like that.
To fix this, I show how to use execute the callback in the main thread, using a Qt signal/event in combination with Promises.
The output of the program is:
fetch page, we are in thread <_MainThread(MainThread, started 47200787479520)>
response is 191548 bytes, we are in thread <Thread(Thread-1, started daemon 47201018689280)>
the other thread should fulfil the result to this promise, we are in thread <Thread(Thread-1, started daemon 47201018689280)>
@maartenbreddels
maartenbreddels / ipython_thread.py
Last active July 28, 2020 14:07
IPython snippet for doing work in a thread, and updating a progressbar
import threading
from IPython.display import display
import ipywidgets as widgets
import time
def get_ioloop():
import IPython, zmq
ipython = IPython.get_ipython()
if ipython and hasattr(ipython, 'kernel'):
return zmq.eventloop.ioloop.IOLoop.instance()
ioloop = get_ioloop()
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Workshop NL Gaia\n",
" * Desktop:\n",
" * module load anaconda # or anaconda3\n",
" * source ~breddels/src/vaex/vaex.sh/.csh\n",
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maartenbreddels
maartenbreddels / notebook-demo-esac.ipynb
Last active November 4, 2016 06:55
Notebook used for the vaex demo at the Gaia DR1 workshop as ESAC
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maartenbreddels
maartenbreddels / doubler.ipynb
Created March 8, 2017 19:48
demo of binary (de)serialization
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.