Skip to content

Instantly share code, notes, and snippets.

View gamesbook's full-sized avatar

Derek Hohls gamesbook

  • Independant Contractor
  • South Africa
View GitHub Profile
@gamesbook
gamesbook / hex_from_glyphicons.py
Last active August 29, 2015 14:06
Extract/find glyphicon name and hex code
"""
Uses the glyphicons.css file from http://glyphicons.com
To use:
python hex_from_glyphicons.py name
or:
python hex_from_glyphicons.py -all
"""
import sys
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Generate a value that occurs within a periodic cycle.
@author: dhohls@csir.co.za
"""
import numpy as np
import random
@gamesbook
gamesbook / obscure_words.py
Created December 30, 2013 10:35
Words...
import urllib2
import string
from BeautifulSoup import BeautifulSoup
#from bs4 import BeautifulSoup # if using BeautifulSoup4
name_out = '/path/to/Desktop/words.csv'
the_file_out = open(name_out, 'w')
for alpha in list(string.ascii_lowercase): # ['a','b','c']: #
@gamesbook
gamesbook / websocket_client.py
Created March 15, 2016 15:40
Simple Python Websocket Client
"""
Simple Web socket client implementation using Tornado framework.
Adapted from:
http://code.activestate.com/recipes/579076-simple-web-socket-client-\
implementation-using-torn/
Usage Example:
# stream messages to console
python websocket_client.py -s 127.0.0.1:9090/websocket
@gamesbook
gamesbook / swathe.py
Last active August 15, 2016 19:11
Generate a colour swathe from colours in an image
"""
Purpose: Generate a colour swathe from colours in an image
Author: D Hohls
Date: 2016/08/16
Requires:
pip install pillow
Usage:
python swathe.py -i IMAGE_IN.PNG -o IMAGE_OUT.PNG
If output (-o) not supplied, name will default to IMAGE_IN_swathe.PNG
@gamesbook
gamesbook / buzzphrase.py
Created October 31, 2016 06:09
Generate management buzzphrases from buzzwords
# -*- coding: utf-8 -*-
"""
Created on: Mon Oct 31 2016
Author: Derek Hohls
Purpose: generate management buzzphrases from buzzwords
BUZZ_WORDS are from http://bollocksphere.co.uk/Content/generationtable.shtml
"""
import random
@gamesbook
gamesbook / say_goodbye.py
Created January 10, 2017 10:44
Simple PyWPS demo for JSON input and output
# -*- 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
@gamesbook
gamesbook / xml_from_jinja.py
Created September 2, 2017 16:18
Show creating XML (with optional elements) from nested JSON via jinja2 templating
# -*- 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 September 4, 2017 07:42
Demonstrate use of Python's basic log operations
# -*- 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 / json_schema_validator.py
Created September 5, 2017 15:16
Python script to validate a JSON file against a schema
# -*- 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
"""