Skip to content

Instantly share code, notes, and snippets.

filetype on
filetype plugin on
filetype indent on
syntax on
set number
set cursorline
set showmode
set showmatch
set hlsearch
set history=1000
@pierdom
pierdom / manual_settings.py
Created February 27, 2020 15:16
[Typeform style for Matplotlib] #python #matplotlib #datascience #visualization #typeform
import matplotlib.pylab as plt
import seaborn as sns
import matplotlib
sns.set_style('whitegrid')
matplotlib.rcParams['figure.figsize'] = [9, 5]
matplotlib.rcParams['figure.facecolor'] = "#f2ece3"
matplotlib.rcParams['axes.facecolor'] = "#f2ece3"
matplotlib.rcParams['legend.facecolor'] = "#f2ece3"
@pierdom
pierdom / shift_labels.py
Created January 27, 2020 11:31
[Shift xaxis labels by 0.5 in matplotlib/seaborn] #python #visualization #datascience #matplotlib
mybins = [0, 1, 2, 3, 4, 5]
ax = sns.distplot(my_df.my_col, bins=mybins)
_ = ax.xaxis.set(ticks=np.arange(0.5, len(mybins)), ticklabels=mybins)
@pierdom
pierdom / my_simple_speed_test.sh
Created July 29, 2019 12:58
[Measure transfer speed with SSH server] #sysadmin #networking #ssh
ssh <user>@<server> "head -c 200M </dev/urandom" | dd of=/dev/null
@pierdom
pierdom / synology_syncthing_certificate.md
Last active August 17, 2022 03:16
[Use Synology default certificate for Syncthing Web UI] #synology #sysadmin

This how-to has been tested using a Synology DS214play nas with DSM 6.X and Syncthing v1.1.4.

Default Synology certificate and private key (e.g., released by Let's Encrypt) at this path: /usr/syno/etc/certificate/system/default/{cert.pem|privkey.pem}.

After installing Syncthing using synocommunity.com repository, its self-signed certificate will be at this path: /volume1/@appstore/syncthing/var/. This directory contains the priv-pub key to identify the device (cert.pem and key.pem) and the certificate and private key for the web interface (https_cert.pem and https_key.pem). We need to replace these last two with the Synology's ones.

Backup Syncthing certificate:

@pierdom
pierdom / groupby_agg_example.py
Created October 4, 2018 13:15
[Passing custom function to agg function in Pandas (with name!)] #pandas #datascience
# define a custom function that calculates the percentile using numpy
def perc(n):
def perc_(x):
return np.percentile(x, n)
perc_.__name__ = 'perc_%s' % n
return perc_
# apply this function (and other stuff) to Pandas Groupby
df.groupby(['group_key_1', 'group_key_2']).agg({
'col_a': np.sum,
@pierdom
pierdom / shapely_to_geojson.py
Created August 17, 2018 08:17
[Convert a shapely Polygon to GeoJson using GeoPandas] from: https://stackoverflow.com/questions/51486454/convert-geopandas-shapely-polygon-to-geojson #python #datascience #gis
In [1]: from shapely.geometry import Point
In [2]: import geopandas as gpd
In [3]: shapely_polygon = Polygon([(0, 0), (0, 1), (1, 0)])
In [4]: gpd.GeoSeries([shapely_polygon]).__geo_interface__
Out[4]:
{'bbox': (0.0, 0.0, 1.0, 1.0),
'features': [{'bbox': (0.0, 0.0, 1.0, 1.0),
'geometry': {'coordinates': (((0.0, 0.0),
@pierdom
pierdom / ssh_config
Created August 14, 2018 09:14
[Example of .ssh/config entry] #linux #sysadmin #networking
Host my_shortcut
HostName my_hostname
User my_username
Compression yes
ServerAliveInterval 60
@pierdom
pierdom / python_x11_colors.py
Created June 22, 2018 09:38
[Using X11 colors] #python #visualization
cnames = {
'aliceblue': '#F0F8FF',
'antiquewhite': '#FAEBD7',
'aqua': '#00FFFF',
'aquamarine': '#7FFFD4',
'azure': '#F0FFFF',
'beige': '#F5F5DC',
'bisque': '#FFE4C4',
'black': '#000000',
'blanchedalmond': '#FFEBCD',