Skip to content

Instantly share code, notes, and snippets.

@alexsavio
alexsavio / python_logging.py
Last active September 12, 2015 10:53 — forked from abhiomkar/python_logging.py
Python Logging Cheatsheet
import logging
# prints to stdout
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(format=FORMAT)
log = logging.getLogger(__file__)
log.setLevel(logging.DEBUG)
# prints log to stdout and also saves to specified log file
log = logging.getLogger('my_logfile')
@alexsavio
alexsavio / install_pyqt_venv.sh
Created August 3, 2015 09:13
Install sip and PyQt in the current virtualenv.
#!/bin/bash
qmake_path=$1
if [ -z "${qmake_path}" ]; then
qmake_path=`which qmake`
fi
echo "Using qmake from ${qmake_path}. If you want to change, usage: install_pyqt_venv.sh qmake_path"
cwd=`pwd`
siproot=`find . -type d -name 'sip-*'`
@alexsavio
alexsavio / autolog.py
Last active August 29, 2015 14:21 — forked from beng/autolog.py
# Written by Brendan O'Connor, brenocon@gmail.com, www.anyall.org
# * Originally written Aug. 2005
# * Posted to gist.github.com/16173 on Oct. 2008
# Copyright (c) 2003-2006 Open Source Applications Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@alexsavio
alexsavio / mcmc
Last active October 2, 2020 22:35 — forked from osdf/gist:5133737
Simple MCMC sampling with Python
"""
Some python code for
Markov Chain Monte Carlo and Gibs sampling
by Bruce Walsh
"""
import numpy as np
import numpy.linalg as npla
@alexsavio
alexsavio / example_google.py
Created November 4, 2014 15:28
Docstring examples
# -*- coding: utf-8 -*-
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
@alexsavio
alexsavio / embed-font-to-svg.py
Last active July 22, 2019 07:08
CLI to embed font-face base64 encoding to SVG files or clear text output for CSS importing
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import os.path as op
import base64
import argparse
import logging
from lxml import etree
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
These computations rely on nearest-neighbor statistics
'''
import numpy as np
@alexsavio
alexsavio / ipynb_present.py
Created September 8, 2014 18:56
IPython notebook presentation launcher.
#!/usr/bin/env python
import os
import shutil
import tempfile
import logging
import argparse
import subprocess
@alexsavio
alexsavio / upper_diagonal_indices
Last active August 29, 2015 14:05
One liner for loop on upper diagonal indices of a square matrix (n_elems X n_elems) (k=0 to include the diagonal)
import numpy as np
for x_idx, y_idx in zip(*np.triu_indices(n_elems, k=1)):
@alexsavio
alexsavio / copy_subtitles_sync.py
Last active December 25, 2016 23:38
CLI command that reads the time data from one SRT file, the speech text from another, mixes them and saves the result into a new srt file.
#!/usr/bin/env python
import os
import os.path as path
import argparse
import logging
from chardet.universaldetector import UniversalDetector
from pysrt import SubRipFile, SubRipItem
logging.basicConfig(level=logging.INFO)