Skip to content

Instantly share code, notes, and snippets.

@levelsio
Created January 11, 2020 10:22
Show Gist options
  • Save levelsio/be7ca3da2895fe087d6460a83aadf1ab to your computer and use it in GitHub Desktop.
Save levelsio/be7ca3da2895fe087d6460a83aadf1ab to your computer and use it in GitHub Desktop.
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;
}
?>
@dw1z4rd
Copy link

dw1z4rd 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.

@riazjutt
Copy link

How download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment