Skip to content

Instantly share code, notes, and snippets.

View mbainrot's full-sized avatar

Max Bainrot mbainrot

  • Canberra, Australia
View GitHub Profile
@mbainrot
mbainrot / Perl play youtube
Created January 28, 2014 10:26
Simple little script to automatically play a youtube file in debian
#!/usr/bin/perl
$videoId = "PhGtxxxorPk";
$url = "https://www.youtube.com/watch/?v=$videoId";
$playURL = "https://www.youtube.com/embed/$videoId?rel=0&autoplay=1";
# Remove temp file
`rm temp.html`;
# Fetch "video"
$cmd = "wget -O temp.html \"$url\"";
@mbainrot
mbainrot / esp8266_homeautomation.lua
Created February 23, 2015 09:41
Work in progress script, having problems with debouncing and reliable triggering
m = mqtt.Client()
-- Configuration
host = "172.16.4.50"
port = 1883
queue = "/hello_8266"
bounceTimeout = 200
targetGpIO = 5
-- Internal Variables
@mbainrot
mbainrot / etc init.d home_automation
Last active August 29, 2015 14:18
Make a python + virtualenv run as a service
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
@mbainrot
mbainrot / gist:ea9e31f14060a0a205f4
Created April 25, 2015 23:57
Creation for the power monitoring table
CREATE TABLE IF NOT EXISTS `tbldailytotal` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`meterid` int(11) NOT NULL,
`day` int(11) NOT NULL,
`month` int(11) NOT NULL,
`year` int(11) NOT NULL,
`hour` int(11) NOT NULL,
`minute` int(11) NOT NULL,
`start_ts` int(11) NOT NULL,
`end_ts` int(11) NOT NULL,
#!/bin/bash
# For use with ubuntu 14.04 LTS, might work for ubuntu 14.10 though ymmv
add-apt-repository ppa:mapnik/boost
apt-get update
apt-get install libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-system-dev libboost-thread-dev
apt-cache policy libboost-dev
@mbainrot
mbainrot / cron
Last active August 29, 2015 14:22
Timelapse Script
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
@mbainrot
mbainrot / process_act_toilet_data.py
Created July 5, 2015 12:17
ACT Coordiniate System Info
EPSG Code - EPSG::5825
Name - AGD66 / ACT Standard Grid
Conversion: http://epsg.io/5825
proj4: +proj=tmerc +lat_0=-35.31773627777778 +lon_0=149.0092948305555 +k=1.000086 +x_0=200000 +y_0=600000 +ellps=aust_SA +towgs84=-117.808,-51.536,137.784,0.303,0.446,0.234,-0.29 +units=m +no_defs
WKT: PROJCS["AGD66 / ACT Standard Grid",GEOGCS["AGD66",DATUM["Australian_Geodetic_Datum_1966",SPHEROID["Australian National Spheroid",6378160,298.25,AUTHORITY["EPSG","7003"]],TOWGS84[-117.808,-51.536,137.784,0.303,0.446,0.234,-0.29],AUTHORITY["EPSG","6202"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4202"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",-35.31773627777778],PARAMETER["central_meridian",149.0092948305555],PARAMETER["scale_factor",1.000086],PARAMETER["false_easting",200000],PARAMETER["false_northing",600000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG
@mbainrot
mbainrot / get_all_petrol_stations2.py
Created November 29, 2015 04:31
Queries an OSM PostGIS database for all the petrol stations along a GPX route (obtained via openrouteservice).
#!/usr/bin/python3.4
import psycopg2
import xmltodict
import pickle
datafile = "/home/max/Desktop/map2.gpx"
with open(datafile) as fd:
oGpxFile = xmltodict.parse(fd.read())
X:12.00 Y:29.00 Z:2.90
# UP
G1 Z4.50 F100
# DOWN
G1 Z2.50 F100
# TOP LEFT
G1 X12 Y29 F1200
@mbainrot
mbainrot / bash commands ran to clean up stuff.sh
Created July 30, 2016 08:11
Troublesome entries in ABCnewsmetadata.csv, this file is a diff of the original metadata csv and the one after I killed 36ish bad entires that where causing the import to fail. Quickly looking at it, it appears mostly to be unescaped double quotes. Seems like the only seperator that wouldn't cause any trouble is an open curly brackets.
echo "COPY article_meta_raw FROM '/tmp/ABCnewsmetadata.sedded.csv' DELIMITER ',' CSV HEADER;" > meh.sql
sed '31121d' /tmp/ABCnewsmetadata.csv > /tmp/ABCnewsmetadata.sedded.csv; cat meh.sql | psql govhack2016
sed '46943d' /tmp/ABCnewsmetadata.sedded.csv > /tmp/ABCnewsmetadata.sedded.csv.tmp; mv /tmp/ABCnewsmetadata.sedded.csv.tmp /tmp/ABCnewsmetadata.sedded.csv; cat meh.sql | psql govhack2016
sed '76305d' /tmp/ABCnewsmetadata.sedded.csv > /tmp/ABCnewsmetadata.sedded.csv.tmp; mv /tmp/ABCnewsmetadata.sedded.csv.tmp /tmp/ABCnewsmetadata.sedded.csv; cat meh.sql | psql govhack2016
sed '98705d' /tmp/ABCnewsmetadata.sedded.csv > /tmp/ABCnewsmetadata.sedded.csv.tmp; mv /tmp/ABCnewsmetadata.sedded.csv.tmp /tmp/ABCnewsmetadata.sedded.csv; cat meh.sql | psql govhack2016
sed '110072d' /tmp/ABCnewsmetadata.sedded.csv > /tmp/ABCnewsmetadata.sedded.csv.tmp; mv /tmp/ABCnewsmetadata.sedded.csv.tmp /tmp/ABCnewsmetadata.sedded.csv; cat meh.sql | psql govhack2016
sed '118533d' /tmp/ABCnewsmetadata.sedded.csv > /tmp/ABCnewsmetadat