Assembly and PHP: A Perfect Recipe?

July 31, 2009

I was working with PHP’s string manipulation functions and was wondering what would happen if we could make Assembly Language process these strings functions? The web would be much faster! I already know of a way to interface ASM (Assembly language) with C++/Java and other high-level language, but there’s no library still to interface ASM with PHP.

If you want to know more about interfacing techniques with ASM, I recommend you to read “The Art of Assembly Language” by Randall Hyde. I think it’s one of the easiest to understand and is very comprehensive.


How to Create An Api?

July 14, 2009

Web Resources Depot has posted a nice selection of tutorials explaning the process behind developing solid  APIs for your website. I also had posted a link to a Particletree.com article that provided a tutorial on creating an API with PHP. Check it out as well.

Source: http://www.webresourcesdepot.com/how-to-create-an-api-10-tutorials/


Using FLIR: FaceLift Image Replacement

July 13, 2009

Yeah, it is pronounced like “fleer“. So what’s this facelifting thing? It’s a type of plastic surgery that makes you look like Michael Jackson (with respect to the King of Pop. R.I.P). But in the sense of web development, it is simply a technique with which you can use any type of font you want to use! Seems too obvious?

Though the web has been around for over 10 years and we’ve seen Flash and other so-called Rich User Interface, one thing has been bothering the web designers for a long time: using the exact font they want to use. FLIR solves this one pretty neatly by implementing PHP and it’s well-known GD library. There’s just two cons to using this procedure:

1) The texts are actually rendered as images. So it is not possible to copy those rendered texts (you can still copy them as images though).

2) GD library introduces some artifacts to the fonts so you can’t expect FLIR to render the true image of the font (pun intended).

Here’s a tutorial that teaches you how to use FLIR: http://net.tutsplus.com/javascript-ajax/how-to-use-any-font-you-wish-with-flir/

You should also check out sIFR


Design Patterns – Introduction

June 26, 2009

Originating from architectural design (as in design of buildings), when design patterns crossed over to computer programming in the 1980’s, only a small group of people using a language called “SmallTalk” were applying them. In 1995, a group of four authors released a book called “Design Patterns: Elements of Reusable Object-Oriented Software”.

The four authors where nicked the “Gang of Four”. SmallTalk, but also C++ where the languages applying design patterns at that time. It is still the most respected book on design patterns to this date. “Gang of Four” (abbr. GoF) is also commonly used to refer to the book, rather than the authors.

Soon after, ‘Gurus’ such as Martin Fowler started publishing their own works, perhaps most notably “Patterns of Enterprise Application Architecture” (abbr. PoEAA). By then, most books where using Java in their examples. The Java community has played a big part in the evolution of Design Patterns, not in the last place thanks to efforts from Alur et al. with their “J2EE Core Patterns”.

Source: http://www.phpfreaks.com/tutorial/design-patterns—introduction/page1


Decoupling models from the database: Data Access Object pattern in PHP

June 26, 2009

Nowadays it’s a quite common approach to have models that essentially just represent database tables, and may support saving the model instance right to the database. While the ActiveRecord pattern and things like Doctrine are useful, you may sometimes want to decouple the actual storage mechanism from the rest of the code.

This is where the Data Access Object pattern comes in. It’s a pattern which abstracts the details of the storage mechanism – be it a relational database, OO database, an XML file or whatever. The advantage of this is that you can easily implement different methods to persist objects without having to rewrite parts of your code.

I’m again going to use the programming language quiz game I wrote as an example. Since I initially wrote it to use Doctrine ORM directly, and both the old and new code are available, you can easily see how the code was improved.

Source: http://codeutopia.net/blog/2009/01/05/decoupling-models-from-the-database-data-access-object-pattern-in-php/


Object-Oriented Programming for Heretics

June 24, 2009

Tony Marston gives a nice intro to OOP:

The problem with OOP is that there is no clear definition of what it is and what it is not. Since its first appearance numerous people have expanded on its original definition (whatever that was) and invented new ‘rules’ which in turn have been subject to different interpretations. For each interpretation there are also many different possible implementations. There is no single definition, or set of definitions, which is universally accepted, therefore, no matter what you do, somebody somewhere will always find a reason to complain that ‘you are wrong!’

This article is highly recommended if you want to know the basics of OOP and also the intermediate level of OO programming.

Source: http://www.tonymarston.net/php-mysql/oop-for-heretics.html


What is/is not considered to be good OO programming

June 24, 2009

This article by Tony Marston is an important one since it deals with the best practices of OO programming. I could say the article is not language specific but since he mostly deals with PHP and MySQL, the codes are based on PHP. Describes topics such as Data Dictionary, Entities, and OOP pagination system. He also shows how to store the state of an object in one page and then “resume” that state in another PHP script by using PHP’s built-in session object. Pretty neat, huh?

Source: http://www.tonymarston.net/php-mysql/good-bad-oop.html


Database Simplicity With Class

June 20, 2009

Database connectivity is one of the most important columns of a dynamic web. Besides being able to handle database queries with great flexibility, a website must provide the database with strong security. One solution is to write some thousands of lines codes and repeat the process for future projects OR use a single class to handle all the database functions for all your projects. Since I have one of the most powerful assets a good programmer must have that is, laziness, I would opt for the second option.

This article from Particletree.com provides a solid background for creating really flexible database classes that you can extend in the future. Also, they provide the article for three different languages (although you can adapt the idea for almost infinite number of languages). Enjoy!

Source: http://particletree.com/features/database-simplicity-with-class/


Create a REST API with PHP

June 17, 2009

The abbreviation API stands for Application Programming Interface. What does it do? Well, let’s say it enables your website to be plugging enabled. This means that other websites can request information from your website and your website can process the data and send the result back to the website that requested it. Your source code is always kept intact from outsiders. API is highly synonymous with Object Oriented Programming (OOP), since without the OOP concept the plug-n-play ability of your website wouldn’t be achieved.

A really good example of an API would the Facebook Platform where thousands of new applications get added everyday. How do they work? Simple. Suppose you have a website and you want to make use of the Facebook API. So you request a particular information (suppose the number of friends of a user) and Facebook returns the result to you. So you see, you are not accessing the source codes of Facebook but you can use the information located in Facebook and adapt it for your own use. That’s API in a nutshell. So how do you get to make one? Here’s a great article by Ian from Gen X Design:

One of the latest (sort of) crazes sweeping the net is APIs, more specifically those that leverage REST. It’s really no surprise either, as consuming REST APIs is so incredibly easy… in any language. It’s also incredibly easy to create them as you essentially use nothing more than an HTTP spec that has existed for ages. One of the few things that I give Rails credit for is its well thought-out REST support, both for providing and consuming these APIs (as its been explained by all the Rails fanboys I work with).

Source: http://www.gen-x-design.com/archives/create-a-rest-api-with-php/


PHP, JSON and JavaScript usage

June 14, 2009

Source: http://ditio.net/2008/07/17/php-json-and-javascript-usage/

Today i want to introduce you to jSON (JavaScript Object Notation), in short, it is a simple format designed to exchange data between different programming languages. I will show you how to create JavaScript object, convert it to JSON string, and send to PHP script, which will decode jSON string to readable format (for PHP). But that’s not all, PHP script will create it’s own data object encode it to jSON string and send it back. All communication between JavaScript and PHP will be done thru AJAX.