Skip to content

Instantly share code, notes, and snippets.

@rossant
rossant / vulkan_sync_warning.c
Last active January 25, 2024 20:45
Vulkan minimal example that generates a SYNC-HAZARD-WRITE-AFTER-READ validation error
// Requires gcc, the Vulkan SDK, and libglfw3-dev
// On Linux, compile with:
// gcc -Wall -o fail fail.c -Ibuild/_deps/glfw-src/include/ -lglfw -lvulkan
#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <vulkan/vulkan.h>
#include <GLFW/glfw3.h>
@rossant
rossant / lru_cache.py
Created January 6, 2020 14:02
Custom LRU cache implementation that gives access to the underlying cache dictionary.
def lru_cache(maxsize=0):
"""Custom LRU cache implementation that gives access to the underlying cache dictionary. [better to used functools one if you don't need this]"""
def wrap(f):
cache = {}
last_used = []
def wrapped(*args):
if args in cache:
# HIT.
# Update the last_used list.
@rossant
rossant / onelight.py
Last active September 24, 2019 09:10
ONE light API proposal
from onelib import one
"""
Different ONE backends are available, HTTP, figshare, etc.
One has to implement the following functions to create a new ONE backend:
* list_all_files(): return a list of relative file paths for ALL available files.
* search(...): return a list of dset_ids (by default, a dset_id is a relative file path).
The default implementation calls list_all_files(), and performs the search directly on that list.
@rossant
rossant / parallel_write.py
Created August 30, 2019 15:04
Write a NumPy array in parallel from multiple CPUs/processes, using shared memory. No copy/serialization involved. Pure Python/NumPy.
"""Write a NumPy array in parallel from multiple CPUs/processes, using shared memory."""
from contextlib import closing
import multiprocessing as mp
import os
import numpy as np
def _init(shared_arr_):
import os
import requests
import shutil
def _dl(url, path):
print("download", url, "to", path)
response = requests.get(url, stream=True)
if response.status_code != 200:
return
@rossant
rossant / glwidget.py
Created November 26, 2018 17:14
Minimal modern PyQt5, OpenGL, QOpenGLWindow working example
#!/usr/bin/env python3
"""
Code from http://www.labri.fr/perso/nrougier/python-opengl/#the-hard-way
"""
import ctypes
import logging
@rossant
rossant / latex_to_image.py
Created February 12, 2018 13:46
Convert a LaTeX equation into EPS and PNG with Python
import os
import os.path as op
from pathlib import Path
import shutil
import subprocess
import tempfile
from IPython.lib.latextools import genelatex
@rossant
rossant / code_postal.vba
Last active December 2, 2016 20:26
VBA code to find French cities associated to a given postal code
Function collectionToArray(c As Collection) As Variant()
Dim a() As Variant: ReDim a(0 To c.Count - 1)
Dim i As Integer
For i = 1 To c.Count
a(i - 1) = c.Item(i)
Next
collectionToArray = a
End Function
@rossant
rossant / latest_pandoc.sh
Created March 28, 2016 14:14
Install latest .deb pandoc, using the GitHub release page -- useful on CI systems
URL="https://github.com/jgm/pandoc/releases/latest"
PANDOCPAGE="$(wget $URL -q -O -)"
DEBURL="$(echo $PANDOCPAGE | grep -oP '"([^"]+.deb)"')"
DEBURL="${DEBURL:1:-1}"
URL="http://github.com/$DEBURL"
wget $URL -O pandoc.deb
sudo dpkg -i pandoc.deb
@rossant
rossant / installer.md
Last active March 26, 2016 18:06
Build cross-plaform graphical installers for Python software

Distributing Python software to non-technical users is too hard. We need to make it simpler.

I'm imagining a tool based on conda.

Ideally I'd like to have something like this:

  • I write an environment.yml file with the conda/pip dependencies for my software
  • I write an installer.yml file that describes my installer: package name, paths to logo/images, icon shortcuts for binaries, etc.
  • I type build-installer and a few files are created:
  • mypackage.sh: for Unix systems