Log in

No account? Create an account

> Recent Entries
> Archive
> Friends
> Profile
> previous 10 entries

Mike Gonzalez (The only good blogger on the internet)
Bitdesigns ~ Bit Santos

November 3rd, 2007

12:14 am - Transform XML into a Javascript object
After the Wordpress editor crashed all three of my browsers (Firefox, IE, Opera), I decided to say "screw it" and post here instead of the blog I made for the stuff that's boring to the public at large.

I’ve been looking for a Javascript way to navigate through an XML document like an object. That is, I wanted to take an XML document returned from an AJAX request (eg:
), and go through it by saying something like “book.author.name”. Surprisingly, it was very difficult to find a solution–or more accurately, impossible. I had figured that this was something someone would have invented long ago, but I actually couldn't any implementations of this idea. I ended up writing my own function, and I’ve posted it below. (I realize that I could have saved effort by using JSON instead, but XML I don't think you'll always be able to get a JSON representation for a project)

I get the impression that this function is going to be slow–I put each node into an array (in case there are multiple nodes with the same name), and afterwards, flatten any arrays of length 1. However, I don't think it's slow enough to have any visible effect on small files (you have no business doing it with big files anyhow!). Any comments are welcome, as this code probably has shortcomings. For starters, it will flatten any array of length 1, even if it makes more sense to keep it as an array (eg: a grocery list consisting of one item should still be an array). Also, this code gets attributes as well, so be sure not to have any conflicting names. I'm sure there I made other unsafe assumptions, but for now, it works on Firefox, Opera, and IE.
    function createObj(xml) {
var obj = {};
if(xml.attributes) {
for(var j = 0; j < xml.attributes.length; j++) {
obj[xml.attributes[j].name] = xml.attributes[j].value;
for(var i = 0; i < xml.childNodes.length; i++) {
var x = xml.childNodes[i];
/* Note: IE and Opera do not define Node or its constants. You'll need to define them yourself
* for the benefit of said browsers.
* Meanwhile, the childNodes.length check is there because Firefox counts any whitespace as text nodes.
* This function, then, will only work on the assumption that "real" text nodes are the lone content
* of their parents.
if ((x.nodeType == Node.TEXT_NODE && xml.childNodes.length == 1)) {
return x.nodeValue;
if (x.nodeType == Node.ELEMENT_NODE) {
// Assume a child node consisting of the empty string if there are no further children.
if (x.childNodes.length == 0) {
return "";
if (!obj[x.nodeName]) {
obj[x.nodeName] = $A();
obj[x.nodeName][obj[x.nodeName].length] = createObj(x);

for(var a in obj) {
if(obj[a] instanceof Array && obj[a].length == 1) {
obj[a] = obj[a][0];
return obj;

(3 comments | Leave a comment)

October 8th, 2007

10:23 pm
I saw the classiest DS Lite today. With a US retail price of $150, I think PhP 8800 is a fairly good price for it, considering it comes with Brain Age 2, a carrying case, and a fairly sexy color scheme. I'm not really the sort of guy who'd spend good money just for a better looking version of something I have, but replacing my DS Phat with it would have practical advantages.
  1. I could play at any time. Technically, you could do this with the DS Phat, but the backlight is so dim that the sun actually DROWNS OUT your game. Contrast this with a DS Lite, which uses some sort of nuclear core for each screen.
  2. It's smaller. Not by much, but it's compact enough to fit in my pocket comfortably. Plus it comes with that nifty carrying case which makes it look like you're an adult by merely holding it.
Anyway, if anyone wants to buy my current DS from me, I can let it go at a negotiable PhP 6000. I'm not sure if my homebrew kit (Supercard plus Superkey, DS is NOT modded) is compatible with the DSL, so if it turns out that it isn't, I can include that in the package for a total of 9000 bucks. Now, you might wonder: why would you pay that much for my DS?
  1. It's harder to play in the sunlight. This will instill discipline, and encourage you to work or study during the day, rather than waste time capturing Pokemon.
  2. It's bigger. Christ, have you seen that DS Lite? It's so tiny that you probably wouldn't notice if you lost it until it was too late. Plus it doesn't need some gay carrying case; it can survive scratches all by its lonesome with its hard and durable casing.
So if you're interested, get in touch with an offer and I'll hook you up.

(1 comment | Leave a comment)

12:11 pm
It took me the longest time to get Python's MySQLdb library running on Cygwin. Since I technically didn't have Python installed (it wasn't in the Windows registry), I couldn't use the binary provided on Sourceforge. I had to build it from source, but several problems got in the way. I'm blogging the process in case anyone else gets the problem (I found the ultimate solution on some random forum which is tucked deep in the the search results).
  1. mysql_config could not be found as it wasn't on my path. I had to edit one of the cfg files in the MySQLdb directory to find it. (I think it was site.cfg)
  2. I then had to edit mysql_config itself because it wasn't outputting the correct paths. That actually didn't work, so I just copied the libs and includes from the MySQL folder into the paths specified by mysql_config.
  3. I couldn't just rename config-win.h into my_config.h--I got a lot of compile errors. I ended up downloading someone's copy of my_config.h off the internet (and editing out a line which was including some local file of his)
  4. Removed the -lnsl link (or something like that) that mysql_config was including. I hope this doesn't impact anything, but some of my search results showed people removing it safely.
  5. I compiled it with thread safety off. I'm not sure if the thread safety version works on cygwin.
  6. This last one was the trickiest and took hours. I was getting a lot of permission denied errors. After chmodding just about everything related to MySQLdb (I didn't think chmod even made sense on a FAT file system), I found out that mysql.dll was getting cached in HOME/.python_eggs, and that's the dll the module was actually using. I chmodded it +x and FINALLY everything worked.
Reading over this entry, it is quite boring and maybe I should just put this sort of thing on a separate blog.

(1 comment | Leave a comment)

October 5th, 2007

11:18 am
Just attention whoring here but I decided to register a blog for talking about what I was talking about in my last entry, and it's right here: http://phillippinos.blogspot.com.

(Leave a comment)

August 21st, 2007

10:14 pm
Well, I guess everyone on the blogosphere is up in arms over Malu Fernandez, and I thARRRGH JUST SHUT THE FUCK UP YOU STUPID GITS

Leave it to the Philippine "blogosphere" to get all riled up the moment someone says something bad about Filipinos. It's fucking ridiculous; people are making a big deal over nothing. Everyone has something bad to say about their country and countrymen, and I doubt any of those things are any more fair than Malu's remarks. So she put her foot in her mouth, or has Tourette Syndrome or something. Big deal. This isn't patriotism, it's nothing but an embarrassing display of mob mentality. ONLINE mob mentality. Way to put yourselves at the level of Harry Potter shippers, guys. You're not exactly doing our image any favors by being all immature about it.

I mean, even Manuel Quezon III is getting into the act. While I'm glad someone disagrees with this fellow and his campaign, I'm disappointed that he followed it up with a terribly unfunny caption contest. Not only is this ridiculous meme in bad taste, but it's completely devoid of anything resembling humor. Believe it or not, getting pictures of the writer and insulting her appearance are not a road to instant comedy. What's next on your agenda, guys? A Photoshop contest? Great! Let's show this bitch just how mature we REALLY are!

What goes on in the mind of the blogger? I can't help but imagine someone shaking his fist in anger, shouting loudly in his mind, "hey guys hey look over there someone just talked trash about the motherland, LET'S GET HER! PHILIPPINE DEFENSE FORCE ASSEMBLE!"

What we need is not gruesome parody. What we need is not some sort of punitive measures. What we need is to CHILL THE FUCK OUT RARRGHH BECAUSE YOU PEOPLE ARE DRIVING ME TO THE EDGE OF INSANITY

See also:
Claire Danes goes to Manila
Americans eat at Jollibee
I'm somewhat ashamed of ever making this one, in retrospect

edit: Congratulations, bloggers. You sure showed her. Are you now going to start blogging about your victory over this week's greatest evil? I guess I have yet another event to append to filipinos.txt.

edit 2:
Here you all go: philippine-defense-squad.txt
Special mention to Dom, whose comments I partially copy-pasted.

(1 comment | Leave a comment)

August 16th, 2007

02:16 pm
Hey everyone! Hey! I have this great idea that I'm sure would take off and make a lot of money if done right, but it's not something I want to associate myself with, so I'm giving it to whomever wants it, in exchange for royalties.

The target demographic is: approximately 70% of white-collar workers. The product idea is: coffee-flavored cigarettes.

I neither drink coffee nor smoke so someone had better hurry and follow up on this idea then give me a 20% cut of the profits. That is all.

(Leave a comment)

July 22nd, 2007

12:21 am
Mark blogged recently about how he reviewed some potato chips, and how its makers, Fukuda, saw the entry and sent him 63 boxes of their various products. Mark went on to give the advice:
I was left in shock and awe after opening both boxes. I simply could not believe my good fortune. Their contents exceeded all expectations, and then some. If this story of mine does not inspire you to go out there and blog about whatever it is you are passionate about, then I do not know what will.

Ahem... the Wii by Nintendo, the Sony Playstation 3, and the Microsoft X-Box 360 are all really great, and I'm really passionate about the video game industry.

Ok, Nintendo, Sony, and Microsoft. I reviewed your products. Come on, guys. Fill 'er up!

(Leave a comment)

November 6th, 2006

01:30 pm - Mystery
Last Thursday, the internet connection at my house went down for the nth time. I, of course, attributed it to PLDT being totally worthless, just as they had continually proven over the years. However, the problem was much worse than I initially thought.
Long ramble... (warning: pointless)Collapse )

(Leave a comment)

October 2nd, 2006

12:31 am

(Leave a comment)

September 19th, 2006

05:33 pm
If anybody tries to speak like a pirate to me today, I will stab him or her in the face (over the internet).

(1 comment | Leave a comment)

> previous 10 entries
> Go to Top