Created
February 1, 2012 18:01
-
-
Save Sequoia/1718350 to your computer and use it in GitHub Desktop.
count some the languages mentioned in the HN jobs listings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//explain usage | |
if( !isset( $argv[1] ) ){ | |
echo "Usage: php " . basename(__FILE__) . " [url]"; | |
die("\n"); | |
} | |
$languages = array( 'python'=>0, 'php'=>0, 'node'=>0, 'ruby'=>0, 'java'=>0, 'javascript'=>0 ); | |
$length = count( $languages ); | |
$url = $argv[1]; | |
$handle = curl_init(); | |
curl_setopt_array( $handle, array( | |
CURLOPT_URL => $url, | |
CURLOPT_HEADER => false, | |
CURLOPT_RETURNTRANSFER => true | |
)); | |
$html = curl_exec($handle); | |
foreach($languages as $lang => $count){ | |
preg_match_all("/$lang\b/i", $html, $matches); | |
$languages[$lang] = count($matches[0]); | |
} | |
arsort($languages); | |
foreach($languages as $lang => $count){ | |
echo $lang, ": ", $count, "\n"; | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this is so very highly unscientific :)