Skip to content

Instantly share code, notes, and snippets.

Avatar

Derek Hohls gamesbook

  • CSIR
  • South Africa
View GitHub Profile
@gamesbook
gamesbook / hex_from_glyphicons.py
Last active Aug 29, 2015
Extract/find glyphicon name and hex code
View hex_from_glyphicons.py
"""
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
View simulator.py
#!/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
View obscure_words.py
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 Mar 15, 2016
Simple Python Websocket Client
View websocket_client.py
"""
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 Aug 15, 2016
Generate a colour swathe from colours in an image
View swathe.py
"""
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 Oct 31, 2016
Generate management buzzphrases from buzzwords
View buzzphrase.py
# -*- 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 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
@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 / 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
"""