Data inside a database should always be post-processed and ready-to-use-as-is. If you can rely on the data provided by the database to be usable as is, then you’ll save yourself a lot of string processing work. Think about it this way, if you have a string, let say “orange” and it’s stored in the database, and you had another string called “apple”, along with other fruit based strings stored in the database. When you do a search for these fruits, you can specify a where condition and then the fruit the name. Even with for usage, you can use the fruit name as is. Whereas if these strings had all these weird characters in it, “orange\’s” and “@pples”, then the where statement will no longer be as effective. Not only that, during run-time, you’ll have to have code to handle these weird characters appropriately. So if you’re ever inserting data into the database save yourself some problems in the future by ensuring that the strings are properly processed.
Archive for the ‘Programming’ Category
Data Inside a Database
Tuesday, October 6th, 2009Feature Gathering
Tuesday, August 18th, 2009There is an important lesson to be learned from the jQuery versus PrototypeJS battle. While there isn’t really anything wrong with Prototype, jQuery is simply better. Yes, there are some pros and cons to either one, but to me, jQuery was simply better designed. It’s as if, one day, some guy decided to come up with a JavaScript framework to make working with JavaScript a lot faster and easier. That person went out, figured out what the day-to-day of JS developers were, and decided to come up a framework based on that. While I can easily write an article on PrototypeJS versus jQuery, today’s article is on the importance of feature gathering.
Feature gathering is the process of consulting your clients about their needs and desires before creating your application. I’ve come across a few programs where they’ve developed what they thought the client would like, instead of directly consulting the clients about their exact requirements. There are pros and cons of each method. The con, your client might be annoyed with your lack of initiative. The pro, work flow can be streamlined, the code can be designed around how features might be added, main ability, scalability, and etc. I like doing things, and I like doing things right from the get-go. Of course, if I was a developer who wanted a ton of project time, then I’d develop the most inefficient most unmaintainable system there is to get all the money I can, but I don’t. So I rather create a solid, efficient, and easy to maintain product, and that can only be accomplished if I did a good job at the feature gathering stage.
Zend MVC plus Smarty
Tuesday, July 21st, 2009I’ve been playing with both Smarty and MVC. I can’t help but feel that having both Smarty and MVC is a bit redundant. Smarty was developed so that people with little to no programming experience can be involved in the designing process through the use of templates. MVC is known as Model, View, and Controller. The whole point of the system is to separate the components behind a major web application such that people with different backgrounds can come together and build an application. The model contains the business logic; it is the layer that accesses the database and prepares the data. The controller is the component that handles the parameters and figure out what kind of data it needs and where which views to render in order to achieve the result desired. The view is the component that contains the design for the application. It’s designed in such a way that even a person with no programming experience can code and develop.
It seems in that regard, Smarty and MVC are achieving the same thing. I know caching is a big benefit provided by Smarty, but you’ll find that most MVC frameworks have caching solutions as well.
The model I was coding employed the Table Data Gateway pattern, the resulting object was then feed into the Zend Paginator object, which is then supposed to be fed into a view. The object takes care of every aspect of pagination. Smarty also has a means of paginating, but it then in order for it to perform pagination, requires SQL statements thereby bypassing the model layer. Even if you attempt to pass the Zend Paginator object directly into Smarty, the iterator for the Zend Paginator is completely useless due to Smarty’s insistence on using arrays instead of objects. Although it’s possible that more recent versions of Smarty might’ve corrected this error, but this is one programmer who would have rather worked with Zend MVC instead of Smarty plus Zend MVC.
Get Your Hot Swapping On
Wednesday, July 15th, 2009There are many ways in which code is rolled out. I’ve noticed in the new environment I’m in, code roll outs are performed more in a “hot swap” fashion than an install / overwrite fashion. In an overwrite manner, code has been throughly tested in a dev and staging environment before being rolled out to live. Whereas in a hotswap environment, staging is on live, except in a different directory. When it’s time to implement the changes, the directories are merely moved around. I thought this concept is interesting because sometimes, even the staging environment, might not be a perfect replica of the live environment, and this “hot swap” can be an additional test on the code before it becomes live.
Finding Problematic Code with Top and Mod Status
Wednesday, July 1st, 2009The first step to fixing a problem is figuring out that there is one. Top is great command to examine what’s going on your system. It can tell you how resource intensive a process is, how long it’s been running, who executed it, and etc. Through Top, you can see if a process like httpd or Apache is taking up a lot of resources, if it is then a script executed via Apache is taking up a lot of resources. The problem with Top is that it doesn’t show you what script were executed via the web and how resource intensive that script is, and it’s not supposed to. Just like Windows’ task manager, it doesn’t make any sense for it to keep track of what files are opened in Excel, that’s Excel’s job.
Good thing for us, Apache is able to keep track of it through an Apache Module known as “mod_status”. Today’s post won’t cover how to install mod_status, what its graph looks like, or how to read it, but it’ll talk about how to use it in conjunction with Top to troubleshoot problematic scripts. This information is readily available on the web, but here’s a link to more info regarding the Apache module: http://httpd.apache.org/docs/2.0/mod/mod_status.html
Top allows us to identify which process is sucking up a lot of resources. Mod status keeps track of web calls and their corresponding PIDs. By look up a problem process in top and then finding that process in mod status, then we can start analyzing and fixing the problem. From that point on, we can start the “blaming” process
Unwritten Rules of Professional Web Applications
Monday, June 15th, 2009While there are many unwritten rules, here are few which I find most significant. To me, these are qualities of any professional web application.
I expect nothing less from any modern day professional web application and applications I develop. The applications I develop might not always fulfill these requirements, but it’s definitely something I strive for each time a line of code pours from these hands of mine.
Back on Top
Friday, May 29th, 2009If you searched for my full name in Google for the past 3 weeks or so, you might have noticed that my site completely disappeared from the famous search engine. The reason it disappeared was probably due to my domain expiring and parked, but after 3 weeks of checking and waiting, it appears my site is once again, back on top. There’s a certain about of pride we web-programmers have in regards to our stuff being on top. I shall enjoy it while it lasts.
People I Admire
Wednesday, May 27th, 2009There really is no particular order in this list:
- Randy Pausch
- Albert Einstein
- Stephen Hawking
- Sun Tzu
- Bruce Lee
- Jet Li
- Stephen Chow
Today, I after watching Stephen Hawking lecture on “The Big Question”, I found a new appreciation for this man. He can only communicate through twitching his cheek, the other parts of his body is rendered completely useless. This man takes roughly 7 minutes to write 20 words. Yet, he finds the ability to give full-blown lectures, books, and to be optimistic about his situation. He states that his conditions actually gives him a lot of freedom to pursue one of his greatest interest in life; Solving the mysteries of the universe. I admire this man not only for his intellect, but his bright-facing outlook, and his ability deal with the countless problems in his day to day life. People like Stephen Hawking make me realize how strong humans can be, how they look adversity in the face and overcome it.
The question is “How does this tie into programming?” If Stephen Hawking can overcome the challenges he faces, the problems we face in the computer world seems trivial in comparison. Men like Stephen Hawking gives me strength tackle monstrous applications and crazy product requirements with great confidence that the problems I face can be overcome.
Invisible Tracking Pixel
Wednesday, May 6th, 2009There already tons and tons of articles on this topic, but I think this knowledge is definitely nifty, so I decided to repeat this information in my blog.
A tracking pixel is a script that is disguised as an image. Each time the image loads, the script does whatever it was coded to do, but at the same time returns an image. This image doesn’t need to be a pixel, but a pixel is the smallest graphical information you can return. The pixel doesn’t need to be transparent either, but I just think it’s annoying to see an out of place pixel sitting on the edge of the page. So for all those who are like me, we like to implement something called a transparent pixel. Without further ado here is the php code for a transparent pixel:
header('Content-Type: image/gif');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " PST");
header("Pragma: no-cache");
$img = imagecreatetruecolor(1,1);
$color = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $color);
return imagegif($img);
The header code is telling the browser that the file is a gif and to not cache it. If you want your tracking pixel to work well, it’s best for you to include it.
For those hardcore nerds out there, you can save the generated gif into a file, check if the file is there, and if it exists, use that existing gif instead of creating a new one. Not only does this method prevent regeneration of the gif, it also allows you to pass file size information through the headers.
For those even more hardcore nerds out there, you can simply print the string that represents a transparent pixel, it’ll save you all that image creation code. Although you’ll sacrifice readability, since only a handful of us can look at a string of bytes and is able to tell exactly its supposed to be.
Myspace and Flash
Tuesday, May 5th, 2009I know flash objects could be listed on MySpace pages for quite some time, but I didn’t really understand what this meant for MySpace pages until I went to a friend’s site. I’ve noticed that my friend’s MySpace on, well, MySpace looked and behaved absolutely different than any other MySpace I’ve seen so far. Being the code monkey I am, I decided to investigate. It turns out, her MySpace page has been pretty much replaced by a massive flash file, and everything else is hidden away. I thought this was very interesting, and opens a lot of possibilities for further development of MySpace pages.
I love tinkering with the technology and creating my own version of it, but for those who don’t want to do that, here’s a link to the page that does it for you: http://www.lovemyflash.com/