Skip to content

Instantly share code, notes, and snippets.

@hubgit
hubgit / programmes-segments.js
Last active August 29, 2015 13:55
Fetch all music segments broadcast on BBC Radio
// fetch all the music brands available on iPlayer
$.programmes.get('genres/music/player').done(function(data) {
var programmes = data.category_slice.programmes;
programmes.forEach(function(brand) {
// fetch episodes available on iPlayer for a single brand
$.programmes.get(brand.pid + '/episodes/player').done(function(data) {
// the latest episode
var episode = data.episodes[0].programme;
@hubgit
hubgit / albums-of-the-year-2013.txt
Created February 5, 2014 11:06
Albums of the Year 2013, by number of tracks starred in Spotify
Dinosaur Pile-Up - Nature Nurture (4)
Bass Drum Of Death - Bass Drum Of Death (4)
Nirvana - In Utero - 20th Anniversary - Deluxe Edition (4)
The Bronx - The Bronx (IV) (3)
All Pigs Must Die - Nothing Violates This Nature (3)
Samantha Crain - Kid Face (2)
Kromosom - Live Forever (2)
Uncle Acid & The Deadbeats - Mind Control (2)
Mazes - Ores & Minerals (2)
Jackson And His Computer Band - Glow (2)
@hubgit
hubgit / README.md
Last active August 29, 2015 13:56
Data Package JSON experiments
@hubgit
hubgit / README.md
Last active August 29, 2015 13:56
Tabular Data Package suggestions

TODO

  • specify fixed rows and columns (allow multiple, rows are headings, columns are primary keys)
  • allow multiple values in a cell, or point to a separate CSV file for repeated values in a column?
  • annotations as JSON-LD
@hubgit
hubgit / download-files.js
Last active August 29, 2015 13:56
Download files from Google search results
var links = Array.prototype.filter.call(document.querySelectorAll('a'), function (a) {
var href = a.getAttribute('data-href') || a.getAttribute('href');
return href && href.match(/\.xls$/)
});
var run = function () {
console.log(links[0]);
links.shift().click();
if (links.length) window.setTimeout(run, 1000)
};
@hubgit
hubgit / list-files.js
Last active August 29, 2015 13:56
Generate a list of files from Google search results
// localStorage.setItem('files-xls', null)
var lines = JSON.parse(localStorage.getItem('files-xls')) || [];
var links = Array.prototype.slice.call(document.querySelectorAll('a'));
links.map(function(link) {
return link.getAttribute('data-href') || link.getAttribute('href');
}).filter(function(href) {
return href && href.match(/\.xls$/);
@hubgit
hubgit / save-data.js
Last active August 29, 2015 13:56
Save data to a CSV file
var blob = new Blob([lines.join('\n')], { type: 'text/csv' });
window.location.href = URL.createObjectURL(blob);
@hubgit
hubgit / nature-xls.txt
Created February 12, 2014 12:36
Excel files from nature.com
http://www.nature.com/ni/journal/v5/n6/extref/ni1070-S1.xls
http://www.nature.com/ni/journal/v9/n1/extref/ni1534-S2.xls
http://www.nature.com/ni/journal/v6/n5/extref/ni1188-S1.xls
http://www.nature.com/ni/journal/v8/n7/extref/ni1478-S8.xls
http://www.nature.com/ni/journal/v5/n7/extref/ni1084-S5.xls
http://www.nature.com/ni/journal/v7/n11/extref/ni1394-S6.xls
http://www.nature.com/ni/journal/v14/n6/extref/ni.2587-S12.xls
http://www.nature.com/ni/journal/v14/n6/extref/ni.2595-S2.xls
http://www.nature.com/ni/journal/v14/n6/extref/ni.2587-S13.xls
http://www.nature.com/ni/journal/v14/n6/extref/ni.2587-S14.xls
http://www.sciencemag.org/content/suppl/2001/09/13/1062191.DC1/Zhusupptable1.xls
http://www.sciencemag.org/content/suppl/2002/04/02/1064987.DC1/S10_Table_4.xls
http://www.sciencemag.org/content/suppl/2001/12/20/1065672.DC1/uptagsdowntags_1.xls
http://www.sciencemag.org/content/suppl/2002/04/02/1064987.DC1/S5_Table_2.xls
http://www.sciencemag.org/content/suppl/2002/04/02/1064987.DC1/S18_Table_5.xls
http://www.sciencemag.org/content/suppl/2012/03/08/science.1219075.DC1/1219075TableS1.xls
http://www.sciencemag.org/content/suppl/2013/02/20/science.1228771.DC1/TablesS1toS8.xls
http://www.sciencemag.org/content/suppl/2008/03/06/1152677.DC1/1152677s-Table_S2.xls
http://www.sciencemag.org/content/suppl/2011/04/13/science.1203043.DC1/1203043TableS1.xls
http://www.sciencemag.org/content/suppl/2013/01/16/science.1233521.DC1/Markle_1233521_TableS4.xls
@hubgit
hubgit / word-count.js
Created February 13, 2014 15:31
Count words of each length in a string of text
var pluralise = function(count, single, plural) {
return String(count) + ' ' + (count === 1 ? single : plural);
}
// zero-fill an array of 20 items
var input = Array.apply(null, new Array(20)).map(Number.prototype.valueOf, 0);
// match words
p.match(/\b(\w+)\b/g).map(function(word) {
// get the length of each word