Sunday, May 24, 2009

Need a Good Shot of the Atlanta Skyline?

Last night I went to a friend's party over in Vinings. It was a fun night because 1) I have some great friends, 2) we had a great time talking and catching up and 3) I had to find the place first!

I have had to become more adventurous while at college, especially after getting a car, and I enjoy the occasional adventure, even when it takes me around/into Atlanta's heart. It took four tries to get to the correct community (there were three gated entrances), but I eventually made it in.

One thing that surprised me was the surreal view of Atlanta that I got a glimpse of in my rear-view mirror. Atlanta was just sitting there, a cluster of towers rising up from the ground. I'm not sure at the moment if it was Buckhead or Downtown that I actually saw, but it was amazing anyway.

Looking at the hard facts, Wolfram Alpha says that Atlanta is 1,050 ft. and Vinings is 915 ft. So, it doesn't make sense that you could get such a great view of the city when you're lower than it...but however the facts come out, the view is still there!

Of course, when I look it up on Google Maps' "driving view" to show you, the weather is cloudy and hazy! The last time I took a good shot of the city, I was in a Cessna 172P looking east from the tail of the plane, but it was getting dark and the city was almost too hazy for a good shot...and I was behind an old scratched-up window.

So, today's lesson: if you ever need a photo of Atlanta, you know where to go!

Monday, May 18, 2009

How WordPress URLs Work

Ah, ha! How silly I feel now that I know the truth. I've been trying to understand how WordPress URL rewriting works, thinking incorrectly that it relied on Apache's mod_rewrite to do the dirty work. That is, however, not the case!

I've googled it ("how do WordPress URL rewrites work?") many a time, but never got a clear answer. I wonder if Wolfram Alpha knows now :P

WordPress does rely on mod_rewrite to invoke index.php, but doesn't use it to do any of the rewriting itself. The .htaccess file that WP uses contains this:


<ifmodule>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</ifmodule>


The !-f and !-d conditions instruct Apache to rewrite "whatever isn't an already-existing File or Directory." Just FYI, the [L] flag means, "this is the Last rule."

This gives me hope. Now, I understand that it is actually possible (because it's in practice) for me to parse and rewrite my own URLs. Doing my own URL processing is starting to make a lot of sense for a project that is right now a bunch of hen-scratch on paper.

Wednesday, May 13, 2009

How to Replace the External Driver's Side Door Handle on a 1997 Toyota Camry

Project specifics: 5 hours, phillips head driver, very small flat head driver, larger flat head driver, 10MM socket driver (must be straight), $2 telescoping magnetic stick, bright light, small hands, low chair or really good knees

A couple months ago, the face of my door handle broke off :/

I'm typically the one to take these types of problems to the shop and have someone else deal with it (and take my money), so I took it over to a collision center and got an estimate: ~$150. They wanted MSRP for the handle itself ($90), plus labour.

Although this was a problem, I could still get in the car by working it very carefully, or just using the passenger side when it was raining. And, exams were coming up. So, I decided to just wait it out.

Actually, I had the inside door handle replaced less than a year ago and I thought that it was time to try my hand at the repair. It couldn't be that difficult, right? Hehe....

I did a Google and found that World Toyota's parts department would sell the handle to me online for about $70. I wound up paying $75 because I went to the dealership and, of course, they had to charge tax. I thought I would save money by going to them because then I could avoid the $10 shipping charge, but they don't keep any parts there, it's all ordered in. Fortunantly, it only took two days for it to arrive. If you haven't bought one yet, I'd try a salvage place. Just get it from a car with the same paintjob :)

The model-specific repair books at Autozone were heatshrunk, so I could not tell if I could use that book as a guide. My brother found a book with instructions for door handles, but I don't know which one it was.

I want to thank About.com for the resource I found there: Do It Yourself: How To Replace The Exterior, Front Door Handle On A 1993 Toyota Camry. It proved very helpful. There were some differences, screw locations on door panel, number of screws on door handle hardware, etc., but the overall method is the same.

There are actually three screws on the very bottom of the door, and there is only one pin on the outer edge of the door. The interior door trim has a single screw behind a tab that must be removed before you can remove it. There is actually another location to which you must apply pressure to pop out the trim, one on top as well as the one on the bottom.

A speaker attached to the the inside front of the door made it a little tricky to remove, requiring a little extra nudging to get it to pop up and off.

Once I was able to remove the bolts that held the door handle, they began falling into the door well. If I did it all over again, I would have stuck my hand inside the door and finished removing the bolts with my fingers. I had to run to Autozone to pick up a magnetic stick to fish them out.

I believe that there were only three bolts, instead of the 4 shown in the About.com article for my Camry model.

Perhaps the most difficult problem that I had was removing the rod. In the end I did not remove it "correctly". I eventually pulled the handle out from the door and used a sharp knife (it was actually a brand new one) to saw away at the molded plastic clip holding it on. The new handle had it's own plastic clip, so there was no harm done by ripping it to shreds.

The second-hardest step to me was getting the lock to fit into place. I had not paid attention when I was unscrewing the bolts and did not see how the lock assembly fit into the handle.

Ultimately, to get the lock to fit back into place, I had to un-screw the door handle and remove it, slide the lock assembly into place and then re-insert the handle, screwing in the bolts so that they tightened the lock into place. The lock actually fits up inside the handle.

I was relieved when no screws were left over at the end! This is typically a problem whenever I remove a laptop case.

For some reason the handle now feels so much more fragile than I realized before!

The interior left rear passenger door won't open from the inside. This has always been a problem, but not as big of an actual issue. I suspect something is broken inside, but after removing the door panel, I realize that I can't get up in there to try to find the problem. I'll have to go to a professional for this one...

Monday, May 11, 2009

Mapping the PCA Churches with Google Maps

Let's get the technical details out of the way: ~8 hours, jQuery, Google Maps API, PHP for preprocessing, and my own web server is the host
_______________

As I have recently graduated and I am looking for work, I decided to work on a mash-up(*) to test my technical prowess.

One source of information, the PCA directory, to my knowledge has not yet been mapped. With just under 2,000 entries that would be about the right size/complexity/magnitude. What a great place to start!



Here is the final product: http://www.maconserv.com/pcamap/.

Of course, the best way to get the most updated information is to scrape the directory web pages whenever somebody load the map. I don't want to have to maintain a copy of their directory myself. I'd rather let them update their directory and simply "scrape" from it whenever needed; however, I'll explain that this isn't practical in just a jiffy.

(Wait, I take that back! The absolute BEST way is to have access to their database so that my map wouldn't need to rely on loading the web pages to get the needed data. However, I'm an outsider and don't have access to their database :/ )

Further, Google Maps documentation states, "Geocoding is a time and resource intensive task. Whenever possible, pre-geocode known addresses...and store your results in a temporary cache of your own design."

Since the PCA directory IS a list of known addresses, it would make sense to ask Google for the latitude/longitude coordinates of each directory entry once and store them in a file so that the map can simply load information from that file (that I will have access to on my server) over and over again.

And my final problem was a security issue. I was being blocked from accessing the PCA directory web pages via JavaScript using jQuery. In modern parlance this is referred to as "cross-site scripting", and can be a viscious little buggar when it comes to online security. The PCA directory uses HTTP POST to tell the server which state's directory information to load, so that also added complexity to the process.

So, now, at this point, it looked like I would scrape data from the PCA directory web pages myself (i.e. copy and paste from my browser, Firefox), store it to a file on my local server to which I had free access, ask Google for the coordinates of each church entry (and save that to a file, of course!), and use the saved file data to display the locations on the map. And, that is basically the final process I used:

  1. Go to the PCA directory site and copy several state's directory information to a text file on my computer. (I wanted to do it bit-by-bit--no pun intended--so as to make it easier to catch problems.)

  2. Upload this "raw" data via FTP to my web server so that a PHP routine can clean up the data in the file.
  3. Run the "clean-up" PHP routine. It removes white space from around the fields (each entry has a church name, city, state, phone number, e-mail address, website address, presbytery name, and pastor name) and then separates each field with a tab character. Each church is listed on an individual line, so it is easy to scroll through the file line by line.
  4. Save the result of the "clean-up" routine to a new file. I'm actually simply appending each line to the new file, but that's not a huge issue.

  5. Run the "cleaned-up" data through a "coding" PHP routine. This takes the "cleaned-up" data, finds the city/state information for each church and asks Google through the HTTP geocoding service for the latitude and longitude coordinates. For about 270 locations, Google responded with 0,0 instead of valid coordinates. Those will need to be obtained individually later.
  6. Save the new coordinate data in a new "geocoded" file. To keep it simple, I added the coordinates to the end of each line after the original fields from the "cleaned-up" file.

  7. Lastly, run a final PHP routine that formats the tab-separated fields to JSON (JavaScript Object Notation). A JSON file can be easily read into the browser using a remote call via jQuery.
  8. Now, I have the directory information, plus the Google-provided geocoordinates in a format that can be easily read by JavaScript. The next part is to display it!
After finageling around a bit, I wound up with this: made custom icons for the point markers because the default Google makers are too big, removed the shadows from the markers as they are not needed anyway, added tabs for markers where multiple churches exist for that point, made larger icon for tabbed markers and smaller icon for markers with a single church.

Loading it is a problem. Originally, it took about 30 seconds in IE/Firefox to load. I was able to reduce that to about 20 seconds by tweaking the code (I had been creating and destroying extra markers that weren't needed, slowing down the render time).

Google's Chrome browser does an outstanding job with JavaScript in general, but especially the Maps code. It loads the map in 5 seconds!

Looking at IE's memory footprint, it was showing about 125 MB (wow!) to load and render the map, and a little more each time the map is moved or zoomed.

All in all, I think I learned from this experience. If you have any comments or suggestions as to how I could improve it, make it faster, etc., let me know! As I mentioned, my copy of the directory is not updated when the PCA directory is modified, so there will be a version discrepancy soon. If you have thought of a way that addresses that problem, let me know that, too!

_____________

(*) Wikipedia: "a mashup is a web application that combines data from more than one source into a single integrated tool"