Wednesday, October 10, 2012

SMB/UNC Path Translator Bookmarklet

I needed a quick way to translate a UNIX-style SMB path to a Windows-style UNC path and vice versa.

For example:
From: smb://my-server/path/to/file
To: \\my-server\path\to\file
OR
From: \\my-server\path\to\file
To: smb://my-server/path/to/file
So I created the bookmarklet below. To use it, drag the link below to your bookmark bar. Then click it, enter a path, and click OK. It will return a translated path that you can then copy and paste.

Path Translator

Thursday, September 27, 2012

Using KDiff3 on Mac with Subversion

I love TortoiseSVN. So I was quite disappointed when I moved from a PC to a Mac and was no longer able to use it. There are several alternatives for Mac, but the one function that I haven't been able to easily find is a way to do a graphical diff between my working copy and the current version of the file. So I wrote a Perl script to do it for me. To get this to work, there were a few prerequisites:

- Install KDiff3
- Save this file in a directory that is part of the PATH
- Create a temp directory in my home directory

Then I just open a Terminal window to the directory where my working copy resides and issue the command svndiff filename. I'm sure it's not perfect but it does the trick for me.

By the way, if you have questions or suggestions or just find this useful, please drop me a comment. Thanks.

#!/usr/bin/perl
###############################################################################
#     Program : svndiff
#     Written : 09/27/2012
#      Author : carmond
# Description : Opens KDiff3 to compare working copy of file with 
#               current version in Subversion (ver 1.6) repository
#      Syntax : svndiff <filename>
#    Modified :
###############################################################################

($file) = @ARGV;

if (!file) {
 print "Syntax: svndiff <filename>\n";
 edit;
}

if (!(-e $file)) {
 print "$file does not exist\n";
 exit;
}

if ($file =~ m|/|) {
 $file =~ m|(.+)/(.+)|;
 $path = $1;
 $file = $2;
}
else {
 $path = `pwd`;
 chomp $path;
}

$svn_entries = "$path/.svn/entries";
if (!(-e $svn_entries)) {
 print "Could not find $svn_entries\n";
 exit;
}

open (IN, $svn_entries);
for ($i = 1; $i <= 5; $i++) {
 $repository = <IN>;
 chomp $repository;
}
close (IN);

$temp_file = "$ENV{'HOME'}/temp/$file";
unlink $temp_file if $temp_file;

$cmd = "svn export $repository/$file $temp_file";
`$cmd`;

if (!(-e $temp_file)) {
 print "Error getting file from repository\n";
 exit;
}

$cmd = "/Applications/kdiff3.app/Contents/MacOS/kdiff3 $temp_file $path/$file";
`$cmd &`;

Monday, July 30, 2012

Exporting the Windows Task Manager Process List

I'm trying to make a case for a new computer at work. One of the things I want to show (besides the incredibly slow boot time) is that I am maxing out my RAM. To do that, I wanted to get a list of tasks running that I could import into a spreadsheet to figure out how how much memory my day-to-day applications consume (Outlook, Eclipse, SQL Developer, Firefox, etc.) versus all of those background processes that I don't even know what they do. Here's how I did it:
Start -> Run -> cmd
tasklist > tasklist.txt
Then open tasklist.txt in Excel as a fixed-width file and go to work.

Wednesday, April 25, 2012

Change Folder Name Using mod_rewrite

For anybody out there that may be needing to do a simple directory name replacement using mod_rewrite:
RewriteEngine On
RewriteRule ^(.+)\/abc\/(.+)$ $1\/xyz\/$2
So http://blah.com/abc/image.jpg becomes http://blah.com/xyz/image.jpg

Tuesday, April 10, 2012

Outlook Messages with Word Attachments

I hate getting emails at work with Word attachments. It just takes too long to open the attachment especially when the content could have been easily included in the message. Let's make a pact that any time we have a meeting agenda, job posting, etc. that has minimal formatting, we will copy and paste it into the message instead. Outlook is smart enough to know what to do with it (most of the time) and it will save everybody some time.

Friday, April 6, 2012

jQuery Newbie Mistake

I just made a jQuery newbie mistake but the worst part about it was that the code still worked in all browsers...except IE7. So I didn't even know that I had done it wrong until one of the developers discovered it.

Here is what I tried to do:

$("blah").each(function(index) {
this.id = newID;
this.name = newID;
});
Here is what I should have done:

$("blah").each(function(index) {
$(this).attr("id", newID);
$(this).attr("name", newID);
});
Once I changed my code to the latter, it starting working correctly in IE7.

Thursday, April 5, 2012

Using Color to Prevent Accidents

We are all familiar with the use of color for keeping our attention: stop lights, construction signs, warning labels, etc. To try to minimize the number of mistakes I make, I color code my terminal sessions.

On Windows I use PuTTY for creating a secure shell session into the servers that I need to access. One of the options it to set a background color for the session.


For production I set the background color to red and for development I set the background to green. The red color is a warning to myself: "You are on the production server. Don't screw things up!" Then for each server I log into, I save a session, and create a shortcut to it. In PuTTY the syntax is putty.exe -load "session_name". For example:

c:\putty.exe -load "dev"
c:\putty.exe -load "prod"

Color can't fix my stupid mistakes, but it has helped me to stay focused.

On the topic of color, I just read this article on Wired.com about how red keeps you focused and blue makes you more creative. Next step is to use Firefox Personas to color code my Firefox windows: red for coding and blue for designing.

Friday, March 9, 2012

Quickly Filing Email in Outlook

I used to keep a ton of folders in Outlook. Any time I would file away an email, I would have to decide which folder it went in, scroll to that folder, and drop it in. But what if it belonged to more than one folder?

I finally found a great solution in Taglocity. Now whenever I get an email, I just hit Ctrl-T, tag it with one more tags, then file it into a folder called "Archive". Then if I need to find something, I just go to my Archive folder and filter by one or more tags.

By the way, I am not being paid to endorse any of these products (although I wish I were.) When I found a time-saving utility or process, I just like to share it with others.

Thursday, March 8, 2012

Fast Application Access on Windows XP

It used to be that anytime somebody saw my laptop screen at work, they would joke about the number of icons in my Quick Launch toolbar. I had 2 rows of icons followed by a row of shortcuts. Although it was organized (Office products, developer tools, Internet apps, graphics, etc.), it did seem a bit overwhelming. So after purchasing my first Mac recently, I decided to look for an equivalent app to the Finder feature of OS X.

I discovered this gem: SlickRun

It sits just about my system tray and using various "Magic Words", I can start up any of those apps that I had bookmarked before. And with auto-complete goodness, it's rather fast. I have now eliminated my Quick Launch toolbar altogether.

Now supposedly having a lot of icons doesn't slow down your computer, but I have noticed an increase in performance since I got rid of the Quick Launch bar. I think having shortcuts to a bunch of networked drives was causing a performance hit.

Best of all it's a free app. They just ask you to shop Amazon using the provided link.

Monday, March 5, 2012

My Essential Firefox Plug-Ins

The more I do Web development, the more I wonder how I ever built any applications without Firefox and its many plug-ins. Here are my essentials:

Firebug
I'm sure I'm not taking advantage of all the great features of this plug-in. As I do more and more jQuery development, the JavaScript console has become a necessity. Also great for debugging AJAX. The inspector is great for working CSS issues.

MeasureIt
Simply drag out a rectangle out the screen and you can instantly get the dimensions of any object on the screen.

ColorZilla
Found a color on the screen that you need? Use the dropper to find it, then right-click the picker to copy the color code in various formats (hex, rgb, hsl).

Live HTTP headers
This plug-in will show you all of the HTTP headers during a page load. I once used this tool to figure out that the reason a particular page was broken was because a key element being included was blocked by the company firewall.

Web Developer
Drop down menu includes: Disable, Cookies, CSS, Forms, Images, Information, Outline, Resize, Tools, and more. Let's you do all sorts of manipulation for debugging Web development.

What about you? What are your "must haves"?

Friday, February 17, 2012

Only Writing One Set of Form Validation Code

Form validation is an important part of Web development. It provides the user feedback when they make a mistake or omit information. And it protects the integrity of the application data.

In the past I have written 2 sets of form validation: 1 client-side and 1 server-side. Server side form validation is essential. Client-side validation wasn't always necessary in the past, but provided a better user experience. However, as more and more dynamic client-side content is being generated, it is becoming more essential and users are not as tolerant of "press the back button to correct your errors".

So instead of writing 2 sets of validation code (one in JavaScript and one in ColdFusion), I now levy the power of AJAX to only write one set of form validation code.

The way it works is to submit the form data to the server first via AJAX. The server side code then generates any and all error messages based on the form data. If there are errors, it sends the error messages back to the browser as JSON array. If there are no errors, then it submits the form to the client.

So what if the user has JavaScript disabled (does anybody do that anymore?) or somehow JavaScript is bypassed? The same error messages are then presented back to the user regardless. Here's some sample code to make more sense of it.

First our HTML form:

Next we add the JavaScript to handle the AJAX check and form submission:

And finally the client-side code:

Tuesday, February 7, 2012

Paperless Billing

One of my goals for 2012 has been to get better organized and get a better grip on my finances. And one way that I've done that is to switch to paperless billing for some of my accounts. I have tried this in the past but it never worked because I would lose the bill in my inbox. But I have come up with a solution that seems to work better this time.


The first thing I did was to download Mozilla Thunderbird onto my desktop and put it in my Startup folder. Then I created a new email called statements@my-domain-name-dot-com and configured Thunderbird to check it. Next I created a second email called bills@my-domain-name-dot-com that forwards all incoming mail to the statements account as well as the email account I check on my iPhone. That way when I get a bill, I get a reminder on my phone AND on my desktop computer at home. Lastly, I used the filtering capabilities of Thunderbird to move the various bills and statements into folders for each company I do business with.
 
Blogger Templates