• 05Dec

    The toolkit is a PHP class/library which allows you to resize, crop and watermark images with ease. It is build using PHP GD methods which are available on pretty much 95% unlike, say, Imagick. Grab it here.

    Tags: , , , , , ,

  • 07Nov

    As a PHP developer using CodeIgniter or any other MVC based PHP framework you know that using Visual Studio level debuggers like the Zend Debugger or XDebug doesn’t work well with a system using URI segments rather than query strings. Personally I am a technologically agnostic software/systems engineer and use what tool/platform is right for the job. So being someone who also uses Visual Studio and it’s outstanding debugger (although I wonder if ASP.MVC has problems now too) I find it making me feel like I am walking around blind and in the dark when it comes to knowing what  my code is doing while it is doing it.

    So I forced myself to find some way of achieving this and managed to come close. The only draw back is that I have to define a query string for each session. If  you are using an Eclipse based IDE like PDT, Zend or Aptana you have to change the debugging configuration each time.

    Ok, enough of that, lets get to business.

    1. open the system/application/config/config.php file
    2. change the permitted_uri_characters option to: ‘a-z 0-9~%.:_\@&?=+-’;
    3. change the enable_query_strings option to TRUE.
    4. now add index.php?c=YOURCONTROLLER&m=YOURFUNCTION to the root of the site URL as the starting point of your debugging session.

    So, as you can see, we our now calling the controller and public method to a query string rather than using MVC based URI segments. There are a couple of drawbacks. The one I have found is that it screws up pagination and another stated  in the framework is that some helpers do not work with query strings enabled.

    Of course you’ll want to turn off query strings when not in development and it doesn’t force you to use them when enabled. You may want to revert the permitted characters as well but you do not have to since the additional characters are harmless. It is not the most elegant of methods but if you really need to see what is going on during execution this is the way to go with this framework.

    Tags: , , , ,

  • 05Sep

    Well being a IT Director for a web based company I have allot of black shirts (i.e., if it isn’t Apple it sucks) around. So of course I sat around watching them happily upgrading to 10.6.

    Right after that I saw them spending the rest of their day finding alternatives to their regularly used programs because after the upgrade, most of them didn’t work. Seem familiar?

    I have been constantly thinking of how Apple is turning into Microsoft in terms of evil business practices. After this, I have to say I no longer think, I know.

    Regardless I am platform agnostic so whatever gets the job done I say.

    Tags: , , , ,

  • 28Aug

    I have put up a page in the CodeIgniter wiki with a tip on making the base url setting dynamic to rid the need of changing it for development or the issues caused by the same application under many URLs.

    http://codeigniter.com/wiki/Dynamic_Base_Url/

    Tags: , ,

  • 16Aug

    As root

    /usr/libexec/mysqld –skip-grant-tables –user=root

    mysql -u root
    UPDATE mysql.user SET Password=PASSWORD(’newpassword’) WHERE User=’root’;

    FLUSH PRIVILEGES;
    quit

    Tags: , ,

  • 16Aug

    A little while ago I was speaking with technical writer, Jon Arking, about test driven development which led me to a conclusion that I believe will be a benefit to anyone reading this. The topic was my experience with test driven development. However it also led into my thoughts on the subject as well.

    I do agree with many aspects of the overall Agile methodology. However I definitely do not agree with all of them. One example would definitely have to be paired programming. I do see the advantages of it however as any software engineer knows, there is a point in our day while developing where we get into a “zone” where we are totally immersed in our development effort and the ideas just keep flowing. I don’t see this happening with paired programming. But anyway, let me get to the point of this article, test driven development.

    There are 3 sides I see developers fall into involving unit testing. There is the stadard unit testers, those who do not use unit testing and the test driven developers. Many from the 2 sides not a part of test driven development have made many arguments against it. They believe it is slows down development or that there is no point in testing anything that hasn’t even been written yet. Well I hope the perspective and analogy helps them to understand test driven development.

    In many sciences, a scientist comes up with a prototype. With that prototype they perform the many tests and modifcations needed before producing anything production worthy. Even in the development of the prototype they performed various tests to get to the point where they have a prototype worthy enough of using it to help them advance it to the level where it can be of use to the general public.

    In computer science, this would be considered test driven development. These scientists don’t come up with an idea and go right to building/creating something meant for use by the general public and perform testing on these production models while producing them. The production/general public release of their innovation was created without the requirement of testing because it has already been through thorough test during and after the development of the prototype. At that point everything has been thoroughly tested and calculated that there is no need for any such testing in the development of a production/general public release.

    I see no reason why computer science should be any different and as I have just stated, this is where test driven development becomes the perfect fit for us to follow the same methods of other science related fields. We come up with an idea and throughout each step of flushing out that idea we test it to make sure we are on the right track. Then after all the ideas are flushed out and tested we have our prototype upon which we can then perform more comprehensive testing.

    Once all of this has been completed we can then, very quickly, produce a production worthy application or subset of an application. Everything is layed out in detail and thoroughly tested. This allows us to be completely confident in the final product. Also, we have the benefit of the Agile aspects this brings us for any future changes such as all the tests we already have in place to be reused to ensure any changes that do come along are released with the same quality as the original release.

    I don’t think it is either faster or slower than other methods. However there are aspects I am sure of, it will provide rock solid software and just makes sense when looking at it from this perspective.

    Tags: , ,

  • 16Aug

    RESTful communication is a great method for light weight communication across systems not requiring the complexity or standards based interoperability of web services. I have used these methods for years with multiple vendors and clients for various CRM related tasks and it worked great. Of course the system supported web services however the need to use them was rare in comparison.

    Now it is no longer something used just for B2B based communication but also for standard everyday services such as Twitter. So I will use their REST based API to demonstrate how to read, write and authenticate using REST.

    Below is a simple read in order to retrieve the friends timeline for the authenticated user.

    public static string GetTimeline(string username, string password)
    {
    //take the Twitter credentials and Base64 encode them

    string encoded_user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
    //create a web request instance for the friends timeline in XML format

    HttpWebRequest tweet_request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/friends_timeline.xml");

    //add the encoded creadentials to the requests header

    tweet_request.Headers.Add("Authorization", "Basic " + encoded_user);
    //since we are performing a read the method is set to GET

    tweet_request.Method = "GET";
    //the call is made and we create an instance of the response’s stream

    Stream response_stream = tweet_request.GetResponse().GetResponseStream();
    //now we simply convert the XML response into a string that can be

    //loaded into an XML document and access the data via XPath

    StringBuilder response_builder = new StringBuilder();
    int i = 0;
    byte[] response_buffer = new byte[8192];
    do
    {
    i = response_stream.Read(response_buffer, 0, response_buffer.Length);
    if (i != 0)
    {
    response_builder.Append(Encoding.ASCII.GetString(response_buffer, 0, i));
    }
    }
    while (i > 0);
    response_stream.Close();
    return response_builder.ToString();
    }

    Here we will now write to the service by updating the twitter user’s current status.

    public static void Send(string username, string password, string status)
    {
    //convert data to be written to a byte array

    byte[] tweet_bytes = System.Text.Encoding.ASCII.GetBytes("status=" + status);
    //Base64 encode the credentials

    string encoded_user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
    //create a web request instance for the status update in XML format

    HttpWebRequest tweet_request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");

    //certain web servers have trouble with HTTP requests using Expect-100

    tweet_request.ServicePoint.Expect100Continue = false;
    //add the encoded credentials to the request header

    tweet_request.Headers.Add("Authorization", "Basic " + encoded_user);
    //since we are writing we now set the method to POST, the size of data to

    //be written and the mime type accordingly

    tweet_request.Method = "POST";
    tweet_request.ContentType = "application/x-www-form-urlencoded";
    tweet_request.ContentLength = tweet_bytes.Length;
    //create stream instance from request

    Stream request_stream = tweet_request.GetRequestStream();
    //finally we write the update to the stream

    request_stream.Write(tweet_bytes, 0, tweet_bytes.Length);
    request_stream.Close();
    }

    So as you can see REST calls are the easy part of handling RESTful communication. It is nothing more than standard HTTP calls. It is what you do to and with the data that is the hard part. So now you can see why it is so simple and light weight. Of course I could go into detail describing REST however it is outside the scope of this article and the code pretty much says it all. Enjoy!

    Tags: , , ,