Skip to content

Instantly share code, notes, and snippets.

@bjjb
Created January 16, 2014 15:16
Show Gist options
  • Select an option

  • Save bjjb/8456583 to your computer and use it in GitHub Desktop.

Select an option

Save bjjb/8456583 to your computer and use it in GitHub Desktop.
Lets you enter the name of a JavaScript library on the command-line, and prints out the library's contents, having fetched it from cdnjs.com. `cdnjs backbone.js`, for example, or `cdnjs jquery > jquery.js` to save it.
#! /usr/bin/env perl
# A simple command-line utility for finding and retrieving JavaScript libraries
# from cdnjs.com
use strict;
use warnings;
use LWP::Simple;
my $lib = shift or die "No script entered on the command-line!";
get("http://cdnjs.com") =~ m#<tr[^>]+data-library-name="$lib"[^>]*>.*?<p[^>]+itemprop="downloadUrl"[^>]+>([^<]+)#;
die "Failed to find $lib at cdnjs.com - are you sure the name is right?" unless $1;
my $url = "http:$1";
my $script = get($url);
print $script;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment