Skip to content

Instantly share code, notes, and snippets.

View evansde77's full-sized avatar

Dave Evans evansde77

View GitHub Profile
@evansde77
evansde77 / pythonic_config.py
Created February 12, 2016 17:10
Example of wrapping a nested JSON config object in a simple python object that allows dynamic object.attr style access to the data elements
#!/usr/bin/env python
"""
example of using a simple python object to wrap a JSON
configuration mapping so that it can be accessed as
a python style object using conf.attr1.attr2.value
"""
CONF = {
"CREDENTIALS": {
def post(self):
"""
Create a new user document in the users and cluster users database.
:json string username: required, the requested username
:json string password: required, the requested password
:json string email: required, and email address to be associated
with the account
:json string first_name: required, the user's first name
:json string last_name: required, the user's last name
:json string company: optional, the user's company
@evansde77
evansde77 / pyfile_to_module.py
Last active May 26, 2016 18:11
Util to convert filenames to python module names as a command line tool
#!/usr/bin/env python
"""
pyfile_to_module
Simple util to convert a python filename like
some_package/some_module/some_file.py to some_package.some_module.some_file
style module name.
"""
import argparse
@evansde77
evansde77 / word_count_histogram.py
Last active February 10, 2021 12:14
Playing around with an ascii histogram example
#!/usr/bin/env python
"""
Example wordcount and ascii histogram script
- Writes a data file in a temporary dir
- defines function to parse file into a word iterable
- Histogram class that does the word count and draws it as
ascii strings with various sorting options
Example usage:
@evansde77
evansde77 / install_pillow.sh
Created June 8, 2016 15:40
Steps to install libjpeg and pillow on Max OSX 10.11.15 (assumes XCode, XCode command line tools etc)
sudo chmod -R a+rw /usr/local/src
mkdir /usr/local/src
chmod a+rw -R /usr/local/src
curl --remote-name http://www.ijg.org/files/jpegsrc.v9b.tar.gz
tar -xzvf jpegsrc.v9b.tar.gz
cd jpeg-9b
./configure --enable-shared --enable-static
make
sudo make install
sudo ranlib /usr/local/lib/libjpeg.a
@evansde77
evansde77 / setup.sh
Last active December 5, 2016 23:19
Python Environment Setup on MacOSX
#!/bin/bash
# assumes that XCode and XCode command line tools have been installed
# xcode-select --install
# assumes that gfortran has been installed
# https://gcc.gnu.org/wiki/GFortranBinaries
# install pyenv & set 2.7.11 as current
# See: https://github.com/yyuu/pyenv-installer
# See: https://github.com/yyuu/pyenv
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
@evansde77
evansde77 / format_pandas_df_html.py
Created July 12, 2016 19:17
Formatting Pandas HTML to add styles example
import pandas
import numpy
# random data with columns A, B, C, D
df = pandas.DataFrame(numpy.random.randn(50, 4), columns=list('ABCD'))
#
# style helpers
@evansde77
evansde77 / mock_examples.py
Last active September 9, 2020 15:21
examples of performing mock.patch actions in three different but equivalent ways
#!/usr/bin/env python
"""
mock examples
"""
import os
import unittest
import mock
import functools