Skip to content

Instantly share code, notes, and snippets.

#### 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.
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:]
'''
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 / 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 / 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')
#!/bin/sh
# btsync service
# Replace with linux users you want to run BTSync clients for
BTSYNC_USERS="mendel"
DAEMON=/usr/bin/btsync
start() {
for btsuser in $BTSYNC_USERS; do
HOMEDIR=`getent passwd $btsuser | cut -d: -f6`
config=$HOMEDIR/.sync/config.json
#!/usr/bin/env bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv
# determine if virtualenv is activated
python -c 'import sys; print(sys.real_prefix)' 2>/dev/null && INVENV=1 || INVENV=0
if [ ! $INVENV == 1 ]; then
echo "You must activate a virtualenv for this to work."
exit -1
fi
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
@alexsavio
alexsavio / kickstart
Last active January 4, 2016 00:18 — forked from ludo/kickstart
install
# Ridiculous URL... I know...
url --url http://nl.archive.ubuntu.com/ubuntu/ubuntu/ubuntu/ubuntu/ubuntu/
text
lang en_US
langsupport en_US
keyboard es
#rootpw pa$$word # you should replace, and use --iscrypted
@alexsavio
alexsavio / useful_pandas_snippets.py
Created February 27, 2016 22:51 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]