The miscellaneous ramblings and thoughts of Dan G. Switzer, II

Rounding to the nearest fraction (i.e. specific decimal place)

I'm working on some "star rating" code and I really wanted to round numbers of to the nearest fraction. While the math is really basic, my math skills are rusty and this took me longer to solve than I care to admit. So I thought I'd just blog the solution for anyone else that might find it useful:

round( value/fraction ) * fraction

Like I said, it's very basic math but is very handy when you want to round to something other than to the closest integer.

From the worst day ever, to the best…

Today started off horribly. But before I get into today, I have to backtrack a bit.

While I haven't blogged about this yet (because it's still very early,) my wife is pregnant. Getting pregnant has been a long process for us and something our family and close friends have known about. Because so many people have known what we've been going through, we announced it to close friends and family a little sooner than we'd probably have liked.

Last Monday at 5am, Jenn woke me up and she had passed a clot. From the look of things, I was really afraid things were bleak. Jenn continued to spot all last week, so I was really worried that something went wrong w/the pregnancy. The doctor's didn't seem overly concerned and we just needed to wait out our appointment which was scheduled for today at 10a.

Needless to say, last week really sucked. We were trying to stay optimistic, but I was preparing for the worst.

This morning at 4:45am (a week almost to the minute) Jenn work me up again. This time the bleeding was really bad (I even had to clean up the path on the floor to the bathroom.) The clot she passed was about the size of a racket ball. As much as I thought last week was bad, this was much worse. The morning was really tough on us. The morning was a long one waiting for our scheduled ultrasound (which I was really assuming the worse had happened.)

When we saw the doctor we explained what had happened. He didn't seem overly shocked (because we had kept him a breast of the spotting) but I was surprised he didn't seem as concerned as we were.

So when the ultrasound started, I was really trying to figure out how to comfort Jenn, just fearing the worse.

Much to my surprise, I saw a similar black blob as we did on our ultrasound on 9/10, but I was still hesitant to get my hopes too high. However, within seconds a little peanut shape emerged from the blackness and once again we saw the little fluttering of a heart.

After basically preparing myself of the worst for the past week and then just feeling like my thoughts were confirmed this morning, I can't even begin to explain the emotions I was feeling--to say it was a relief doesn't even begin to explain it.

We even got to hear the heart for the very first time. The heartbeat was very healthy and was over the healthy 150 beats per minute they like to hear.

While we're still not sure what's causing Jenn's spotting, the doctor didn't find any lesions--only another smaller clot and he doesn't feel like it's threatening the baby.

So everything looks to be going great. The bleeding is still a concern, but thankfully the baby appears healthy.
It's funny how quickly your life can change with just the lubb-dub sound of a heartbeat. I've always heard how life change on a heartbeat, now I truly understand.


Create iPhone-style buttons with the iButton jQuery Plug-in

At work we just released another jQuery plug-in called the iButton jQuery Plug-in (which brings the total of open source jQuery plug-ins we've released to four.) This plug-in allows you to generate iPhone-style buttons from checkbox and radio elements. While there are several libraries out there that generated iPhone-style buttons, we couldn't find one that did everything we needed, so I wrote one!

The users of our application are very keyboard centric, so it was very important that we supported keyboard entry. Keyboard support often seems to be overlooked in most UI plug-ins—developers get so focused on the mouse interaction, they forget completely about keyboard entry. So we always make keyboard support a key feature in the jQuery plug-ins we write.

Anyway, here's a list of the key features:

  • Works with checkboxes or radio elements
  • Full keyboard support — use the [TAB] key to move from field to field and use the spacebar to toggle the status of the iButton (or use the arrow keys for radio buttons)
  • Custom event handlers
  • Detach iButton behavior from the element
  • Metadata support — when used with the jQuery Metadata Plug-in, you can define the properties for your button completely within the class attribute of your input elements
  • Enable/disable drag support — while the dragging behavior is intuitive on touch-based devices, it's not always be the best or expected UI behavior and may cause some mouse users problems (NOTE: In order to help differentiate between an intended mouse click or an actual drag event, we're developed the clickOffset option. If the time (in milliseconds) is under this value (120ms by default) it's assumed the user was attempting to click the button and not drag the handle.)
  • Enable/disable animation
  • Single sprite image — easily change the look of your button by just replacing the image sprite
  • Customizable labels — use any labels you want for your buttons
  • Support for disabled buttons
  • Easing support for animations
  • iPhone support

You can see a demo of the plug-in on the Giva Labs - iButton Example Page.

We're pretty happy with the end result and are planning on using it in a few locations in our application. If you like plug-in, don't forget to Digg it!