Skip to content

Instantly share code, notes, and snippets.

@alexsavio
alexsavio / pip-update
Last active August 29, 2015 13:56
Python script to use pip and upgrade all packages in the currently activated virtualenv.
#!/usr/bin/env python
import os
import sys
import subprocess
env_root = os.getenv('VIRTUAL_ENV')
if sys.platform == 'win32':
bin = 'Scripts'
#### Start IPython, generate SHA1 password to use for IPython Notebook server
$ ipython
Python 2.7.5 |Anaconda 1.8.0 (x86_64)| (default, Oct 24 2013, 07:02:20)
Type "copyright", "credits" or "license" for more information.
IPython 1.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
@alexsavio
alexsavio / repo.py
Created June 25, 2014 14:19
GitHub to Gitlab repository version copier/control.
#content of the config file .python-gitlab.cfg:
#[global]
#default = local
#ssl_verify = true
#[local]
#url = http://***************
#private_token = **************
import colorsys
def hex_to_rgb(hex_str):
"""Returns a tuple representing the given hex string as RGB.
>>> hex_to_rgb('CC0000')
(204, 0, 0)
"""
if hex_str.startswith('#'):
hex_str = hex_str[1:]
@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 / 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
'''
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 / 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 / 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 / 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-*'`