Skip to content

Instantly share code, notes, and snippets.

@bmcbride
bmcbride / thumbnail.sql
Last active August 22, 2016 21:43
Get a direct link to the thumbnail of the first image in a photo field with Fulcrum data shares. Useful for pulling an image into a CartoDB image header info window.
SELECT *, CASE WHEN photos != '' THEN left(photos_url, position('/view' in photos_url)) || split_part(photos, ',', 1) || '/thumbnail.jpg' ELSE photos END AS thumbnail FROM my_fulcrum_table
@wboykinm
wboykinm / .block
Last active June 10, 2016 15:11 — forked from mbostock/.block
Papua coast histogram
license: gpl-3.0
height: 1452
@nickpeihl
nickpeihl / README.md
Last active April 5, 2017 16:24
NDVI With ArcGIS Image Services and Geojson.io
  1. Go here: http://geojson.io/#map=18/34.12668/-84.11506

  2. Open the browser developer console - ctrl + shift + k on Firefox or ctrl + shift + i on Chrome.

  3. Type the following into the browser console: window.api.map.addLayer(L.tileLayer('http://tileify-ags.herokuapp.com/tiles/{z}/{x}/{y}?url=https%3A%2F%2Fgis.apfo.usda.gov%2Farcgis%2Frest%2Fservices%2FNAIP%2FGeorgia_2015_1m%2FImageServer&renderingRule=%7B%20%20%20%22rasterFunction%22%20%3A%20%22NDVI%22%2C%20%20%20%22rasterFunctionArguments%22%20%3A%20%7B%20%20%20%20%20%22VisibleBandID%22%20%3A%202%2C%20%20%20%20%20%22InfraredBandID%22%20%3A%203%20%20%20%7D%2C%20%20%20%22variableName%22%20%3A%20%22Raster%22%20%7D'));

  4. Try replacing the ArcGIS Image Service URL with a different URL from here. Be sure to encode the URL correctly. For help encoding go here

[More info on ArcGIS Image Service Raster

@bmcbride
bmcbride / fulcrum-data-share-cartodb-webhook.js
Created September 18, 2015 01:30
Fulcrum Data Share CartoDB Webhook
function doPost(e){
return handleResponse(e);
}
function handleResponse(e) {
var jsonString = e.postData.getDataAsString();
var payload = JSON.parse(jsonString);
var formId = "my-form-id";
var shareToken = "my-data-share-token";
var cartodbTable = "my-cartodb-table";
@bmcbride
bmcbride / fulcrum-report-rename.sh
Last active July 22, 2016 00:14
Fulcrum PDF reports are named with the record's unique fulcrum_id. This bash script loops through the parent CSV file and renames the PDF files based on the index of user-specified fields.
#!/bin/bash
INPUT=fire_hydrants.csv
OLDIFS=$IFS
IFS=,
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read -a csv_line
do
mv ${csv_line[0]}.pdf ${csv_line[8]}-${csv_line[0]}.pdf
done < $INPUT
@JavaScript-Packer
JavaScript-Packer / base64-encode-decode.js
Created July 1, 2015 00:45
Perfect ATOB/BTOA alternatives (Base64 encoder/decoder) for JavaScript/Jscript.net Demo on http://jsfiddle.net/1okoy0r0/
function b2a(a) {
var c, d, e, f, g, h, i, j, o, b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", k = 0, l = 0, m = "", n = [];
if (!a) return a;
do c = a.charCodeAt(k++), d = a.charCodeAt(k++), e = a.charCodeAt(k++), j = c << 16 | d << 8 | e,
f = 63 & j >> 18, g = 63 & j >> 12, h = 63 & j >> 6, i = 63 & j, n[l++] = b.charAt(f) + b.charAt(g) + b.charAt(h) + b.charAt(i); while (k < a.length);
return m = n.join(""), o = a.length % 3, (o ? m.slice(0, o - 3) :m) + "===".slice(o || 3);
}
function a2b(a) {
var b, c, d, e = {}, f = 0, g = 0, h = "", i = String.fromCharCode, j = a.length;
@wboykinm
wboykinm / decode_osrm.js
Created June 10, 2015 14:20
Get a GeoJSON-friendly linestring from a Valhalla/OSRM route request
// Get a GeoJSON-friendly linestring from a Valhalla/OSRM route request
// Adapted from
// https://github.com/DennisSchiefer/Project-OSRM-Web/blob/develop/WebContent/routing/OSRM.RoutingGeometry.js
// Usage: decode(<"shape" object>, 6) //(precision = 6 seems legit)
var decode = function(encoded, precision) {
var len = encoded.length,
index = 0,
lat = 0,
lng = 0,
array = [];
@jczaplew
jczaplew / README.md
Last active August 29, 2015 14:19
Rolling tiles with mapnik + tilestache instead of Tilemill

Rolling tiles sans Tilemill

Perhaps you've had problems programmatically creating tiles with Tilemill, or are concerned about the future stability of project (or you just like playing with geo software).

Install mapnik and TileStache

brew install mapnik --with-gdal --with-postgresql
sudo pip install -U PIL modestmaps simplejson werkzeug
git clone https://github.com/TileStache/TileStache.git TileStache
cd TileStache
@wboykinm
wboykinm / cr-leaflet.js
Last active May 2, 2018 19:22
Census reporter GeoJSON tiles
CensusReporter = {
GeoIDLayer: L.GeoJSON.extend({
addGeoID: function(geoid) {
var request = new XMLHttpRequest();
var url = this.options.api_url + "/1.0/geo/show/tiger2013?geo_ids=" + geoid;
request.open('GET', url, true);
var self = this;
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
@bmcbride
bmcbride / fulcrum_email_webhook.gs
Last active November 17, 2019 00:39
Simple Google Apps Script, which can be used as a Fulcrum webhook endpoint to email the webhook JSON payload for debugging. Required URL parameter: email. Optional URL parameter: form (Fulcrum form_id).
function doPost(e){
return handleResponse(e);
}
function handleResponse(e) {
var email = e.parameter.email;
var form = e.parameter.form;
var jsonString = e.postData.getDataAsString();
var payload = JSON.parse(jsonString);
var subject = "Fulcrum Webhook Payload";