Skip to content

Instantly share code, notes, and snippets.

View hoogenm's full-sized avatar

Marc van den Hoogen hoogenm

  • The Netherlands
View GitHub Profile
@hoogenm
hoogenm / gaphviz.txt
Created October 24, 2018 10:26
gaphviz on Jupyter
Cell 1:
!conda install -y graphviz
Cell 2:
%load_ext graphviz
Cell 3 (example use):
import pyproj
def RD_to_wgs(x, y):
rd_projection = pyproj.Proj("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812 +units=m +no_defs")
wgs84_projection = pyproj.Proj(proj='latlong',datum='WGS84')
lat, lon, _ = pyproj.transform(rd_projection, wgs84_projection, x, y, 0.0)
return [lat, lon]
@hoogenm
hoogenm / swish.py
Last active June 30, 2018 08:25
Swish ANN Activation Function (for Keras)
import keras
keras.utils.generic_utils.get_custom_objects().update({'swish': keras.layers.Activation(lambda x: keras.backend.sigmoid(x) * x)})
@hoogenm
hoogenm / install_gophernotes.sh
Created February 5, 2018 19:08
Setup go and gophernotes (Jupyter go) on Centos/Fedora
#!/bin/bash
# For Fedora/Centos/RHEL
# Install go, add to path, install gophernotes
GO_VERSION = 1.9.3
cd ~
wget https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz
tar -xvzf go${GO_VERSION}.linux-amd64.tar.gz
sudo mv go /usr/local/
@hoogenm
hoogenm / vim_color_scheme.md
Created August 23, 2017 09:05
Solve dark blue color(s) in VIM

Add the following line to .vimrc: :color desert

@hoogenm
hoogenm / clear-iptables.sh
Created August 16, 2017 11:39
Clear ip tables (and accept)
#!/bin/bash
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t raw -F
iptables -t raw -X
iptables -P INPUT ACCEPT
@hoogenm
hoogenm / bluray_backup.sh
Created August 7, 2017 18:41
Shell script to backup a folder on a Blu-ray disc
#!/bin/bash
# Script to backup a folder to a Blu-ray medium
# 1) Change /dev/sr1 (if /dev/sr1 is not [the device name of] your bluray burning device)
# 2) Change ~/folder_to_backup into you choice of folder to backup (be aware of BR capacity, typically max 25 GiB)
# 3) Prior to running the script, installation of 'xorriso' is required and probably available in your distro packages
# Credit goes to Thomas Schmitt for providing a helpful explanation of xorriso.
@hoogenm
hoogenm / Mtrix.py
Created August 6, 2017 20:09
Matlab-like Matrix-constructor for Python's sympy
import sympy as sp
def Mtrix(matrix_def):
'''
Constructs a Sympy Matrix from the string matrix_def that has a Matlab-like syntax:
E.g.: Mtrix("a b c; d e f; g h i") creates a 3x3 matrix where [a b c], [d e f], [g h i] are the rows.
Example: Mtrix("0 1/2 7; 3 -4 8; 17/3 4 87")
@hoogenm
hoogenm / roman_to_int.py
Created July 9, 2017 15:30
Roman numerals (Roman numbers) to integer (concisely in Python)
def roman_to_int(roman_string):
symbol_groups = [{'IV': 4, 'IX': 9, 'XL': 40, 'XC': 90, 'CD': 400, 'CM': 900},
{'M': 1000,'D': 500 ,'C': 100,'L': 50,'X': 10,'V': 5,'I': 1}]
result = 0 # initially
for symbol_group in symbol_groups:
for symbol, value in symbol_group.items():
result += roman_string.count(symbol) * value
roman_string = roman_string.replace(symbol, '')
@hoogenm
hoogenm / to_pdf.sh
Last active April 16, 2017 13:34
nbconvert to PDF, with smaller margins and smaller 8pt font (Linux)
# Script takes one parameter: ipynb source filename WITHOUT the .pynb extension
# Results in a specialized .pdf version, with smaller margins (wider page) and smaller font size (i.e. more text on a line)
# Tested with up-to-date jupyter/nbconvert version on April 16th, 2017
jupyter nbconvert --to latex $1.ipynb
# -i for inplace substitution, -r for full regex
sed -r -i 's/documentclass\[11pt\]\{article\}/documentclass[8pt]{extarticle}/' $1.tex
sed -r -i 's/geometry\{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}/geometry{verbose,tmargin=0.5in,bmargin=0.5in,lmargin=0.2in,rmargin=0.2in}/' $1.tex
pdflatex $1
rm $1.tex; rm $1.out; rm $1.aux; rm $1.log