The bunny theory of code

An interesting article that someone at work posted. I thought I would share it here. I truely agree with what the author said. Detect it early and resolve it early before it gets messed up!

Anyone who’s ever worked with me knows that I place a very high value on what ends up checked-in to a source code repository. The reason for this is very simple: once code gets checked-in, it takes on a life of its own. Checking in is akin to sharing your code with others, and once out in the world, it’s hard to predict what that code will do. Hard, but not impossible, as there is one thing I can virtually guarantee will happen.

Read more at The bunny theory of code | NCZOnline.

Twitter OAuth API package via Composer

I had been wanting to implement twitter’s follower count, statuses count on my website. Being a bit more familiar with composer, I went through and created a packagist which is avaiable via composer to be used on any site.

The packagist is rather simple at the moment and allows only getting User Info at the moment but will be adding more features to it later on.

If you are using composer, all you have to do is add the following to the require section of your composer.json file.

"rabinshr/php-twitter-oauth-api": "dev-master"

Twitter counts

Showing follower count, friend count, status count in Twitter


Read More

How to set SSL version when sending requests via SoapClient?

Every now and then you are required to work on a API which is pretty big. However, the SSL version they have used is depreciated one so you cannot use standard SoapClient class to communicate with them. The following snippet allows you to create your wrapper class which extends SoapClient and allows you to execute a curl request with the correct SSL version. Thus allowing you to make a successful communication with that API

class WrapperClass extends SoapClient {
    protected function callCurl($url, $data, $action) {
        $handle = curl_init();
        curl_setopt($handle, CURLOPT_URL, $url);
        curl_setopt($handle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml", 'SOAPAction: "' . $action . '"'));
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
        curl_setopt($handle, CURLOPT_SSLVERSION, 3);
        $response = curl_exec($handle);
        if (empty($response)) {
            throw new SoapFault('CURL error: '.curl_error($handle),curl_errno($handle));
        }
        curl_close($handle);
        return $response;
    }

    public function __doRequest($request,$location,$action,$version,$one_way = 0) {
        return $this->callCurl($location, $request, $action);
    }
}

Read More

Avoiding offset on tables with high volume data

In web development, it is common to be able to perform some action on each row of a high volume table. The first thing that comes to mind in doing this is fetching rows from the table in batches using LIMIT OFFSET,BATCH statement.

SELECT * FROM `table` LIMIT OFFSET,BATCH;

The flaw of this method is as the offset goes on increasing, it takes that much longer for the database engine to return the result. The reason being the engine has to go though all the rows to find that offset and then return the batch of records.

The solution would be to use a where clause on the primary key instead of offset: Read More

Issues with having underscore in domain name

I have come across wierd hair scratching problems and this is one of them. Turns out, if there is an underscore in your domain/sub domain name, IE stops saving cookies. Which i have already mentioned in my earlier post title ‘IE Why? Why?‘.

Now another issue that I have noticed with underscore in domain is that PayPal will not accept this url as a valid url. So if your site has PayPal processing then it will error out.

All the fun with having underscore in domain names.

IE why? why?

Today, I came to know about another issue with IE browser. Apparently, IE browser does not allow cookies from sub domains that do not follow URI RFC. I wasted a few hours of my time trying to figure out why cookies were not working on my test site. Turns out this was the case.
IE why? why do you have to suck?