Skip to content

Instantly share code, notes, and snippets.

View sbuys's full-sized avatar

Sebastian Buys sbuys

View GitHub Profile
/*!
* quantize.js Copyright 2008 Nick Rabinowitz.
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
// fill out a couple protovis dependencies
/*!
* Block below copied from Protovis: http://mbostock.github.com/protovis/
* Copyright 2010 Stanford Visualization Group
* Licensed under the BSD License: http://www.opensource.org/licenses/bsd-license.php
# Ruby script for parsing traceroute stream to JSON
require 'rubygems'
require 'open3'
require 'json'
#Array of top 25 US sites by Alexa rank (daily visits & pageviews)
destinations = %w{ google.com facebook.com yahoo.com youtube.com amazon.com wikipedia.org twitter.com ebay.com craigslist.org blogspot.com live.com msn.com go.com bing.com aol.com linkedin.com espn.go.com myspace.com cnn.com wordpress.com netflix.com paypal.com imdb.com flickr.com microsoft.com }
traceroutes = Hash.new()
require 'open3'
#Array of top 25 US sites by Alexa rank (daily visits & pageviews)
destinations = %w{ google.com facebook.com yahoo.com youtube.com amazon.com wikipedia.org twitter.com ebay.com craigslist.org blogspot.com live.com msn.com go.com bing.com aol.com linkedin.com espn.go.com myspace.com cnn.com wordpress.com netflix.com paypal.com imdb.com flickr.com microsoft.com }
destinations.each do |destination|
puts "\nTracing: #{destination}"
cmd_string = "traceroute -m 25 -w 1 #{destination}" #25 hops, 1s timeout
stdin, stdout, stderr = Open3.popen3(cmd_string)
stdout.each_with_index do |line, index|
/* XML Schema:
* <plusService>
* <status>
* <runList endIndex = "x" startIndex = "y">
* <run id="x" workoutType = "y">
* <startTime>
* <distance>
* <duration>
* <syncTime>
* <calories>
class Run {
int id;
String startTime;
String distance;
String duration;
int heartAvg;
int heartMin;
int heartMax;
String date;
void parseXML(String _doc){
String doc = _doc;
xml = new XMLElement(this, doc);
//Retrieve runList from plusService
//runList is the second child element of plusService, position = 1
XMLElement runList = xml.getChild(1);
int runCount = runList.getChildCount();
//println(runCount); //print to the console
HashMap runElements = new HashMap();
XMLElement xml;
int id;
String workoutType, startTime, date, time, distance, duration, heartrateAvgString, heartrateMinString, heartrateMaxString;
float k_to_m_conversion=1/1.609344;
float distance_k, distance_m;
float durationFloat;
int durationM, durationS;
int heartCount;