Skip to content

Instantly share code, notes, and snippets.

@averagehuman
averagehuman / ibm-iot-register-device
Created February 27, 2018 10:08
Register an IoT device with IBM Watson IoT using curl
#!/bin/bash
command -v jq >/dev/null 2>&1 || {
echo >&2 "ERROR: jq is not installed. This is required for parsing json responses."; exit 1;
}
if [ $(id -u) != 0 ] || [ ! -w /etc ]; then
echo "ERROR: Requires root privileges (or write permissions to /etc). Try again with sudo."
exit 1
fi
@averagehuman
averagehuman / get_belfast_trees_csv.py
Last active February 13, 2022 11:06
Download data on Belfast Trees and convert from JSON to CSV
"""
Download information about approximately 38,000 trees in Belfast (N. Ireland) from
the opendatani.gov.uk data api and convert from JSON to CSV.
Usage::
$ python get_belfast_trees_csv.py <outfile>
where <outfile> is a local file path to which the csv file will be written.
"""
Use for anonymizing strings not for cryptographic purposes
Makes use of the following identities::
ord('1') % 48 == ord('a') % 48 == 1
ord('2') % 48 == ord('b') % 48 == 2
...
ord('6') % 48 == ord('f') % 48 == 6
@averagehuman
averagehuman / twitter-html-transform.py
Last active April 13, 2017 16:51
Markup twitter hashtags and usernames within a html fragment
#!/usr/bin/env python
"""
The twitter-text-python library (https://pypi.python.org/pypi/twitter-text-python) can be used
to urlify text containing @<username>s and #<hashtag>s. It is a bit trickier if you want to do
the same with HTML, but BeautifulSoup makes it straightforward.
"""
from bs4 import BeautifulSoup, NavigableString
from ttp import ttp
parse_text = ttp.Parser().parse
@averagehuman
averagehuman / make-info.py
Last active August 29, 2015 14:06
Resolve variable substitution in `make` include files by recursive interpolation.
#!/usr/bin/env python
"""
Resolve variable substitution in `make` include files by recursive interpolation.
Example:
$ ./info common.properties env.properties
or:
@averagehuman
averagehuman / postgres-docker-config.sh
Last active April 3, 2019 22:36
Run postgres on docker host, connect from docker containers
#!/bin/bash
################################################################################
# Rather than run postgres in its own container, we want to run it on
# the (Ubuntu) host and allow:
#
# + peer connections on the host
# + local md5 connections from any docker container
#
# THIS IS COPY/PASTED FROM COMMAND LINE INPUT AND IS UNTESTED AS A SINGLE SCRIPT
################################################################################
set-option -g status-keys vi
set-window-option -g mode-keys vi
set-window-option -g set-titles on
set -g set-titles-string "#T"
set-window-option -g mode-mouse on
setw -g terminal-overrides 'xterm*:smcup@:rmcup@'
@averagehuman
averagehuman / eclipse.vim
Last active December 30, 2015 21:19
vim color scheme - an eclipse-like theme by juandfrias with some customisations
" Vim color file
" Maintainer: Juan frias <juandfrias at gmail dot com>
" Last Change: 2007 Feb 25
" Version: 1.0.1
" URL: http://www.axisym3.net/jdany/vim-the-editor/#eclipse
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
@averagehuman
averagehuman / create-pg-user-and-db.sh
Last active December 25, 2015 16:19
postgres group role setup
#!/bin/bash
##########################################################################################
#
# create-pg-user-and-database
#
# The context here is a typical Django web app. If you have a single application instance
# then it is straightforward to create a database user with a randomised password, and a
# database which is owned by this user:
#