Dexter

Dexter Season 1 DVD People who know me, know that I love watching television and when I cannot watch a certain show (due to timings or because it comes on pay tv), I go out and try and buy the seasons on DVD. Recently I came across a new American show called Dexter. The show is based on the novel Darkly Dreaming Dexter, and revolves around the life of Dexter Morgan (played by Michael C. Hall), a forensic blood spatter pattern analyst for the Miami Police Department, who is actually a serial killer who tracks down and kills people “who deserve it” (mainly killers who have avoided justice).
While the show does have more than its fair share of blood, its actually quite a fascinating watch and its intriguing to see how the cast make a serial killer ‘likable’.
While the show has finished its second season in the states and has been scheduled for a third later this year, we in Australia have only received the first season on DVD, and even though I am only halfway through it, I have already put it on my ‘must keep an eye out for future seasons’ list (still working on a better name for the list though).
Check out the showtime fan wiki as well for more info.

  • Came across this link a few days ago (via a colleague at work). Goosh.org, bills itself as the “unofficial google shell”, and happens to be just that. It provides access to Google search results via a command line interface. Go to the site and type help, to view a list of the commands you can run. It has all the favourites including image, wiki, blog, news searches.
  • Firefox 3 are trying to set a world record for most downloads in a 24 hour period. Check out their Download Day Page and pledge your support!

Save login info in a cookie using CURL (PHP)

At work I was using a simple script that connected to a secure API, logged in and saved the result. This seems simple enough and is fast enough when calling it a few times, however one of the tasks I was then assigned was actually running this script for different values over 60,000 times! Each call (including the logging in) would take a little over a second, so calling it 60,000 times would take a while.

It was then decided to try and improve this by making the script only login once and save the session, so that subsequent calls would not have to login each time. This is one of the solutions we came up with ( because finding this online was not very easy :) )

The first step is the login, the agent variable is being set to trick the API into thinking that the request has come from a browser.

//Set the cookie file name
$cookiefile = tempnam("/tmp", "cookies");
$agent     = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
//Set the user name and password values
$USER      = 'user';
$PASS      = 'pass';
//The API url, to do the login
$url = "https://www.example.com/";

//Initialise CURL
$ch = curl_init();
//Set all the various options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 0); // set POST method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//Set the cookie file you want to use
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_USERPWD, $USER.":".$PASS);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

//execute the CURL
$mRes = curl_exec($ch);

Remember not to close curl at this point. Now we look at the loop that will carry out the 60,000 calls to the API

while ($row = [get row value for the 60,000 entries])
{
    $url       = “https://www.example.com/API?check=$row”;
    //We do not have to initialise CURL again
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_POST, 0); // set POST method
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //Remember to use the same cookiefile as above
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    //execute the CURL call
    $mRes = curl_exec($ch);
    //DEAL WITH THE RESULT FROM THE CURL CALL
}
//only close CURL once the work is finished.
curl_close($ch);

If you’d like to know more the various CURL options I have used above like ‘CURLOPT_SSL_VERIFYHOST’ etc, have a read through the curl_setopt page on php.net. You can also read more about CURL there as well.

LOLCODE!

I’m sure most people by now know about the whole Lolcat phenomena, however, for those still living under a rock:

A Lolcat, or LOLCAT, is an image combining a photograph, most frequently a cat, with a humorous and idiosyncratic caption in (often) broken English—a dialect which is known as “Kitty Pidgin”,[1] “lolspeak”, or Lolcat.

Lolcat or Kitty Pidgin has been around for a while now, and has been made popular by sites like I Can Has Cheezburger?…however in spite of its popularity, to find a programming language based on Kitty Pidgin still came as a real surprise to me.

Lolcode, created on 25 May 2007, is a programming language created by Adam Lindsay based on lolcat.
The language is still fairly young and at the moment has the following subset of keywords

Writing a program in lolcode seems surprisingly easy for people who understand lolcat, the main thing to remember is that HAI is used at the start of a program and KTHXBYE ends the program.
The default hello world program is as simple as

HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE

The language also contains error handling using AWSUM THX on success and O NOES which is the exception block!
The reason you probably haven’t yet seen a whole slew of lolcode applications yet, is that the language is still being defined with respect to operator priorities and correct syntax. Some compilers, however, already exist, like this one in python.

For the time being, this is another addition to my ‘must try at least once’ list…KTHXBYE!

  • Google Doctype: Check it out, its an online encyclopedia written by devs, covering areas like web security, JavaScript DOM manipulation, CSS tips and tricks etc, and also includes a bunch of test cases for checking cross-browser compatibility.