Home
Argument

> Recent Entries
> Archive
> Friends
> User Info
> previous 20 entries

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

Advertisement

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:
<book>
  <author>
     <name>Miguel</name>
  </author>
  <title>Hello</title>
</book>
), 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;
}

(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.
Tags:

(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 28th, 2006


10:23 am
I cannot believe I spent half an hour writing this, but hey. :(
Hello, my name is Miguel Arguelles, and I live in the Philippines. I am writing on behalf of several people in the Philippines who are, as I have learned, unable to purchase Wii points.

We in the Philippines typically purchase American versions of Nintendo systems, as we are mainly an English-speaking country. Unfortunately, upon purchase of the Wii, we learned that the Philippines is not even available as an option when choosing our home country. Among other things, this bars us from purchasing Wii points with our Philippine-issued credit cards.

We do not know how people outside the Philippines view my homeland, but we do know that it would be a large shame for us if we could not purchase Wii points. We understand that Nintendo has a Hong Kong distributor, but the inflation caused by importing, even from Hong Kong, is very large--we are not inclined to pay 600 American dollars for a Wii, and we are even less inclined to pay $40 for only $20 worth of Wii points.

I do not harbor illusions that this letter might even make it up high, to the people who have the power to change things, but I do what I can to raise awareness of the matter. This issue, as far as gaming goes, has significance to all of us here; most of us have gone through the first-generation systems like any American, and the only thing we can be faulted for is living in the wrong country.

Nintendo has long pushed for togetherness; this is evident even in the very choice of name for the Wii. It is in this spirit that we in the Philippines hope that, for once, we can share in the opportunities available to everyone else.

(2 comments | 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) )

(Leave a comment)

October 2nd, 2006


12:31 am
TRAPPED IN BLACKOUT STOP SEND HELP STOP

(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)

September 4th, 2006


01:13 pm
Steve Irwin dies of stingray barb through chest
oh god, steve...
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
This is made worse by the fact that his wife is hiking up a mountain and does not yet know. Amazing. Millions of Internet denizens will know about it before she does.

(Leave a comment)

August 12th, 2006


02:38 pm - I just heard this story
So, there's a man crawling through the desert.

He'd decided to try his SUV in a little bit of cross-country travel, had
great fun zooming over the badlands and through the sand, got lost, hit a
big rock, and then he couldn't get it started again. There were no cell
phone towers anywhere near, so his cell phone was useless. He had no family,
his parents had died a few years before in an auto accident, and his few
friends had no idea he was out here.

Read the rest... )

(2 comments | Leave a comment)

July 19th, 2006


01:45 am
I've started writing stuff on argument.88-mph.net. I'll probably be crossposting most of the stuff here, though, especially as I think we're doing something wrong with the Rails config right now, as it seems slow despite being on the supposedly fastest Apache + FastCGI. Routing is also NOT fixed yet; the URLs look very ugly at themoment. I certainly would not want the data there wiped out by a fatal error during debugging.

(Leave a comment)

June 13th, 2006


01:36 pm - Newbie on Rails Mini-entry
Some cool features of Rails that I've found recently (and some important reminders to myself):

I was writing a simple blog engine that supported multiple blogs for multiple authors. One problem I was thinking about for a while was retrieving the most recent comments on a single blog. Now, of course, you can easily do this with some good SQL, but I figured that this was such an obvious need that Ruby must have handled it somewhere without requiring me to write a SQL query. Thankfully, handle it they did.
# It's as simple as
# A
def Comment
  belongs_to :entry
end

# B 
def Entry
  has_many :comments
  belongs_to :blog
end

# C
def Blog
  has_many :entries
  has_many :comments, :through => :entries, :order => 
end

# TA DAAAAH
@comments = Blog.find(params[:id]).comments

Sometimes, you want to let the user choose between multiple views of your site. In that case, override this method in the controllers you want to do this in. Make it return the correct rhtml file based on the contents of action_name and you're all set.
def default_template_name default=action_name
  "view_name"
end
Yes, I may have forgotten to mention that the variables action_name and controller_name will contain the names of the invoked action and controller. Useless in the actual action definitions, but these variables are also defined for the filters that are executed before and after the actions.

Very cute stuff.

(Leave a comment)

May 28th, 2006


01:39 am
Politicians today don't know what the hell they're doing. I was hoping they would end the war once and for all, but now all they're doing is fueling the flames with their latest retarded announcement. They made Hank McCoy the fucking US representative for the United States? Hello? He's a goddamn mutant! This won't end well! These fucking mutants just walk around like they own the place, and now this is going to make them feel as if their actions are justified! The government needs to wipe out the mutant threat now! This is like permitting nuclear bombs to freely walk around the planet! We don't even know if Magneto is still actively masterminding a new plot against us; why don't they go after him? Shit shit shitshit I can't stand these idiots any longer. We need to make a stand NOW.

(Leave a comment)

May 17th, 2006


02:13 pm - Public service announcement
Read more... )

(1 comment | Leave a comment)

April 26th, 2006


03:00 pm - Ex-excommunicado
A: Two weeks of no internet.
B: One week with no phone.
C: One day with no cable.

A∩B∩C = Hell

A Haiku

At last it happened,
the nightmare is finally
over. Finito.

Hallemotherfuckinglujah.

(Leave a comment)

April 4th, 2006


01:45 am - With a preemptive "sorry" to the involved party.
It's been a year since we've graduated and people still keep repeating a certain phrase I hate.

BUT SHE'S SACHA CHUA!

Okay, what's wrong with everyone? Every time I suggest doing something challenging, people who lack confidence will say they can't do it. And when I enumerate people who've accomplished it, Sacha often included therein, those I speak to will inevitably reply with this accursed phrase. I hate to break it to you people, but she is A HUMAN, albeit one with extraordinary dedication to what she loves. Certainly, there may be acheivements that she is more qualified to accomplish than others, but why should one let that stop him or her from trying? Here's a helpful hint. "Sacha can do something" is very different from "only Sacha can do something." The awesome things a person does are supposed to inspire, not discourage! Just because someone does something does not mean she is the only one capable of doing it!

I've said it before, and I will say it again: CARPE THE FUCKING DIEM. Why not try taking on that challenge?1 Trust me, though, it's never what you failed to do that you'll regret later on, but what you failed to try. Who knows? Maybe you'll do it, and maybe you won't. Either way, you'll come out stronger.

The lesson is simple: Have some more confidence in yourselves. The fact that someone you know has extraordinary qualities should NEVER prevent you from realizing that, perhaps, there might be something extraordinary about you too.

1 Necessary disclaimer: Note that this is directed towards those who lack confidence. If you're disinterested in something to begin with, that's a different story.

(3 comments | Leave a comment)

March 25th, 2006


01:04 am
Why did the little sidebar jump from my LJ's left side to its right?

EDIT: And why is it now back to normal?

(Leave a comment)

> previous 20 entries
> Go to Top
LiveJournal.com