Archive

Archive for the ‘Programming’ Category

Syncing Gmail Contacts Birthdays and Events with Google Calendar

May 10th, 2011 No comments

I am horrible with other people’s important dates, e.g., birthdays, anniversaries, date you got your appendix removed, etc.

I just realized I should put all that info into my Gmail Contacts, and then it will appear on my Google Calendar automatically. Oh wait… It doesn’t show up. Damn. Why doesn’t it work?

Turns out, this obviously valued feature is not turned on by default, but it is available.  To get your contacts’ birthdays and other events to show up, simply perform the following in Google Calendar:

Click Settings (the little gear icon in the upper right corner of the screen), then Calendars (link just under the "Calendar Settings" tab), then the Browse Interesting Calendars (lower right) link, then More (under the heading), and finally Subscribe next to the Contacts’ birthdays and events.

Fantastic!  Now you, and more importantly, I should have no reason to forget to remind our friends and family a Happy Birthday.

Code Review Does Not Have to Suck

February 24th, 2011 No comments

I have been using this saying for the last 6 years, “Code Review Does Not Have to Suck”.  I just saw today that SmartBear, who makes the wonderful CodeCollaborator peer code review tool, which I also use, released a quick 3-minute video explaining this.

Peer code review is a critical milestone step in any good development process; especially with distributed teams.  CodeCollaborator, Crucible, and Kiln are all great tools for facilitating peer code review without having to go through all the headache of gathering files, scheduling meetings, pissing off your co-workers, etc.

Check out the video.  It’s worth the 3-minutes.

How to Design a Good API and Why It Matters

February 4th, 2011 No comments

I am starting to design a new API for an application that will need to integrate with other applications.

Before doing so, I always make it a point to re-watch and re-read this presentation given by Joshua Bloch from Google.  Joshua does a fantastic job going over the DOs and DON’Ts of good API design.

 

Joshua Bloch Presentation on API Design

 

You can also download the slides here.

To root, or not to root

December 6th, 2010 No comments

To root, or not to root: that is the question:

Whether ’tis nobler in the mind to suffer

The crap of HTC is not outrageous fortune,

Or to take arms against a sea of useless apps,

And by opposing end them? To root, to be free;

No more; and by freedom to say we end

The heart-ache and the thousand worthless apps

That cannot be uninstalled, ‘tis unavailable option

Devoutly to be wish’d. To root, to be free:

To freedom, perchance to control: ay, there’s the rub:

For that freedom of rooting what mistakes may come

When we have removed the controls in place that make us mortal,

Must give us pause; there’s the respect

That makes calamity of superuser privs;

For who would bear the segfaults and core dumps of time,

The oppressor’s wrong, the geek’s contumely,

The prags of despised garbage-ware, the sudo’s delay,

The insolence of Footprints and the Peep

That patient merit of the unworthy takes,

When he himself might his rm –rf make

With a bare sudo? Who would fardels bear?

To grunt and swear under a weary life,

But that the dread of something after root,

The undiscover’d access from whose bourn

No n00b returns, puzzles the will

And makes us rather bear those typos we have

Than make other that we know not of?

Thus conscience does make cowards of us all;

And thus the native hue of resolution

Is sicklied o’er with the pale cast of thought,

And enterprises of great pith and moment

With this regard their currents turn awry,

And lose the stability of my phone. – root you now!

The fair Incredible! Fantastic, in thy orisons

Be all my sudo remember’d.

(from Hamlet 3/1 – slightly altered by Eric Silva)

Simple Calendar Control for Web Application

March 19th, 2010 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 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 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 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 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 No comments

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