Breaking Bad Habits – Stop Using The Mouse!

Posted January 25th, 2010. Filed under Code

Lately I’ve been really trying to avoid using the mouse while coding.  You may not realize it but it’s a huge distraction to:

  1. Stop typing
  2. Find your mouse
  3. Find your cursor
  4. Hunt for the icon you need
  5. Click the icon
  6. Release mouse
  7. Resume typing

That is a lot of work! And you probably do that quite a bit during a typical day.

Lately I’ve been using Mousefeed (http://www.mousefeed.com/) to help me break this habit.  Mousefeed is an Eclipse plugin which will encourage you to use the keyboard.  If you click on a menu item with the mouse it will display in a small popup the appropriate keyboard shortcut:

Mousefeed popup showing keyboard shortcut

Mousefeed popup showing keyboard shortcut

Unfortunately the author has stopped development on the plugin. The site mentions it works in Eclipse 3.3 but I downloaded the Mousefeed jar file and dropped it into my Eclipse ‘dropins’ folder (C:\eclipse\dropins\com.mousefeed_1.0.0.jar) and it seems to work fine with Eclipse 3.5 and the latest CFEclipse.

By using the keyboard I can eliminate the steps above required by the mouse and dramitically speed up my coding!

FYI – I’ll be presenting on more time saving tips like this at cf.Objective and CFUnited!

Quix – A Super Bookmarklet

Posted January 19th, 2010. Filed under Code

I’ve been tinkering around with Quix, a ’super’ bookmarklet that can easily replace several Firefox addins and overall reduce your dependency on your mouse.

Installing Quix is a simple matter of visiting the Quix site and dragging the bookmarklet to your toolbar. Since I didn’t want to click on the bookmarklet to activate I used Firefox’s keyword to it:

Firefox Keyword Shortcut

Firefox Keyword Shortcut

So now I can do a ALT+D to take me to the address bar and type qq+Enter to pull up the Quix dialog.

Quix Dialog

Quix Dialog

There are quite a few commands and shortcuts available on the Quix site (enter ‘Help’ in the Quix dialog to get a complete list).

While I have a few shortcuts like this setup in Find and Run Robot (my launcher) having this bookmarklet running inside the browser adds a lot more power to what can be done.

I’ll probably only use a small percentage of these but even then I can already see it being a timesaver.

Getting Ant Build Updates Via Growl

Posted November 25th, 2009. Filed under Code

I have a few build scripts that take some time to run and I hate staring at the Eclipse console to see how things are progressing.  I've heard of Growl before and today decided to see if I could make this work to popup notices during my build.

Growl is originally for the Mac but there is a port for Windows aptly named Growl For Windows.  Download and install.  I also added the install path to my Windows PATH so I can run the growlnotify script from the command line.

Once you've done this you can verify it's working by popping open a DOS box and typing:

C:> growlnotify "THIS IS A TEST"

And you should get a popup:

Growl Popup

Growl Popup

Next you'll need to grab a few things so you can interact with Growl from Ant...

Download growlbuildlistener

An Ant BuildListener that displays notifications via Growl/JGrowl

Follow the installation instructions (in the wiki section).

This simply involves downloading two files that contain jar files - you'll need:

  • the growllistener jar  (growllistener.jar)
  • the JGrowl jar (binaryblizzard.jar) (from JGrowl)

Drop those in your Ant lib folder, and in Eclipse make sure those jars are added to your classpath (Ant Home Entries).

Next you will need to add a listener so Ant can use the GrowlBuildListener.  Run the following line from a command prompt:

set ANT_ARGS=-listener net.slimeslurp.growl.GrowlListener

Next I had to add a new taskdef line to my build script:

<taskdef name="growl" classname="net.slimeslurp.growl.GrowlEcho"/>

And now you should be able to drop in a new GrowlEcho task in your build file wherever you want a popup to occur.

<growl message="Kicking off build of ${projectname}"/>

Now when I kick off my scripts I see something like this:

Growl Example

Growl Example

I did this mainly for fun but I can see some applicable uses for this. Growl also looks neat because it appears you can configure it to push notices over the network. So in theory I could setup everyone on my team with Growl and when someone kicked off a build we could all be notified.

If you come up with a creative use for this please let me know in the comments!

Introduction To Cron

Posted November 5th, 2009. Filed under Code

In my previous entry Cron For Windows I discussed using cron as a better replacement for Windows Scheduled Task.  Today we will look at how easy cron is to configure and look at a few examples that I have configured.

This tuturial will assume you have downloaded nnCron Lite and have it configured according to the online documentation. If you are on Mac or Linux you should already have cron available.  nnCron's format is the same as Unix so everything here should work anywhere you have cron available.

I installed nnCron to C:\Program Files\cron.  Within that directory you should have a file called cron.tab. This is the main file used for starting and stopping your applications. While it's not a GUI interface like Scheduled Tasks the configuration file is very easy to understand.  Open cron.tab with Notepad or your favorite text editor.

The syntax is very simple...

# Classic crontab format
# Minutes Hours Days Months WeekDays Command

Some things to note: comments are preceeded by a "#" sign. Empty lines, leading spaces and tabs are ignored.  nnCron also allows you to skip wrapping filenames and paths in quotations, and there is no need to call the command interpreter. Please see the nnCron documentation for more information.

For our first example we will run a batch file every morning to refresh my ColdFusion services to make sure everything is up and running when I get into the office.  So assuming I have a batch file (cf8_restart.cmd) configured to stop and restart my ColdFusion services I can do the following:

# restart web/cf services every morning
0 7 * * 1-5 D:\_documents\scripts\batch\cf8_restart.cmd

The time format breaks down like:

0 = this is minutes - we want to run our script at the top of the hour
7 = equals hours - and we want to kick off our script at 7am (24hr format)
* = no value for days and months
1-5 = weekdays - we want this to only run M-F

For another example I run a backup utility to backup our JIRA instance:

# run JIRA backup procedure every day at 12am and 12pm
0 0,12 * * * C:\Program Files\2BrightSparks\SyncBack\SyncBack.exe -m "JIRA Backup"

0 = this is minutes again - we want to run our script at the top of the hour
0,12 = equals hours - in this case I backup every 12 hours - at midnight and noon
* = no value for days, months and weekdays - this script runs everyday

These examples are very simple but the cron format can do very complicated schedules.

Here are a few examples taken from the nnCron documentation:

  • 59 23 31 12 5  -  One minute  before the end of year if the last day of the year is Friday
  • 45 17 7 6 *   -  Every  year, on June 7th at 17:45
  • 0 9 1-7 * 1   -  First Monday of each month, at 9 a.m.
  • 0 0 1 * * - At midnight, on the first day of each month

If you are using Windows Scheduled task and looking for more flexibility and reliability in your scheduled tasks I would encourage you to check out cron.

Autohotkey + Dropbox = The Perfect Combo

Posted August 28th, 2009. Filed under Code

So you've downloaded Autohotkey and are writing all kinds of automation scripts to help you out during the day at work.  But what about home?  You can setup routines to help you out there as well. I have several setup for email signatures, shortcuts for my home PC, etc.

To make juggling your Autohotkey scripts easier take a look at Dropbox.  I've been keeping more and more stuff in Dropbox lately. It serves as a simple version control system, and best of all it's truly cross platform so I can dual-boot my laptop into Windows or Linux and access the same files!

With Autohotkey you can drop your .ahk file in Dropbox and access your shortcuts from any computer (with Autohotkey installed of course).

Autohotkey Week: Day 5 – Conclusion

Posted August 21st, 2009. Filed under Code

So hopefully this week I've provided you with a few ideas to get you started with Autohotkey!   Here are a few more links to help you...

Autohotkey

Similar tools:

More resources:

If YOU create a useful Autohotkey script please let me know.  I am planning on a opening a section on my wiki to store and share scripts!

Autohotkey Week: Day 4 – Launching Apps and GUI

Posted August 21st, 2009. Filed under Code

So last session we looked at using the clipboard.  Today we'll explore using Autohotkey to launch applications and build a very simple GUI.

I'm always amazed at the effort people go through to launch applications.  Desktops full of icons, long Start menus, quick launch bars full of icons.  All those take an amazing amount of time to process through, find your app and click.

With Autohotkey we can reduce all that searching down to one simple keystroke.  I start CFBuilder many times throughout the day by simply clicking F6:

;F6------------------------------
SC040::
Run C:\eclipse-bolt\eclipse.exe -vm "C:\Program Files\Java\jre6\bin\javaw" vmargs -Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m
return

This is really straightforward - SC040:: translates to the F6 key on my Microsoft Natural keyboard.  I then simply execute a standard Run command and point it to the Eclipse executable with the appropriate startup flags appended.

Now I click F6 and CFBuilder starts. No hunting, searching, digging through menus, etc.  I have a series of 3-4 programs I use very frequently all assigned to hot keys for easy startup.

Autohotkey is far more than text replacement and application shortcuts.  You can also build complete GUIs with Autohotkey.  I'll direct you to the documentation online if you want to pursue this but I will show you a very simple example.

At work I've been trying to keep better track of my time throughout the day and stumbled across this Autohotkey script to ask for user input every XX minutes and write it out to a text file:

SetTimer, #a,900000
#a::
; Show the Input Box to the user.
inputbox, text, Diary,,,300,100

; Format the time-stamp.
FormatTime, CurrentDateTime,, MM/dd/yyyy h:mmtt  ; It will look like 9/1/2005 3:53 PM

; Write this data to the diary.txt file.
fileappend %CurrentDateTime% | %text%`n, c:\diary.txt
return

Here we're assigning our script to WIN+A, and using the SetTimer function to click that every 900000 milliseconds.  When you click WIN+A (or the timer clicks it) an input dialog will be displayed where you can enter text.  I'm also writing a time/date string to include as well.  This data is then appended to a defined text file - in this case diary.txt.

So I end up with a .txt file containing a list of things I do throughout day:

08/20/2009 2:05PM | Complete weekly report
08/20/2009 2:21PM | Surf Reddit
08/20/2009 2:35PM | Get Diet Coke
08/20/2009 2:50PM | Work on Bug-123

The Autohotkey site has some much more complex GUI examples I'd encourage you to check out if this interests you.

Next post we'll wrap this up, and I will provide some links to similar tools and other resources that will help you get started with Autohotkey.

Autohotkey Week: Day 3 – Clipboard

Posted August 19th, 2009. Filed under Code

So now we have Autohotkey installed and have learned to do some basic text manipulation.  Next we will explore how we can use Autohotkey to manipulate existing text by using the clipboard.

Remember in our previous example how we used Autohotkey to go UP and LEFT to position our cursor?  Since Autohotkey can press keys for us, there is no reason why it can't press CTRL+C for us!  Here is one I use all the time - the classic CFDUMP:

F1::
clipboard =
send ^c
clipwait, 1
If ErrorLevel = 0
{
clipboard = <!--- TODO - for debugging --->`n<cfdump var="#%clipboard%#" top=5 label="My Dump">`n<cfabort>
send ^v
}
return

We are getting a bit more complicated but I think you should be able to follow along.  I've got this setup to fire when I hit F1 (you of course can select any key). BUT I first have to select something or there will be nothing to copy!  So select something, hit F1 and it does a send ^c which is the Autohotkey syntax for 'press CTRL+C'.  It waits a sec, checks for errors and then writes out a new string to the clipboard and pops in the text we first selected  %clipboard% and outputs a nice string with our variable wrapped up:

<!--- TODO - for debugging --->
<cfdump var="#myVariable#" top=5 label="My Dump">
<cfabort>

Here is another great use. I'm working on an old project with no queryparams.  Ugh!  So I wrote this shortcut to grab a variable from a query, strip out the single quotes (if they exist) and wrap it with a variable.  I've got a few of these defined so I can output a varchar or numeric depending on my shortcut.

!q::
clipboard =
send ^c
clipwait, 1
If ErrorLevel = 0
StringReplace, clipboard, clipboard, ', , All
{
clipboard = <cfqueryparam value="%clipboard%" cfsqltype="cf_sql_varchar">
send ^v
}
return

I have several more of these setup to do UCase(), Upper(), Trim(), etc. All by simply modifying the clipboard.  Hopefully by now you are seeing the power of Autohotkey!  Tomorrow we'll explore how you can use it to fire off programs.