Archive

Author Archive

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.

What I Learned Today While Reading Wikipedia

March 31st, 2010 Eric Silva No comments

I learned that Fryderyk Chopin, the composer, had his heart removed before burial because he had a fear of being buried alive.

I also learned that Thousand Island dressing did not originate in the Thousand Islands area of the St. Lawrence river. It originated in New Orleans before 1900.

Categories: General, Observations Tags:

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>

Funniest Thing on the Twitter All Day

January 13th, 2010 Eric Silva 3 comments

A conversation between @cwgabriel from Penny Arcade and @pvponline from PVP.

Brought a tear to my eye after @wilw got involved.

gabriel_pvp_tweets

Categories: Humor, InterWebNet Tags: , ,

New Cub Scout Belt Loops and Pins

January 13th, 2010 Eric Silva No comments

The Boy Scout Trail has posted the requirements for the twelve new Cub Scout Belt Loops and Sports/Academic Pins on their website.

The new Sports loops and pins are:

The new Academic loops and pins are:

Good Ol’ Healthcare

January 12th, 2010 Eric Silva No comments

Now, let me get this straight…..We are going to pass a health care plan written by a committee whose chairman says he doesn’t understand it, passed by a Congress that hasn’t read it but exempts themselves from it, to be signed by a president that also hasn’t read it and who smokes, with funding administered by a treasury chief who didn’t pay his taxes…all to be overseen by a surgeon general who is obese, and financed by a country that’s nearly broke. What could possibly go wrong?

~Anonymous

From today’s "The Gartman Letter"

Silverado Vineyards

January 1st, 2010 Eric Silva No comments

Type: Chardonnay
Year: 2007
Location: Napa County, California
Link: silveradovineyards.com
Rating: 8 out of 10
Opinion: Very good chardonnay comprised of fruit from vineyards in the Napa Valley into Carneros. Minimal oak flavor as to not overpower the fruit. Hints of golden apple and pear aroma with green apple, lemon zest, and honeysuckle flavors provide a refreshing finish.

Categories: Wine Tags:

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