Sizzle: A Standalone CSS3 Selector Library

Sometimes a full blown javascript library like JQuery, MooTools, or Dojo is impractical.

I just had such a project, but the one feature I could not live without was CSS3 selectors. Walking the DOM manually would have taken hours to implement correctly, especially since each page needed to be treated differently. My first thought was to rip out the JQuery selector functions. That’s when I discovered Sizzle.

Sizzle is the CSS3 selector engine written by John Resig that was originally written for JQuery and is now also used in Dojo. Since it’s a standalone library, you can also use it directly for your projects.

The first step is simple, you need to include the Sizzle js file in your page. Once you do that, you can call Sizzle just as you would call $ in normal JQuery.

Examples:

// get all divs
Sizzle("div")
// Get all links in the paragraphs in the sidebar
Sizzle("#sidebar p a")
// Get all li elements under a ul
Sizzle("ul > li")

Just like JQuery, right? Well no. Unlike JQuery, which returns a JQuery object that can be accessed with JQuery’s easy and cross browser API’s. Sizzle returns a list of elements.

If you wanted to set the text of the first link element to “Go To This Page,” then what you’d have to do is the following:

var elements = Sizzle("#sidebar p a");
a[0].innerHTML = "Go To This Page";

If the necessary manipulations are simple, using Sizzle standalone is the way to go. It’s much smaller than a full blown JS library and it gives you what’s normally the most painful part.

  • Share/Bookmark

2009 In Review

It’s the first work day of the new year and in order to delay heading out into the frigid cold (it’s about 15 right now), I figure it’s a good time for a 2009 recap.

It was definitely one of the busiest years of my life. The year started normally enough, with both Sonali and I working for a large public company. Unfortunately, it didn’t take long before the economic meltdown affected them as well and the downsizing started in our division. This overarching storyline probably made the year seem more stressful than it really was, due to the multiple rounds and the general sense that something wasn’t quite right as far back as March. That all ended in September 30th, coincidentally my birthday, when both Sonali and I were let go. On the upside, I had an interview scheduled for later that afternoon. On the downside there was a going away lunch, complete with tequila. More on that later.

While this was all going on, I still needed something to do while building my rails chops and started putting some hours in Journalistics on the nights and weekends. We’ve launched one product, and are coming really close to launching the first preview of our main offering.

Perhaps the biggest work difference in 2009 was some first hand experience on the management and organizational side of product development. The challenges and solutions are significantly different than development. The biggest lesson learned is to not come up with a product plan without also coming up with a sales plan. It doesn’t matter what you build if you can’t convince people to use it.

While much of this post focuses on the negative, it was overall a very positive year. We did some very good work in my time at Premiere and it’s unfortunate we never got our product out the door. While the economic conditions resulted in a lay-off on my birthday, it had a happy ending. The interview was at Vertical Acuity, an Atlanta startup building a new syndication model for publishers. It was a great fit for both parties and I accepted their offer.

2010 finds me back where I want to be, in an small startup working on interesting problems. Being part of a small team with a lot on the line is very appealing to me. Also, since I apparently don’t like to sleep much there’s aforementioned Journalistics beta and the launch of Scoutmob. It’s going to be another busy year, but one that should be as enjoyable as 2009.

  • Share/Bookmark

Is better photo printing worth it? (and fotoflot review)

The holiday season is in full swing, which means shopping, lots of eating, some traveling and lots of pictures. If you’re not 80 years old, every photo you you take is now digital. Of course there are always a few each year that you really want a physical copy of, and maybe one that you would love to see blown up hanging on your wall.

There’s no shortage of digital photo printing options, all touting different benefits and prices. I’m not exactly what you’d call a professional photographer. There’s a lot of subpar pictures on my Flickr account. Therefore, I’ve generally gone with more consumer grade printing services, thinking that it’s not really worth the extra cash for some of the more professionally oriented printers. You can get a 20″x30″ blowup for $9.99 at Costco’s photo center. Even if the picture sucks, it costs less than lunch.

I had a picture that I really liked and decided to spend the cash to get it printed at a real printer. A friend of mine suggested FotoFlot. They’ve got a unique system that prints on high-quality photo paper then fuses it to an acrylic backing. It comes with a mount that secures the pictures via magnets, making it trivial to swap out pictures as you desire. All the coolness comes with a hefty price tag. The same 20″x30″ print that costs $9.99 at Costco will cost you $185 at FotoFlot.

I went ahead and ordered at 15″x30″ crop at FotoFlot and, out of curiosity, a 20″x30″ blowup from Costco. I had expected the FotoFlot to be better, but I was surprised at how much better.

The first obvious difference is the the color. For best results, you can include your color profile with FotoFlot and they will make adjustments to their printing process. With Costco, you upload just the original image and they do the normal big-box color correction.

In this picture, I’ve overlaid the FotoFlot print on the bottom of the Costco print to capture the difference. The grass is much greener in the FotoFlot print, while both made the mud redder. Personally, I like the richer green, even though it’s not as bright in the source print.

Far more important than the color differences is the difference in detail. Take a look at the close up of the Peugeot (FotoFlot on top, Costco on the bottom).


You can see that the lines on the Peugeot in the top frame are far crisper and sharper. A zoom in comparison of the Peugeot badging on the side of the car really highlights this difference.

In the top frame, almost every letter is legible. Only the P, U, and G are clear in the Costco print.

The definition of objects is clearer when looking at the Mazda6 sign. It’s bold and clear in the FotoFlot, but faded in the Costco print.

In the FotoFlot print, the individual pieces of rubber are clearly visible. On the Costco print, only the very large chunks appear. The rest blend into the track. Even more troubling on the Costco print are the vertical lines left by the printing process. The FotoFlot doesn’t have any introduced artifacts of the process.

While the price difference is as large as the differences in photo quality, I think getting large prints printed professionally is completely worth it. The details that made the picture interesting are simply lost in commodity printing. If it’s good enough to put on a wall, then it deserves a quality printer. I see myself using FotoFlot a lot more in the future. I couldn’t be happier with the results. If you would like to see all the images associated with this review, you can find them in this Flickr Set.

  • Share/Bookmark

Zimbra Disaster Recovery

I had queued up a post about the improvements/deprovements in Zimbra 6. Except a comedy of errors led the power supply my mail server to die before I had the chance. This is the second hardware failure this year, so we decided to move our mail and calendars to Google Apps.

That was the easy part, the not so easy part was moving the 4+ years of email sitting on the dead servers hard drive. Most of the process is general recovery hacking: pull out the hard drive, put it in a new machine, do a backup. Restoring onto a new server is where it got a complicated.

I used VirtualBox to host my Centos 4.8 vm with a Mac OSX guest. This Guide on the Zimbra wiki is the correct procedure to recover from this situation. Its very accurate, but it’s worth mentioning a few important highlights.

First, make sure you’re setups are identical. I had forgotten to install a few of the services on my restore machine which caused all sorts of problems and startup failures.

Also, for reasons that I have yet to determine, Zimbra is incredibly crash prone when running in a virtualized environment. You may have to restart often. When trying to test this process, I encountered multiple segmentation faults in Zimbra’s services.

Since this means that you’ll restart often, it’s best to shut off all extraneous services.

You only need these

You only need these

Changing these setting will allow for quicker reboots, shutdowns, and reduce the number of things that can go wrong. I also disabled SSL on my zimbra instance, to future reduce the number of problems.

Now you’re ready to move your email. The best approach is to use imapsync. This utility, written in perl, is like rsync for your mail. It will only move mail that does not exist in the remote location. It can also be restarted after a crash to continue on after a crash (see a few paragraphs above). You’ll probably have to baby-sit the process for a bit, but within a few hours, you should be off your self-hosted email solution and into the manged services of Gmail.

  • Share/Bookmark

Hackintosh

There’s a sizeable gap between Apple’s low end stand-alone desktop (the mac mini) and the next tier (the $2500 mac pro). I found that my current mini wasn’t keeping up with what I wanted to do. Textmate, passenger, a couple virtual machines and Photoshop were enough to send the machine, and it’s 3G of ram to it’s knees.

Therefore, I did what any person that can handle a philip’s screwdriver would do, I built a “Hackintosh.” A good set of parts, including a Core 2 Quad and 16GB of ram will cost about $900 if you shop the combo deals on Newegg. Also, while of dubious legality, it’s really easy to do.

This guide has all the information.

The only additional advice I have to add is to be patient while installing Snow Leopard. On my machine, it took an hour for the install to boot. Or four hours clock time as I continued to fiddle with the hardware and settings. So do yourself a favor and when you start the install grab a beer, relax for a bit, then come back and check on the progress.

  • Share/Bookmark

Are you there to ship, or write code?

Amro Mousa tweeted about a great post by Joel Spolsky about Duct Tape Programmers. Also known as hackers, rockstars, and problem-solvers duct tape programmers are the ones that just get it done.

The line that resonated the most with me is the following quote from Jamie Zawinski:

But that’s not the point—you’re not here to write code; you’re here to ship products.

Unfortunately, I don’t think this is always true. In many organizations, especially the larger, more layered organization, the responsibilities of developing the software and shipping it are held by two different stake holders. The job is to write code, nothing more, nothing less.

This can be the most infuriating and frustrating environment for a duct tape programmer. The metrics are all wrong. Number of test-cases, tickets closed, features on the box, length of scrums, etc, don’t matter if nobody is using the product.

Thankfully, if you think your responsibility is really to make things that get used, there are some early signs that a position might or might not be a fit:

Things that should make you worry:

  • Being asked for a BrainBench certification
  • A 30-minute interview of nothing but syntax questions
  • Lots of questions about keywords
  • Greater emphasis on process than the problem
  • Constant quizzing on the technology mentioned in your resume

Things that should make you feel good:

  • The interviewer describes the problem and how they’ve solve some of it
  • You describe some of the problems you’ve faced and how you’ve solved them
  • You and the interviewer start brainstorming how you’d start solving the rest of the problem
  • You and the interviewer realize that you’re both way over time and are missing something important

The first set of questions determine how well or quickly the candidate can produce code, but there’s nothing in there that explores whether any of that code ever did anything useful. The product is the vehicle, the code is the driver.

The second set is for the duct tape programmer. The code might not have been the most idiomatic or the best covered, but this person has written code to solve the problem in the past and is already thinking about how solve the next ones. In this case, the code is the vehicle that’s driven by the product.

Using these these lists as guidelines can help you find the right fit and place where you can be the most productive, while avoiding misery and a padded cell. Is there anything missing from the lists?

  • Share/Bookmark

LASIK vs PRK: Differences and benefits with each

Disclaimers first. This post is not medical advice and I’m not a medical professional. Always consult with your eye-care professional about anything involving your vision. Always.

With that out of the way, I want to answer a question that I’ve gotten a lot recently. Almost everyone has heard of LASIK (laser-assisted in situ keratomileusis). Most companies and doctors offering corrective surgery advertise this procedure. Not as many people have heard of PRK (Photorefractive keratectomy). PRK is the procedure that Sonali had done a few weeks ago. LASIK is what I will be having done tomorrow.

Both are corrective, out-patient eye surgeries, and eliminate the need for the patient to wear corrective equipment, such as glasses or contacts. The recommended procedure depends on many factors. This post seeks to explain some of these differences.

What they are

LASIK is the more common procedure. In this procedure, a surgeon cuts a flap in the cornea to expose the area on which the laser operates. Once the laser has finished, the surgeon replaces the flap, which stays in place naturally. The creation of this flap leaves a permanent scar that is visible in close examination (when the eye-doctor shines the bright light in your eye).

PRK involves the removal of the top layer of quickly regenerating cells in order to reach the layer that can be effected by the laser. There is no flap. Over time, new cells replace the ones removed and the eye returns to its natural strength.

Both surgeries take only a few minutes in the operating room.

One over the other

LASIK is the preferred procedure, because the patient is able to function normally within a few days. As long as the patient refrains from rubbing their eyes, the risk of flap displacement remains low.

However, the creation of this flap permanently reduces the strength of the cornea and increases the risk of flap displacement in the case of trauma. In situations where the patient’s career exposes them to abnormally high levels of risk for head trauma, such as mixed martial artists, astronauts, and professional deep-sea divers, PRK is the only viable option.

Even if you don’t have an exciting career and are a normal software professional, the doctor may require PRK if the corneal tissues lack the necessary thickness. This was the case with Sonali.

Also, if you’ve had LASIK, but your vision has degraded, the follow up procedure will be PRK. If PRK was not so inconvenient, almost nobody would get LASIK.

Benefits

The obvious benefits are you don’t have to wear glasses or contacts. If you’re someone like me, with absolutely horrible vision, glasses are not really a viable option. Even the most expensive and thinnest lenses have noticeable levels of diffraction for any object not in the center of my field of view. While tolerable during the day or at home, being outside at night is frustrating experience.

Contacts are far superior for vision, but they are inconvenient for traveling. There are other risks as well, including the increased risk of eye infection and eye-fatigue caused by the lack of oxygen to the eyeball.

Major Downsides

The risk with both these surgeries is that you may never regain the same corrected vision. There’s a chance of halo’s, glare and reduced night vision.

With Lasik, the most terrifying risk is that your eye might fall apart. It’s not very likely long-term, but highly likely if you rub your eyes within a month of the procedure.

PRK is a far safer procedure, but requires much more time to heal. The same level of vision correction that is enjoyed by a Lasik patient in 48 hours takes 6 weeks to achieve with PRK. It will take at least a week for a PRK patient to be able to carry out normal tasks. The first week after PRK also involves more discomfort and pain.

Dry eyes are also a problem. There are other downsides and risks. Again, please consult your doctor.

Why does PRK take longer?

Instead of resealing a cut, the eyes of PRK patient have to re-grow tissue that has been removed. This has two side-effects. One is that there are more exposed nerve-endings being stimulated, causing the pain and discomfort experienced by PRK patients.

The second is that the cells regrow, it takes time for them to regain uniform density, resulting in blurry vision. There is no way for your brain to focus the image because light is not being aligned correctly, but during this period the patient does not have a prescription. Corrective lenses will not help.

Is it worth it?

I dunno, too early to tell. Check back in a few months.

This is just an overview, since many people are unaware of the existence of a second procedure. There is much more information out on the web. Please post any questions in the comments.

  • Share/Bookmark

Startup Compensation and Fortune 500 Extraction

This topic starts with a conversation I was having a while back about how small developer pool available for startups in Atlanta and how difficult it is to pry development talent from jobs in large companies. While never explicitly stated, the difficulty baseline is The Valley.

I think that this situation is not as bad as many make it out to be. Home Depot, UPS, Delta, AFLAC and SunTrust conjure up very different images than Google, Yahoo!, Apple, eBay, and Oracle. Yet all are Fortune 500 companies and none of them count as startups. However, we do think that individuals working at the latter set of companies are more startup friendly.

While not as terrible as the perception, I do believe that this phenomena is real and it has little to do with the makeup or mentality of the workforce. It’s a result of simple economics. A standard for working for a startup is the assumption that the employee will give up some base salary in return for performance based compensation in the form of stock options.

An Atlanta company puts itself at a hiring disadvantage using the same compensation trade-off as its Valley counterparts. Lets put some numbers to this to see why.

I’m going to assume that the company has issued 1 million shares at $1/share, and will never dilute. Implicit in this assumption is that pre-money valuations and eventual dilution is similar between the average Atlanta and Valley companies. Differences here will skew the outcomes but the goal isn’t trying to figure out specifics, but the relative reward between regions.

Now the real numbers. According to Salary.com, the salary for a Senior Software Engineer is approximately $84,000 in Atlanta and $100,000 in Palo Alto.

For exit numbers, I used the charts in this post from Scott Burkett’s blog. The average exit in Atlanta is $259 million, the Bay Area is $356 million.

Generally, in my experience, the tacit assumption is that some dollar value of salary is forgone for equity. For this example, I’m going to use $2 of salary equates to one share. Percentage trade-offs make the final outcome look better, but there will still be a difference. The final large assumption is that everything goes to plan, and the company sells right at the end of the four-year vest for the average sale price in the region.

Here are the numbers after 4 years:

Normal Salary Startup Salary Stock Value Startup Comp % Diff
Atlanta $336,000 $296,000 $125,000 $421,000 25%
Greater SF $400,000 $360,000 $175,000 $535,00 33%

The Atlanta employee looking to be part of a startup is taking on the same risks, for a lower reward. This will reduce the pool of talent available to any startup looking to grow to a self selecting set that appreciates the lifestyle and is willing to burden the risk at that reward threshold.

I don’t know if this is a positive, negative, or even correct (those assumptions are pretty large). Please leave any feedback, corrections, or methodological faults in the comments.

  • Share/Bookmark
Return top

About

This is my blog about programming. For random stuff, checkout my Twitter or Tumblr