Last Updated: February 25, 2016
·
1.604K
· projectcleverweb

Chuck Norris In Your Terminal

Well jokes about him at least.

Usage: (assuming the file is named "chuck-norris")

chuck-norris 5

Output:

* When Chuck Norris plays Monopoly, it affects the actual world economy.

* Chuck Norris doesn't stub his toes. He accidentally destroys chairs,
bedframes, and sidewalks.

* What many people dont know is Chuck Norris is the founder of planned
parenthood. Not even unborn children can escape his wrath.

* Wilt Chamberlain claims to have slept with more than 20,000 women in his
lifetime. Chuck Norris calls this "a slow Tuesday."

* With the rising cost of gasoline, Chuck Norris is beginning to worry
about his drinking habit.

Source: (Windows with Xampp and Git Shell or Cygwin installed)

#!C:\xampp\php\php.exe -q
<?php

$amount = 1;
if (isset($argv[1])) {
    $amount = (int) $argv[1];
}
if (!$amount) {
    $amount = 1;
}

$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://api.icndb.com/jokes/random/'.((string) $amount)
));
$json = curl_exec($ch);
curl_close($ch);

$data = json_decode($json);
foreach ($data->value as $joke) {
    $joke_msg = wordwrap("\n    * ".html_entity_decode($joke->joke), 75, "\n    ", TRUE)."\n";
    echo $joke_msg;
}