Archive

Archive for the ‘Tips’ Category

Dynamic Title and Meta Tags using Ruby on Rails

July 9th, 2009

Here’s a quick tip on one way to do dynamic Title and/or Meta tags in your rails apps. It may not be the best way, but it works for us :-)

The problem is that you generally define your title and meta tags in your layout, but you may want to change the content in your templates depending on what page you are on. Here’s a quick way to keep it all in the view and do it using the content_for tag:

In your layout:

<title><%= (html_title = yield :html_title) ? html_title : 'My Default Title' %> - MySite.com</title>

<meta name="description" content="<%= (html_description = yield :html_description) ? html_description : 'My Default Description.' %>">

Then, in your template you can do something like this:

<% content_for :html_title, 'My Specific Page Title' %>
<% content_for :html_description, 'My Specific Page Description' %>

Hope that makes sense!

Gee RoR, Tips , , ,

Building Universal Binaries on MAC OS X with configure

May 8th, 2009

I recently ran into a ton of problems while trying to build the latest version of Remobo as a universal binary with OS X 10.4 support on my MacBook Pro running 10.5. In the end, all the problems were solved by passing in the right compiler flags and configure parameters. Here is a quick rundown of what I learned. Hopefully it will help someone out in the future!

Our project uses configure and automake etc… so we did not have XCode to help us with the settings. This will be true for many open source projects and libraries you come across since they are mostly written for Linux.

1) Make sure to pass the right compiler flags.

For a universal binary, use:
CFLAGS="-arch ppc -arch i386"
LDFLAGS="-arch i386 -arch ppc"

If you also want backwards compatibility with a previous version of OS X (10.4 in this example), use something like:
CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386"

This will compile using the 10.4 SDK instead of the default 10.5 since I am runnign Leopard.

2) Pass in the right configure parameters.

Make sure to add this flag to configure:
./configure --disable-dependency-tracking

This will ensure there are no problems when compiling for multiple architectures.

3) Check your output binary.

You can use the “file” command to make sure everything went according to plan. If the binary is truly universal, you will see something like this:
file ./src/hello
src/hello: Mach-O fat file with 2 architectures
src/hello (for architecture i386): Mach-O executable i386
src/hello (for architecture ppc): Mach-O executable ppc

Hope that helps!

One last tip: make sure all the dependencies and libraries you are using are also compiled in this way or else you will get link errors since the linker cannot combine regular binaries with universal binaries.

Gee C++, Remobo, Tips , , , , ,

wxWidgets GUI and Multiple Threads

March 26th, 2009

logo9This is an obscure tip, but if you are using wxWidgets as the GUI library in your application, this may come in handy. We currently use it for Remobo and it has served us well as a cross-platform GUI framework.  In particular we are using the C++ lib.

Never try to call any GUI related functions or even instantiate any wxWidgets GUI elements such as Frames and Dialogs from any other thread except the main one!

This is a documented caveat, but for some reason we thought it would be ok to just instantiate a custom wxDialog object in the secondary thread and leave the actual GUI calls to the main thread.  Turns out that even creating the object in a secondary worker thread will cause subsequent UI calls to hang indefinitely.  What made this worse is that it did not show up in MAC OS X but only on Windows…

We just spent a few days on this and it was impossible to find via regular debugging methods since the calls went deep into the Windows UI library… no fun at all. The solution is to call soemthing like wxPostEvent() to post some event from your secondary thread to the main thread and do all your wxWidgets stuff from there… including the wxWindow instantiation.

Gee C++, Remobo, Tips , ,

Buiding an iPhone Photo Sharing App on Google App Engine

March 18th, 2009

I did a “lightning talk” today at a local meetup for developers interested in cloud computing and Google’s App Engine specifically.  The demo covered the basics of how Rotzy (which is built entirely on AppEngine) works and what it does etc… but I also tried to fit in as many tips and tricks for using App Engine as I could.  Seemed like at least a few devs found it useful which is great!

Here are some of the (poorly made) slides I used while explaining some of the App Engine specific stuff.  Hopefully some more people will find it useful too.  Also, definitely check out Rotzy for the iPhone… it was built in our spare time and we are excited that it is growing steadily with a great community of users :-)

Gee Projects, Python, Tips, rotzy , , ,

Google Maps API Alternative: the Static Maps API

February 10th, 2009

If you are looking into adding some map functionality to your app or web site, remember to also consider the Static Maps API for a non-interactive version of Google’s maps. This static API takes a list of parameters such as the map center, width & height, any markers or path data… and returns a static IMAGE instead of using javascript to render your map.

You won’t be able to interact with the map… but the main advantage here is speed.  The javascript needed to run the regular Google Maps API is quite heavy.  It doesn’t run well on mobile browsers and can take a few extra seconds to finish loading on regular desktop browsers as well.  So, if all you need is a nice looking map, the static API is a great choice.

For example, it seems to load a good 10x faster than the regular Google Maps API when loaded into a UIWebView controller on the iPhone.  Even on a wifi connection, the javascript API takes a good 5-10 seconds to show up, whereas the static image API loads almost instantly.  For mobile devices, speed currently trumps functionality in many cases such as this one.  The user won’t be able to pan and zoom, but they won’t complain if the map loads fast :-)

We are using the static maps API in our Rotzy iPhone app and will just give users the option of clicking on it and bringing up the native Google Maps application if they really want to pan and zoom.

Here’s an example of how easy it is to generate a map by simply passing paramters to the API url:

# Note that this URL wraps at the '\' character.
# For clarity, we don't write the actual API key in use.
#
http://maps.google.com/staticmap?center=40.714728,-73.998672\
&zoom=14&size=512x512&maptype=mobile\
&markers=40.702147,-74.015794,blues%7C40.711614,-74.012318,\
greeng%7C40.718217,-73.998284,redc\
&key=MAPS_API_KEY&sensor=false

The code above will generate a map that looks like this:

staticmap

Read more and get the full documentation here.

Gee API, Projects, Tips , , ,

Hosting Multiple Blogs with One WordPress Installation

February 8th, 2009

wordpress_logoI recently spent some time looking for the ideal platform for this blog… starting with free hosted solutions like wordpress.com and blogger.com. They both worked fine and got me up and running right away, but wordpress.com doesn’t allow any javascript or flash embeds and blogger just didn’t seem powerful enough.

I was trying to avoid hosting yet another custom WordPress installation on my own servers because maintaining them can be quite annoying sometimes… but in the end I figured it would give me the most flexibility. Luckily, I found a hack called Virtual Multiblog for WordPress. This simple download lets you install WordPress on your server just once, but gives you the ability to run many different blogs from it. So I was able to consolidate all my self-hosted blogs under one installation, making upgrades and maintenance MUCH easier down the line. Each blog can still have its own template, plugins, config file, etc.

If you need to host more than one WordPress blog on your own server, definitely take a look… it only takes a few minutes to set up but does require some knowledge on how to set up symbolic links etc. In the long run it should save you many hours of maintenance work :-)

Gee News, Tips , , ,

7 Tips for a Better AdWords Account

January 28th, 2009

Got an e-mail from Google today… here are 7 tips they included for getting the most out of your AdWords account:

  1. Have at least two ads in each ad group
  2. Include keywords in your ad text to make those phrases bold
  3. Have tightly themed ad groups (preferably three or more)
  4. Set a unique destination URL for each group
  5. Have at least 50 active keywords in your account
  6. Focus on 5-15 keywords in each ad group
  7. Remove keywords with a clickthrough rate (CTR) less than 0.1% in the search network

    These may or may not be news to you, but in my experience with using them I think its some very good basic advice for anyone starting out.  You don’t have to necessarily follow every one of them, but if you implement the majority of these, you should be well on your way to a successful Adwords campaign :-)

    Gee Advertising, Tips

    Calculating Distance Between Latitude Longitude Pairs in Python

    January 24th, 2009

    Here is a code snippet that I found very helpful thanks to zachary:

    I needed to calculate a simple distance between two latitude, longitude pairs in miles and this did the trick.  Apparently, its not the most accurate way to do it since the Earth is not a perfect sphere, but its close enough (an error of 0.5% at most I believe).

    import math
    #
    # The following formulas are adapted from the Aviation Formulary
    # http://williams.best.vwh.net/avform.htm
    #
    nauticalMilePerLat = 60.00721
    nauticalMilePerLongitude = 60.10793
    rad = math.pi / 180.0
    milesPerNauticalMile = 1.15078
    def calcDistance(lat1, lon1, lat2, lon2):
    """
    Caclulate distance between two lat lons in NM
    """
    yDistance = (lat2 - lat1) * nauticalMilePerLat
    xDistance = (math.cos(lat1 * rad) + math.cos(lat2 * rad)) *
                    (lon2 - lon1) * (nauticalMilePerLongitude / 2)
    distance = math.sqrt( yDistance**2 + xDistance**2 )
    return distance * milesPerNauticalMile
    

    Hopefully someone will find this useful as well.

    Gee Python, Tips

    Monitor Your Advertising Accounts Daily

    January 22nd, 2009

    google-adwordsJust a quick tip to make sure and monitor your PPC advertising accounts on a regular basis!  Its easy to let them cruise along on auto-pilot for weeks or even months at a time… but don’t be surprised if something looks way off the next time you decide to login to your AdWords account.

    Here are 2 examples from my own experience as a PPC marketer:

    1) The meanings of keywords change over time!

    This one is pretty random, but here’s the story… I have an e-comerce site that sells unique No Drip Umbrellas that I import and fulfill through Amazon.  You can imagine the keywords that I bid on in the search engines: umbrella, umbrellas, etc. etc.

    56534_rihannaumbrellaThe campaign was working pretty well for a while… generating a decent number of sales and some even better leads for large quantity orders etc.  I obviously did not feel the need to monitor this account daily.  Enter Rihanna and her uber hit single “Umbrella“…  I’m sure you can see where this is leading.

    As soon as it became a hit, the number of impressions on “umbrella” related keywords skyrocketed almost overnight!  You would think people would be smart enough not to click on an ad that said “Rain Umbrella on Sale”, but then you’d be wrong.  The number of clicks spiked as did my costs.  I doubt even 0.01% of the resulting clicks were from people actually looking to buy an umbrella, so my conversion rates plummeted.  It took me a while before I caught on, and by then the damage was done. The result was a large amount of wasted ad dollars.  Granted, it wasn’t THAT much money, but remember… you never know when one of your keywords will become the title of a hit single.

    For those interested, the solution was to add a whole bunch of negative keywords, “-Rihanna”, “-lyrics”, “-mp3″, “-download”, etc. etc. :-/

    2) Identity Theft

    manstealingdataI pride myself on the fact that I would NEVER click on a phishing email, let alone fill out the resulting login form… but apparently I’m wrong.  One day I noticed there was a $15,000 charge in my Google Adwords account for just one campaign on one day. Apparently someone had “broken into” my Adwords account using my login credentials and created an ad with travel and flight related keywords that pointed to a page full of Adsense ads.  The bids were all in the $5.00 range and that’s why it racked up so many clicks in such a short period of time… talk about the perfect Adsense arbitrage setup (0 cost)

    I quickly contacted Google and they halted my account.  They then looked into my claim that this was fraud and got back to me within a couple days.  They happily refunded my money and suggested I run some antivirus and anti-spyware programs… to this day I have no idea how they stole my login credentials.  I was very pleased with Google’s response and to be honest I hadn’t expected anything less from such a great company.  The biggest damage was that this particular AdWords account is no longer usable.  This could have been really bad, but luckily I had already started to phase this one out and wasn’t using it for much anymore…

    So, the point is to be careful out there!  Keep an eye on all your advertising accounts and be sure to optimize, optimize, optimize… you probably can never 100% prevent cases like Identity Theft, but at laest you’ll be right on top of things to minimize the damage :-)

    Gee Advertising, PPC, Tips