Skip to content

Instantly share code, notes, and snippets.

View adg29's full-sized avatar
📱

Alan Garcia adg29

📱
View GitHub Profile
@adg29
adg29 / README.md
Created April 21, 2016 17:32 — forked from dmachat/README.md
Map click + updateChoropleth bug
@adg29
adg29 / Contentful Visual Search with Paid Post Components.markdown
Last active May 6, 2016 06:38
Contentful Visual Search with Paid Post Components
@adg29
adg29 / topojson-csv-merge.md
Last active July 24, 2017 04:28
How to merge external properties from a CSV into a topojson

##External Properties

Please see this visual editor that is available for editing properties of a topojson file.

Please refer to the external properties section of the Command Line Reference for the topojson tool to learn about how to merge properites from an external CSV file into an existing topojson file.

##Merging a region property for each country in Asia and Africa The output topojson should contain a modified properties object for each country in Asia or Africa. For example:

@adg29
adg29 / JSONToCSVConvertor.js
Created May 31, 2016 19:21
JSONToCSVConvertor
function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel) {
//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var CSV = '';
//Set Report title in first row or line
CSV += ReportTitle + '\r\n\n';
//This condition will generate the Label/Header
<?xml version="1.0" encoding="UTF-8"?>
<gpx creator="StravaGPX" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<trk>
<name>Tour de France - Etape 20... MAGIQUE!</name>
<trkseg>
<trkpt lat="45.2027360" lon="6.6691160">
<ele>0.0</ele>
</trkpt>
<trkpt lat="45.2027360" lon="6.6691160">
<ele>1061.0</ele>
@adg29
adg29 / README.md
Last active July 26, 2016 15:29 — forked from monfera/.block
circinus

Playing with reusing d3.geo for plotting. Subsequent example: http://bl.ocks.org/monfera/11085004

Mike Bostock and Jason Davies have added cool geo features, some of which can be of interest for regular data plotting too (most of which not covered in this example):

  1. The use of projections to easily change between Cartesian, polar, spiral, etc. plots
  • d3.geo supports spherical projections; this example projects a sphere-bound spiral
  1. Traditional, but data-intensive plots can benefit from adaptive resampling and line simplification
@adg29
adg29 / concat.js
Created August 22, 2016 21:17
Concat Handlebars helper
module.exports.register = function (Handlebars, options) {
Handlebars.registerHelper('concat', function() {
var outStr = '';
for(var arg in arguments){
if(typeof arguments[arg]!='object'){
outStr += arguments[arg];
}
}
return outStr;
@adg29
adg29 / tdf-2015-stage-1-top10.csv
Created September 7, 2016 21:29
TDF 2015 Stage Top 10 Results Data
Rank Rider Team Time Seconds Time Label
1 Rohan Dennis (AUS) BMC Racing Team 0 14' 56"
2 Tony Martin (GER) Etixx–Quick-Step 5 + 5"
3 Fabian Cancellara (SUI) Trek Factory Racing 6 + 6"
4 Tom Dumoulin (NED) Giant–Alpecin 8 + 8"
5 Jos Van Emden (NED) LottoNL–Jumbo 15 + 15"
6 Jonathan Castroviejo (ESP) Movistar Team 23 + 23"
7 Matthias Brandle (AUT) IAM Cycling 23 + 23"
8 Adriano Malori (ITA) Movistar Team 29 + 29"
9 Wilco Kelderman (NED) LottoNL–Jumbo 30 + 30"
@adg29
adg29 / README.md
Created September 21, 2016 19:13 — forked from veltman/README.md
Smoother polygon transitions

Smooth transitioning US tour in the same vein as this example. Steps:

  1. Compares both shapes and adds evenly-spaced points to whichever polygon has fewer so that both have the same number of points
  2. Picks the winding of the first polygon that minimizes the sum of the squared distances between point pairs

Some possible improvements:

  • Adding additional points to both shapes first such that every segment longer than a certain distance is bisected
  • Tweaking the placement of added points with simulated annealing
  • Using a cost function that factors in self-intersections at the halfway mark in addition to distance traveled
@adg29
adg29 / index.js
Last active December 16, 2016 22:40
express server rendering nutritionix fooditem JSON response after request-promise request
var express = require('express')
var rp = require('request-promise')
var bodyParser = require("body-parser");
var app = express()
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());