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.
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.
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:
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!