Skip to content

Instantly share code, notes, and snippets.

View ewalstad's full-sized avatar

Eric Walstad ewalstad

  • Nevada City, CA, USA
View GitHub Profile
@ewalstad
ewalstad / gist:11119429
Created April 20, 2014 17:11
Mege GPX tracks
gpsbabel -t -i gpx -f a.gpx -i gpx -f b.gpx -x track,merge -o gpx -F combined.gpx
@ewalstad
ewalstad / csv_utils.py
Last active January 2, 2016 15:48
Utilities to help with using CSV IO. See also: http://docs.python.org/2/library/csv.html#csv-examples
#-*- coding:utf-8 -*-
"""
====================================
Utilities to help with using CSV IO
====================================
Example usage
-------------
See: https://github.com/ewalstad.keys
@ewalstad
ewalstad / top_disk_pigs.sh
Created December 26, 2013 16:54
List the 10 directories or files that are consuming the most disk space. Requires one argument, the top directory to search.
function ds(){
# A script to list the 10 directories or files that are consuming the most
# disk space.
# Requires one argument, the top directory to search
du -hs $(du --max-depth=1 $1 \
| sort -nr \
| mawk -W interactive '{printf("%s\n", $2)}' \
| head -n 10 \
| tail -n 10)
}
@ewalstad
ewalstad / find_python_source.sh
Created December 26, 2013 16:52
Change to the directory containing the Python module passed as the first argument. Thanks Chris Lamb: http://chris-lamb.co.uk/2010/04/22/locating-source-any-python-module/
function cdp(){
# Change to the directory containing the Python module passed as the first
# argument.
# http://chris-lamb.co.uk/2010/04/22/locating-source-any-python-module/
cd "$(python -c "import os.path as _, ${1}; \
print _.dirname(_.realpath(${1}.__file__[:-1]))"
)"
}
@ewalstad
ewalstad / virtualenvwrapper_python.sh
Last active January 1, 2016 11:09
bash_aliases snippet for choosing the correct Python version for, andsourcing of, virtualenvwrapper.
# Tell virtualenvwrapper to use the python that was used to install
# virtualenv. It's the full path after the shebang (#!)
# This should keep us from seeing virtualenvwrapper errors re: "hooks"
VIRTUALENVWRAPPER_PYTHON=`head -1 $(which virtualenv) | cut -d ! -f 2`
source $(which virtualenvwrapper.sh)
-- currency_plus(val NUMERIC, decimals INT DEFAULT 2)
-- Returns a US Dollar formatted string.
-- Takes one required argument, the value to be formatted
-- and one optional argument, decimals, the number of decimal places to
-- display (default is 2 decimal places).
--
-- Example Usage:
-- currency_plus(123.45678) -> '$123.46'
-- currency_plus(123.45678, 0) -> '$123'
-- currency_plus(123.45678, 3) -> '$123.457'

Python Number Conversion Chart

From To Expression
@ewalstad
ewalstad / pg_dump_ssh.sh
Last active December 9, 2015 22:48
Transfer a db from one host to another from your local host. Dump the database on $SRC over ssh to the $TEST server. Load the db into the $DEST server using psql from the $TEST server.
DEST="destination.example.com"
SRC="source.example.com"
TEST="testserver.example.com"
DB="my_db"
SSHER="mysshuser"
ssh -C $SSHER@$SRC "pg_dump $DB" | ssh -C $TEST "cat > /tmp/$DB.pgdump && dropdb -h$DEST $DB ; createdb -h$DEST $DB -E UTF-8 && psql -h$DEST $DB < /tmp/$DB.pgdump && rm /tmp/$DB.pgdump"
@ewalstad
ewalstad / classtionary.py
Last active October 8, 2022 15:42
A Python class-like dictionary, or dictionary-like class, that allows access to values using dot notation. See the docstring for example usage.
class Classtionary(dict):
"""A Class, er, dictionary, um, attributes-as-keys thingy.
>>> c = Classtionary(foo="bar")
>>> d = dict(foo="bar")
>>> c, d
({'foo': 'bar'}, {'foo': 'bar'})
>>> c.fizz = "bang"
>>> d.fizz = "bang"
Traceback (most recent call last):