Reading time: 3 – 4 minutes

Early today I was looking for some Christmas presents and found a very nice Binary Watch.
I was wondering who uses this kind of stuff, but I’m sure somebody uses. Imagine yourself in a club when that hot chick comes to you asking what time is it. Would you show that nerd piece on your wrist?
On the other hand a ColdFusion Clock would be very nice. So when the hot chick comes to you with that question, you could use your blackberry to say the time.
Nahh… The time is already on your blackberry, but… Well, it was a nice exercise at least.

Here’s the CF code:

<cffunction name="getBinary">
    <cfargument name="value" required="true">
    <cfargument name="mask" required="true" hint="Four (Hours) or six (minutes) numbers are returned">
    <cfreturn numberformat(formatBaseN(arguments.value,2),arguments.mask)>
</cffunction>
<cffunction name="isChecked">
    <cfargument name="position" required="true">
    <cfargument name="value" required="true">
    <cfset var marked = "off">
    <cfif mid(arguments.value,position,1)>
        <cfset marked = "on">
    </cfif>
    <cfreturn "<img src=" &amp; marked &amp; ".jpg />">
</cffunction>
<cfset hour = getBinary(hour(now()),"0000") />
<cfset minutes = getBinary(minute(now()),"000000") />

And then some crappy HTML to display the clock

<table border="1" width="20%">
    <cfoutput>
        <tr>
            <td colspan="6">Hours</td>
        </tr>
        <tr id="hours" align="center">
            <td>8</td>
            <td>4</td>
            <td>2</td>
            <td>1</td>
            <td> </td>
            <td> </td>
        </tr>
        <tr align="center">
            <td>#isChecked(1,variables.hour)#</td>
            <td>#isChecked(2,variables.hour)#</td>
            <td>#isChecked(3,variables.hour)#</td>
            <td>#isChecked(4,variables.hour)#</td>
            <td> </td>
            <td> </td>
        </tr>
        <tr>
            <td colspan="6"></td>
        </tr>
        <tr>
            <td colspan="6">Minutes</td>
        </tr>
        <tr id="minutes" align="center">
            <td>32</td>
            <td>16</td>
            <td>8</td>
            <td>4</td>
            <td>2</td>
            <td>1</td>
        </tr>
        <tr align="center">
            <td>#isChecked(1,variables.minutes)#</td>
            <td>#isChecked(2,variables.minutes)#</td>
            <td>#isChecked(3,variables.minutes)#</td>
            <td>#isChecked(4,variables.minutes)#</td>
            <td>#isChecked(5,variables.minutes)#</td>
            <td>#isChecked(6,variables.minutes)#</td>
        </tr>
    </cfoutput>
</table>

Hope you like it!

4 Responses to “Binary clock in CF”

  1. Jez… I think you are the first woman posting a comment into my Blog. Welcome! :-)

    But now the big question. This woman who uses the watch. Am I talking to her now?

    How was flash on the beach BTW?

    Cheers

  2. Yes, I’ll try to do it next year. I used to work with some action script, and sometimes I still do it, but not so frequently.

    Talking about the restaurant, I believe I’ll eat loads of Brazilian food next week as I’m off to Brazil until the 15th of January.

    Cheers

  3. The only person I know who has one is a woman. She is also a geek and just in case you think that makes her ugly… She is actually beautiful.

    To answer you question as a woman – I think its cool :)

  4. Hi Marcos

    Her name is Sarah and she does mobile development. I was well impressed and thought about it just for the novelty factor but really can’t read binary.

    FOTB was amazing. It was so surreal to have dinner at my favorite Brazilian restaurant with a bunch of the speakers and top developers from all over the world.

    The speakers were inspirational! You have to make it to next years if you are even remotely interested in Flash!

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>