Skip to content

Instantly share code, notes, and snippets.

View pierreglaser's full-sized avatar
:octocat:

Pierre Glaser pierreglaser

:octocat:
View GitHub Profile
@pierreglaser
pierreglaser / install_miniconda.sh
Last active June 18, 2020 09:37
install latest miniconda on a new machine
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/.local/miniconda3
# Activate conda env by default
echo 'source $HOME/.local/miniconda3/etc/profile.d/conda.sh
conda activate
' >> $HOME/.bashrc
source $HOME/.bashrc
@pierreglaser
pierreglaser / repro.py
Created December 23, 2019 01:56
reproducer of windows permission errors in joblib
import time
import numpy as np
from joblib import Parallel, delayed
from joblib.externals.loky.backend import resource_tracker
resource_tracker.VERBOSE = True
import os
print(f"PARENT PID IS : {os.getpid()}")
@pierreglaser
pierreglaser / air-quality-api.sh
Last active October 8, 2019 16:01
Integrate air-quality data to your desktop environment
# this will fetch no2 concentration for Paris, France.
curl https://api.openaq.org/v1/latest?city=Paris | jq -r '.results[0].measurements[0]'
@pierreglaser
pierreglaser / test.py
Last active July 19, 2019 17:09
allow processes to have a context attribute in a backward-compatible way
import multiprocessing as mp
from multiprocessing.reduction import AbstractReducer, AbstractPickler
from multiprocessing.context import SpawnContext, SpawnProcess, DefaultContext
class PicklerProtocol2(AbstractPickler):
@classmethod
def dumps(cls, obj, protocol=2):
return super().dumps(obj, protocol=protocol)
"""
Dump a function in Python3.6, and try to reconstruct and run it in Python3.5.
Cloudpickle will fail at this task because of bytecode incompatibility between
different Python versions.
However, if instead of pickling the bytecode, we pickle slightly higher level
abstraction such as instructions, and reconstruct the code object from the
depickled instructions, the reconstructed functions works fine.
"""
import pickle
@pierreglaser
pierreglaser / pairwise_distances_bechmarks.py
Last active February 27, 2019 14:08
benchmark of parwise distances when using different backends
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Wall clock time measurement of pairwise_distances"""
import os
import csv
import time
import itertools
import numpy as np
import pandas as pd
@pierreglaser
pierreglaser / benchmark.py
Created February 22, 2019 10:30
Use c pickler extension to communicate data to workers
import time
import loky
def process_dict(x):
return len(x)
if __name__ == "__main__":
e = loky.get_reusable_executor(max_workers=2)
@pierreglaser
pierreglaser / test_backward_compat_base_globals.py
Created February 7, 2019 11:09
Load (with cloudpickle PR #240) functions of dynamically created modules that were pickled using older version of cloudpickle (0.5, 0.6, 0.7)
import cloudpickle
import os
import pickle
import sys
import types
VERSION = cloudpickle.__version__
script = """