Archive for October 2010

Is this string numeric?

This VB code was brought to my attention.  It is meant to look at a string variable (prefixText) and decide if the string is numeric or not, and return a data set (ds) by using a different method based on the result of the numeric test. (As always, this code is in a heavily used production environment.)

If Left(prefixText, 1) = "0" Or Left(prefixText, 1) = "1" Or Left(prefixText, 1) = "2" Or Left(prefixText, 1) = "3" Or Left(prefixText, 1) = "4" Or Left(prefixText, 1) = "5" Or Left(prefixText, 1) = "6" Or Left(prefixText, 1) = "8" Or Left(prefixText, 1) = "9" Then
    ds = New Users(_ConnStr).getUsersListByNumber(prefixText)
Else
    ds = New Users(_ConnStr).getUsersListByLastName(prefixText)
End If

I have some great ideas on how to improve this code. The first thing I would have done was to use OrElse instead of Or, it would speed things up tremendously. And I would also have added in the test for the “7” character.

[super dealloc];

Sorry about the delay between posts, readers. I have been fighting with getting as much coded as possible with our newest iPhone application, along with fighting with bugs and crashes in our existing iPhone applications. The App Store approval process continues to baffle me to no end.

From a development perspective, one thing I learned the hard way was to make sure that the dealloc methods in the classes that you roll in Objective C need to have the [super dealloc]; come last. If it does not come last, your code may or may not have memory problems and crashes.  If you are not sure if you are always doing this last, check your classes now.

Go ahead and check, I’ll be here when you get back.

No quarters required

Thanks to a little assist from my coworker John Boker, the amazing Asteroids javascript from Erkie is now fully integrated into this here very web site. Alls you have to do is type asteroids on any web page of this roided up web site (just make sure the focus is not set on a text field or the URL field), and blast away.

Here is the javascript that I added to the footer of my pages:

<!-- asteroids -->
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
 
    <script type="text/javascript">
        function asteroids()
        {
            var s = document.createElement('script');
            s.type = 'text/javascript';
            document.body.appendChild(s);
            s.src = 'http://erkie.github.com/asteroids.min.js';
        }
        var roids = "";
        $(document).keypress(function(e)
        {
            roids += String.fromCharCode(e.which);
            if ("asteroids".indexOf(roids) != 0)
            {
                roids = "";
            }
            else if (roids == "asteroids")
            {
                roids = "";
                asteroids();
            }
        });        
    </script>

Enjoy.