Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@westurner
westurner / broadband_cap.py
Last active August 29, 2015 13:57
Calculate time to reach broadband cap with specified bandwidth speeds
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
from __future__ import division
"""
broadband_cap
==============
Calculate time to reach broadband cap with specified bandwidth speeds
Usage::
@westurner
westurner / imgcomp.py
Created November 27, 2013 06:48
Recompress an image with PIL a number of times.
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
"""
imgcomp -- [re]compress an image multiple times, saving intermediate output
* https://en.wikipedia.org/wiki/JPEG
* https://en.wikipedia.org/wiki/Generation_loss
"""
@westurner
westurner / README.rst
Last active December 18, 2015 01:29
Draft 00: HTTP Problem JSON Object --> HTTP Problem RDFS/OWL Ontology in Turtle
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
"""
parse_editable_url
"""
import urllib
import urlparse
import logging
@westurner
westurner / rst_shift.py
Created September 16, 2012 23:21
ReStructuredText Heading Shift
#!/usr/bin/env python
"""
A utility for modifying ReStructuredText headings by the
specified shift offset.
For example::
==========
Title
==========
@westurner
westurner / gist:3723284
Created September 14, 2012 17:08
To Remember
from pandas import DataFrame, Series, Index
N = 1.7
index2 = Index(range(0,200))
uhh = [(n**N) for n in index2[:95]]
uhh.extend( (n**(-N)) for n in index2[95:100] )
uhh.extend( uhh )
series = Series(uhh, index=index2)
uhh2 = uhh[:95]
uhh2.extend( (uhh[-6],)*5 )
@westurner
westurner / mobile_voice_data.py
Last active October 10, 2015 17:08
Mobile data/voice cost comparison
AMR = {'12.20':12.20}
def calculate_data_mb(minutes=10, kbps=AMR['12.20']):
seconds = minutes*60
kilobits = (kbps*seconds) / 8.0
mb = float(kilobits) / 1024.0
return mb
def data_transfer_in_minutes(transfergb=0.134, kbps=AMR['12.20']):
gbits = transfergb * 1024**3 * 8.0
@westurner
westurner / pulse.sh
Created September 9, 2012 02:00
PulseAudio Configuration
#!/bin/bash -x
export PULSE_SERVER=127.0.0.1
DEFAULT_COOKIE="/etc/pulse/default_cookie"
SOUNDCHECK="/usr/share/sounds/alsa/Front_Center.wav"
# see: http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules#module-native-protocol-.7Bunix.2Ctcp.7D
COOKIE_CONFIG="auth-anonymous=0 auth-cookie-enabled=1 \
auth-cookie=${DEFAULT_COOKIE}"
# COOKIE_CONFIG="${COOKIE_CONFIG} auth-ip-acl=127.0.0.0/8;192.168.0.0/24"
@westurner
westurner / setup_pandas_notebook_deb.sh
Created August 5, 2012 15:35
Setup IPython Notebook and Pandas for Ubuntu
#!/bin/sh -x
# Setup IPython Notebook and Pandas for Ubuntu
IPYTHONDIR="${VIRTUAL_ENV}/src/.ipython"
IPYTHON_NOTEBOOK_DIR="${VIRTUAL_ENV}/src/notebooks"
IPYTHON_NOTEBOOK_SH="${VIRTUAL_ENV}/bin/ipython_notebook.sh"
setup_python_dev () {
sudo apt-get install -y build-essential python-dev python-setuptools \
python-pip python-virtualenv virtualenvwrapper