Skip to content

Instantly share code, notes, and snippets.

@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).

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

Testing a Pigshell gist

@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
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 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 October 31, 2015 15:00
Life Expectancy - Orthographic Projection

Life expectancy data for countries, obtained from Wikipedia and plotted with pigshell on an orthographic projection. The template is based on Rotate the world by Jason Davies. Colors by Cynthia Brewer

ycat http://en.wikipedia.org/wiki/List_of_countries_by_life_expectancy | hgrep -r 0 table.wikitable | table2js foo country data | iframe -o proj=orthographic -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
World Map Template

World map chloropleth template

This template follows pigshell's convention for "gist templates":

  • It is supplied data using postMessage(), as a single object of the form { opts: {...}, data: [...] }
  • It posts a message to the parent with an object of the form { height: <number> } to enable the framing context to adjust the height of the iframe.
  • If the URL does not contain a hash fragment, it displays sample data from the containing gist.
@ganeshv
ganeshv / .block
Last active June 5, 2024 17:05
Zoomable Treemap Template
license: gpl-3.0
@ganeshv
ganeshv / README.md
Last active August 29, 2015 14:04
GDP Treemap

Countrywise GDP data for 2012 obtained from Quandl visualized using the Zoomable Treemap Template

Click a cell to zoom in. Click the orange bar at the top to zoom out.

@ganeshv
ganeshv / 2014-electoral-rolls3.csv
Last active August 29, 2015 14:05
India's Voter Sex Ratio
key STATE_CODE PC_NO STATE PC_NAME 18-19 Male 18-19 Female 18-19 Others Above 18 Male Above 18 Female Above 18 Others Electors with EPIC Electors with Photo
AN1 AN 1 ANDAMAN AND NICOBAR ISLANDS ANDAMAN AND NICOBAR ISLANDS 1529 1370 0 136356 121500 0 254093 254093
AP1 AP 1 ANDRA PRADESH ADILABAD 30191 20152 16 674909 686044 132 1361085 1361085
AP2 AP 2 ANDRA PRADESH PEDDAPALLE 23342 15088 19 702419 676669 93 1379181 1379181
AP4 AP 4 ANDRA PRADESH NIZAMABAD 23285 13463 5 701661 749739 64 1451464 1451464
AP5 AP 5 ANDRA PRADESH ZAHIRABAD 21456 11559 8 703663 712913 60 1416636 1416636
AP3 AP 3 ANDRA PRADESH KARIMNAGAR 24941 15453 8 755526 751194 67 1506787 1506787
AP6 AP 6 ANDRA PRADESH MEDAK 26421 14428 12 749671 737580 84 1487335 1487335
AP7 AP 7 ANDRA PRADESH MALKAJGIRI 49191 31744 20 1596146 1357475 294 2953915 2953915
AP14 AP 14 ANDRA PRADESH BHONGIR 22289 12421 7 739084 717775 44 1456903 1456903