Binary clock in CF
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.
<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=" & marked & ".jpg />">
</cffunction>
<cfset hour = getBinary(hour(now()),"0000") />
<cfset minutes = getBinary(minute(now()),"000000") />
<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=" & marked & ".jpg />">
</cffunction>
<cfset hour = getBinary(hour(now()),"0000") />
<cfset minutes = getBinary(minute(now()),"000000") />
And then some crappy HTML to display the clock
<cfoutput>
<table width="20%" border="1">
<tr>
<td colspan="6">Hours</td>
</tr>
<tr align="center" id="hours">
<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 align="center" id="minutes">
<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>
</table>
</cfoutput>
<table width="20%" border="1">
<tr>
<td colspan="6">Hours</td>
</tr>
<tr align="center" id="hours">
<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 align="center" id="minutes">
<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>
</table>
</cfoutput>
Hope you like it!


To answer you question as a woman - I think its cool :)
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
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!
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