Skip navigation

Category Archives: Nerd Notes

I’ve always wanted to discuss algorithm problems here but a quick look over at my posts (even just the tags) reveals that I haven’t really done much of that. Over at Github, I have a repository dedicated to solving Programming Praxis problems1 and I’ve thought of discussing my answers here but I haven’t had the time. My interview with Google is, I think, a good chance to dish out something similar to my intentions.

(Author’s note: Of course, I won’t discuss the specific problems I encountered during my interview. For reasons that will become clear if you think about it for a moment, Google clearly prohibits that.)

There are three stages I encountered during Google’s interview process. The first is a short initial (phone) chat with a recruiting coordinator. Next I had a phone technical interview which, aside from taking a longer amount of time, had me coding on a Google Doc. The third part is where they flew me to Mountain View, an interview which Google terms as “panel interview” but I will forever stubbornly refer to as a “circuit interview”.

My interviews, in general, looked at my problem solving skills. For a company like Google, I expected that they will be more interested in my engineering competence, i.e., questions like “How do you get things done?”, “What frameworks have you used?”, “Why would assembly trump everything?”, “Concurrency, Cloud Computing, Parallelization, Multi-core issues, Efficient Caching Mechanism, High-Throughput Responsive MVC Framework Layer MOAAARRRRR!!!”2 .

Watch this short video featuring Laszlo Block on the type of people Google is after. It may be hard to believe, as it was for me, but based on my experience, this is so true.

Overall, I’d say that my Google interview was 85% algorithms/problem solving and 15% engineering.

I found the second phone interview a bit bumpy that afterwards I did not really expect much. I was just happy that I got a Googler asking me technical questions. My interviewer’s voice wasn’t very clear through the phone (as opposed to the first one). It did not help that I was having coughs that day which later developed into a slight fever.

And, as you may know, Google Docs isn’t really made for coding. I wish Google used a platform more suitable for writing code than a word-processing document. My interviewer wasn’t meticulous about syntax but it was still awkward indenting my lines.

That said, here are some tips:

  1. For this part, do not use Python (or any similar whitespace-based language). I was intending to use Python even though I’ve already expected indentation to be difficult. Thankfully, my interviewer stated at the beginning that he’d prefer me to use Java. With Java, you can skip indentation for small blocks of code. Convenient when your line is getting long or the nesting goes deep3.
  2. Indent using two spaces. This is the indentation style of my first company. Tab is too wide and your lines might easily bleed off the edge, especially if you follow my first tip (new BufferedReader is already 18 characters!).

    Why indent at all? Well, no one’s forcing you but I find it easier to debug if I have indentations. Moreover, code is easier to read.

  3. Don’t hesitate to use the Google Doc for things other than code (like clarifications). Remember I said that my interviewer’s voice through the phone wasn’t very clear? Well, this is exactly what saved me.

As for the onsite, Google will be kind enough to fly its candidates in two days before the actual interview so you can settle down. Due to PyCon Philippines, I was unable to take full advantage of this. Nonetheless, I felt little to no jetlag that I even had time to explore a bit on my first night.

Here’s a little tip though: when coordinating with Google’s recruitment team, be clear and patient when it comes to your travel requirements. Based on my experience, Google’s recruitment team is very accommodating and helpful but that is not to say that they are 100% knowledgeable on the arrangements their applicants have to make for travel. (Cut them some slack as I’m sure they handle applicants from more countries than what you can name off the top of your head.)

In my case, I raised the point of needing a Visa for USA travel early on but it was ignored in the email thread so I assumed it’s okay. Thankfully, the issue came up when I coordinated with their preferred travel agency. This delayed me by almost a month. I should’ve been persistent because I’ve been raised since childhood knowing that Filipinos entering the USA need a USA Visa.

Google would really want you to focus on your interview so there is very little that you need to mind during your stay. They’d have your basics covered (accommodation, reimbursable food allowance, reimbursable transportation allowance) so just keep your receipts.

Here’s the interesting part. The onsite interview itself will last for five hours, lunch included (for comparison, the longest job interview I’ve had lasted for, I think, three hours, and it was more a personality interview; HR was talking to me). The reason why I will forever term it as “circuit interview” is because you will have five sets of interviewers, each of them in turn, as opposed to having all your interviewers in one panel.

As I’ve said, my interview was more algorithmic than engineering. One of my biggest anxieties was if they’d give questions the kind they give at ACM ICPC. I’m pretty sure I’d be tongue-tied had that happened. But fear not. The problems I encountered were less obscure and they won’t require you to provide full implementations for the more complicated ones.

Well, I did not make it so you may want to take the following with some grains of salt. But, hey, some tips:

  1. Use Python, finally. Or, bring your own whiteboard markers, as Steve Yegge advises. I’ve read Steve Yegge’s post prior to my interview but I missed the point on his tip about the whiteboard markers. I thought he was advising it just for the “preparedness” factor but notice that he advises it for the sake of whiteboard space. And yes, whiteboard space can be a real blessing. I want to note that, when I was there, Google’s Mountain View office had those flat-tip markers in stock, the kind like highlighters. In my opinion, that’s worse for an interview than the “fat ones” Yegge refers to in his post.

    Nonetheless, with Python, I was able to squeeze in three functions plus lots of scratch and some illustrations in a whiteboard of standard office size. I cannot imagine how that’d look like with Java (or worse, C/C++), nor can I overstate how good a thing is this.

    For the record, I brought my own whiteboard marker but I did not use it, did not even show or mention it, because I got anxious as to coming across as “too eager”.

  2. Use Python, again. This might vary from programmer to programmer but Python gave the advantage that I can focus on high level stuff. Given the nature of Google’s interview process, I believe this worked to my advantage. It’s really like doing runnable pseudocode.
  3. Use Python, not. I think I know where the weak points of my interview was and I believe I was weakest during the last interview. You see, the interviewer started with “I heard you use Python so just keep using that.” So I did. But then he gave me a problem that would require some low-level manipulation and, as I was using Python, I took time clarifying what am I allowed to do and what am I allowed to assume.
  4. Just keep talking. Remember my anxiety above that I might get tongue-tied? Well, here’s the tip: just keep talking, as long as you’re making relative sense. I’ve been told in a pre-interview email that they want to learn how I think so think out loud. Obviously, I’m not sure if this worked to my advantage or what but at least I managed to avoid that Great Wall of Social Awkwardness Produced by Silence. It might even help you; there was a part in my interview when I was like “Let me try some combinatorics here…so 2 will give this…3 will give that…but 4, oh wait—this is easier to to solve programmatically!”. No kidding.
  5. Relax, this isn’t the ACM ICPC. This comparison might deserve a post on its own but for now, the most obvious difference is the time constraint. I realized that the people interviewing me would like to get a picture of me in just around 45 minutes. So, in contrast to the ACM, they’d give you problems that are solvable in 45 minutes or less. Moreover, your code won’t be ran so (at least I think, and this I did), you are allowed a certain extent of handwaving and just say this function does this and that. At times, high-level descriptions of algorithms will also suffice (read: implementation, with all the debugging that might entail, is not needed).

Finally and most importantly, Prepare with a capital ‘P’. Read the Steve Yegge blog post I linked above and follow his advice on having long-term and short-term preparations. I just said above that Google interview isn’t ACM ICPC but I think ACM ICPC is good standard practice material and not just for Google interviews.

What do you prepare for? In my case, knowledge of data structures like some obscure variants of balanced binary trees and even-rarer forms of trees and forests helped as it gave me some talking points. A good knowledge of textbook algorithms will also help. In one case, repurposing a textbook algorithm allowed me to reduce a naive O(n2) algorithm to just O(n).

That said, even if you’re not planning to take a Google interview anywhere in the foreseeable future, I still find preparations of this kind useful for everyday. So just keep reading up and honing your problem solving knack!

  1. I have a similar private repository for the other algorithm problems I’m solving—ACM ICPC practice, to be specific. As a matter of principle, I’m willing to show my code solution to algorithm problems provided that the problem setters are expressly showing solutions, as with Programming Praxis. []
  2. Okay I’m trying to be funny here. But you get my idea of engineering vs. algorithmic skill. []
  3. Generally, I’d be cautious against getting too deep a nesting. When I encounter this in my code, it’s a sure sign that I’m getting lost and that maybe I need to refactor or re-read the problem []

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 http://skytreader.net/journal/post-title instead of http://skytreader.net/journal/post-title.php. 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 /skytreader.net/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /skytreader.net/index.php [L]
</IfModule>

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]
</IfModule>

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!

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.

appearance_menus

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.

So, I noted here the hell I went through just to get Windows 8 to dual-boot with Ubuntu 12.04. However, just today, I had another problem with it.

To recap, I settled with my system unable to load Windows 8 from GRUB. I resorted to using rEFInd to be able to choose between Ubuntu and Win8. This isn’t a very clean solution as my Ubuntu option at rEFInd still loads GRUB (as opposed to having Ubuntu straightaway) but hey, it works.

Well, just this morning, as I booted into Ubuntu, I was greeted by a message from rEFInd which, in essence, tells me that Secure Boot is not allowing me to load grubx64.efi . Puzzled as it was only last night that I used Ubuntu, I did not see any cause to panic as the workaround is something I’ve mastered during my previous tussle with Secure Boot: I just need to (re)authorize grubx64.efi from my BIOS.

I rebooted to do this. However, when I booted into Ubuntu, I was greeted with a message that really made me panic. It read,

error: Secure Boot forbids loading module from (hd0, gpt7)\boot\grub\normal.mod

grub rescue>

Like, what the hell is normal.mod, much more (hd0, gpt7)?! I’ve encountered hd’s and gpt’s in my readings during my dual boot session last time but they were never really clearly explained and I haven’t bothered to look into them deeply.

After moving around (very carefully!) around my BIOS, I noticed two things:

  1. Some new entries has been added into my boot order list and it has definitely changed. I remember leaving the Windows Bootloader at the bottom of the list but it is now at the top of the list; and,
  2. There is an option to disable Secure Boot.

Yes. I don’t know why I haven’t noticed that I can disable Secure Boot before but disable it, I did. I can now boot into Ubuntu again. What’s more is that it fixed the rather-convoluted set-up I had with rEFInd: I can now boot into Windows 8 from GRUB though it still shows some errors which I can bypass with just a button press.

So, is Secure Boot actually good for anything aside from annoying people and wasting time?

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

screenshot_skytreader

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
     $temp = $wp_query;
     $wp_query= null;
     $wp_query = new WP_Query();
     $wp_query->query('posts_per_page=5'.'&amp;paged='.$paged);
        if($wp_query->have_posts()):
            while ($wp_query->have_posts()) :
                $wp_query->the_post();
?>
...
<?php
             endwhile;
         endif;
?>

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:

1
2
3
4
5
<h1><a href=<?php echo '"'; the_permalink(); echo '"'; ?>>
    <?php the_title(); ?>
</a></h1>
<?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. []