Skip to content

Instantly share code, notes, and snippets.

View caged's full-sized avatar
🎸

Justin Palmer caged

🎸
View GitHub Profile
@caged
caged / spina-pro-messages.md
Last active January 8, 2025 15:28
Getting started with spina pro message inbox.

Spina Pro Message Inbox Setup

As of 01/07/2025, the Spina Pro Messages guide is unpublished, making it a little difficult getting up and running with message inboxes. Below is information I've peiced together while trying to get it running. Hopefully it can help the next person.

Prerequisites

  • Spina pro installed using this guide.
  • You have config.plugins = [ "Pro" ] set in your config/spina.rb config.

Generate your Message object

@caged
caged / d3-server.js
Last active October 17, 2023 04:05
Directly render and serve d3 visualizations from a nodejs server.
// Start `node d3-server.js`
// Then visit http://localhost:1337/
//
var d3 = require('d3'),
http = require('http')
http.createServer(function (req, res) {
// Chrome automatically sends a requests for favicons
// Looks like https://code.google.com/p/chromium/issues/detail?id=39402 isn't
// fixed or this is a regression.
@caged
caged / README.md
Last active March 11, 2023 18:50 — forked from mbostock/.block
Using d3-tip to add tooltips to a d3 bar chart
@caged
caged / create-psql-database.sh
Last active March 1, 2023 06:15
Shell script to import data into Postgres from https://www.nhgis.org. If you use this, you'll need to edit line 14 to include the census data you're importing.
#!/bin/sh
# usage ./create-psql-database DATABASE
#
DB_NAME=$1
FOLDER_NAME="nhgis0004"
# Drop and recreate database
dropdb --interactive "${DB_NAME}"
createdb --encoding UTF8 $DB_NAME
@caged
caged / scale.rb
Created November 22, 2012 04:04
Linear scale interpolation in Ruby based on d3.js's implementation
# Returns a lambda used to determine what number is at t in the range of a and b
#
# interpolate_number(0, 500).call(0.5) # 250
# interpolate_number(0, 500).call(1) # 500
#
def interpolate_number(a, b)
a = a.to_f
b = b.to_f
b -= a
lambda { |t| a + b * t }
@caged
caged / .gitignore
Last active February 26, 2022 23:33
US Federal Judicial Districts
.DS_Store
node_modules
us-judicial-districts.zip
build
@caged
caged / svg-to-png.js
Created January 27, 2013 18:11
Convert SVG's to PNGs. This works OK if the SVG's styles are inline. The SVG element must contain an xmlns attribute. Webkit also requires you specify a font size on `text` elements.
var svg = document.getElementById('graph'),
xml = new XMLSerializer().serializeToString(svg),
data = "data:image/svg+xml;base64," + btoa(xml),
img = new Image()
img.setAttribute('src', data)
document.body.appendChild(img)
@caged
caged / point-dispersal.sql
Last active July 24, 2021 11:26
Naive dispersal of overlapping points in PostGIS
drop table if exists inspection_point_buffers;
-- Group identical overlapping points and count how many occupy
-- the space.
create temporary table inspection_overlappoing_points as
select a.geom as geom,
count(*)
from latest_inspections a,
latest_inspections b
where st_equals(a.geom, b.geom)
@caged
caged / graphite.md
Created March 3, 2012 20:25
Installing Graphite on OS X Lion

This is a general overview (from memory) of the steps I used to install graphite (http://graphite.wikidot.com) on OS X Lion. I think the steps are in order but YMMV. Please fork and fix if you find an error.

Install Python 2.7.2

brew install python

Check your env

$ python --version
WITH
bad_geometries AS (SELECT
(a.p_geom).path[1] AS path,
(a.p_geom).geom
FROM
(
SELECT
st_dump(shape) AS p_geom
FROM
us_district_court_jurisdictions