Archive for the ‘Coding’ Category

Overlapping Audio Tracks in Safari

Friday, April 20th, 2007

Apple’s Safari is definitely a work in progress with the kind of weird bugs I keep running into. One of the bugs I hadn’t documented about is overlapping audio tracks in Safari under a very special circumstance.

The issue is this: When using AJAX to load one quicktime clip over another, if the first movie hadn’t finished playing as the second movie is loaded in via AJAX, the user will hear the audio tracks of both movie clips playing at the same time. I have no idea why that is, and I am not even going try to guess. And apparently this has not been documented (or the little that I’ve found in Google) by any developer that I know of…

Fortunately there’s a quick fix to this problem (or my clients will drive me crazy). The upside is that this problem can be mitigated with a quick Javascript since the Quicktime object supports Javascript controls. And here’s how it’s done. We all know websites, especially college ones, are reliable and all, you know, their content never changes and they never disappear… But I decided to keep a snapshot of it anyway for future reference. Apple also has a couple of decent documentations on the subject.

Basically I used Javascript to stop playback of the first video before the second one is even loaded in by embedding the event as onClick. In some cases, it may help to dynamically embed it in the < body> tag as onLoad.

An interesting side note: Javascript documentation says that onLoad events can be triggered with < body>, < iframe>, < frameset>, < img> and < object> tags in HTML, but in reality, use of < iframe> and < object> are weird among browsers.

IE6, IE7, Firefox, Opera — support onLoad in the < iframe> tag, but they do not support it in the < object> tag.
Safari — the only loner browser that supports onLoad in the < object> tag, but NOT the < iframe> tag…

Sometimes it can really suck being a web developer.

Done with Java Programming Class

Tuesday, April 3rd, 2007

Today was the last day of the intensive Java programming class. I actually completed the final project ahead of my estimated scheduled time. I even had enough time to complete a make-up assignment I didn’t turn in. This class was especially tough because it was one of those “part one” and “part two” courses rolled into one. I kind of started falling behind during the second half of the class.

Knowing more about Java now made me realized something — PHP is a relatively easy language to pick up and for someone to be comfortable with. But precisely because of these “advantages”, PHP also makes someone without strong programming fundamentals a lazy programmer. Now that I know more about Objected Oriented programming with a “proper” language, I shall apply similar concepts to my future PHP projects. But I hope I get to work on Java programming more so some of that good stuff will actually stick!

Notes on Java: Garbage Collection

Friday, February 16th, 2007

One of the advantages that proponents of Java love about the language is garbage collection — the process in which JVM cleans up after your program is done partying and messing with your computer’s memory — free of charge. Th-unk you. Com’ again. Buh-bye.

Simplistically speaking, in comparison, C and C programmers typically need to clean up after themselves. The problem with that is, sometimes these parties get so wild that it makes the clean up afterwards impossible. That’s when “memory leaks” occur (ahem, Safari). The “parties”, of course, are the programs that rampage through your computer’s memory when they are having the time of their lives (which is not all that long). I mean, WHO likes cleaning up after parties, right? Think about it: Even if you try, there are bound to be spots where you just can’t get to or miss out from all the other cleaning you have to do YOURSELF. Java frees programmers from that headache by being in the business of memory salvation. Bless Java.

So here’s how it works… Whenever your Java program disposes something that it no longer cares for in your system memory, it’s considered trash, garbage, litter, junk, scrap, rubbish, Microsoft’s customers, whatever name suits your fancy, and is eligible for Java’s free garbage collection service. Did I mention enrollment is automatic, and it’s free? With small parties, Java only cleans up after your mess once in a while. But with parties in the size of Coldplay’s concerts, Java will do it a bit more frequently.

Well, I lied when I said it’s free. Com’on, nothing is free. You know that. Luckily, it costs in terms of system performance with all that bookkeeping and cleaning Java has to do. But it’s not really that bad if you consider the work Java’s done for you and the time and brain cells it saves you. I may be going out on a limb here, but I’d say the small performance hit your program suffers is well worth the price. And besides, with today’s qua-gazillion-megahertz computing power and memory availability, these performance hits are barely noticeable. It’s like being thrown at with a penny — of course it hurts. But just a little, and the pain only lasts long enough for you to realize that the sucker who threw the penny is now a penny poorer, and you are now a penny richer…

On a different note, the new Mac OSX Leopard is supposed to ship with a new version of Xcode that comes with garbage collection feature… Buh-bye, major memory leaks…

Dreaming in Code

Monday, February 12th, 2007

Ever since I started prepping for the GRE, I’ve been somewhat lagged behind on my Java programming homework. So when I was done with the GRE, I feverishly tried to catch up by reading all the assigned sections in the book plus trying to program for the assignments. Maybe I am just not very bright… but it just takes me a while to pick up a new programming language in the beginning trying to orient myself in the new syntax and constructs.

Maybe it’s because of all the codes I’ve been reading, programming and tinkering with. For the past couple of nights, my dreams have been nothing short of me trying to solve some obscure programming problems in Java! How weird is that? The messed up part is, every line of code in the dream made sense!

Damn I need some rest and time away from Java…

Java Kicking My Ass

Saturday, February 3rd, 2007

My excitment over Java waned a bit after having my butt kicked by all the syntax differences. What comes natural to me in PHP takes a bit of fiddling in Java not knowing all the “right” ways to do things. Digging through Java documentation is slightly useless for me at this point since I am still trying to get used to how everything works and fits together.

Since this is as close to formal programming training as I’ll get, I found some of the brain teaser questions on some homework problems more challenging to figure out since I am really not a “left brain” kind of guy (which is why I have two art degrees in the first place). When it comes to slightly complicated if/else statements or for, sometimes my brain just locks up, and I get “writer’s block” for coders… The assignment on writing a “Bubble Sort” messed me up quite a bit before I could immerse myself in how it should be coded… I think Alex got annoyed a few times after the 100th time I asked him how something trivial works in Java… But really, my brain completely went on a strike…

I still got one last problem on writing a “Magic Square” class on the assignment… Hopefully I can complete that in time for class on Tuesday.

Rebel Forces Have Landed

Wednesday, January 31st, 2007

At long last, the much anticipated Java class I’ve been wanting to take all year in 2006 finally started on Tuesday. After having played with PHP for 4 years, I’ve finally felt the need to pick up something else for a change. Partly, my cousin Alex is to “blame” for pushing me into Java for its enterprise-readiness.

A couple of interesting statistics about this class:

1. A typically uber-geek class has almost 1/2 of the students being women.
2. Everyone else in the class has either an IBM ThinkPad or some sort of loser Dell laptop. I am the lone Mac user in the class with the only Mac laptop (yoohoo!).
3. Everyone else planned on coding Java using Windows; I am the only person using Mac OSX (yoohoo!) while one other guy is using Solaris.

Hopefully this class will worth its weight in tofu. I had the same instructor in a previous database design class, and that class turned out to be very “profitable” for me. So hopefully I’ll be able to make what I learn here equally successful economically. :)

Get Rid of Dotted Outlines on Windows Browsers

Friday, December 22nd, 2006

For you web developers, I am sure your clients have often tried to make you do the impossible — correct mistakes and/or idiotic decisions made by Microsoft on how browsers should behave on the Windows operating system. Fortunately some of these mistakes can be corrected with hacks and work arounds. Here’s another one…

Some browsers (namely IE and Firefox) have this annoying behavior that’s a Windows-only trait — upon clicking an active link, it leaves a ghosting outline of dots around the link enclosed by the anchor tag. There are two work arounds that I know of to get rid of, or rather, prevent this from happening.

Method 1: Javascript — Yes, yes, I know client-side scripting is not reliable and all that jazz. All I am saying is, this is A work around. The idea is to make these links sans-anchor tags… That is to say, write a Javascript to respond to “onClick” events within, say, < div> or < span> tags.

EXAMPLE:

< div onClick="doSomething();">Click Me< /div>

Method 2: Div tags — If you are trying to avoid Javascript at all costs, < div> or < span> tags may be your best friend. Simply enclose your links with a < div> or < span> tag immediately following the < a> anchor tags, the ghost dots will disappear all by themselves. Sweet, huh?

EXAMPLE:

< a href="linkToSomething.html">< span>Click Me< /span>< /a>

Again, if Microsoft had bothered to adhere to industry standards, there wouldnt’ be a need to use work arounds like these. So I beg of you, use an alternative browser as much as possible. And only use IE sparingly when you must (for those idiots who develop sites that work ONLY with IE).

Review of Mac PHP Development IDEs

Tuesday, November 14th, 2006

Coding, some argue, is an art form. You try to achieve the best results with the most elegant codes you put together within the deadline. And those codes often go through different stages of metamorphosis as you gain more understanding and insight in the knowledge of coding… I don’t mean to get all “Zen” about this, but true geeks know what I am talking about.

And that’s how some people approach the kind of tools they choose to use doing what they do. I, for one, like the minimalistic and swiftness an all-purpose text editing tool like BBEdit offers. It’s light, fast and pretty powerful. And more importantly, it doesn’t screw up my codes like Dreamweaver probably would. But after having dealt with a couple of decent-size web developments, it’s become pretty evident that BBEdit is showing its weaknesses in areas like, for example, debugging, syntax auto-completion and project organization. So I started investigating using IDE to speed up development time and accuracy. I looked at and tested the following packages for Mac OSX:

Apple Xcode
Zend Studio
Eclipse (via PHP plugins: phpEclipse or PHP IDE for Eclipse)
ActiveState Komodo

I also checked out a couple of other simpler, not-quite-IDE, apps just for comparison’s sake against BBEdit:
PHP Studio
Smultron

For you Windows people, someone at IBM also did some homework for you…

Apple’s Xcode was pretty much out of the game as soon I started looking at the specs. There’s no debugging for PHP at all. PHP support stops at syntax coloring. Considering that the IDE is really meant for Macintosh desktop application development, there was no reason for me to pursue further… though I secretly wished it would just somehow magically work…

Next I tested Zend Studio along with Eclipse. Zend’s PHP debugger is very useful in catching even the most insignificant things like if a variable was declared but never used. It also supposedly comes with a “profiling” feature that tests which parts of my codes take the longest to execute so that I can perhaps write a more efficient code. But I never got that feature working. Even Zend’s own documentation and online forums are useless in solving the problem. Another very annoying thing Zend did was including features that are NOT supposed to work unless I paid for and installed Zend’s other products. Zend should at least have the courtesy to gray out those features. But instead, the company simply assumed that those products were already there and lets the user generate endless errors. There are other issues I ran into which made me feel that no one should have to pay for this software — it felt like a cheap beta.

Eclipse is an open source software which plenty of Java developers seem to love. Kyung first told me about Eclipse when he was using it. The setup was pretty straight forward and the debugger was also pretty nice, but its messages weren’t as contextual and as helpful as those in Zend Studio. But it was still a lot more helpful than PHP’s useless error messages. The only complaint I have about Eclipse is its performance on my aging PowerBook and lack of straight forward support for profiling (no graphics, just a bunch of tables).

Komodo is made by the same company that makes ActiveState Perl for Windows. It has by far the BEST user interface of all IDEs for Mac that I’ve tested, and it’s also most Mac-like. Unfortunately, it complained that my installation of PHP was bad (and won’t say why) and refused to work with it. And in order to get profiling to work, I’d have to install xDebug (which I did) and mess with a bunch of settings… It was pretty disappointing not getting Komodo to work.

PHP Studio and Smultron are pretty much like BBEdit except that PHP Studio has a more superior IDE-like code organization (like recognizing functions and classes that I’ve written within the same project and put them nicely in a side panel) which BBEdit doesn’t even come close to having. Unfortunately I could only work on one file at a time (no multiple tabs!). Smultron is pretty much a free version of BBEdit with a few things missing (which I don’t really care about). I probably wouldn’t have paid for BBEdit if I’d known about Smultron sooner….

So at the end, open source rules again. Come to think of it, I’d be pretty embarrassed if I were the project manager woking for Zend Studio or Komodo for making such awful products (though I should give Komodo the benefit of doubt since I couldn’t get it to work).

No wonder Apple ended up making its own IDE seeing that the mac programming IDE market is littered with such inferior alternatives. I wish someone would write an extension/plugin for Xcode and actually make it useful in coding web-based projects (PHP, Javascrit… etc). Maybe Xcode 3?

(More) Ajax Woes in Safari

Sunday, October 29th, 2006

The more I deal with Ajax and Safari, the more interesting problems I get with the combo from time to time. Since my last run in with the dual, which forced me to rebuild that particular section of the site using more traditional means, I have recently discovered one more issue having to do with multiple XMLHttpRequest calls via the same object from the same page. The short version of the story is: It CAN’T be done in Safari* (or not in the method that I know of). Firefox and IE, however, seem perfectly happy with using a single object to make multiple asynchronous calls.

Fortunately I am not crazy. I found an article that briefly touches on this issue. This article is also a very good short tutorial on how to get started on Ajax (though the author uses a Ruby backend to iterate the codes, which can easily be replaced using any code you are comfortable with.). Another article offers more depth on the same issue with some code samples to show (via Ajaxian.com).

To get around the problem, one way is to simply create multiple objects, one for each call request, as opposed to have one object to handle all the requests. If you don’t do this, when you make one XMLHttpRequest call, all the other Ajax fields on the same page will start loading as if they are expecting something back from the same request (for which they’ll wait an eternity and never get anything back).

Sometimes I just don’t know how I solve these kinds of voodoo-like problems. Even Google is powerless before I knew what the problem was. I mean, how do you Google for problems you don’t even know how to describe? And this issue was particularly annoying because Safari’s Javascript console didn’t report any errors.

*I also discovered that the same issue takes place in Webkit (the HTML rendering engine at the heat of Safari) based browsers, including Shiira. Though strangely enough, Camino (a cousin of Mozilla FireFox), much of whose gut is based on Safari’s renderer, didn’t have the problem at all! It’s also interesting to note that Opera 9 also suffers from the same issue.

More Geek Talk

Friday, October 27th, 2006

Mike Neely discovered something pretty freaking awesome: It’s called Meebo. It’s basically Adiumx (or Trillian for you Windowz folks, gaim for you Linux dorks) except it’s web based. It supports quite a bit of stuff that you are accustomed to using desktop apps.

Speaking of apps, Neely revealed the other day that he’s doing some cocoa programming! I am so envious of him having the initiative and drive to pick up cocoa/objective-c. This reminds me that I ought to get back into desktop programming!

While I am on the topic of “desktop” programming, I tried upgrading my Fedora Core 5 to the latest Core 6 last night but failed. I guess it’s too new that various issues aren’t widely discussed yet (bless Google). I’ll probably give it another try another time. Strangely though, the audio in FC5 just magically started working all by itself — I spent days downloading and compiling various drivers for it to no avail. And that piece of sh*t just decided to work all of a sudden? WTF?! This is yet another reason Linux is far from being ready for mainstream consumption — lack of usability for everyday-users.

Back in Web Development

Thursday, October 26th, 2006

I have been working on a project non-stop for 2 weeks to get the final features up and running. But I just couldn’t stop squeezing in some good-to-have features to boost the overall “value” of the product a bit. Here’s a short list of what I thought were really slick features:

1. Javascript lightbox: This one feature can probably single-handedly describe what the Web2.0 movement is all about. The BEST part is, integrating Lokesh Dhakar’s code to the project (or ANY project, really) is just a couple of copy and pastes and one line of code change!! That guy is a genius.

2. Recursive delete: This a pretty kick-ass class for recursively deleting whole directory structures even if they are not empty (PHP programming in Unix environments, this is a big deal). My project requires my PHP scripts to interact with physical directories. I thought it’d be a complete waste of my time to write a function/class to do this if someone else’s already got a solid script. Implementing this just took one line of code.

3. Directory compress & backup: I used this script to work in conjunction with “Recursive delete”. Basically before anyone deletes a whole directory, my PHP application will automatically back it up and nicely tug the compressed file in a safe place. Again, this is a kick ass class because it only takes a copy/paste and defining of a couple of variables.

4. Unique ID check via Ajax + PHP: I wrote this myself using an Ajax class I assembled from prior projects. It simply goes to the database and checks if whatever the user ID (or product ID or whatever) already exists. One bug I encountered under Safari was that if XMLHttpRequest returns nothing from the database (which means the ID the user entered was unique), Safari makes status undefined or null value complaints. One way to get past solve this problem is for XMLHttpRequest to return an empty space via PHP (or whatever language you prefer)… i.e. echo " ". Here’s a nice blog about Ajax related issues. This issue is also pretty well documented here though “bitterpill.org’s particular trick didn’t solve the problem for me.

5. Multiple file uploads: The Stickman has some really neat references to a handful of technologies I am currently exploring. This “multiple file upload” script isn’t particularly elegant but does its job exceptionally well. I was able to integrate this, along with everything above, into one coherent code base, fortunately.

6. Snif (stands for “simple and nice index file” ) is probably one of the best-looking and utilitarian directory and file index script I have found thus far. There are tons of others that do way too much or too little (some of which cost quite a bit too). The downside of snif is that the code hasn’t been maintained for quite a while, and its forum is littered with more questions than answers. But I did find some nice “mods” to enhance its core functionalities quite a bit. Another problem I had with snif was how hard it was to integrate into my existing code base. That said, snif is still a very solid standalone directory index script though!

7. By accident, I stumbled upon a list of Web2.0 sites from Tucows. I look forward to studying up the latest eye candies these sites offer for my future projects.

So now that most of the core features are done, I just need to find a fast(er) Windows environment to test the css layouts, mostly for IE. I wish IE would just go away so that us web programming types don’t have to deal with Microsoft’s snobbish approach towards web standards. Go Firefox, Opera and Safari.
.
.
.
Apple finally decided to release Core 2 Dual version of MacBook Pro right before Christmas! How kind. I made a pseudo promise that I’d get a MacBook Pro if they upgraded it to Core 2 Dual… not knowing they’d do it before January’s Macworld… But since the budget is kind of tight these days, I will hang on to my trusty old PowerBook G4 until OSX.5 Leopard comes standard with MacBook Pros! Hah!

Refuge

Sunday, August 20th, 2006

Most people don’t realize just how impossible it is to work at home in peace, especially when everyone else is also at home. But even when nobody is at home to bug you, there’s still plenty of distractions:

“Have I paid the electric bill yet? I better do that now.”
“What’s that sound in the living room? Did one of the cats knock something off? I better go check it out.”
“Did the postman just drop off the mail? I better go get that…”
“Why doesn’t the neighbor pick up her phone? It rings so damn loud…”

It’s especially tough this month because my mom’s visiting, and I basically gave our spare bedroom, a.k.a. “my office”, to her and work on our dinning table in the kitchen where it’s almost impossible to work because Grace and mom watch Korean drama, marathon style. Besides, mom is always doing stuff in the kitchen when she’s not watching Korean drama with Grace… Then there’s Bryan playing with his toys just 3 feet away in the living room right next to me.

With my latest project being 2 months overdue, and I am under tremendous pressure to “show” something in 3 days, I have had to “escape” from the house and find refuge elsewhere to concentrate and just crank out codes. At first I tried the library, but then it’s almost eerily quiet after having been in a house where there’s always something going on.

The most unlikely refuge, I found out, is the Mall, of all places, the most crowded and noisy space. The interesting thing about the mall though, specifically Vally Fair Mall in Santa Clara, is that the music is always blasting in full volume (which I never noticed before). The crowd and the noise actually help me concentrate even more. It’s like I find peace in my little 15.4″ laptop screen in a massive crowd where I intended to find refuge away from a small crowd at home. What an oxymoron.

Just a couple of months ago I debated really hard whether or not to rent a small corner office for a few hundred bucks a month just so that I have a place to go and just focus on my programming, homework and everything else. But I just couldn’t justify having to spend that kind of money when we are trying to save every penny we can being in the situation that we are in.

The mall then becomes an interesting choice because it has no distractions (as long as I don’t lift my head up from the screen), no trivial household tasks to take care of, even going to the bathroom is inconvenient. And it’s got free wifi connection right next to the Sony Store where there are lots of seats, tables and even power outlets. So there, about the only thing I can do is bury my head in my thoughts and programming logics and just work.

The joke between me and Grace now is: if you ever need me, I’ll be in my “office” at the mall…. Hah!