Skip to content

Instantly share code, notes, and snippets.

@mbafford
mbafford / .gitignore
Last active February 4, 2020 14:17
Quick and simple program to convert the Diecast podcast (http://www.shamusyoung.com/twentysidedtale/?cat=287) RSS feed into something my podcast reader can handle. It simply pulls the mp3 URL from the description and adds an enclosure element pointing at that URL.
diecast.xml
run.sh
original-rss.xml
.env/
@mbafford
mbafford / SONOS Pandora Ad Auto-Mute
Created March 11, 2015 14:17
You can't skip Pandora ads on Sonos (not even with UPNP commands), but you can mute them. This just watches for a Pandora ad playing and mutes the audio until the ad has finished. A much better approach is to just pay for Pandora.
#!/usr/bin/env python
import soco
import time
import re
# pandora song:
# {u'album': 'Everything All The Time', u'artist': 'Band Of Horses', u'title': 'The Funeral', u'uri': 'pndrradio-http://audio-ch1-t1-2-v4v6.pandora.com/access/?version=4&lid=3729520&token=slyAWqqgjJ8Bl3TgMB%2F03C4tamOHsLj%2BOQLq1T8xbiwSzkcoc253HeYbNFTcOP7K6Oy9GOq6tcaManOhyKDpECIiCENj7hjBsH%2FJVhJnDjLzyPRWjg8q0LtX1mn80yFiurvB1r0G0Be76YBZJUswLdWtNZtfYSO2y2WdYHSge8Ul2hML1MWvkv23AQjw9%2BAKPmIHXX8nUzfcfFfLfmyKk%2Flxwh2cf%2BvDrJIbnnVZfvlfirWhshENZDm7BBofIlUqR0qsPXWbYN5m7WD4bS3XCK4dedE0QtHIlBaGvNIwNrorp3j5EoZM%2BybBEigsDXg%2B9To1w30%2BRbV8V3o6hyM5lpviYM4icmRBYVVjmA4hlWOE7aOFqcNAPA%3D%3D&a=http%3a%2f%2fcont-sv5-3.pandora.com%2fimages%2fpublic%2famz%2f0%2f2%2f0%2f9%2f098787069020_500W_500H.jpg&m=94f084d4cda66036692600d16036898d258a387c7a546916b33f7d907698ddf0e59d86721b571e2bfd793b4d25efc3cc856420f223031811&f=1&r=0&g=-5.93&x=000020aa', u'playlist_position': '4', u'duration': '0:05:22', u'position': '0:03:09', u'album_art': 'http://cont-sv5-3.pando
@mbafford
mbafford / gist:d32c67fe8b8f56159e99
Created March 18, 2015 01:31
Google Location History to Heatmap
Download location history on takeout
https://www.google.com/settings/takeout
Extract and get json file
Convert json file to coordinates
python -c 'import sys, json; e7=10000000.0; locs = json.load(sys.stdin)["locations"]; print("\n".join( "%s %s" % ( loc["latitudeE7"]/e7, loc["longitudeE7"]/e7 ) for loc in locs ))' < LocationHistory.json > locations.lst
@mbafford
mbafford / litter_monitor
Created March 20, 2015 19:37
Arduino Nano w// Ethernet Support - Litter Box Monitor
#include <EtherCard.h>
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
int PIN_DETECTED = 6;
int PIN_CYCLING = 5;
int PIN_WAITING = 4;
int PIN_LED = 13;
void flash(int n, int d) {
@mbafford
mbafford / owntracks_mqtt_connect_error.md
Created April 9, 2015 01:35
owntracks: Invalid protocol "MQTT" in CONNECT

In case someone else is trying to search for this error and can't get it figured out.

In trying to set up Owntracks ( http://owntracks.org/ ) I was running into an error on connection.

The error logs from Mosquitto:

1428534995: New connection from 10.10.10.1 on port 8883.
1428534995: OpenSSL Error: error:140D9115:SSL routines:SSL_GET_PREV_SESSION:session id context uninitialized
1428534995: Socket read error on client (null), disconnecting.

1428535258: New connection from 10.10.10.1 on port 8883.

@mbafford
mbafford / summarizejson
Last active April 5, 2024 17:54
summarizejson - Summarize JSON Structure (keys and data types)
#!/usr/bin/env python
# Gives a quick summary of the structure of a JSON file, including the keys, object types, and
# leaf node types. Provides a count of each data type so you can quickly tell which data points
# are common.
#
# Example:
#
# $ curl -sS 'https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json' | python summarizejson
# 9191 {features}.[].{geometry}.{coordinates}.[].[].[].[].float
# 41 {features}.[].{geometry}.{coordinates}.[].[].[].[].int
@mbafford
mbafford / journey_cloud_json_to_evernote_enex.py
Last active August 20, 2022 12:08
Convert Journey.Cloud (Diary) JSON Export to Evernote Export (ENEX)
#!/usr/bin/env python3
# Converts the JSON export of Journey.Cloud diary entries into an Evernote Note Export format (ENEX) for easy import back into Evernote.
#
# This was a quick and dirty script to save someone the trouble of doing this process manually.
#
# Create/update date, journal text, location, and photos are preserved in the resulting Evernote Note.
import sys
import os
@mbafford
mbafford / osm-bulk-change-node-tags.py
Last active November 11, 2018 13:20
OSM API - search and bulk change
#!.env/bin/python
import overpass # https://github.com/mvexel/overpass-api-python-wrapper
import osmapi # http://osmapi.metaodi.ch/#osmapi.OsmApi.OsmApi.ChangesetClose
opass = overpass.API()
osm = osmapi.OsmApi( username = "USERNAME", password = "PASSWORD")
# nodes of interest were manually determined using a query on
# https://overpass-turbo.eu/
@mbafford
mbafford / naive-maven-mirror.py
Created May 9, 2020 23:22
A pretty naive mirror which will check a local folder for a Maven artifact, and if not found, fetch from the requested server.
#!/usr/bin/env python3
import sys
import os
import socket
import threading
import socketserver
import mimetypes
import shutil
from urllib import request, error
@mbafford
mbafford / dockerfile
Last active August 10, 2021 17:39
ical_to_gcal_sync dockerfile
# Quick and dirty docker build for andrewramsay's ical_to_gcal_sync script
# - copy a config.py on the host at /path/to/config.py ( https://github.com/andrewramsay/ical_to_gcal_sync/blob/master/config.py )
# - set all paths to be under /opt/config/ in the container
# - follow the readme steps from the repository
# can run as:
# docker run -it --rm --name 'ical_to_gcal_sync' -v /path/to/config.py:/opt/ical_to_gcal_sync/config.py -v /path/to/config/:/opt/config/ ical_to_gcal_sync
FROM python:3.8-slim-buster
WORKDIR /opt