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": {
@evansde77
evansde77 / mock_requests.py
Last active January 31, 2024 08:49
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError
@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 / 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 / Gumbo.txt
Created December 13, 2020 21:43
Gumbo
Gumbo
Ingredients:
6 Cajun style andouille sausages or smoked sausage or mix
4 boneless skinless chicken thighs
1 lb raw shrimp, peeled, deveined, chopped
1 cups flour
1/2 cup peanut oil
@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
@evansde77
evansde77 / Recipe.md
Created February 23, 2020 14:42
Gumbo recipe

Ingredients

  • 4 Cajun style andouille sausages
  • 6 boneless skinless chicken thighs
  • 1 lb raw shrimp, peeled, deveined, chopped
  • 2 cups flour
  • 1 cup peanut oil
  • 1 cup canola oil
  • 2 onions
  • 2 green bell peppers
(base) root@0343625ee20e:/opt/unicron/imc-unicron-jupyter# conda list
# packages in environment at /opt/conda:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main
asn1crypto 1.0.1 py37_0
attrs 19.2.0 py_0
backcall 0.1.0 py37_0
bleach 3.1.0 py37_0
ca-certificates 2019.8.28 0
from contextlib import contextmanager
@contextmanager
def context1(arg):
print("Bronte")
yield "Tolkien"
print(arg)
@evansde77
evansde77 / mac_install_hdfs3.sh
Created July 5, 2017 21:15
Installation steps to install hdfs3 and underlying libhdfs3 on a Mac
#
# required downloading source of cmakem protobuf, gsasl as well as hdfs3
#
mv ~/Downloads/cmake-3.9.0-rc5.tar.gz .
tar -zxf cmake-3.9.0-rc5.tar.gz
cd cmake-3.9.0-rc5
./bootstrap && make
sudo make install