2010-4-19

Updates to Truncation Script

I made a few improvements to my Firefox truncation method this past weekend:

  • No longer depends on YUI to run. Since it's Firefox-only, I can assume a few nifty JS bits like getComputedStyle() and getElementsByClassName().
  • Improved the truncation algorithm. I was simply lopping off characters until it was the right length, but that performed very poorly, for obvious reasons. I'm now doing a binary "search" for the right length, which runs great (in my opinion).
  • onresize "debounce": I've written a little helper method that wraps the event handler for the resize event. When resizing the browser window, the event is fired every time the mouse is moved, causing a load of lag. The helper method limits how often the event handler fires, and makes sure it stops firing once the resize is over.

Here's the source of the debouncer:

function debounce(fn, ms, ctxt) {
    var ctx = ctxt || window;
    var it, to, del = ms, fun = fn;
    return function () {
        var args = arguments;
        if (!it) {
            it = setInterval(function () {
                fun.apply(ctx, args);
            },del);
        }
        clearTimeout(to);
        to = setTimeout(function() {
            clearInterval(it);
            it = false;
        },del);
    };
}

To use it:

document.onresize = debounce(handler, 100);
2010-4-17

Cheap Eats- Tomato Sauce!

When I'm not embarking on various food adventures with my culinary partners in crime, I'm a fairly frugal at-home cook. One of my favorite things to make is my own tomato sauce. It's easy to make a bunch at once, it's turbo-versatile, and it freezes well.

My recipe for tomato sauce:

  • 1 large (28oz) can of crushed or whole tomatoes in juice/puree
  • 1 carrot carrot, diced
  • 1 stalk of celery, diced
  • 1 medium onion, chopped
  • garlic (as much or as little as you fancy), chopped finely
  • spices (parsley oregano, basil) to taste
  • olive oil

In a large dutch oven or saucepan, heat up about a quarter cup of olive oil (eyeballed, like most of the things in this recipe). Cook the celery and carrot together with a pinch of salt over medium-low heat for about 5 minutes. Then add the onion, and cook for another 5-10 minutes, or until everything is soft, and the onions are translucent. Push the vegetation to the edges of the pan, and add a little more oil to the center. In that, cook the garlic for another few minutes, until it's just starting to take color. Then add the tomatoes and spices, stir, and bring everything up to a simmer. Cover the pan, and simmer for at least 45 minutes- but it will only get better from there.

What to do with it?

  • Poach eggs in about a cup of sauce in a small saucepan. Serve with crusty bread or toast.

  • Use it as the base for a quick chili- Take a can of black or kidney beans, ¼-½ cup sauce, lots of cumin and chili powder, some hot sauce, and bring it all to a simmer. Then, I crush (or stick-blend) some of the beans to thicken slightly, and cook for another 15 minutes.

  • Spanish Rice- prepare rice, substituting half the liquid with sauce. Add diced peppers and cumin. Cook normally, being sure to stir often.

What else can you do with it?

Put it on pasta, dummy!

2010-4-10

Three Little Projects

I recently cleaned up 3 little JavaScript projects I've made for myself, and thought I'd share them here:

LoadBar

A simple progress bar. Right now it expects a specific width and height for its container, but I'm working on generalizing it.

Authoring TextArea

A few JS-based enhancements for textarea elements:

  • tab key produces a four space indent
  • return inserts a newline, and, more importantly, preserves the indentation of the previous line

I wrote this up to allow me to more easily write and edit the Markdown format that these posts are stored in for my blogging system (which will receive its own post shortly).

Firefox Truncation

A JavaScript implementation of text-overflow:ellipsis in CSS. Of all the modern browsers, Firefox doesn't support this fairly useful property (though it does have an open ticket for it). My solution? I use a canvas element to measure the size of the rendered text, and iteratively truncate the the text until it fits. All elements with the class of truncate recieve this treatment. The full text is available as a tooltip on hover. Right now, this script only works under the YUI library, but I am working on generalizing it to be framework-agnostic. See update here!

2010-3-10

Getting Around To It.

I'm a serial procrastinator by nature. My unfinished projects folder is chock full of half-baked ideas- some of them are even good ideas. But somewhere around the 35% mark, I hit a wall. The lures of younger, more attractive ideas call to me in their untapped potential. Because this, very little of my work finds its way into the light of day.

No more!

Inspired by the rantings of the likes of Merlin Mann, and in nearly blatant imitation of the inimitable Jonathan Coulton, I hereby make the following pledge:

For the next 365 days, I will post no less than one interesting/silly/dumb project on this website a week every so often (heh). They may be programming/electronics projects, music recordings, videos, or short essays. Whether I succeed or fail, this website will stand as a record of that success/failure.

Stay tuned!

I'm getting there...

Gosh. I hardly recognize the place now.