Skip to content

Instantly share code, notes, and snippets.

Avatar

Derek Hohls gamesbook

  • CSIR
  • South Africa
View GitHub Profile
@gamesbook
gamesbook / bgg_games.py
Last active Apr 27, 2018
Create summary of BoardGameGeek.com games
View bgg_games.py
# -*- coding: utf-8 -*-
from __future__ import print_function
import csv
# via https://github.com/lcosmin/boardgamegeek
from boardgamegeek import BoardGameGeek
import logging
logging.basicConfig()
GAMES = """Monopoly
@gamesbook
gamesbook / dice_histogram.py
Created Apr 1, 2018
Histogram for two dice of any size
View dice_histogram.py
"""
https://stackoverflow.com/questions/33454739/distribution-of-dice-rolls
&
https://stackoverflow.com/questions/20335617/unlimited-sides-to-dice-in-simulator/
"""
from collections import Counter
import sys
from random import randint
# Python 2/3 compatibility
@gamesbook
gamesbook / fee2metres.py
Created Oct 16, 2017
Convert imperial units (feet, inches) to metres
View fee2metres.py
# -*- coding: utf-8 -*-
""" Purpose: Convert imperial units (feet, inches) to metres
Created: 2017-10-17
Author: dhohls@csir.co.za
Notes:
This is quite useful if you have a house plan where all the units are
Imperial (typically American or old European plans) and you need to
compare against modern plans.
@gamesbook
gamesbook / xml_validation.py
Created Sep 27, 2017
Use lxml to validate an XML file against a Schema (XSD)
View xml_validation.py
# -*- coding: utf-8 -*-
""" Purpose: Use lxml to validate an XML file against a Schema (XSD)
Created: 2017-09-27
Author: dhohls@csir.co.za
Requires::
pip install lxml
@gamesbook
gamesbook / extract_directives.py
Created Sep 24, 2017
Extract and print directives from files in a software project
View extract_directives.py
# -*- coding: utf-8 -*-
""" Purpose: Extract and print directives from a software project.
Created: 2017-09-24
Contact: gamesbook@gmail.com
Usage::
python extract_directives.py
python extract_directives.py -d=/path/to/ -i=FIXME -e=js
@gamesbook
gamesbook / log_to_sentry.py
Created Sep 6, 2017
Capture shell script output via Python logging to Sentry.io
View log_to_sentry.py
# -*- coding: utf-8 -*-
"""Purpose: Capture shell script output via Python logging to Sentry.io.
Setup:
First export the SENTRY_DSN value in your .bashrc file. Then::
pip install raven --upgrade
pip install autoenv
echo "source bin/activate" > .env
@gamesbook
gamesbook / json_schema_validator.py
Created Sep 5, 2017
Python script to validate a JSON file against a schema
View json_schema_validator.py
# -*- coding: utf-8 -*-
""" Purpose: Use Python schema module to validate JSON files vs a schema.
Created: 2017-09-05
Author: dhohls@csir.co.za
Usage::
python json_schema_validator.py --json=ajsonfile.json --schema=aschemafile.json
"""
@gamesbook
gamesbook / xml_from_jinja.py
Created Sep 2, 2017
Show creating XML (with optional elements) from nested JSON via jinja2 templating
View xml_from_jinja.py
# -*- coding: utf-8 -*-
"""Purpose: Show creating XML from nested JSON with optional elements.
Created: 2017-09-03
Author: dhohls@csir.co.za
"""
from __future__ import print_function
from jinja2 import Template
xml_template = """<?xml version="1.0" encoding="UTF-8"?>
@gamesbook
gamesbook / logging_demo.py
Last active Sep 4, 2017
Demonstrate use of Python's basic log operations
View logging_demo.py
# -*- coding: utf-8 -*-
""" Purpose: Demonstrate use of Python's basic log operations
Created: 2017-09-01
Contact: dhohls@csir.co.za
Usages::
python logging_demo.py
python logging_demo.py -ll=ERROR
@gamesbook
gamesbook / say_goodbye.py
Created Jan 10, 2017
Simple PyWPS demo for JSON input and output
View say_goodbye.py
# -*- coding: utf-8 -*-
"""
Purpose: Demo of basic PyWPS JSON functionality (requires PyWPS v4.0.x)
Created: 10-01-2017
Author: dhohls@csir.co.za
Adapted from:
https://github.com/geopython/pywps-demo/blob/master/demo.py
"""
import json