Send As SMS

Technology / Dev Soap Box

Thursday, October 26, 2006

ASP.NET AJAX

I mostly just wanted to post something here since no one has done it for months! I've been using Microsoft's ASP.NET AJAX and really like it. It has come a long way since it first came out with its code name 'Atlas'. Check it out, its HOT!

Friday, June 16, 2006

SQL: Convert seconds to MM:SS format

Moises asked me how to convert some number of seconds into a human-readable string in the format MM:SS (minutes and seconds). On a previous project, Eric Ruhlman created a user-defined function (UDF) in MS SQL Server to do this very thing.

First create the UDF:


CREATE FUNCTION dbo.FormatNrSeconds(@nrSeconds decimal)
-- return varchar with length of at least 5
RETURNS varchar(10) AS
BEGIN
Declare @tempStr varchar(20),
@MinNum varchar(20),
@SecNum varchar(20)
-- Get a string of the number of minutes
set @MinNum = Cast((Cast(@nrSeconds as int)%3600/60)as varchar(20))
-- Prepend a 0 if < 10
if(@minNum<10) set @minNum = '0'+@minNum
-- Get a string of the number of seconds
set @SecNum = Cast((Cast(@nrSeconds as int)%3600%60%60)as varchar(20))
-- Prepend a 0 if < 10
if(@secNum<10) set @secNum = '0'+@secNum
-- concatenate the two values into MM:SS
set @tempStr = Cast(@MinNum as varchar(20))+':'+Cast(@SecNum as varchar(20))
return @tempStr
END



Second, use that UDF in a select statement:


select dbo.FormatNrSeconds(356) as formattedTime


The result should be (just under 6 minutes):


formattedTime
-------------
05:56


Now, Moises was using SQL's DATEDIFF function to compare two dates, as shown here:


declare @date1 datetime
declare @date2 datetime
set @date1 = '6/1/2006 14:30'
set @date2 = '6/1/2006 14:35:56'

select dbo.FormatNrSeconds(datediff(ss, @date1, @date2)) as formattedTime



The result is the same as above:


formattedTime
-------------
05:56

Thursday, June 08, 2006

For stability, choose Windows

I just had to post this because of all the Linux posts, the Yankee Group does an annual server reliability survey and this year Windows 2003 beat out the popular Red Hat Enterprise Linux with nearly 20 percent more annual uptime. It claims the reason that Linux servers are offline more and longer is the scarcity of Linux and open source documentation. The group did also say that Unix, such as HP-UX and Sun Solaris 10 are more reliable than Windows.

I haven't had a ton of experience with Linux, and very little in a production environment, so I can't say that I can back up the results with experience. I have messed with Linux enough to know that when issues arise it can sometimes take a little bit to figure them out, and finding answers can be more difficult than in the Windows world because of the hundreds of distros and lack of good, free documentation for open source products.

Don't get me wrong, I like Linux...I just like Windows more and have had more experience with it and think that I am destined to remain a Microsoft fan. :)

Wednesday, June 07, 2006

Ubuntu Linux Distribution

So, my latest linux craze is now Ubuntu linux. Thanks to William Jager and Brian Fromm I'm now trying to create this XGL desktop experience. There is a video of the XGL desktop that shows a really cool 3D experience. Click here to see the video.

Tuesday, May 02, 2006

Enough DSL Linux...go with Killbill Slax

I did a previous post about DSL Linux and how cool it is to run it from a thumb drive. Well, Nick pointed me in the direction of a Slax distro for USB drives that a co-worker uses. If you go to http://slax.linux-live.org and find the Killbill download, that's my new toy. The initial download is 190MB+ but it's so much better than DSL.

Don't get me wrong, DSL is cool...but Slax really rocks! In fact, I'm logged in on my laptop on the Slax distro running from my USB drive. There are still some weird nuances that I have yet to figure out, but it's fun to play with. For instance, I have issues with getting an IP address from one boot to the next. At first, only my wireless would work. Right now, my wireless isn't working and the LAN is working.

OH! The coolest thing when I first loaded up Killbill was that my laptop hard drive was automatically mounted as an NTFS partition on /mnt/hda1. I haven't been able to write to that hard drive yet -- I'm not even sure if that's possible. I can write to my USB drive though, but I can see myself running out of space quickly, unless I get a fancy thumb drive like Bernd's.

Here's a screen shot I took of my desktop:

Wednesday, April 26, 2006

Simulating Button Click with JavaScript

This post goes along with the previous post about handling the enter key. How do you simulate a button click in JavaScript? See the code below:

<script>
function doClick() {
// Perform the click of the "Other" button obj = document.getElementById('myButton');
obj.click();
}
function handleClick() {

// Show that the "Other" button's onClick handler was fired alert('caught the click event');}
</script>

<input onclick="doClick()" type="button" value="Simulate clicking the other button">>
<input id="myButton" onclick="handleClick()" type="button" value="the other button">

Note the line obj.click();. This is where the click is simulated. I found that case matters on that method--it cannot be obj.Click();.

Tuesday, April 25, 2006

DSL Linux: Small distro that packs a big punch

DSL Linux: Small distro that packs a big punch: "Need a teeny-tiny, business-card-sized, open source operating system that squeezes a lot of software into a little space? Take a look at DSL Linux. This quick review shows you how to use the miniscule OS, highlights the on-board applications, details how to load and start it, and explains how to save between sessions when using a bootable CD."

This is so cool. I installed DSL on my tiny 64MB thumb drive, changed my BIOS to boot to USB and (insert Brant Frank voice here:) BAM! I booted into linux on my laptop. I couldn't get the networking to work, but I'm sure with about 7 hours of wasted time I could figure it out.

Autocomplete on Web Pages

I decided to branch out and go Web 2.0. Tyler Young showed me a site a while ago: http://script.aculo.us/. These guys do a Google-suggest style autocomplete textbox. I implemented one of these widgets on the DirectPointe Support Portal. Previously, we were providing four or five search fields to lookup a contact via web services. Now, I just load up a string array in JavaScript of all the contacts in our database and we have Google-suggest for searching. This eliminated the 4-5 second web service call to the backend to perform a SQL query with an "OR" on five columns in the table. Much faster thanks to script.aculo.us!

Here is a link to all their demos: http://wiki.script.aculo.us/scriptaculous/show/Demos

Enter Key in ASP.NET 2.0

So, one thing I hate about ASP.NET, is that you can't just hit "Enter" to submit a form on a web page. Instead, you submit this form full of ViewState. So, in order to make the enter key work to perform some action on your page do something like this with JavaScript:

<script type="text/javascript">
function openCustomerViewOnEnter() {
// catch the enter key
if (window.event && window.event.keyCode == 13) {
openCustomerSupportView();
return false;
}
return true;
}


var txtNameObj = document.getElementById('txtContactName');
txtNameObj.onkeypress = openCustomerViewOnEnter;

</script>
<input id="txtContactName" type="text" />

With that code, pressing the enter key when your cursor is inside the "txtContactName" textbox will execute the "openCustomerViewOnEnter" JavaScript function.