About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 35 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

Cringley's Second Law: Ease of use with equivalent performance varies with the square root of the cost of development. That means that to design a computer that's ten times easier to use would cost 100 times as much.

— Robert Cringley



Navigation





<July 2024>
SMTWTFS
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 6/2/2024

Totals
Posts - 2654
Comments - 2677
Hits - 2,680,669

Averages
Entries/day - 0.34
Comments/entry - 1.01
Hits/day - 348

Updated every 30 minutes. Last: 7:24 AM Pacific


  02:01 AM

Update I did manage to make a client-side version of this.


In his blog, Mikhail shows a picture of a mystery object, noting that visitors don't always know what it is. Well, it turns out to be a clock that shows the hh:mm:ss as binary values. Cute.

In a comment, Mikhail adds "Actually, it is possible to ask [interview] candidate to write code that would light LEDs for this kind of clock." Well, shoot, that sounded like fun. Although I don't have any LEDs handy. Plus I usually work in ASP.NET Web pages, which don't exactly lend themselves to an interactive clock.

I played around with it just to get some ideas. My first attempt is hacked together. Turning the time digits into a string representation of binary (e.g., 0110 for 6, say) wasn't bad, and gave me a rare opportunity to use integer division. Turning the binary string into a representation on the page was a challenge. I wanted to use radio buttons to kind of approximate the look that Mikhail's clock has -- pseudo-LEDs stacked vertically. I tried a RadioButtonList, but wouldn't you know it, the buttons in the list are mutually exclusive by design. In the end, I decided to conjure up ungrouped radio buttons dynamically. A second problem was reversing the representation. I stumbled across an indirect solution for that one by using an array as a buffer for the strings.

This is what it looks like, big whoop:



If you want to see it as a page, click here.

It would be interesting to turn this into a more interactive clock using client script. The basic technique would have to be scrapped (the number of radio buttons would need to be fixed, not dynamic), which is probably why I won't be jumping on that opportunity real soon. But it'll be something to keep around for a rainy day. Along with the notion of using GDI+ to create the LED look.

Anyway, here's the code for the page. The layout is hard-coded as a table, which I figured was ok.
<%@ Page Language="VB" Debug="true" %>
<script runat="server">
Sub Page_Load()
Dim currentTime As DateTime = DateTime.Now
Dim timeString As String = currentTime.ToString("HH:mm:ss")
lblTimeString.Text = timeString


IntToBinary(CInt( timeString.SubString(0,1) ), hoursTens, 2)
IntToBinary(CInt( timeString.SubString(1,1) ), hoursOnes, 4)
IntToBinary(CInt( timeString.SubString(3,1) ), minutesTens, 3)
IntToBinary(CInt( timeString.SubString(4,1) ), minutesOnes, 4)
IntToBinary(CInt( timeString.SubString(6,1) ), secondsTens, 3)
IntToBinary(CInt( timeString.SubString(7,1) ), secondsOnes, 4)
End Sub


Sub IntToBinary(num As Integer, container As Control, bitcount As Integer)
Dim binaryArray(bitCount) As Integer
Dim ctr As Integer = bitCount
While ctr > 0
If num mod 2 = 1 Then
binaryArray(ctr) = 1
Else
binaryArray(ctr) = 0
End If
num = num \ 2 ' Integer division, no remainder
ctr -= 1
End While
For i As Integer = 1 to binaryArray.Length - 1
Dim rb As New RadioButton
rb.checked = binaryArray(i)
container.Controls.Add(rb)
container.Controls.Add(New LiteralControl("<br>"))
Next
End Sub
</script>
<html>
<head>
<style>
TD { VERTICAL-ALIGN: bottom }
TD.timestring { TEXT-ALIGN: center }
.clock {
background-color: black;
border-color: gray;
border-width: 2;
border-style: solid;
padding: 2;
font-weight: bold;
color: lightgreen;
font-family: arial;
}
</style>
</head>
<body>
<form runat="server">
<table>
<tr>
<asp:tablecell id="hoursTens" runat="server"></asp:tablecell>
<asp:tablecell id="hoursOnes" runat="server"></asp:tablecell>
<td width="10"></td>
<asp:tablecell id="minutesTens" runat="server"></asp:tablecell>
<asp:tablecell id="minutesOnes" runat="server"></asp:tablecell>
<td width="10"></td>
<asp:tablecell id="secondsTens" runat="server"></asp:tablecell>
<asp:tablecell id="secondsOnes" runat="server"></asp:tablecell>
</tr>
<tr>
<td class="timestring" colspan="8">
<br />
<asp:Label id="lblTimeString"
runat="server" cssclass="clock">
</asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>

[categories]  

|