Finding distance and time between two places with Google Maps
Wednesday 11/19/2008 – Category: Uncategorized – No Comments
Instead of doing ghetto (and inaccurate) coordinate math, let's use Google Maps to do the work. This is a bit obscure, but you can append &output=kml to any search query and it will give you output in KML (XML for Google Earth) which makes scraping just a tad bit cleaner.
Instead of parsing the XML, I chose the quick and dirty way of isolating the distance and time.
To calculate DISTANCE, pass 1 as the first argument. To calculate TIME, pass 2.
CAVEAT: If Google Maps can't find your start or end address, it will output an empty file.
Talking vs Typing: Google Voice Search
Wednesday 11/19/2008 – Category: Uncategorized – No Comments
Google recently updated their iPhone app with voice search, and I must say...it's pretty impressive. I can imagine it being really convenient when I'm driving or in a situation where it's not convenient to type. You just have to hold it up to your ear and it prompts you to speak the phrase to search for and it does it's thing. It also uses your location data to find relevant results in your area. A voice search for pizza yielded results of places right down the street.
What's really impressive is the speed that it records, uploads, and processes--just a few seconds on EDGE, and even less on wifi.
Of course, it's not perfect. I whistled a tone into it, and one time it gave me "yahoo", and another time "nude". I'm wondering how their detection engine works...
Google Mobile app is available in the App Store.
content_for in Rails
Tuesday 11/18/2008 – Category: Uncategorized – 1 Comment
I'm not sure why I hadn't come across this before, but Rails has a nifty helper called content_for that allows you to insert stuff anywhere in your layout.
A classic use case is inserting a javascript source file that is only used on a specific page.
In your view:
<% content_for :head do %> <%= javascript_include_tag 'whatever.js' %> <% end %>
In your layout:
<head> <title>Hello World</title> <%= yield :head %> </head>
apache2-mpm-prefork, apache2-mpm-worker, and PHP5
Tuesday 11/18/2008 – Category: Uncategorized – 1 Comment
So I was reading up on Apache MPMs and whether it's better to use worker (threaded) or prefork.
The worker MPM uses multiple child processes. It's multi-threaded within each child, and each thread handles a single connection. Worker is fast and highly scalable and the memory footprint is comparatively low. It's well suited for multiple processors. On the other hand, worker is less tolerant of faulty modules, and a faulty thread can affect all the threads in a child process.
The prefork MPM uses multiple child processes, each child handles one connection at a time. Prefork is well suited for single or double CPU systems, speed is comparable to that of worker, and it's highly tolerant of faulty modules and crashing children - but the memory usage is high, and more traffic leads to greater memory usage.
Since I'm on a Slicehost 256slice, I wanted to try out worker to see if memory/speed performance was improved.
sudo apt-get install apache2-mpm-worker
Performance was a tad bit better--my test Merb app was handling a few requests/sec more with worker than prefork. However, apache2-mpm-prefork is a required dependency when installing PHP5, so installing apache2-mpm-worker totally removed my PHP installation. I didn't realize this until I was figured out why Apache was suddenly spitting out PHP pages as downloads. (Moral of the story: really read the messages when you're prompted to do something)
So why is prefork a dependency? From the PHP docs:
PHP is glue. It is the glue used to build cool web applications by sticking dozens of 3rd-party libraries together and making it all appear as one coherent entity through an intuitive and easy to learn language interface. The flexibility and power of PHP relies on the stability and robustness of the underlying platform. It needs a working OS, a working web server and working 3rd-party libraries to glue together. When any of these stop working PHP needs ways to identify the problems and fix them quickly. When you make the underlying framework more complex by not having completely separate execution threads, completely separate memory segments and a strong sandbox for each request to play in, feet of clay are introduced into PHP's system.
If you feel you have to use a threaded MPM, look at a FastCGI configuration where PHP is running in its own memory space.
So, lesson learned. You're stuck with prefork if you have to serve PHP files with Apache.
Sending email through Gmail SMTP with Merb
Monday 11/3/2008 – Category: Uncategorized – No Comments
I was having email delivery problems while using Postfix (emails were getting caught by spam filters) so I decided to try using Gmail SMTP to send stuff off.
Initially I tried to follow a tutorial like this to get Postfix to relay to Gmail but there was a lot of footwork involved setting up certificates, etc...and I couldn't get it to work at the end.
Finally, after searching around the Merb wiki, I found that it's really a lot more simple:
Gmail SMTP
Install tls mail to enable SSL support (required by Gmail).
$ gem install tlsmailThen configure Merb Mailer to work with Gmail
in config/init.rb:
Merb::BootLoader.after_app_loads do dependency 'tlsmail' # Activate SSL Support Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) # Configure Merb Mailer Merb::Mailer.config = { :host => 'smtp.gmail.com', :port => '587', :user => 'user@gmail.com', :pass => 'pass', :auth => :plain } endThen to send mail:
m = Merb::Mailer.new :to => 'foo@bar.com', :from => 'bar@foo.com', :subject => 'Welcome to whatever!', :text => partial(:sometemplate) m.deliver!
Recent Posts
- More Flickr Original Updates
(Sunday 01/23/2011 – Uncategorized – 13 Comments) - Flickr Original updates
(Saturday 08/7/2010 – Uncategorized – 19 Comments) - LED Light for iPhone 4
(Monday 06/28/2010 – Uncategorized – 65 Comments) - WWDC 2010: Worth Every Minute
(Monday 06/14/2010 – Uncategorized – No Comments)
