Skip to content

Instantly share code, notes, and snippets.

View pjbull's full-sized avatar
🥦

Peter Bull pjbull

🥦
View GitHub Profile
@pjbull
pjbull / monitor.py
Created October 4, 2021 17:27
Terminal process monitoring in Python
from collections import Counter, deque
from copy import copy
from dataclasses import dataclass, asdict
import datetime
from itertools import islice
import json
import os
from pathlib import Path
import sys
import time
@pjbull
pjbull / fspath-open-journey.ipynb
Last active April 4, 2021 06:49
Can we detect if a class implementing __fspath__ is called with a writeable mode from open?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pjbull
pjbull / joblib_deap.py
Created March 19, 2020 17:17
Deap OneMax Example with JobLib
import os
import time
from itertools import repeat
import random
from deap import creator, base, tools, algorithms
import numpy as np
from joblib import Parallel, delayed
from joblib import dump, load
@pjbull
pjbull / path_accessor.py
Last active January 2, 2020 22:13
pathlib.Path access for pandas series
from pathlib import Path
import pandas as pd
@pd.api.extensions.register_series_accessor("path")
@pd.api.extensions.register_index_accessor("path")
class PathAccessor:
def __init__(self, pandas_obj):
self._validate(pandas_obj)
{
"name": "Default color scheme for shell prompts",
"groups": {
"hostname": { "fg": "brightyellow", "bg": "mediumorange", "attrs": [] },
"environment": { "fg": "white", "bg": "darkestgreen", "attrs": [] },
"virtualenv": { "fg": "gray2", "bg": "solarized:green", "attrs": [] },
"mode": { "fg": "darkestgreen", "bg": "brightgreen", "attrs": ["bold"] },
"attached_clients": { "fg": "white", "bg": "darkestgreen", "attrs": [] },
"gitstatus": { "fg": "gray8", "bg": "gray2", "attrs": [] },
"gitstatus_branch": { "fg": "gray8", "bg": "gray2", "attrs": [] },
@pjbull
pjbull / vifs.ipynb
Created July 2, 2018 23:24
VIF Calculations
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pjbull
pjbull / run_all_nb.sh
Created June 9, 2018 00:07
Run all notebooks
find . *.ipynb -maxdepth 0 -type f -exec jupyter nbconvert --ExecutePreprocessor.timeout=-1 --to notebook {} --execute --output {} \;
@pjbull
pjbull / mpl_colors.py
Created May 29, 2018 23:59
get colors from colormap for arbitrary data
import matplotlib as mpl
import matplotlib.pyplot as plt
# whatever the data is
a = np.arange(5, 15)
# get colors for data from colormap (viridis in this case)
norm = mpl.colors.Normalize(vmin=a.min(), vmax=a.max())
rgba_color = plt.cm.viridis([norm(v) for v in a])
@pjbull
pjbull / tree_as_md_table.py
Last active March 12, 2017 18:23
Prints the output of the tree command as a markdown table for documentation
import subprocess
path = ROOT_DIR
result = (subprocess.check_output(['tree', '--dirsfirst', path])
.decode("utf-8", "strict"))
file_list = result.split('\n')
root = file_list[0]
file_list = file_list[1:-3]
@pjbull
pjbull / SparseInteractions.py
Last active April 18, 2021 12:09
Sparse Interaction Terms for scikit-learn
from sklearn.base import BaseEstimator, TransformerMixin
from scipy import sparse
from itertools import combinations
class SparseInteractions(BaseEstimator, TransformerMixin):
def __init__(self, degree=2, feature_name_separator="_"):
self.degree = degree
self.feature_name_separator = feature_name_separator