Skip navigation

Category Archives: Personal Projects

There. I beat my deadline. The main site is live again! Yay!

But that is not to say that I got this without glitches. Let’s see…

After feeling good with the WordPress site I developed locally, I pushed it live by uploading all my local files (and changing password-related configs) to my server. However, I noticed that all my links start with “localhost”—they are pointing to the local version I developed. The only page I can view from my remote site was the home page.

The fix is easy enough. I just had to change all option values in the wp_options table of my WP site so that they don’t refer to localhost. To that end I ran the following query in my database:

UPDATE wp_options
SET option_value = REPLACE(option_value, 'localhost/', '');

Note: be careful when running queries like this. The pattern matching went fine for me but some future version might use the term ‘localhost’ for something else. Always back-up before running! Also, you could’ve set this option up in your WP Admin. Just go to Settings -> General and change the URL-related settings. I wasn’t able to do it in this case because even the WP Admin was getting redirected to localhost!

So, after running that, I got my links good. However, clicking on the links returned a status 500 error (Internal Server Error)!

Googling around, it seems that this has something to do with my .htaccess . The .htaccess is a config file for web servers famous for allowing URL rewriting. It’s the magic behind instead of You can also do cool (or sick, depending on your tastes) things with it like having pages with a .exe extensions (or pointing unsuspecting users to a normal .html page but is actually a sketchy .exe download). Here’s one tutorial I’m quite fond of.

Anyway, my .htaccess looked like, this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [L]

Now, I had no idea what to do with my .htaccess to prevent the status 500 from happening. Thank goodness that kodeplay itself is WordPress-powered. So, I just patterned it from kodeplay’s .htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Aaaaannnd voila! Main site up and running! (Though, I won’t be surprised if there are still bugs with my launch.)

It seems that WordPress has a tutorial for migrating WP set-ups. Guess I should’ve read that first no?

Now, a TODO: Write a new entry on my main blog. The most recent one is now more than a year old!

Okay. I know it’s already February and that it’s kinda late. But it’s in times like this that I say “better late than never!”. But as I’ll show, I’ve already started with my resolutions—I’m just writing about them now.

But since this is my coding blog, the resolution I will mention here will be my technical-life resolution (as opposed to the personal ones everybody makes). So, without further ado…

I resolve to learn a new technology every month. Or, at least, get deeper with one I’m already acquainted with.

Also, I’d go into programming competitions/contests again. Team requirements limit my choices but, hey, there are a lot I can do alone online, not to mention free! (Though if anyone wants to team-up with me, let’s talk.)

And, just so I’ll stick with it, I’ll write a blog post every month about what I’ve been up to. Consider this the one for January.

For my first resolution, I created this sandbox repository at GitHub. And since my GitHub account is, in itself, already my sandbox of sorts, I guess this is some sandbox-ception eh?

January, I did sockets in Python. I didn’t manage to dig as deep as I’d have wanted because the Facebook Hacker Cup kicked in earlier than I expected and that falls under my second resolution. So it had to give way. Besides, I’m already dealing with a few sockets too many at work.

Regarding my second resolution, I don’t really expect much from it. At least, I won’t get rusty from the lack of problem sets in the real world (read: industry). At most, I might score a free trip to some world finals. But that world-finals scenario is still very out of my league. I’ve been doing ACM-ICPC problems since I was in my sophomore year in College and even now I find most of them really tough and tricky. Also, after less than a year out of school, I’m bound to have some rust in my system (not that school is a sure fire way to keep you sharp though). I only decided to start practicing with my algorithms sometime in December so there isn’t really much to expect.

(Note: I started writing this post in the last hour before the first round of Hacker Cup started. It’s now over and everything fell within my expectations. There’s a lot to learn. Maybe, I’ll write about this soon.)

So, what do I think about sockets in Python? (This will be short since, as mentioned, I didn’t have much time to dig deep into this.)

As with all things Python, it looks super neat. I got a client and server up and running in just 41 lines of code combined. The biggest savings comes from the fact that socket I/O is direct in Python; you no longer have to create OutputStream and InputStream objects as the socket objects themselves have methods for sending and receiving. It’s also interesting to note that Python’s socketserver class has a serve_forever method which, as the name implies, handles requests as long as it can (the official phrase is: “until an explicit shutdown signal is received”).

Oddly, this design reminds me how I handled one of the things I did at work. Won’t go into the details but I thought that it’s neat to have one class responsible for managing one whole session: packet numbers, windowing, etc. One instance of a class maps to one client; when client goes away so does this instance (at least, I no longer care if the garbage collector marks it as garbage). Makes OO live more peacefully with concurrency.

Awesome that Python enforces this design by default. Really, the more I discover about Python, the lovelier programming gets.

‘Till I get my February experiments done! ~Chad

Still working on my revisions for my personal site. It was on full throttle last December but had to take a backseat due to work and something I’m preparing for. Oh well…I’m trying to meet a personal deadline of end-of-this month to mid-February (Feb 16! Mark the concrete date!).

It’s not exactly a tough project but, being the OC guy I am, I’m making sure all ends are ironed well and that’s what’s taking my time. To meet my deadline, I had to cut certain pages (not posts) for which I only have a vague idea as to the content they’ll hold. It feels so long since I did some creative writing.

Now, I ran into a problem removing them from my nav bar (since I don’t want users to see not-even-baked pages, right?). I thought that marking them as “draft” would do the trick. However, they remained on my nav bar.

I’ve been looking into the database and how WP queries for the navbar’s contents, to no avail. There are forum posts regarding this, both I’ve found to be two years old, not to mention not-at-all helpful. That’s when I realized that, last December, I was able to customize my nav bar from the CMS itself, as opposed to hacking the code.


After some clicking-around the CMS I found what I’m looking for in “Menu” under the “Appearance” tab. You should see some click-and-drag interface for managing what appears on your navbar.

It seems that publishing a page automatically adds it to your navbar but marking it as “draft” does not trigger anything. To make things worse, users not logged-in as an author will hit a 404 if they click a “draft” link. If you are a registered author on the WP site concerned, you’ll still see the actual content. Tsk. First timers might miss the fact that their users will hit a 404.

That’s all for now. Keep coding ~Chad.

If you’ve been anywhere near my main blog recently the front page has been looking like this for quite some time now


Yeah. I’m currently redesigning the website. I don’t know why. Guess it’s just that the look and feel I designed when I was just in my sophomore year in college is not me anymore. Tsk.

Anyway, this is the fourth time I’d be redesigning my main blog ever since I got my mind around blogging. I started blogging when I was in third year high school. Four versions in five/six years? Not bad, I say.

This time, I’m relinquishing controls over to WordPress. The first two “versions” of my blog were all static HTML plus some JavaScript. And it was hosted at GeoCities. The third one had some CMS/parser I wrote using Java, the result of which I’d upload using FileZilla to my own bought webspace. It was in PHP and XML—no databases. The CMS/parser was one hell of spaghetti code; it’d break at corner cases every now and then and I never got around to fix those bugs since, hey, I can live with it. Come to think of it, as I switched machines over the last few years, I’m not sure if I still have the original source codes. I only have the jar file.

But I’ve been woolgathering. My whole point here is to note what I learned with tweaking WordPress.

Where do I start?

Depends on where you want to go. Don’t want your blog posts on the front page but, instead, have some dedicated page for it, featured on your nav bar? WordPress got you covered easily. Just go to “Settings” -> “Reading”, and you should see something like this:

reading_settingsPretty self-explanatory eh?

But what if you have already have a theme which displays your latest posts on the front page but you just want to customize it somehow? Enter, WordPress’ The Loop.

Put simply, The Loop1 is what is responsible for displaying the posts in your blog. You can invoke The Loop in many ways. What I’m using for my main site is as follows:

     $temp = $wp_query;
     $wp_query= null;
     $wp_query = new WP_Query();
            while ($wp_query->have_posts()) :

Again, pretty self-explanatory. Note that this uses PHP’s templating syntax: you can write HTML in the position of those elipsis and they’d be written at every iteration of the loop, if they apply. Also note that I could have used the more-common “curly brace” syntax when writing loops and conditionals but, for templating, it makes more sense to ditch this tradition and go ending blocks with the end syntax as this makes it cleaner to distinguish which block you are ending.

So, what can go inside the loop?

This is where you’d typically print out your blog posts. WordPress provides a host of the_* functions for you to access the parts of your post. All their names are very self-explanatory. Of note are:

Putting it all together

If you want your theme to display your posts on the front page, you’d have to put The Loop in some file like “home.php” or “index.php” found at the wp-content/themes/themename of your WordPress installation. So, say you want a basic list of recent posts that show the title (which links to the posts “solo” or “permanent” page), author name, and the contents, you’d end up with something like this inside The Loop:

<h1><a href=<?php echo '"'; the_permalink(); echo '"'; ?>>
    <?php the_title(); ?>
<?php the_author(); ?> <br />
<?php the_contents(); ?>

But wait! I’ve too many posts!
This is the time you handle pagination in your blog. To display the “pagination links” (as I call them), you have plenty of options (which are, again, very self-explanatory):

Note that WordPress is smart enough not to display a pagination link if it does not apply (i.e., if no posts are newer/older).

404 Trouble

When you click on your pagination links, it may happen that you get a 404 (Not found) message. This is easily fixed.

At line 5 of my The Loop code listing above, I indicated the number of posts I want per page. This value should be equal to what is set in your WordPress settings. At Settings -> Reading, see the value “Blog pages show at most”.

Is that all?

By now, this should be good to deviate a bit from the themes you get. You can do more by tweaking the CSS of your theme though if you had to use someone else’s theme I wouldn’t advice intensive CSS tweaking (you’re probably no designer). But well, whatever floats your boat.

  1. Can’t help it but WordPress’ terminology reminds me of another “The Loop” in my geek life: The Game Loop. But that is for another time entirely. []

UPDATE: Having problems making your DDLs utilizing foreign keys work with InnoDB? This may answer some questions.

In retrospect, I made the same mistake when I asked that at SO as when I made this post. The errant statement when I made this post is

timestarted DATETIME NOT NULL,
PRIMARY KEY (timestarted),

No column reference.

Note: This post is a summary of this Ubuntu Forums Programming Talk thread. With special thanks to nklatt for asking the questions which led me to my resolution.

I’ve been working on a JDBC-backed application. Since I am familiar with MySQL, the MySQL Connector/J comes as a natural choice for a database driver. Since I’m using Java, I expected my code to run on both Linux and Windows environments.

Testing it with Vista, it runs well. However, when I tested it in Ubuntu, I was greeted with the following error:

java.sql.SQLException: Can't create table 'dbname.timelogs' (errno: 150)

Googling around, I found this which says that this error happens since MyISAM, the default storage mechanism used by MySQL, doesn’t support foreign key constraints. And yes, I am using foreign keys in my tables. Also, a quote from the official MySQL docs says,

Foreign key constraints are supported for the InnoDB storage engine only. For other storage engines, the foreign key syntax is correctly parsed but not implemented.1

I checked the tables created at Vista and found out that they use the MyISAM storage engine as I expected since I didn’t specify any storage engine in my CREATE statement and so should fall back to the default. This made me wonder all the more why didn’t it throw the error in Vista when MyISAM isn’t supposed to support foreign key constraints.

At this point, I must note that Vista runs XAMPP 1.7.3 while Ubuntu runs version 1.7.4 . I didn’t think that my XAMPP version will matter—after all, Vista is only a version behind. Spoiler: I thought wrong.

I changed my CREATE statements such that they explicitly specify the InnoDB storage engine. I ran my modified code in Vista and, surprisingly, Vista threw the very error Ubuntu does.

Confused, I switched back to Ubuntu and, for the first time in this bug-hunt, checked the table created2 at phpMyAdmin (I have two tables in my database, only one of which specifies a foreign key. The one without the foreign key gets created, of course). I discovered that MySQL 5.5.8 (the MySQL server that comes with XAMPP 1.7.4) actually defaults to InnoDB and not to MyISAM3.

So it turns out that, weirdly, the InnoDB storage engine was the one causing all my problems despite the documentation declaring that it supports (in fact, it is the only storage engine that supports) foreign key constraints. Resolution: stick with MyISAM since that is where my code runs, despite the fact that it doesn’t really support foreign key constraints.

(In any case, the user will interact with the DB through a GUI. So, it’d be more or less the GUI programmer’s fault, i.e. me, if some record doesn’t make sense. Sigh. So much for being a one-man team.)

  1. , retrieved 6/22/11, 11:09PM GMT+8. []
  2. This was still the one created by the code not specifying any storage engine causing MySQL to default. []
  3. If you read the thread I linked above, nklatt pointed this out beforehand for MySQL 5.5 . []