Archive for the 'code' Category

Yahoo! Pipes - Wow

Friday, February 9th, 2007

Pipes is an interactive feed aggregator and manipulator. Using Pipes, you can create feeds that are more powerful, useful and relevant.

Pipes: Rewire the web

Yahoo! Pipes, is, without a doubt, one of the most impressive web applications I’ve seen thus far. In a few minutes, you can mash up very distinct data points, run them through several filters based on user input, and get back results, all while using one of the most supportive web interfaces I’ve seen. Yahoo! has really done something here.

I am curious to know why there’s no IE support as it may be limiting to a wider auidience, but I bet Pipes’ target audience &ndash people like us – are going to skew Mozilla- and Safari-heavy anyway.

Definitely take the time to check out Pipes, if only for the interface. It’s easily the closest a web application has gotten to a desktop application that I’ve seen. Everything is there, from the bendy pipes joining objects together, to context-based tooltips, and really nice uses of alpha transparency. The interface really shows the power of drag and drop as a metaphor for interacting with modular applications: in cases like this, drag and drop is not just a gimmick but a powerful way to interact with objects on the screen.

Yahoo! has certainly created a delightful experience, one in which you can walk in a novice and become advanced in a matter of minutes. Spectacular job.

technorati tags:, ,

Flash Object for Flash Integration

Thursday, February 8th, 2007

I try to stay away from Flash altogether, but when I need to integrate it in the future, I’ll be using SWFObject.

technorati tags:,

IE6 Ordered List Bug

Wednesday, January 31st, 2007

This is, without a doubt, the strangest IE 6 bug that I’ve ever encountered (and, I’ve encountered just about every one). Here’s the gist of it: when a list item (<li>) in an ordered list (<ol>) has layout, it can’t keep track of it’s correct number any more. That’s right: every item in an ordered list will be item 1. Insane.

How do you get this crazy behavior? Do things like give an <li> width or height. Due to IE’6 wonky list rendering in general, it will also probably no longer display the number indicator entirely, but this can be fixed by using list-style-position:inside or giving the <ol> in question some margin-left. Once that number displays, if it wasn’t already, it will be "1." Over and over and over again.

How can you combat this bug? Well, you can give width to the parent <ol> and use padding to acheive the width you’d like. (Also, you’ll probably need to give the parent <ol> some negative left margin to combat the crazy margin you’ll need to use to get the list item numbers to display in the first place).

Confusing? Yes. Just remember: width and height on <li> tags can lead to strange behavior in IE6.

technorati tags:, ,

Equal-height, 100% height columns with CSS and JavaScript

Friday, January 5th, 2007

Yes, that title was a mouthful. But, you know the idea: you have a CSS-based two-column layout, and you want both columns to always be the exact same height. Maybe you have a narrow left navigation column with a background color (or a gradient) and a wide right content column; if you want that background color to appear for the entire height of your content column, then you’ll need this trick, otherwise, it’ll stop when it reaches the height of its container.

Here’s an example of what we’re looking to achieve in a layout I built at my day job over at TheLadders.com. In this case, the left-hand column has a solid color fading into a gradient at the bottom of our content block. Since the right column will stretch that block down, we need to force the left-column to have the same exact height as the right column. How do we go about doing that?

There are plenty of ways to do make equal height columns using crazy CSS hacks and other methods. They work well, but they’re not very clean. To make it nice and easy, we need to use JavaScript for its main purpose: controlling presentation. And, we’ll only need a few lines of code to do it.

The Set-up
Here’s some example CSS to get that two-column look:

div#container{
  width:800px;
}

div#container div#leftColumn, div#container div#rightColumn{
  float:left;
}

div#container div#leftColumn{
  background-color:#CCC;
  width:250px;
}

div#container div#rightColumn{
  margin-left:50px;
  width:500px;
}

There’s a two-column layout for you. Here’s what that would look like with some example, placeholder content.

The JavaScript
See? That right column extends far past the left column, but we can take care of that with a simple JavaScript function (I had to add a line wrap to fit everything in the page; remove it to actually use the function):

function equalColumns(){
  var l = document.getElementById('leftColumn');
  var r = document.getElementById('rightColumn');

  r.offsetHeight >= l.offsetHeight ? l.style.height =  \\ line wrap
  r.offsetHeight + "px" : r.style.height = l.offsetHeight + "px";
}

Let’s examine what this function does. First, we store references to our two columns. Then, we do the dirty work, using the ternary operator for our comparison. Let’s examine what it’s doing:

  1. offsetHeight is an element’s rendered height, the total height it takes up in the browser window.
  2. If the right column is taller than the left, we set the left column’s CSS style height property to the right column’s height, then add "px" since CSS demands a unit of measure, and offsetHeight is measure in pixels.
  3. What if the left column is taller than right right? We do the same thing: find the left columns offsetHeight in pixels, and assign that to the right column’s CSS height.

Now that we have this function, we’ll add it to window.onload or the body tag’s onload attribute. You can use the addEventListener / attachEvent combination, too. As soon as the body loads, our columns will snap to the same height.

There’s one problem with this little method: if your pages are larger in size you’ll see them finish rendering, the onload event will trigger, and you will see the columns’ height being set (the background image or gradient will jump from its orginal height to its new height). It looks choppy, like you see here.

Can we fix it? Of course! Why run that function onload when you can run it immediately after the columns load in the document?

We’ll move that onload function into a script tag, and place that script tag containing our function immediately after the close tag of our second column. This means that the script will run immediately after that second column loads in the document, and the user will never see anything choppy. The height will be set before content finishes rendering and appears in the browser. Case closed. And, you now have equal columns as seen here. (Unless you’re stuck with using onload?)

But what about that gradient?
If you’ve been looking at the gradient here, you’re probably wondering how that shows up. Well, that’s a topic for another article coming soon. :-) (It’s right here now.)

A Google search can turn up many, many equal height column sites, but, of those I looked at, here’s one of the best (and they have a script modified to take padding into account, something that I didn’t need when I wrote my version for TheLadders).

technorati tags:, , , ,

Stuck with using onload? We can smooth out the height jump by adding a few bits to our CSS and another line to our JavaScript. We’ll change our CSS to:

div#container div#leftColumn{
    width:250px;
}

    div#container div#leftColumn.bg{
        background-color:#CCC;
    }

And, we’ll add a single line to our JavaScript function (and remove that line break I had to add):

function equalColumns(){
  var l = document.getElementById('leftColumn');
  var r = document.getElementById('rightColumn');

  r.offsetHeight >= l.offsetHeight ? l.style.height \\ line wrap
  = r.offsetHeight + "px" : r.style.height = l.offsetHeight + "px";
  l.className = "bg";
}

Now, our background color is applied after the new height is set. This looks much more natural, almost as if a background image is being loaded and applied. If you’re using an image heavy site, odds are users will never notice.

The Power of method_missing

Sunday, December 3rd, 2006

Ruby’s method_missing (which essentially provides a rescue hook for any calls to methods that are missing - not defined) comes in pretty handy with Rails. (Now, I’m no Ruby on Rails guru, so take the following with a grain of salt, but I found it pretty effective.

Every URL maps to a controller then a view (after your URL, it’s /controller/view). What if a user tries to go to a view that’s not there? Say you have a controller called “foo” that has a view mapped to “bar.” /foo/bar works just fine. But if a user types in /foo/baz, you’re in a little bit of trouble. Here’s where method missing comes in: in your application.rb file, just add a declaration for method_missing and have method_missing take care of things for you by redirecting or otherwise re-routing that bad request. Here’s an example:

def method_missing(url)
  redirect_to :controller => "foo", :action => "bar"
end

Any errant method calls (read: any attempts to visit a controller action that doesn’t exist) is now safely handled: you’ve essentially intercepted that phony URL in application.rb and handled it as gracefully as possible. You can redirect, render a special template, or anything else you’d like. A really, really neat trick!

technorati tags:, , , ,

IE7 Automatic Update Has Begun!

Tuesday, November 7th, 2006

IE7 is slowly spreading. The morning, I booted up my computer only to see the little MS auto update shield. No big security fixes this time: Microsoft was giving me IE7. If you’re a web engineer like me, I hope you’ve had time to run regression testing on your site. If you’re scrambling, here are a few links to know:

  • Been procrastinating on your IE7 roll-out plan? Here’s what I recommend: just keep checking your logs, looking for the point at which the update causes IE6 and IE7 stats to "flip" Since it’s an automatic update, everyone will convert at once: the stats for user agents visiting your page should flip flop, with IE7 picking up IE6’s numbers. At that point, make the switch yourself and begin developing exclusively in 7.
  • Still need a copy of IE6 for testing purposes? Evolt has you covered with a downloadable copy of every browser in the history of mankind. Grab a copy of IE6 to keep for testing purposes, because your current copy won’t be around much longer.
  • If you haven’t checked the excellent Microsoft IE developer blog yet, you may wish to do so. They’ve been keeping running updates of what IE7 will and won’t do, and what will change (and break) between IE6 and 7.
  • Finally, Microsoft has an Internet Explorer developer center with more (albeit cursory) information on the browser, and a few readiness toolkits that will walk you through changes.

I’ll post any quirks or hacks I can find. In the meantime, good luck!

technorati tags:, ,

Adaptive Path’s Take on the Web 2.0 Spec

Thursday, November 2nd, 2006

How do you make product specifications comprehensive enough for AJAX, Web 2.0 apps? Simple boxes and arrows aren’t going to cut it: your spec must talk about complex interactions and behaviors, timings (of updates or polling), and application states. In short, you’re not just writing a document that talks about how code should work; you’re writing a document that talks about how people should work with your code.

Adaptive Path took a stab at the Web 2.0 spec and what’s beyond wireframes and came up with a three-pronged approach to documenting Web Twenty apps. Their approach is as comprehensive as any I’ve seen. However, cranking out specs like this seems like a product of having a lot of time (read: billing clients for hours worked) and may only play out will on large, highly interactive projects. (On short projects, these specs might take longer to build than the actual end product).

Specs really do help development, and Adaptive Path’s spec helps capture all of the important pieces of end-user interaction that make or break an app. Ultimately, these things are only as good as your product team: the people responsible for building the spec must have comprehensive knowledge of what can happen in an application for them to document that behavior or they must be willing to work with, and adapt their ideas to, the knowledge of practicing developers or designers whose knowledge of possibilities is greater. In all, writing specifications should be an iterative process with input coming from across all disciplines, a change advanced web applications are forcing to happen.

technorati tags:, ,

Ruby on Rails: Selecting the last item in a database table

Thursday, October 26th, 2006

Ruby on Rails has the great find(:first) method that lets you grab the very first ActiveRecord object out of a given database table. That’s all well and good, but what if you want the last? Use this: Model.find(:first, :order => “id DESC”). That will give you the first record in a reversed list of IDs: basically, the record with the highest ID value, or the last record in the table.

Not good enough for you? Order by any other field. Want a different first record ? Sort by a field ASC. The :first record really depends on what order your records are in.

technorati tags:, , Ruby, Rails, ActiveRecord

IE7 is on its way…

Saturday, October 7th, 2006

The final release of IE7 is fast approaching … and I mean really fast … and will be delivered to customers via Automatic Updates a few weeks after it’s available for download. We want to ensure that you are ready and the information below will help get you there.

IEBlog : IE7 Is Coming This Month…Are you Ready?. I hope that IE7 site-wide audit I’ve been pushing for at work gets bumped up super-high priority…

There’s also a lot of complaints about MS pushing out this update to everyone. I, for one, am actually in favor of it. Why? Because it means there will be a lot more uniform distribution of browsers: we won’t have
to worry designing and developring for a staggering amount of stragglers that never upgrade, because they’ll all be pushed to the new product at one. That said, I’ll echo the words of one commentor on the MS blog I’m citing: my job is about to get harder.

technorati tags:, ,

How to Shoot Yourself in the Foot in Any Programming Language

Wednesday, October 4th, 2006

Here’s something that’s a tad bit lighter than usual. My personal favorite:

Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.

technorati tags:,

Blogged with Flock

I'm Reading…
Search This Site
You are currently browsing the archives for the code category.

AddThis Feed Button

Need great hosting?

Categories