Archive

Archive for the ‘Computers’ Category

Really Slick OpenGL Screen Savers

July 15th, 2010 Eric Silva No comments

Tired of the boring screen savers that come with Windows and haven’t changed since Windows 3.1?  Take a look at Really Slick Screensavers for some cool OpenGL savers available for Windows, Linux, Solaris, or Mac OS X.

Greenshot – free screenshot tool

July 13th, 2010 Eric Silva No comments

After using SnagIt for several years with my old company, I was in need of an open source replacement.  After using everyone’s favorite research assistant, I found Greenshot.  It doesn’t have all the bells and whistles that SnagIt has, but it has the basics which is what you use 80% of the time anyway.

So far, so good.  If you are need of a good screenshot/capture tool, and don’t feel like forking over $50 for a SnagIt license, check out Greenshot.

Simple Calendar Control for Web Application

March 19th, 2010 Eric Silva No comments

I originally did this back in 2007, but did not want to lose the content, so I decided to put it up here.

I found a robust and relatively simple calendar control to use for web UIs. It can use a pop-up window or a floating <div> tag. I prefer the latter as it makes the page look good and avoids a pop-up.

To use the control simply put the CalendarPopup.js file in your application’s “scripts” directory and be sure to include it in your JSP. (I used this in a Java app, but you can apply it to any language.)

Download the and put it in your images directory.

Add the following lines to your application’s JavaScript file (or include on the same page if you don’t have an external JS file):

// Set up Calendar control
var calObj = new CalendarPopup("calDiv");
calObj.showNavigationDropdowns();
calObj.setMonthNames('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');

// Handle the Calendar control
function doCalendar(destObjId, srcObj) {
    calObj.select(document.getElementById(destObjId),srcObj.id,'dd-MMM-yyyy');
}

Then add the following lines to your JSP:

<script>document.write(getCalendarStyles());</script>

In your JSP, add the following HTML code where you want your date field and calendar control:

<input id="dateField" style="width: auto;" maxlength="11" name="actualDate" size="25" type="text" />
<img id="imgCal" onclick="doCalendar('dateField',this);return false;" src="cal.gif" border="0" alt="" />

That’s it!

In order to workaround IE 6′s inability to recognize the z-index attribute on the tag, I made some modifications to the original JavaScript code. You will need to pass the an ID value to be used for the hidden that will overlay the box.

var calObj = new CalendarPopup("calDiv", "calFrame");

You will also need to specify the following styles in a stylesheet. The ID values in the stylesheet must match the names of your DIV and IFRAME IDs on your page.

div#calDiv {
    position:absolute; visibility:hidden;
    background-color:white;
    layer-background-color:white;
}
.select-free {
    position:absolute; z-index:10;/*any value*/
    overflow:hidden;/*must have*/
    width:152px;/*do not change value for calendar control */;
}
.select-free iframe#calFrame {
    display:none;/*sorry for IE5*/
    display:block;/*sorry for IE5*/
    position:absolute;/*must have*/
    top:0;/*must have*/
    left:0;/*must have*/
    z-index:-1;/*must have*/
    filter:mask();/*must have*/
    width:3000px;/*must have for any big value*/
    height:3000px/*must have for any big value*/;
}

Your JSP now needs the following line:

<div id="calDiv" class="select-free"></div>

Primality Test v2.0

December 14th, 2009 Eric Silva No comments

After feedback from some friends of mine, and doing a little bit of background research, I am writing this update to my original post last week.  As it turns out, by checking all the numbers in the form 6k ± 1 \scriptstyle{}\leq\sqrt n instead of checking each number up to the input value, I have increased the speed by 7 times! determineIsPrime3 (line 48 below) is the fastest algorithm so far.  determineIsPrime2, a simple comparision against the \scriptstyle\sqrt n, was twice as fast as the original algorithm.

For now, I am putting this one to bed.  It was a fun exercise, but I have got what I need from it.

'''
Checks the specified value to determine if it is a prime number.
If it is not prime the divisor will be returned instead.

@author: Eric Silva
'''

import math, time

#Change this value to whatever value you want to test for prime.
#testValue = 65027
#testValue = 155188329701
testValue = 99194853094755497
#testValue = 10888869450418352160768000001
print 'Testing %d...' % testValue

def determineIsPrime(testPrime):
    if testPrime % 2 == 0:
        return 'Divisible by 2'
    if testPrime % 3 == 0:
        return 'Divisible by 3'
    testNum = 7
    testLimit = testPrime
    while testLimit >= testNum:
        if testPrime % testNum == 0:
           return 'Divisible by %d' % testNum
        testLimit = testPrime/testNum

        testNum = testNum + 2

    return '%d is prime!' % testPrime

def determineIsPrime2(testPrime):
    if testPrime % 2 == 0:
        return 'Divisible by 2'
    if testPrime % 3 == 0:
        return 'Divisible by 3'
    testNum = 5
    sqrt = math.sqrt(testPrime)
    while testNum <= sqrt:
        if testPrime % testNum == 0:
           return 'Divisible by %d' % testNum

        testNum = testNum + 2

    return '%d is prime!' % testPrime

def determineIsPrime3(testPrime):
    if testPrime % 2 == 0:
        return 'Divisible by 2'
    if testPrime % 3 == 0:
        return 'Divisible by 3'
    testNum = 7
    sqrt = math.sqrt(testPrime)
    while ((6 * testNum) + 1 <= sqrt) or ((6 * testNum) - 1 <= sqrt):
        if testPrime % testNum == 0:
           return 'Divisible by %d' % testNum

        testNum = testNum + 2

    return '%d is prime!' % testPrime

startTime = time.time()
result = determineIsPrime(testValue)
endTime = time.time()

print result
print '1. Calculation took %f s\n' % (endTime - startTime)

startTime = time.time()
result = determineIsPrime2(testValue)
endTime = time.time()

print result
print '2. Calculation took %f s\n' % (endTime - startTime)

startTime = time.time()
result = determineIsPrime3(testValue)
endTime = time.time()

print result
print '3. Calculation took %f s\n' % (endTime - startTime)

Results:

Testing 99194853094755497...
99194853094755497 is prime!
1. Calculation took 202.609000 s

99194853094755497 is prime!
2. Calculation took 114.813000 s

99194853094755497 is prime!
3. Calculation took 28.781000 s

Determining if a Number is Prime

December 10th, 2009 Eric Silva No comments

While working on some caching settings, I had a need to know if a number is prime. I wrote this little Python script which will tell you if the number defined in the script is indeed a prime.

'''
Checks the specified value to determine if it is a prime number.
If it is not prime the divisor will be returned instead.

@author: Eric Silva
'''

#Change this value to whatever value you want to test for prime.
testValue = 3011

def determineIsPrime(testPrime):
    if testPrime % 2 == 0:
        return 'Divisible by 2'
    testNum = 3
    testLimit = testPrime
    while testLimit >= testNum:
        if testPrime % testNum == 0:
           return 'Divisible by %d' % testNum
        testLimit = testPrime/testNum

        testNum = testNum + 2

    return '%d is prime!' % testPrime

result = determineIsPrime(testValue)

print result

Peer Code Review: An Agile Process

December 10th, 2009 Eric Silva No comments

Smart Bear Software recently released a white paper discussing the misconception that peer code review is a hindrance to Agile development methodologies.  For anyone who regularly performs peer code reviews, would like to start performing them, or thinks they are an obstacle when it comes to Agile development should read this paper.

The paper talks about the history of code review, how code review aligns with Agile, types of lightweight code review, and techniques to perform optimized code reviews.  Some of the key statements that I took away from the paper are this:

  • Code review allows for “continuous attention to technical excellence and good design”.  These enhances the agility of the code, the developers working on the code, and the overall Agile process.
  • Code review “promotes sustainable development”.  The “bus number” concept is one that I use consistently when promoting peer code review in my own workspace and corporate environment.  The white paper explains it simply, “How many team members would have to get struck by a bus before no one was left that understood the code?  If the bus number for a section of the code is less than two, then that’s a problem.”
  • The final take-away comes from the Agile Manifesto Principles itself, “The best architectures, requirements, and design emerge from self-organizing teams.”  The same is true of quality peer code review; “If peer code review is mandated by someone outside the team, its chance of success decreases.  If team members do not want code review to succeed, it will fail.”
    I use Code Collaborator.  I think it’s the best tool out there for performing peer code review, especially with distributed development teams.  I think peer code review allows developers to become better developers through the visibility and social nature of performing the review itself.  My opinions may be a bit biased, based upon my experiences with Smart Bear Software, but, in fairness, this white paper discusses the enormous benefits of peer code review without discussing specific products. It only discusses the principals and observed benefits, and is in no way a sales pitch to buy their product.

GWT 2.0 Released!

December 9th, 2009 Eric Silva No comments

I just saw on my RSS that GWT 2.0 has been released.  Gonna go play now. Bye.

Converting a Visual Studio 2005 Web Application Project to a Visual Studio 2008 Web Application Project

December 6th, 2009 Eric Silva No comments

For anyone looking to upgrade their VS 2005 Web Application project to VS 2008, I found good walkthrough provided by Microsoft here.

Visual Studio 2008 and Visio for Enterprise Architects

December 3rd, 2009 Eric Silva 7 comments

I have started working on a new project in .NET and the Problem Domain (PD) was modeled in Visio UML.  Fantastic.  Now I wanted to forward engineer the UML into C# classes to begin development, but wait, I can’t.  I only have Visio 2007 Professional, and the forward engineering features are only available in the Visio for Enterprise Architects version.  Okay, not a problem, I’ll go download it from MSDN.

After starting the installation, I got an error message, “You must first install one of the qualified Visual Studio editions”.  What the hell?  Visual Studio 2008 isn’t good enough?  I sure as hell don’t want to install another, older version Visual Studio just so I can install Visio for EA.

After poking around, I came across this registry trick.  Visio for Enterprise Architects is looking for the existence of the following key:

HKLM\Software\Microsoft\VisualStudio\8.0\Setup\VS\VSTD\

Within this key should be the String value “ProductDir”.  The text value for ProductDir can be anything other than a null value.

Once you add this key to your registry, the Visio for Enterprise Architects installer will work as hoped.

Google Chrome Frame

November 25th, 2009 Eric Silva No comments

I installed Google Chrome Frame about a month ago, and I am very impressed with how responsive and quick Internet Explorer is with JavaScript intensive web pages now.  If you use a lot of JavaScript intensive websites, e.g., Facebook, Gmail, Google Maps, Google Calendar, etc., you will notice a significant improvement in performance when using IE with the Chome plug-in.

I was also interested to find out that the new Google Wave application only works with IE if you have the plug-in installed.

The plug-in works in Internet Explorer 6, 7, and 8, and requires you to have Windows XP, Vista, or Windows 7.