Icon_search
Stephanie Sharp Jennifer Fleece Buck Sharp Kim Landrum Charlie Maffitt Juli Tredwell Kevin Warrick

Travis' Blog

RSS

Plexus iPhone Conversion

Posted on 01/21/2009
10 Comments

I started wondering a few days ago, "Why don't we have an iPhone version of the Plexus site?" So I did some research and found that enabling a Ruby on Rails site for the iPhone was easier than I thought. I found a great tutorial outlining how to create a custom mime-type and create iPhone-specific pages.

I took advantage of a few tools to make my job a bit easier. iUI is a collection of javascript and css files that enable ajax, sliding page loads, and presentation to more closely resemble a native iPhone application. iPhoney is a Mac desktop application that emulates what your site might look like on a real iPhone.

But, with all the best laid plans, a few snags arose.

Plexus takes advantage of page caching to speed up load times. This presented a problem because I didn't want to cache the iPhone views, only the HTML views. The caches_page method in Rails will take a hash with a Proc to prevent pages from being cached under certain conditions. This is the example they give in the documentation:

The application will not cache any action that is being requested in json format. This approach didn't quite work because I created a custom mime type called iphone. After some hacking and failing, I finally came up with the following solution for not caching pages for the iPhone:

Definitely not the prettiest way to detect the iPhone format, but the only one I found that would work reliably. It checks the HTTP_USER_AGENT for Mobile Safari (that way, you can catch the iPhone and the iPod Touch).

Another problem I ran into was trying to keep the iPhone from loading the cached HTML views. This problem was a lot easier to fix. I just had to add the following RewriteRules to the site's conf file (keep in mind that we use a moved cache directory - public/cache):

If the http user agent is Mobile Safari, then it won't direct the request to the cached page.

The final hurdle was to make sure that people couldn't access the iPhone version of the site if they didn't have an iPhone or iPod Touch. Again, it was as simple as adding another RewriteRule.

----------------------------------

If you have an iPhone or iPod Touch, you can access the optimized version of this site at http://iphone.plexusweb.com.

Tagged:  iphone, ipod touch, rails, ruby on rails

Back to top

Batch add/remove files to Subversion

Posted on 01/13/2009
27 Comments

Recently, I was thinking how great it would be to have some script that I could run for a project to automagically add all new files (or remove all deleted files) with subversion. I know, I know, git is the new hotness, so why am I still using subversion? Well, all of our projects here at Plexus are tracked with subversion, and it would be more trouble than it's worth to convert (not to mention re-training everyone who uses it).

Well, I found a great little one-line script that would do exactly what I wanted here. The only problem was that I would never remember that whole line of code, plus I didn't want to type all of that out every time I wanted to run it. So, I decided to add an alias to my .bash_profile file so that I could call that script with just one word.

I played around with single and double quotes for a while trying to get it to act correctly as an alias. The script uses awk, which worked great on the command line, but was backfiring in my alias. Finally, with some Googling and help from Colin, I figured out that the dollar sign in the awk call needed to be escaped. After that, it all worked great.

Here are the two lines that I added to my .bash_profile file:

The first alias will run svn st, get all of the files with a ? next to them (new files that aren't part of the subversion project), then add them to the repository. The second functions similarly, but will svn rm all files that have been deleted from the project.

*NOTE: Make sure you've added an svn:ignore to your project so that it doesn't check in any files that you don't want in the repository.

Tagged:  svn, subversion, bash

Back to top

Easy Syntax Highlighting for Code

Posted on 12/03/2008
22 Comments

Syntax highlighting of code is a real pain. You have several options: javascript, roll your own, or use handy-dandy embeds. I'll go through each.

On my rails blog, I use the SyntaxHighlighter javascript plugin. It works really well and looks pretty good. My only complaint is that the color highlighting leaves a little to be desired. Only certain keywords and strings are highlighted. I guess I'm spoiled by TextMate and it's awesome color-coding.

Before using SyntaxHighlighter, I was color-coding my code by hand using span classes. I do not recommend this. It took forever and made the source totally unreadable.

By far the easiest option, IMHO, is embedding. There are two options for embedding code: gist and pastie. After you paste in your code to either site, they provide you with a one-line js script for embedding the syntax-highlighted code into your site. Both work great, so it's just a matter of preference which one you choose.

First, a gist embed:

Now, the same code in a pastie embed:

Both look really great, so it's up to you to decide which you like better. Even though the pastie includes line numbers, which is nice, I tend to lean more towards the gist just because it seems to look better to me. I can't put my finger on exactly why.

Tagged:  pastie, gist, syntax highlighting

Back to top

Plexus vs Internet Explorer 6

Posted on 09/18/2008
7 Comments

If you've ever worked with CSS, you know what a pain it can be to get things looking right in all of the major browsers (Firefox, Safari and IE). IE is, of course, the major offender, causing extreme frustration at times. With the release of IE 7, the Microsoft dudes made a giant stride in standards compliance, but IE 6 is still hanging around in the fringe (I think the percentage of users on this site is only around 9%). So, that means haxoring the codes to make the site look acceptable in Internet Explorer 6.

When we first launched the new version of the site, we included a notice heading telling users with IE 6 that we suggest they upgrade to a modern browser (IE 6 was released in August of 2001!!). Well, we got a little bit of flack for taking the easy way out. So, I put on my big-boy pants (once again) and went to work on IE 6 compatibility. Here are some of the tools that I used to accomplish this:

Parallels Desktop - A wonderful invention. Let's me run Windows from within OS X. I can test on Firefox (Mac and Win), Safari(Mac and Win), and IE all at the same time!

IE Conditional Comments - I actually have to hand it to the Internet Explorer development team for including these. They knew their browsers would require a little extra attention and some off-the-wall tricks to get things looking right. Just put this in the HEAD of the page to apply CSS styles only to versions of Internet Explorer less than 7:

<!--[if lt IE 7]>
  <style type="text/css">
    #custom_style { just:for_ie; }
  </style>
<![endif]-->

IE7 Script - Equally as important as the conditional comments. This script will update IE 6's CSS rendering to be compatible with IE 7. After including this script in the site, it fixed about 50% of the IE 6-specific problems. It even has support for transparent pngs as background images! Invaluable.

While the site still doesn't look perfect in IE 6, it's definitely pretty close. If you see something odd in any browser that you're using (except Netscape, I don't acknowledge its existence), please send an email to support@plexusweb.com and let us know.

Tagged:  ie, standards compliant, css

Back to top

Twitter from the Command Line

Posted on 07/23/2008
2 Comments

Many of the staff here at Plexus are on Twitter. While it's hard to explain to other people (micro-blogging?!?!), we've embraced it as a way to share information, see what each other are doing, and, in some cases, decide on lunch plans.

While perusing an especially interesting query on Twitter's search today, I came across a tweet about using Twitter from the command line. Being the computer nerd that I am, this intrigued me. I did some Google-ing and found a few entries from people who had written scripts to make this possible. The best explanation I found was here. He just wrote a simple shell script that used curl to post a status via Twitter's API.

The code is pretty simple.

curl --basic --user "<User>:<Password>" --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json"

Just create a file with that line of code, replace the user and password with your account info, save the file as "twitter", put it in your /usr/local/bin directory (Mac), and make it executable. Now you can run the following line in Terminal to post your status:

twitter "Command line status updates FTW!"

Tagged:  Twitter, cli

Back to top