November 2007 Archive

Converting to an int without exception

By Luke Smith on November 25, 2007 11:25 PM

The comp.lang.javascript FAQ has a nifty little trick in the type conversion section for converting anything to an int and rather than possibly getting NaN, you will always receive a number.

It's all about the bitwise OR

The method uses the bitwise OR operator | with a non-impacting 0 operand to leverage the JavaScript native ToInt32 function otherwise unavailable within your code. Simply OR a variable and it will be a number.

var foo;
...much chaos ensues...

foo = foo|0; // convert foo to an int

Similar to the unary + operator, |0 will convert false and the empty string to 0 and true to 1. However, it will also convert invalids, such as undefined, "foo", or function foo() {} to 0.

Cryptic? Yes. Idiomatic? Yes. Nifty? I think so. I don't anticipate using it any time soon, as its applicability seems limited, but still something to have in the tool belt (and never use without annotation).

Check out the FAQ page for more info.

What do you know, she's a model

By Luke Smith on November 13, 2007 10:09 PM

Perhaps a year ago, I was sorting the recycle when I noticed a familiar face amidst the junk mail. On the cover of the Title Nine (oops) Athleta catalog was Monica Halsey. I went to high school with her. I believe junior high as well. My memory is so bad, I may have even gone to elementary school with her.

She was very nice. Smart, friendly, level headed. Pretty, too, though I was never on the make. I was a teenaged nobody, but I remember she was never holier-than-thou.

Well I guess now she's a model, and by the fact that she has recently shown up in the marketing vids for Microsoft Surface, I guess a successful one at that.

Kudos to her. I have nothing but fond memories of Monica and I wish her the best. Still weirds me out to see her everywhere, though.

Did you mean null?

By Luke Smith on November 10, 2007 9:47 PM

Uhm...no? But perhaps I might settle for undefined.

Scrollbars and Firefox on OS X

By Luke Smith on November 8, 2007 10:09 AM

Scrollbars bleed through absolutely positioned elements on Firefox Mac 2.0.x. This is similar to how <select> elements bleed through in IE <= 6. The difference being that there's a fix for the latter.

screen shot of the scrollbars bleeding through

There was a moment of hope when I noticed that setting the positioned element to overflow: auto.

screen shot of the scrollbars obscured by the overflow: auto rule

However, they bleed through again when the window loses focus.

screen shot of the scrollbars bleeding through

Turns out the bug is fixed in the repository head for version 3, but they're not planning on rolling a fix for 2.0.x. This makes me sad.

Javascript instanceof WHATEVER

By Luke Smith on November 8, 2007 9:38 AM

Pointless revelation of the morning:

function Foo() {}
var fooInstance = new Foo();

var Bar = Foo;
var Baz = Bar;

if (fooInstance instanceof Foo) {} // true
if (fooInstance instanceof Bar) {} // true
if (fooInstance instanceof Baz) {} // true

Not that this is particularly helpful in any way, but interesting enough to a groggy morning brain (it doesn't take much).

Font zoom, FireBug, and failing eye sight

By Luke Smith on November 7, 2007 12:20 PM

My eyes aren't exactly top notch. In fact, my vision is pretty bad. In the last few years, I've been finding myself squinting and/or moving a reading target away or towards my face to find the right spot where everything is clear. Old before my time, perhaps.

At any rate, I've increasingly been using font zoom when reading blog entries that were clearly written for eagles. This has helped a great deal, but more often than not, the content will be in a fixed width container, so as the font size increases, the text measure decreases. It's still annoying to read the content because it's now awkwardly thin.

FireBug to the rescue

So here's my less than perfect, but relatively simple fix:

  1. Right click in the content area and select Inspect Element
  2. Look for a width setting in the style tab. If you don't find one, browse up the node tree until you do
  3. Change the width declaration from pixels to ems. I find about 35ems to be a good width for me
  4. (optional) Taking stock of the design impact you've now made, find other major fixed width elements and change their units to ems, tweaking size as needed to put things more or less back in place
  5. Enjoy the zoomed in reading with said crappy eyes
  6. Profit?

This of course assumes you are browsing in Firefox and that you have Joe Hewitt's excellent FireBug extension installed. I can understand choosing a different browser (so long as it's not IE) but if you're using Firefox and you have anything to do with web development, you have no excuse not to have FB installed.

Incidentally, this blog uses ems for its structural dimensions, so scale the font size to your heart's content.

Update

Turns out this post was coincidentally timed with a similar read from a different (read: opposite) perspective.

I'm surprised, that text measure wasn't addressed as a relationship between the font/word size, but I find the discussion of visual degrees interesting.

From this, it seems I prefer not to move my seat, but attempt to zoom the entire site. Practically, I'm only interested in the content, so font scaling serves the purpose. If I want to read a page from a particular distance (typically from within natural reach of my keyboard and mouse), and I anticipate spending a few minutes consuming it, I am willing to resize my browser window to fit readable font size with text measure in tact.

!Phone

By Luke Smith on November 4, 2007 9:37 PM

I took my phone swimming, but it didn't like it. In fact, it didn't like it in a very terminal way.

Yes, apparently I am that kind of dumbass.

Guess I'm in the market for a new phone. In the mean time, don't be offended if you call me and I don't answer.

Good thing I didn't buy an iPhone.

Update

I stopped by a Verizon chop shop today and picked up a cheap refurb, so I'm back in business.

Interestingly, the phone came complete with the former owner's contact list, SMS history, and extensive photo gallery of what appears to be a marijuana farm. Maybe they're just ferns; I'm no expert. Hopefully tomorrow I can stop by a kiosk somewhere and wipe their stuff and transfer my own.

At least now I have something to use until my contract expires in April.

ls.n

LucasSmith.name

Luke and Liam

I'm Luke. I am a front end engineer at Yahoo! on the YUI team.

Mostly I write about code stuff, but occassionally I'll mix in some real life. You've been warned.

Archives

Tags

Feeds

Subscribe to feed Recent entries

Content licensed under Creative Commons

Code licensed under BSD license

©2005 - 2010 Lucas Smith

Powered by Movable Type