Skip to content

Instantly share code, notes, and snippets.

@ganeshv
ganeshv / README.md
Last active October 31, 2015 15:02
Life Expectancy Map

Life expectancy data for countries, obtained from Wikipedia and plotted with pigshell

ycat http://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy | hgrep -r 0 table.wikitable | table2js foo country data | iframe -g /usr/template/d3-worldmap1

Running through the pipeline step by step:

  • ycat uses YQL to retrieve the contents of the Wikipedia page. We use ycat to jump the same-origin barrier.
  • hgrep selects HTML elements using a jQuery/CSS-like expression.
  • table2js converts the table contents into plain Javascript objects, the
@ganeshv
ganeshv / README.md
Last active August 29, 2015 14:04
GDP time series - 2

GDP data for various countries, obtained from Quandl and plotted with pigshell

Similar to this, except we run the script in a non-interactive shell and dump output to the div. In most cases, the interactive shell is preferred as it gives the reader an opportunity of trying out their own variations, but occasionally you don't want the reader distracted by what's happening behind the curtain.

@ganeshv
ganeshv / README.md
Last active August 29, 2015 14:04
GDP time series

GDP data for various countries, obtained from Quandl and plotted with pigshell

Use up-arrow to walk through the command history and edit to select your own countries. Redirecting the output of the chart command to /downloads will cause a PNG file to be saved to the browser's download directory. e.g. echo $gdp | cut -f "Date,IND" | chart -t tseries >/downloads/india-gdp.png

@ganeshv
ganeshv / README.md
Last active August 29, 2015 14:04
Banana chips

Testing a Pigshell gist

@ganeshv
ganeshv / README.md
Last active August 13, 2017 13:04
Browserified cheerio.js.

Browserified Cheerio

Manually browserified cheerio.js. Edit 3 files, one in cheerio itself and two dependencies - lib/cheerio.js, - node_modules/domutils/index.js - node_modules/entities/index.js to replace dynamic "require" lines with static equivalents. Holds up to simple hand testing. cheerio is exposed in the browser as a global (window.cheerio).