Created
January 17, 2018 13:00
-
-
Save mountainash/98775e415136aa07dcb65325fc7c5175 to your computer and use it in GitHub Desktop.
Deborah in lights
This file contains hidden or 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
#!/usr/bin/php | |
<?php | |
/** | |
* Deborah | |
* black lights indicate the remaining days until she gets here | |
* white lights mark them off | |
* so more lights are lit up when she arrives! | |
*/ | |
include 'class.holiday.secretapi.php'; // from https://github.com/Djelibeybi/PHP-Holiday-SecretAPI | |
function daysRemaining($enddate = '6 March 2018') { | |
$future = strtotime($enddate); // the UNIX timestamp of the end date (in seconds) | |
$timefromdb = time(); // the current timestamp | |
$timeleft = $future-$timefromdb; // minus | |
$daysleft = round((($timeleft/24)/60)/60); // work out the days from the number of seconds | |
return $daysleft; | |
} | |
printf("Days Remaining: ".daysRemaining()."\n\n"); // output to the console | |
if ( isset($argv[1]) || $_GET['web'] ) { // need to pass the IP address or hostname of the Holiday on the command-line | |
$holiday = new HolidaySecretAPI($argv[1]); | |
// loop-de-doop | |
while (true) { | |
$positions = []; // empty array | |
$numglobes = intval($holiday->NUM_GLOBES); // the number of globes on a holiday (50) | |
$lightcount = $numglobes - daysRemaining(); // the globes to "light" up | |
$spacing = $numglobes / $lightcount; // spread them out equally | |
$spacing = floor( $spacing ); // round down to a whole number | |
for ($i=0; $i < $lightcount; $i++) { | |
$position = $spacing * $i; | |
array_push($positions, $position); // add a numeral to the array which is the spacing and then multipled by the light count | |
} | |
for ($globe=0; $globe < $numglobes; $globe++) { // loop though each globe | |
if ( in_array($globe, $positions) ) { // check if the globe number is in the `positions` array | |
$holiday->setglobe($globe, 255, 255, 255); // set it to white | |
} else { | |
$holiday->setglobe($globe, 0, 0, 0); // set it black (off) | |
} | |
// printf("Globe: ".$globe."\n\n"); | |
} | |
// Render the globes | |
$holiday->render(); | |
} | |
} else { | |
printf("I need the IP address of one or more holidays listed in left to right order\n"); | |
exit(1); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment