Skip to content

Instantly share code, notes, and snippets.

View cvanelteren's full-sized avatar

Casper van Elteren cvanelteren

View GitHub Profile
git clone --bare https://github.com/cvanelteren/dots.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
mkdir -p .config-backup
config checkout
if [ $? = 0 ]; then
echo "Checked out config.";
else
echo "Backing up pre-existing dot files.";
@cvanelteren
cvanelteren / spacemacs-keybindings
Created April 4, 2020 01:33 — forked from adham90/spacemacs-keybindings
spacemacs keybindings that i need to learn
SPC s c remove highlight
**** Files manipulations key bindings
Files manipulation commands (start with ~f~):
| Key Binding | Description |
|-------------+----------------------------------------------------------------|
| ~SPC f c~ | copy current file to a different location |
| ~SPC f C d~ | convert file from unix to dos encoding |
| ~SPC f C u~ | convert file from dos to unix encoding |
@cvanelteren
cvanelteren / nested_pybind.cpp
Last active May 12, 2020 11:46
Binding nested subclasses in pybind11
#include <pybind11/stl.h>
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
namespace py = pybind11;
using namespace pybind11::literals;
using namespace std;
template<typename T>
class Property{
@cvanelteren
cvanelteren / convert.py
Last active May 25, 2020 12:55
convert using k2pdfopt to e-reader friendly format
from subprocess import run
from multiprocessing import cpu_count
import os, click
@click.command()
@click.option('--source', default = "~/Phd/ereader")
@click.option('--target', default = "~/Calibre Library")
@click.option('--args', default = f"-as -w -ocr -nt {cpu_count()} -ocr -x -ui-")
def run_reader(source, target, args):
eReaderConverter(source, target, args).convert()
@cvanelteren
cvanelteren / vispy_networkx_numpy.py
Last active October 19, 2020 16:41
Using networkx layouts and numpy coordinates for vispy.
from vispy.visuals.graphs.util import _straight_line_vertices, issparse
import networkx as nx, numpy as np
class NetworkxCoordinates:
def __init__(self, graph, layout = None, *args, **kwargs):
self.graph = graph
self.positions = np.zeros((len(graph), 2), dtype = np.float32)
# default random positions
if type(layout) is type(None):
self.positions = np.random.rand(*self.positions.shape)
test-microphone() {
arecord -vvv -f dat /dev/null
}
@cvanelteren
cvanelteren / discrete_colorbar.py
Last active April 6, 2021 10:18
Small utility to create a discrete matplotlib colormap
# Original by Jake VanderPlas
# https://gist.github.com/jakevdp/91077b0cae40f8f8244a
# License: BSD-style
# cvanelteren: small edit since the original was not compatible with latest mpl
import matplotlib.pyplot as plt, numpy as np
def discrete_cmap(N, base_cmap=None):
"""Create an N-bin discrete colormap from the specified input map"""
# Note that if base_cmap is a string or None, you can simply do
# return plt.cm.get_cmap(base_cmap, N)
@cvanelteren
cvanelteren / simple_progbar
Created April 15, 2021 14:29
Creating a simple progression bar
import sys, time
class progbar:
def __init__(self, x, stream = sys.stdout,
char = "#"):
self.x = x
self.stream = stream
self.char = char
def __iter__(self):
self.n = len(self.x)
@cvanelteren
cvanelteren / gaussian_roll.py
Created June 7, 2021 07:51
Gaussian roll - matplotlib animation for 3d line plots with colored segments
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Line3DCollection
fig, ax = plt.subplots(subplot_kw = dict(projection = '3d'))
# generate data
x = np.linspace(-5, 5, 500)
y = np.linspace(-5, 5, 500)
z = np.exp(-(x - 2)**2)
@cvanelteren
cvanelteren / complex_layout.py
Created June 10, 2021 13:47
Example of mosaic_layouts
import matplotlib.pyplot as plt, cmasher as cmr
import numpy as np
layout = np.zeros((10, 10), dtype = object)
layout[-1, :] = np.arange(1, 11)
layout[:, -1] = np.arange(20, 30)
fig = plt.figure(constrained_layout = 1)
axs = fig.subplot_mosaic(layout)
ax = axs.get(-1)