Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get random Twitter follower from your exported followers.js
<?
// str_replace removes the JS part and makes it into a normal JSON file
$followers=json_decode(str_replace('window.YTD.follower.part0 = ','',file_get_contents(__DIR__.'/followers.js')),true);
echo "\n\n";
echo number_format(count($followers)).' followers';
echo "\n\n";
echo "\n\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
echo $followers[mt_array_rand($followers)]['follower']['userLink'];
echo "\n";
function mt_array_rand(Array $array, $num = 1) {
$count = count($array);
if ($num > $count) {
return null;
}
$keys = array_keys($array);
$res = [];
for ($i = 0; $i < $num;) {
$rand = mt_rand(0, $count - 1);
if (isset($res[$keys[$rand]])) {
continue;
}
$res[$keys[$rand]] = $i;
$i++;
}
$res = array_flip($res);
sort($res);
return (count($res) === 1) ? reset($res) : $res;
}
?>
@segfault-philosopher

This comment has been minimized.

Copy link

segfault-philosopher commented Feb 11, 2020

I think it's awesome that you went out of your way to make the giveaway fair to all your followers and went the extra mile to circumvent Twitter's API limitations in order to do so.

That being said, I was just wondering why not use a loop to print it out? Lots of repeat code. But I've done that too, when I'm in a hurry, sometimes hitting ctrl-V a few times is easier than writing a loop or another function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.