, LJ username: tgies
* Released under a Creative Commons Attribution-ShareAlike 2.5 license.
* See http://creativecommons.org/licenses/by-sa/2.5/ for more info.
* Put simply: Make derivative works, give me credit, let everyone else do the same.
* Thanks (in fairly random order):
* Sean "Redlof" Murray: Some questions. LJ username: redlof
* Paul "Slugbug" Millar: Assisted in determining which code comments were hilarious.
* See his LJ: tehslugbug, or his website: wgiowrb.net
* Suuji "Suujita" Tanaka: Provided much-needed distraction and interruption.
* Catering. Baselessly insulted programming skills for pure hilarity value.
* Made a few small contributions here and there, increasing overall speed.
* See her LJ: suujita
* Alex Musayev: His lj_mugs userpic gallery generator was used as a reference for
* the caching and fdata-getting subsystems. Very significant to the project.
* See his LJ: dreikanter, or his website: alex.asis.ru
* Alan V: Wrote the LJ quiz script that inspired this whole thing. Told me where
* to get the friends list of a given user (livejournal.com/misc/fdata.bml?user=USER).
* See his website: alanv.org
* Rev. Joe "G-Flex" Comire: Contributed questions. LJ user: gohanmastaflex
* Corey "csmith "Sasuke"" Smith: Some questions. LJ user: sasuke73
*/
//i am quizzin' bev
//do you like fun
//ok
//well these are pretty much the options I guess
//I mean some guy told me that they were I think
//okay so I lied about the guy telling me they are
//questions file
define("QUESTIONS_FILE", "d/questions.txt");
//where do we cache the friends lists! answer me NOW
define("CACHE_DIR", "d/cache");
//cleverly I log those who have taken the quiz! the intelligent may view it
define("USER_LOG", "d/logs/users.txt");
//THIS CACHE TASTES SORT OF STALE, MINERVA!
define("CACHE_SUSTAIN", 3600);
//there is no damned way you actually have that many friends
//quit trying to crash me
//bitch
define("MAX_FRIENDS", 100);
//TEE HEE
//define("TODAYS_BEAT_FREQUENCY_HZ", 81);
//it is a matter of public record that I am William N. God, Esq.
//okay first it is of UTMOST IMPORTANCE that we probably have some functions
//I personally like functions wherein they perform a task or procedure
//let's get some of those in here
//guys you need PHP_Compat
require('file_put_contents.php');
//random get
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
//mersenne-twisted shuffle
//thank you Japan
function mt_shuffle($array){
$rand_array = array();
$tmp_array = array();
mt_srand(make_seed());
foreach($array as $ar_key => $v){
$rand_array[$ar_key] = mt_rand(0,count($array));
}
asort($rand_array,SORT_NUMERIC);
$i=0;
foreach($rand_array as $r_key => $value){
$tmp_array[$i++] = $array[$r_key];
}
return $tmp_array;
}
//this one gets the array of friends one way or another
function friends_array($ljuser) {
//firstly we are attempting the cache
$filename = CACHE_DIR . '/' . $ljuser . '.cache';
if (file_exists($filename) && (time() - filemtime($filename) < CACHE_SUSTAIN)) {
$arrfriends = unserialize(file_get_contents($filename));
} else {
//there was no cache! the method is to get it and then cache it
$arrfriends = download_friends_array($ljuser);
file_put_contents($filename, serialize($arrfriends));
}
return $arrfriends;
}
//this downloads fdata and builds the array
function download_friends_array($ljuser) {
//we are going to need some TCP/IP over here
$socket = fsockopen("www.livejournal.com", 80, $errno, $errstr, 30);
if (! $socket) {
die("Error #$errno connecting to www.livejournal.com: $errstr
Check back later.\n