Skip to content

Instantly share code, notes, and snippets.

Avatar

Jorge Leitao jorgecarleitao

  • Munin Data ApS
  • Copenhagen, Denmark
View GitHub Profile
@jorgecarleitao
jorgecarleitao / set_plot_settings.py
Created Jul 4, 2017
A minimal change of settings parameters for quality images with matplotlib
View set_plot_settings.py
import matplotlib.pyplot as plt
def set_plot_settings(font_size=18):
# a font that is very close to LaTeX.
plt.rcParams['mathtext.fontset'] = 'stix'
plt.rcParams['font.family'] = 'STIXGeneral'
# ticks with the same width as axis, and consistent with font size (below)
plt.rcParams['axes.linewidth'] = 1
plt.rcParams['xtick.major.width'] = 1
@jorgecarleitao
jorgecarleitao / cache.py
Created Feb 17, 2017
A decorator of functions that stores a dictionary *args->result in a pickle and returns cached versions after first call
View cache.py
import os
import pickle
def cache(file_name):
"""
A decorator to cache the result of the function into a file. The result
must be a dictionary. The result storage is in pickle
"""
def cache_function(function):
@jorgecarleitao
jorgecarleitao / install_sphinx.sh
Created Mar 21, 2015
Installs Sphinx search on the machine. Useful for travis CI.
View install_sphinx.sh
# usage: `bash -c "$(curl -fsSL <gist_url>)" <version>
VERSION=$0
wget http://sphinxsearch.com/files/sphinx-$VERSION-release.tar.gz
tar -xf sphinx-$VERSION-release.tar.gz
cd sphinx-$VERSION-release
./configure --with-pgsql
make
make install
@jorgecarleitao
jorgecarleitao / pt_health_entities.dat
Created Feb 27, 2015
DB of portuguese public entities related to public health
View pt_health_entities.dat
# name, Fiscal number
Gabinete do Ministro da Saúde;600052303
Gabinete do Secretario de Estado Adjunto do Ministro da Saúde;600071006
Gabinete do Secretario de Estado da Saúde;600052290
Secretaria-Geral do Ministério da Saúde;600080684
Direcção-Geral da Saúde;600037100
Instituto da Droga e da Toxicodependência;506452654
Inspecção-Geral das Actividades Saúde;600018857
Autoridade para os Serviços de Sangue e da Transplantação;600082695
Alto Comissariado da Saúde;600082709
@jorgecarleitao
jorgecarleitao / nginx_installer.sh
Created Jan 14, 2015
Installs nginx in a local directory (e.g. for webfaction)
View nginx_installer.sh
# prepare
VERSION=$1
DIRECTORY=$2
# download
curl -O http://nginx.org/download/nginx-$VERSION.tar.gz
# extract
tar -xzf nginx-$VERSION.tar.gz
@jorgecarleitao
jorgecarleitao / xapian_installer.sh
Last active Apr 14, 2020
Install Xapian in current Python virtualenv
View xapian_installer.sh
#!/usr/bin/env bash
# first argument of the script is Xapian version (e.g. 1.2.19)
VERSION=$1
# prepare
mkdir $VIRTUAL_ENV/packages && cd $VIRTUAL_ENV/packages
CORE=xapian-core-$VERSION
BINDINGS=xapian-bindings-$VERSION
View .gitignore
# Exact copy of original, https://gist.github.com/adamgit/3786883,
# but removed comments.
# OS related
.DS_Store
*.swp
*.lock
profile
# Xcode related
@jorgecarleitao
jorgecarleitao / gist:a7ef61d4d918ee8059d6
Created May 21, 2014
Generates a unitary random vector in D dimensions
View gist:a7ef61d4d918ee8059d6
std::vector<double> unitaryVector(unsigned int dimension)
{
std::vector<double> vector(dimension);
double norm = 0;
for (unsigned int d = 0; d < dimension; d++)
{
vector[d] = grandom(); // RNG call for a gaussian with mean=0 and sigma=1
norm += vector[d]*vector[d];
}
norm = sqrt(norm);