Skip to content

Instantly share code, notes, and snippets.

View openfirmware's full-sized avatar

James Badger openfirmware

View GitHub Profile
@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 / 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],

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 / gist:9555e0459ca3e6e7c594
Last active November 22, 2016 23:42
Logstash Template for ElasticSearch
curl -XPUT localhost:9200/_template/logstash -d '
{
"template" : "logstash-*",
"settings" : {
"index.refresh_interval" : "5s"
},
"mappings" : {
"_default_" : {
"_all" : {"enabled" : true},
"dynamic_templates" : [ {
@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
@openfirmware
openfirmware / README.markdown
Last active January 17, 2024 11:15
Restoring ZFS Snapshots of PostgreSQL Database

ZFS Snapshots and PostgreSQL

I recently set up a host running Ubuntu 14.04 LTS, ubuntu-zfs, and PostgreSQL 9.3. Using the ZFS snapshot feature I was able to make a snapshot of the file system holding the PostgreSQL database, write the snapshot to a compressed file, transfer it to another Ubuntu 14.04 LTS host running ubuntu-zfs, restore it, and launch PostgreSQL using that data directory with all the data (seemingly) intact.

The database is very low-traffic, so I do not know how effective this strategy would be for a busier database.

I take no responsibility if you attempt this setup and it causes data loss or other issues. Use it at your own risk; this document is meant to explain a potential setup and open discussion about limitations and potential improvements.

First Host Setup

@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 / README.markdown
Created April 1, 2014 18:40
roar-rails nested association pagination example

Roar-rails and representing AssocationRelations with Pagination

The roar-rails gem can be used to generate custom REST representations of resources for your Rails application. If you have an app with any sort of nested resources, then you may not have many found examples of representing the layers of resources. Here is one that I've found works and is mostly straight forward.

As the routes file and models show, it is just a simple has_many/belongs_to relationship. You likely want to show representations of the resources: People, Person, Pets for Person, and Pet. Writing representers for People, Person, and Pet are simple enough, and the roar-rails documentation explains it. There are multiple ways to represent the Pets for a Person; which is a resource in its own right. Because it is a resource, it should have its own representation: PersonPetsRepresenter.

A simple way is to respond_with @person and then read the #pets relation in the

@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 / dummy_server.sh
Created November 12, 2013 20:32
For Rails Engines, to start the dummy server with a single command. Save in `bin` directory, and make executable with chmod. Will pass arguments along to `rails server` (e.g. `-p 8080`).
#!/bin/bash
cd "test/dummy" && rails server $@