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 / 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 / excel_to_numpy
Created June 27, 2014 07:48
Load Excel into numpy array
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
Note:
In numpy, every "append" action requires re-allocation of the array memory
and short-term doubling of memory requirements. So, the more general
solution is to allocate arrays to be as large as the final output of your
algorithm.
"""
import os
@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 / 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 / ticks.py
Last active February 3, 2024 13:20
Convert C# tick dates into a Python / readable date
# -*- coding: utf-8 -*-
"""
Purpose: Convert .NET ticks to formatted ISO8601 time
Author: D Hohls < dhohls@csir.co.za>
"""
from __future__ import print_function
import datetime
import sys
@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 / 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