Skip to content

Instantly share code, notes, and snippets.

View openfirmware's full-sized avatar

James Badger openfirmware

View GitHub Profile
@openfirmware
openfirmware / ntc-agent.nut
Created February 4, 2014 20:54
Updated version of my NTC device and agent code, for use with the newer Electric Imp IDE and Xively.
const FEED_ID = "HERE";
const API_KEY = "YOUR KEY";
function send_xively(body) { //take in csv value
local xively_url = "https://api.xively.com/v2/feeds/" + FEED_ID + ".csv"; //setup url for csv
server.log(xively_url);
server.log(body); //pring body for testing
local req = http.put(xively_url, {"X-ApiKey":API_KEY, "Content-Type":"text/csv", "User-Agent":"Xively-Imp-Lib/1.0"}, body); //add headers
local res = req.sendsync(); //send request
if(res.statuscode != 200) {
server.log("error sending message: "+res.body);
@openfirmware
openfirmware / gist:fc582a0cd4f19091e520
Last active August 29, 2015 14:01 — forked from mtigas/gist:952344
Merge in details from other tutorial.

Client-side SSL

For excessively paranoid client authentication.

Using a Central Certificate Authority

See other tutorials.

Self-Signed Certificate

@openfirmware
openfirmware / check_zfs.pl
Last active August 29, 2015 14:03
check_zfs for nagios, updated for open-zfs
#!/usr/bin/perl -w
# check_zfs Nagios plugin for monitoring ZFS zpools
# Copyright (c) 2014-2015
# Written by James Badger
# Released under the GNU Public License
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by

Keybase proof

I hereby claim:

  • I am openfirmware on github.
  • I am jamesbadger (https://keybase.io/jamesbadger) on keybase.
  • I have a public key whose fingerprint is CBC3 4794 FE8E 75E4 1069 7966 262D 1CF1 48CD CC9A

To claim this, I am signing this object:

@openfirmware
openfirmware / convert.rb
Created November 5, 2014 19:09
Osmosis replag output converter
#!/usr/bin/env ruby -KU
# Convert output from osmosis to CSV for spreadsheets.
# Usage: ./convert.rb output
file = ARGV[0]
def parse(line)
matches = line.match(/^\[([^\]]+)\] \d+ start import from seq-nr (\d+), replag is (\d+) day\(s\) and (\d+) hour\(s\)$/)
{
date: matches[1],
@openfirmware
openfirmware / projection.markdown
Last active August 29, 2015 14:25
Notes on osm2pgsql and Mapnik

Custom Projection Import with osm2pgsql and Mapnik

This note is about building a web map tile server using OpenStreetMap data and the Mapnik stack.

osm2pgsql is a tool for importing data from OpenStreetMap database extracts into PostgreSQL. By default, it imports into Spherical Mercator (900913) and that is great if you want to build a web map tile server that serves tiles in Spherical Mercator projection. If however you want to use a custom projection to enhance the display of geometry in a specific region, you can import using a custom projection.

For this example I will use EPSG:3573, a projection that vastly improves visualization of geography in the Arctic. To do the import, you can modify your osm2pgsql import command to include a reprojection (-E):

$ sudo docker run -d --

@openfirmware
openfirmware / check_replag.sh
Created July 27, 2015 20:12
Nagios-compatible script for reporting the replag of a mod_tile tile server
#!/bin/bash -e
# check_replag Nagios plugin for monitoring mod_tile replag value
# Copyright (c) 2015
# Written by James Badger
# Released under the GNU Public License
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@openfirmware
openfirmware / 6147-patch.diff
Created December 16, 2010 02:01
[PATCH] Fix find_or_create_by_x on association bug [#6147 state:resolved]
From 12c8326e8c6c1f21a6b56f4d0a5fcdb932d0fa56 Mon Sep 17 00:00:00 2001
From: James Badger <Jamesbadger@gmail.com>
Date: Wed, 15 Dec 2010 15:55:51 -0700
Subject: [PATCH] Fix find_or_create_by_x on association bug [#6147 state:resolved]
Commit fdfc8e3b9c4905057677fd009f463a377be60b93 fixed the
find_or_create_by_x find() being confused by the extra parameters,
but the create_by_x code from b64d1fe637d16916c59e2ddec403d9c7cd54b0f8
does not convert the array properly for create(). This patch allows
sending of params with additional hash attributes by changing the
@openfirmware
openfirmware / gist:747804
Created December 19, 2010 23:03
Return iTunes Selection
(*
Return the quoted paths of the currently selected tracks in iTunes
Returns error if iTunes is not running
Call from command line with 'osascript -e itunes_selection.scpt'
*)
on run
tell application "System Events"
if (name of processes) contains "iTunes" is false then
return "Error: iTunes is not running"
@openfirmware
openfirmware / gist:748778
Created December 20, 2010 18:32
A really quick and dirty script to parse log files, look for errors, and send a report to multiple email addresses
#!/usr/bin/env ruby
require 'date'
require 'net/smtp'
# Who to send the report to
RECIPIENTS = %w( me@example.com )
# Who the message will be sent as
FROM_ADDRESS = "root@example.com"