Skip to content

Instantly share code, notes, and snippets.

View jorgecarleitao's full-sized avatar

Jorge Leitao jorgecarleitao

  • Munin Data ApS
  • Copenhagen, Denmark
View GitHub Profile
@jorgecarleitao
jorgecarleitao / xapian_installer.sh
Last active September 10, 2022 06:30
Install Xapian in current Python virtualenv
#!/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
@jorgecarleitao
jorgecarleitao / set_plot_settings.py
Created July 4, 2017 09:13
A minimal change of settings parameters for quality images with matplotlib
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 February 17, 2017 15:33
A decorator of functions that stores a dictionary *args->result in a pickle and returns cached versions after first call
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 March 21, 2015 09:29
Installs Sphinx search on the machine. Useful for travis CI.
# 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 February 27, 2015 16:17
DB of portuguese public entities related to public health
# 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 January 14, 2015 18:10
Installs nginx in a local directory (e.g. for webfaction)
# prepare
VERSION=$1
DIRECTORY=$2
# download
curl -O http://nginx.org/download/nginx-$VERSION.tar.gz
# extract
tar -xzf nginx-$VERSION.tar.gz
# 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 13:01
Generates a unitary random vector in D dimensions
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);