Skip to content

Instantly share code, notes, and snippets.

View phillipkent's full-sized avatar

Phillip Kent phillipkent

View GitHub Profile
@phillipkent
phillipkent / convert-docx.py
Last active November 7, 2023 09:19
Python code using the python-docx module to convert a DOCX file to another DOCX file
# Converts a docx file with tables and images to a new docx file
# The new file is based on a 'stub' document which contains preamble text and styles
#
# Requires the Python module 'python-docx' <https://python-docx.readthedocs.io>
# Written for Python 3
#
# Source documents are taken from the directory 'source' and converted documents are saved
# to the directory 'converted'
#
# Two types of source documents are handled: 'Fiscal Guide' or 'Economics Regime'. Each one
@phillipkent
phillipkent / convert-docx-to-html.py
Created April 17, 2019 12:27
Python code using the python-docx module to convert a DOCX file to HTML
# Converts a docx file with tables and images to (simple) HTML
# ORIGINAL CODE BY DAVID SSALI AT SOURCE: https://medium.com/@dvdssali/docx-to-html-1374eb6491a1
#
# Requires the Python module 'python-docx' <https://python-docx.readthedocs.io>
#
# Example use:
# >>> s = convert('./SOURCEDIR', 'SAMPLE.docx')
# >>> print(s)
# or
# $ python .\convert-docx-to-html.py > temp.html
#! /usr/bin/env python
# This program is configured for Python version 2.6/2.7
#
# Copyright (C) Interoute Communications Limited, 2016
#
# The config file should have the form:
# {"api_secret": "ABCDEFe17Pgc5WMs28Jwm3H4Drn9CZa3y2K1RiFj5x9S8TzQo64Yfk0L7GqXp71AdWe3k9E0NzPw56XpHd8n4",
# "api_key": "GHIJKL7H0XeKt25Ygi6ANp89JrWj46Fbo5L0Zfc7PTn1z9D3MwQy28EaBq42Sdk4RJd85SoHc0s6FBw39LyDp",
# "api_url": "https://apiserver.example.com/host/c6142d6b-69d8-4114-9721-a627a76f8cce"}
@phillipkent
phillipkent / citeulike_init_session.py
Created May 16, 2016 11:07
Using the 'requests' module in Python, initiate a session with citeulike.org and run queries on citeulike accounts
# citeulike_init_session.py
#
# by Phillip Kent
#
# Using the 'requests' module in Python [http://docs.python-requests.org], initiate a session with citeulike.org
# to generate a login cookie. A simple function cquery is defined to make queries on a specified citeulike account and
# return results as a Python dictionary (equivalent to JSON format)
#
# You can use this interactively on the Python commandline by running:
# $ python -i citeulike_init_session.py
@phillipkent
phillipkent / docker_test_haproxy.cfg
Created February 23, 2015 11:21
Example haproxy.cfg file for a Docker test installation of WordPress containers [http://cloudstore.interoute.com/main/knowledge-centre/blog/coreos-docker-vdc-part3]
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
user haproxy
group haproxy
defaults
log global
mode http
option httplog

"check-vm-state.sh" A shell script for using the Virtual Data Centre API

[content to come]

@phillipkent
phillipkent / cloudmonkey.json
Created July 23, 2014 09:49
Problem JSON object
{
"count": 12,
"virtualmachine": [
{
"account": "Interoute Tutorial",
"affinitygroup": [],
"cpunumber": 1,
"cpuspeed": 2000,
"cpuused": "0%",
"created": "2014-06-17T10:34:59+0000",
#!/usr/bin/python
#
# This file is part of cloudmonkey version 5.1.0
# [https://pypi.python.org/pypi/cloudmonkey/5.1.0]
# Modified for use with Interoute VDC
# [information: http://cloudstore.interoute.com/main/knowledge-centre/library/vdc-api-introduction-api]
#
#
@phillipkent
phillipkent / AnagramTest.java
Last active December 21, 2015 17:18
Anagram Test method in Java. Original question from Gayle Laakmann, "Cracking the Coding Interview", Chapter 1
// Anagram Test: Test if two strings are anagrams of each other
// Original question: Gayle Laakmann, "Cracking the Coding Interview", Chapter 1
//Anagram rules:
// spaces are ignored
// case is ignored
// punctuation is ignored
// letters a..z and digits 0..9 are significant (?)
//Program logic:
@phillipkent
phillipkent / nplustransform.py
Last active December 15, 2015 22:19
N-plus-transform: An implementation in Python of the Oulipo 'S+7' ('noun + 7') text transformation. [http://www.oulipo.net/contraintes/docs/s-7 , http://www.spoonbill.org/n+7/ ] Requires the NLTK toolkit http://nltk.org, and uses a nouns list sourced from http://www.ashley-bovan.co.uk/words/partsofspeech.html
'''
Created on 14 Mar 2013
@author: phillip
INCOMPLETE CODE UNDER DEVELOPMENT
'''
# Oulipo's 'N plus' transformation for text
#
# Words list 'nouns91k.txt' contains 91000 nouns, found at
# http://www.ashley-bovan.co.uk/words/partsofspeech.html