Wednesday, November 21, 2007

Tile OS X Terminal window to Finder with AppleScript

I updated my AppleScript that will tile the terminal window nicely below the frontmost finder window.

For some reason setting the Terminal window bounds is very buggy. I resorted to using the deprecated methods {position and size} and have to loop it three times to ensure that it positions correctly.

I tied this to command-; in my app launcher, QuickSilver



tell application "Finder"
--make new Finder window
activate
if not (exists window index 1) then
make new Finder window
end if
set {x1, y1, x2, y2} to bounds of window index 1
end tell

tell application "Terminal"
activate

if (count of windows) is 0 then
tell application "Terminal" to activate
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
end if

-- For some reason it can take up to 3 times for Terminal to be properly adjusted
set L to {1, 2, 3}
repeat with xxx in L
set {xx1, yy1, xx2, yy2} to bounds of window index 1
set position of window index 1 to {x1, y1 + {yy2 - yy1}}
set size of window index 1 to {x2 - x1, y2 - y1}
end repeat

end tell

Saturday, November 3, 2007

OS X Leopard - Improved Terminal (almost perfect)

Sorry iTerm, my long friend. I may be giving you up now that Leopard's terminal has tabs and an over-all improved UI. Terminal starts up fast and is pretty dang stable. One gripe - "Why can't I name the tabs!" Ugh, this seems so obvious a feature. Yeah, you can use AppleScript to set the name of the overall window but that isn't all that helpful when you have multiple tabs open. Come on, this has got to be a two-day feature (one to implement, one to test).

Weird thing is that somewhere in Apple-land there is a small team that is responsible for maintaining Terminal. And they are programmers so you'd think that they'd make the shell as nice as possible and think of these features on their own.

Anyway, bravo for the improvements that did make it in but a small "boo" for my couple of wasted hours trying to figure out how to ActionScript custom tab names. Oh Apple, when you fall short, it really hurts.

OS X Leopard - Incompatibilities

I'm an early-upgrader to Leopard. After a week I'm digging it quite a bit. This is my small list of bitches in a otherwise pretty nice OS. I think a lot of the inconsistencies with the Java-based programs has to do with Apple's new GUI rendering. I don't know much more about it but I'm guessing that it broke (well damaged) a lot of SWT and Swing widgets. Mostly I'm posting these in case somebody else is running into the same issues:

  • Intellij - Works but now the UI is unstable. Switching tabs don't always work and a few other creeks and groans. I use this every day so it is a bit painful.

  • Popcorn 3 - Bought this last week for my iPhone so I could scale down movies and move them over. This won't even start up. Funny thing is Popcorn 1 still works fine. Roxio has a message on their site that a fix is forthcoming.

  • TextMate - Breaking Input Managers was an issue from day one. There is a work-around for the "edit in textmate" bug that works well but it is slightly kludgy.


I don't entirely blame Apple, seems to me if you are a maker of Apple software you'd do some work with the pre-releases to ensure your software still works with the upgrade.

Java 6 on OS X

Hey Apple, please be more vocal with your plans for Java. I love my mac and want to continue using it as my main development machine. I don't doubt good things are happening - just would like more (good) buzz out there. I've seen many Java developers be converted to mac (me included - now I own three macs and an iPhone) and then go on to spread the good word.

13949712720901ForOSX

Monday, September 17, 2007

Groovy XML Markup Builder CDATA block

This is one of those things that turns out to be easy but takes a bit of time to figure out.

Using Groovy's builders there are times where you want more control, like when you want to pump out a CDATA block. This turns out to be quite straight forward:

out = new StringWriter()
xml = new groovy.xml.MarkupBuilder(out);
xml.test_xml {
normal("Some text in a normal element")
data('') {
out.write("<![CDATA[Hello]]>")
}
}
println out

Basically since we have reference to the writer we can dump out anything directly to it. I'm sure this works with most builders.

The resulting xml block should look like:

<test_xml>
<normal>Some text in a normal element</normal>
<data><![CDATA[Hello]]></data>
</test_xml>


UPDATE EDIT:

Please note that MarkupBuilder also gives you the special field 'mkp' to do similar actions.

For example:

def out = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(out)

xml.test_xml {
normal("Some text in a normal element")
xml.mkp.yieldUnescaped('<data><![CDATA[Hello]]></data>')
}

println out


Also works and probably is more-correct.

Sunday, August 26, 2007

OS X Finder iTerm applescript window tiling

If you are an OS X developer no doubt you use iTerm. If you haven't set up your unix environment to synchronize between Finder and OS X you should. There are a number of examples but here is the ones I used since I'm a zsh fan:

iTerm Terminal Customization

Now the other thing I wanted was to have a quick-key combination to display both the front finder and iTerm windows and position them nicely tiled. This way I could work in an IDE but have my bare-bones development windows appear in a snap. Here is my applescript code:


tell application "Finder"
--make new Finder window
activate
if not (exists window index 1) then
make new Finder window
end if
set {x1, y1, x2, y2} to bounds of window index 1
end tell

tell application "iTerm"
activate
if not (exists window index 1) then
set myterm to (make new terminal)
tell myterm
launch session "Default Session"
end tell
end if

set {xx1, yy1, xx2, yy2} to bounds of window index 1
set bounds of window index 1 to {x1, y2, x2, y2 + (yy2 - yy1)}
activate
end tell


Store the script in your home/Library/Scripts folder and from there you can assign a hot-key.

Why don't I just use PathFinder? Well I own it and used it quite a bit but there are things that just make me angry about it that hopefully they'll fix.


1. It is a resource hog
2. It doesn't allow me to simply type a path into an input box (actually almost all OS X Finder clones have this issue). OS X developers seem to like the mouse and drilling down.
3. The UI can be quite busy and some things that should be simple (finding files in the current directory or below for example are a pain in the butt.


Anyway, now that I'm doing quite a bit of development on my mac I'm using QuickSilver, Finder, and iTerm with applescript to glue them together. Simple.

What inspired me to dump PathFinder? This great podcast that showed how much hidden value is in the limited basic Finder application and how a little knowledge can make it much better suited to your workflow.

Living with the Finder

Thursday, August 2, 2007

Tomat 5.5 Spring 2.0 log4j debugging

Had to dig for this one a bit to get spring framework debug to show up.

Set up logging in Tomcat 5.5


Note: CATALINA_HOME is probably the environment variable pointing to your tomcat installation.
* put log4j and commons-logging in ${CATALINA_HOME}/common/lib
* put a basic log4j.properties file in ${CATALINA_HOME}/common/classes

for example:

log4j.rootLogger=DEBUG, stdout
log4j.logger.org.apache=INFO

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

Note: I turned org.apache to INFO to ensure I don't get a few miles of digester logging
Note: Of course you could add file appenders if you wish - I'm keeping this minimal

Make sure commons-logging.jar is not in your WEB-INF/lib directory of your web-app. That seemed to be the thing that switched off the availability for Spring debug logging. I'm sure there are other ways to get this going but this worked for me.

Thursday, July 12, 2007

TextMate ZSH ZShell

TextMate has a bias toward bash and doesn't pick up your environment's path if you are using zsh.

See Shell Commands: Search Path for details

I added the following to my .zshrc file to create/update a .profile file whenever I log into zsh

ECHO PATH=$PATH > .profile


Now bundles like Subversion work as they should :-)

TextMate Wiki

Quick note to advertise an awesome TextMate bundle:

Plain Text Wiki

Basically it turns TextMate into a plain text file wiki engine. You can save your notes, serial numbers, whatever in a folder and hyperlink between them.

Benefits are:
- Completely open format - just plain text files
- Spotlight searchable

This is exactly what I needed.

Sunday, April 22, 2007

Z-Shell command completing

Alright, I admit it. I've been using the z-shell for a few years now and have never really dug in beyond what you'd find in bash. So it finally dawned on me to figure out how to create my own completions.

Granted, I didn't dig in too far beyond the basics but still it has been extremely handy.

For any commonly used command line util get the list of commands:
grails help

Then make a line in your .zshrc (found in your home directory) that maps those commands to the grails keyword:


compctl -k '(bootstrap bug-report clean compile console create-app create-controller create-domain-class create-job create-plugin create-script create-service create-tag-lib create-test-suite generate-all generate-controller generate-views generate-webtest help init install-dojo install-plugin install-templates package package-plugin package-plugins run-app run-webtest shell test-app upgrade war)' grails


compctl can do much more powerful tricks but for me just mapping the given array of words is great.

Now I can simply type 'grails c[tab]' to list all the commands that start with 'c'

I've also made a similar array for Subversion:

compctl -k '(add blame cat checkout cleanup commit copy delete diff export help import info list log merge mkdir move propdel propedit propget proplist propset resolved revert status switch update)' svn

The best part is if you type 'svn help [tab]' you'll still get the list of keywords so you can easily get detailed help.

Good stuff.

There is a bash plugin available to help program similar completions.

Monday, April 9, 2007

Currently Reading: Groovy In Action

I'm about 75% through "Groovy In Action" and would recommend it as a great introduction to the power of scripting for Java developers. I'd also recommend reading "Programming Ruby" for a comparison to a similar, modern scripting language.

Main Thoughts:


In the corporate world I've been finding it a small uphill battle convincing talented Java developers that they should take scripting seriously. It will take a word-of-mouth campaign and probably better tools to get them on board. I suppose another way would be if someone came out with a "killer-app" written in Groovy.

Less code is less code (Or less code is like gold?)


Less code means less code to maintain and also less code to read through to understand what is going on. A main benefit of a higher level language is that the code you type has more to do with the objective and less to do with the boilerplate required to achieve that objective.

Put more succinctly: Groovy code is about an order of magnitude less than Java code performing a comparable function.

Less dependencies on Frameworks and Patterns


Getting proficient in a scripting language like Groovy will take less time than it takes to learn a new Java framework (JSF, Struts, Hibernate, etc) and may replace the need for one.

A good example of this is database persistence. In Java we have JDBC, EJB3, Hibernate, iBatis, Spring JDBC, etc. Some of these are pretty heavy frameworks that attempt to make database usage easier and less error-prone.

When you see an example of database usage from Groovy it really makes you wonder about why you'd want to jump to an external framework. The argument has often been that heavier frameworks like Hibernate take a lot of the work off your shoulders and reduce the amount of code needed. I've found that the size of the code just gets transferred to XML configuration and setup.

It seems very possible that with a language like Groovy you could have much of this power and security within the language itself, or at least with a much lighter support library.

If you could write your DAOs in Groovy I know Spring JDBC would be reduced down to a handful of technology-specific helper classes. Much of this API is resource handling, which is taken care of natively by Groovy's closures.

Design Patterns
A few years back at a conference, Dave Thomas (Pragmatic Programmers) made the comment that design patterns are a work around for deficiencies in a given programming language. It took some thinking for this idea to click but it makes so much sense. What is a design pattern other than simply boilerplate code for a concept not natively supported by the language you are using?

AOP/Visitor Pattern: Required in Java due to the lack of meta-programming that would allow interception of method calls.
Adaptor Pattern: Required in Java due to the lack of "duck typing" or "mix-ins"
Facade Pattern: Required in Java to hide usage complexity of heavy frameworks/APIs.

Side note: If you've done any tech hiring lately you'll notice how many resumes come in with "design patterns" on the technology list.

Monday, April 2, 2007

Great intro article to the power of LISP

I found this great blog entry on why any Java programmer should be interested in learning some LISP. I'm still a LISP newb but even the little I know makes understanding how to best use scripting languages like Ruby and Groovy better.

Anyway, take some time to read this:
The Nature of Lisp

Friday, March 16, 2007

Groovy on OS X and MacPorts

Update Note: This is still the case with Groovy 1.6.x and Leopard the same fix still works.

The default MacPorts install of groovy didn't work out of the box. When I ran groovy from the prompt I got a nasty java.lang.SecurityException.

The problem ended up being that my Java CLASSPATH included classes.jar.

The solution ended up clearing out the CLASSPATH system variable altogether before invoking groovy. You can do this with a command line switch but the easiest way to do it was to edit the startGroovy file (found in the /bin directory of the groovy installation). A fast way to find this is using Spotlight

I simply added CLASSPATH= as the first thing in the file:

...
##
## $Revision: 4298 $
## $Date: 2006-12-04 02:39:45 +0100 (Mo, 04 Dez 2006) $
##

CLASSPATH=

PROGNAME=`basename "$0"`
...

Groovy Process Piping: Follow-up

Thanks to some comments from those a bit more savvy on this topic I'm suggesting the following method from charlesanderson:

p=['sh','-c','ls -l | sort'].execute()
println p.text

This is mostly cross-platform (assuming CygWin) and is nicely succinct.

I like this method over using the Groovy Groosh module as suggested by Yuri Schimke if only because it doesn't require an import:

def f = gsh.find('.', '-name', '*.java', '-ls');
f.pipeTo(lines);

As always there are many ways to skin the same cat.

Monday, March 12, 2007

Groovy Process Piping

I was playing around with using Groovy as a shell scripting language. While convenient, I found that shelling out to my trusted unix commands is many times faster for file operations than handling them within Groovy.

Creating and executing a process is trivial in groovy:

p = "ls -l".execute()
println p.text
But using pipes or redirection is not allowed:

p = "ls -l | sort".execute()
println p.text
For some reason it took me awhile to understand the java.lang.Process well enough to come up with this script, which contains a helper class for piping one Unix shell command into another.
def class Pipe {
private Process p

def Pipe(cmd) {
p = cmd.execute()
p.out.close()
}

def to(cmd) {
def p2 = cmd.execute()
p2.out << p.in
p2.out.close()
p = p2
this
}

def text() {
p.text
}
}

def output = new File('output.txt')
output.delete()

output << new Pipe("grep -h -e '^.* ERROR .*' input.txt")
.to("sort")
.to("tail -n50").text()


Note 1: The Process object is in the standard JDK so with a bit of alteration, one could create the Pipe utility in straight-up Java. But in regular Java I wonder how often one needs to run a shell command?

Note 2: If you are on Windows and are using Cygwin you'll need to be aware that the Windows "sort" command clobbers the Unix version and is hardly as robust. You may need to hard code which sort you want to use: "C:\\cygwin\\bin\\sort"

Thursday, January 25, 2007

Posting from Flickr


DSC_0121.JPG
Originally uploaded by devilelephant.
Testing the ability to blog my Flickr photos directly.

Flickr

This is a test post from flickr, a fancy photo sharing thing.

Back to Blogger

Moved my blog back to Blogger after experimenting with Typo, the Ruby on Rails blogger, on my own server: http://devilelephant.com.

I'll have to work on getting my view back to what it should be.

Lessons Learned:
  • Managing your own blog software is a big job.
  • Typo is hard to upgrade - at least it was for me
  • The version I was using allowed too many spam messages and talkback links
  • Fun AJAX interface is not worth the spam and maintenance.
  • Kept me from wanting to publish.

Dealing with Crap Code

Who doesn’t? Only those who are lucky enough to work on small dedicated teams.

I think it would be an interesting article to face the fact that crap code and low-level developers are a staple of corporate development. The leaders in our industry whine about this a lot but it is a fact of life and it won’t improve due to economic forces. As long as a corporation can pick up a six-pack of developers from Walmart that will work for 50% of what a talented and experienced developer would work for there will be crap code. It doesn’t matter that statistics show the project will take 10x as long or that maintenance costs will be through the roof. I’ve yet to meet a corporation where those concerns matter to anybody above IT manager (if that). Long term maintenance is usually not a planning concern and is part of some other department's budget anyway.

A sad truth is that the majority of crap code performs similar to quality code so many times it is hard to argue for a decent refactoring. I’d be interested in figuring out how to use existing frameworks to better localize the crap code to small crap islands (crapplets?). Early n-tier development did this by letting the so-called junior developers do the 5000-line-per-JSP programming while the experienced developers worked on the server. This was great until people started expecting more usable web interfaces. Now the UI might have as much JavaScript and AJAX magic as the business side of the application.

I have yet to see a software process or framework that tackles this issue realistically. They have “roles” but they don’t specify degrees of capability. When 80% of your team thinks threading concerns are when your clothes start to wear out how do you best place them within a project?

I think it would be fascinating to see a software framework that specifically breaks apart concerns so that you can use your A, B, C, and D developers to the best of their abilities while minimizing the impact of the crap code that the less capable will crank out.

I don’t want to hear any feedback about how you should just get rid of the junior programmers. They have families, they have to eat, and realistically, if downsized, the more expensive developers will get the boot first. Our industry has to figure out how to best utilize the majority of its C and D-level developers. We can’t make them all project-managers.

Commenting fields/methods

Less comments but more content.

Along with methods, if a field has to be commented, I’ve found it is usually because it is misnamed.

// Counter that keeps track of login attempts private int counter;

Would be better expressed as: private int loginAttemptCounter;

It is funny how this simple DRY concept can keep you on the high road of development. Also important is spell-checking and grammar. While a comment shouldn’t be an English thesis paper it should be professionally written. If English is not your strong point have a buddy on the team review your code for errors. Even the best authors lean heavily on editors (the human proof-reading kind not the text-editing kind).

EZ Project Management

No matter what the chosen process is or how tasks are broken up, every major project I’ve been on has been time blocked:

  1. Management decides the new system should be finished by date X.
  2. The analysts and project manager divide the amount of tasks by the number of iterations available before date X.
  3. For each iteration-task-set you divide it evenly amongst your available developers.
  4. You ask your developers for an estimation on their tasks for each iteration.
  5. They respond by taking the number of assigned tasks, divided by the hours available in the iteration.
  6. Some magic happens (scope reduction, overtime, bring in experts to clean up, implement tasks with TODO: statements)
  7. The project finishes on date X.

I’ve developed this project management process on a single MS excel sheet. I’m making it available for a cost of $1000 per seat with an annual $10K maintenance charge. Of course I can offer consulting services to customize it to your corporation at a $300/hour bill rate. Do you like curly fonts?

Corporate Code Smells

Mostly venting here, how many of these have you seen?

Corporate Code smells:
  1. WSAD - There is a reason it isn’t called WHAPPY
  2. Only javadoc is the eclipse message telling you how to change your default javadoc templates
  3. No interfaces at all or an interface for every class
  4. junit.jar exists in the lib directory but no tests to be found
    • I got this unit test that calls the production database
  5. optimized imports? code formatting? we don’t have time in the project plan for that
  6. Sure we use Spring, but we wrap it with our own classes so we can switch it out later
    • We’ve cached the bean instance returned by Spring to speed things up
  7. We added hibernate because we knew we were going to hit the database
  8. Synchronization? Threads? the container takes care of that
  9. Guys, look at this framework I cranked out last night!
  10. With annotations I was able to expose all my classes as web services, you know, for reuse!

Notes on getting Ruby on Rails working on my Powerbook 15

Used darwin ports to install ruby and rb-rubygems

I’m using z-shell so I needed to edit the

'~/Library/init/zsh/environment'

file to make sure that

'/opt/local/bin'

was the first folder on my path. Then I simply did a

gem install rake
gem install rails

This sounds simple but it only took 5 hours of digging to get right!

Come on Apple. If you are going to include Ruby then make sure you install it correctly.

Some kids just got to touch that hot stove

One of my project’s biggest challenges right now is working around the limitations of a validation “framework”, which is both too restrictive and configuration-heavy. It’s almost always a mistake to attempt to write any kind of “framework” in-house but maybe it is good for this client to get a few of these mistakes under their belts. Some lessons have to be learned the hard way no matter how many books, articles, blogs are written on software development anti-patterns.

The Dumbening

But then I started to notice something about the Java projects I was involved in: weak teams and weak programmers will go to great lengths to do the wrong thing

Glenn Vanderburg
No Fluff Just Stuff - 2006 Anthology
Buried Treasure Chapter

Has the pragmatic press put out a bad book yet?

I like this quote. It reflects a lot of my experience with teams lately. I’d put a different twist on it.

Here the author was talking about if the “weakest programmers” on the team could be trusted with more powerful language features. An argument may go along the lines of “we need static typing to protect developers from themselves…”.

A trend I’ve seen in large corporate development is to invest more in smart tools than smart developers. The problem is that smart tools keep developers dumb.

I’ve been on teams with very green developers and have had two experiences:

Simple Tools: Sophisticated Development

The first is that we set up an ant build that has simple targets. Basically, made it easy for the developer to use whatever IDE they wanted. I just gave them the golden rule that the ant build was king. I also set it up so that server processes kicked off in a console window. Taught them how to use the unix “tail” command on the network servers.

It turned out that even the weakest developers felt very comfortable with this setup. If something didn’t build they could figure out quickly if it was a code issue, a missing library, or something else. I saw them grow very comfortable with the command line and with Java development in general. In short trusting the developers made them smarter and made the team stronger. I’d see signs of this when the developers would be able to solve complicated problems independently. Because they felt close to the metal they felt comfortable trying to dig out and solve issues themselves. Try a little AOP? Sure.

The funny thing is that the code was also better. Smaller classes, less code doing more, better javadoc. Pretty much everything that would make a team leader proud.

Smart Tools

The second experience I’ve had is with a company that felt that tools were the solution. Builds, deploys, servers, were all launched from within an IDE. A right-click generated a web-service, or EJB, or JavaBean. Separate teams were responsible for configuration and deployment and each had their own tools. One example was a tool that would try to inspect the .project file from an Eclipse project setup and use that to generate a build script to be used only by the deployment team. Want to take a guess at how much productivity that sucked away? Here is a hint: The solution was to have the development team check in all generated artifacts so the deploy team’s tool would be easier to use.

The tools were smart but kept the developers from knowing what was going on behind the scenes. These developers would be able to crank out 100’s of lines of code but would stumble at the basics. They’d be asking why their workstation has red flags while mine didn’t. They’d be lost as to why a deploy didn’t work. Javadoc would be limited to the crap the IDE spewed out. 100s of TODO statements littered the production code.

In short, smart tools made for dumb programmers.

Why is this? One theory I have is that programmers want to program - not draw pictures or use someone else’s software. If we wanted fancy tools we would be word processors, graphic artists, CAD professionals, etc.

If fancy tools were the solution to good software development then industry would have solved the issue long ago. Yes, I love my IDEs. I love code completion when I can get it. Even debuggers, which I feel is the ultimate “smart tool that keeps programmers dumb” come in useful. I’m just saying that the focus should be on what the developers feel would make them most productive.

Invest in people first, not tools

It is rare to find the developer who does not have potential. Most want to do the best job they can. Most want to learn new things and be considered competent by the team. At the same time, a company that treats its developers like a disposable and replaceable commodity will get developers who live up to that perception. The U.S. military can take 18-year-olds and train them to use million dollar equipment with confidence. That institution knows that setting the bar high will create a team that works well together and as individuals.

The Dumbening

As always The Simposon’s has a relevant episode. In this one Lisa lives down to her expectations when she thinks she has a Simpson-gene that dooms her to slowly become an idiot.

ze environment is ze file to configure ze shell

Bad french aside, here are my notes for configuring the z-shell to find the Darwin Ports version of programs first.

~/Library/init/zsh

This path points to where the “environment” is set.

Edit this file and make sure that your /opt/local/bin folder comes first

prependPath PATH /usr/local/sbin
prependPath PATH /usr/local/bin
prependPath PATH ~/bin/powerpc-apple-darwin
prependPath PATH ~/bin
prependPath PATH /opt/local/bin

appendPath PATH /usr/local/mysql/bin
appendPath PATH /usr/bin
appendPath PATH /bin
appendPath PATH /usr/sbin
appendPath PATH /sbino
appendPath PATH /Developer/Tools

Note that prependPath and appendPath are functions defined earlier in the “environment” file.

Darwin Ports Notes

Warning: These notes are mostly plagarized from some other website but I wanted them on mine for easy lookup.,

sudo port selfupdate                   
sudo port upgrade
sudo port install vile
port search 'vile'

The search facility uses standard regular expression syntax, so you can also do much more complex searches. Additional Steps: fetch, configure, build, destroot, install

Once the port has been installed, you may want to delete all the intermediate files that DarwinPorts has created while building the port. To do this, simply use the clean option:

port clean vile
port clean --all vile

Getting Information about a Port

port info vim
port search '.+'
port list
port installed
port installed
port outdated
port contents vile

Variants and Dependencies

Before you install a port, you may want to check what variations of that port are available to use. Variants provide additional configuration options for a port. To see what variations a port has, use the variants option: port variants vile

You also may want to see what dependencies a port has. You can use the deps option to check: port deps vile

If you want to find out which ports depends on a port you have installed, use: port dependents gettext

For more information you should look at the port manpage by entering: man port. The portindex command

Most of the time you won’t need to use this command as it is used to build the index of all the available ports, but sometimes the index you have is out of date or innacurate for some reason. When this occurs you will get an error message like ‘port search failed: expected integer but got “PortIndex”’. You can fix problem by moving to the dports directory (/Users/mike/darwinports/dports in our examples) and executing: portindex. This will go through all the available ports in the dport directory and build an index file called PortIndex.

Removing ports

Ports are removed using the port command described above, simply execute the command: sudo port uninstall vile

Upgrading ports

You can check if a port is outdated with the following command: port outdated gnome

To check if you have any outdated ports: port outdated

To upgrade a port execute: sudo port upgrade gnome

This will deactivate the old version and install the new, and also install the newer versions of the dependencies of the port.

If you would like to upgrade the port, but not the dependencies of the port, you can: sudo port -n upgrade gnome

To upgrade all installed ports simply do: sudo port upgrade installed

If you dont like that upgrade just deactivates the old version of the port, you can get it to uninstall the old version by using the -u option: sudo port -u upgrade gnome

Using force

While upgrading you can run into cases when you have to use force (-f). This is especially true if you are upgrading a port that wants to install a file that another port allready has installed, or if you use the -u option to upgrade (and uninstall) a port that could be installed as a dependency. Allways remember to use the -f option with caution.

Rails, Plural table names - lame

O.K. I’ve been working with Rails for several weeks now and am loving the ease for cranking out websites. Good stuff.

But…

(and that’s a big butt)

For some insane reason the developers of Rails decided plural table names was a convention worth promoting by having it as the default.

Most experienced DBAs will tell you that the name of a table should describe what one record in that table would represent. Who would recommend plural table names? Developers seem to like plural names because they equate database tables with Collections (think java.util.List). I guess I come from a more traditional background where I think of tables as set theory.

Naming guidelines aside there is another reason not to go down this route. Rails then has to be smart enough to parse the plurals for almost every noun in the English dictionary.

What short-circuited in the developer’s brains? They develop this slick environment and then slap in some hacky idea. I think it is only useful to add to the perceived “wow” factor that the Rails enthusiasts get at conferences. yee-ha!

Luckily there is a work-around to make Rails work just as nicely with singular table names.

Thanks to this post on justinram.wordpress.com for providing the answer on how to switch off this really stupid bug in rails:

Add the following to the bottom of your config/environment.rb file:

# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false

Design by convention

Final thing that “really grinds my gears” (Family Guy) is that it goes against the grain of “design by convention” that is Rails major contribution to the web space. Why would all my controllers, views, helpers, etc be called Employee and my table name be Employees?

Why would my code refer to “Sheep” and my table name be “Sheep”. Well, maybe that wasn’t a good example.

I guess in the end there is a difference between convention magic: “Hey, all my MVC objects are named the same so I don’t have to configure them - that makes sense” and spooky “under the covers” magic “Hey I magically figured out that your Alumnus class should be related to the Alumni table”

It is a good thing that Rails has that call to the Dictionary.com web service to get the plural name for every model.

Be a Better Blogger

This week I’ve stumbled upon a great web link that I’d like to share with all of us who feel compelled to pound out a few paragraphs a day on a favorite topic:

50 Writing Tips

Note: if the above link no longer works see my notes at the bottom of this article.

I haven’t traversed the entire website yet but the “Writing / Editing” section is excellent. I clicked through the “Fifty Writing Tools” articles and they are relevant and entertaining. Entertaining? Yes. Author Roy Peter Clark deserves respect for not only presenting his writing tips clearly but also for sampling across great literature as examples.

Dammit Jim, I’m a tech blogger not a Journalism major!

Make no bones about it, if you blog or comment frequently in a public space you are a journalist. You don’t need the degree hanging on your office wall but you should try to write like you do. Have you ever stopped reading an article because it was confusing, had spelling or grammar mistakes, or maybe the author’s laptop was missing all of the punctuation keys? We are judged both on our ideas and how well we express them.

Here’s an exercise: The next time you are reading your favorite board, take a critical look at how the posters express themselves. Which posts do you think give off a sense of authority? Which ones make the authors look juvenile or just plain ignorant?

How do you want to be perceived?

I’m by no means a successful blogger. I get maybe a half-a-person a day to come read my stuff but I do post a lot on other boards. The main purpose for this blog is to practice writing and expressing myself so that if the opportunity comes up to write professionally, I’ll be practiced and in shape. Regardless, I’m trying to write like I have a large base of constant readers.

Of Course! Head slap.

Ok, here is the bad news. These 50 writing tools are supposedly going to be taken down soon because the author has a book deal and the publisher doesn’t want the content online. I’ve used FlashGot to download all of them locally so I have a chance to go through them. Anyway, I think the site is worth a look and as long as Google stores cached versions.

Shh, don’t tell the publisher but…

Alright, have you heard of the WayBack Machine. Why, no Mr. Peabody. Well it is an internet archiving site that basically makes snapshots of the internet how it was throughout time. Want to see what the Google home page looked like eight years ago?

Well if they do take the 50 links off the main site you may be able to still find them somewhere else.

Tech Resumes

Recently, I’ve been helping out interviewing prospective candidates for Java design and architect level positions. You wouldn’t believe how much writing affects your chances of getting an interview. Or maybe I should say you wouldn’t believe how fast your resume gets dragged to the trash can if it is not clear and effective.

Before you apply for your next position get someone you trust to take a critical look at your resume. Even if you have to shell out money to have someone prepare a professional resume for you it is well worth it. Don’t make the mistake of letting your resume get in the way of your next job. This is especially good advice if English is not your primary language.

Does it matter?

I think there is the perception out there that for tech resumes all you need is a pile of acronyms and a list of companies you worked for. This isn’t true.

Find a standard template that suits your experience

There are many good books out there on effective resume writing. There are great examples on the web. You should try to find a template that emphasizes your abilities and can be easily tailored for each position you are applying for.

If you are new to the job market, you may want to move your education section before your experiences. If you’ve been on the job for awhile you may want to trim down the descriptions of jobs you held 10 years ago.

Tech resume essentials

  • No spelling, grammar, or punctuation errors. Period.

    Now that the tech-job market is bouncing back you may be able to get jobs with your sloppy resume. All that means is that you are missing out on better positions.

  • Tech grid.

    Yes, you need the dumb little table that tells the HR-bots all of the acronyms that you have under your belt. AJAX, HTML, JAVA, CSS,…. Try to make this grid clear and easy to read for the humans. Try not to include every last technology you’ve come across. Only list the technologies where you consider yourself proficient. Don’t put Ant down if all you’ve done is run an ant build someone else wrote. Don’t put Tomcat down if all you’ve done is write a JSP that someone else delivered to a production box. You don’t have to be an expert on everything you put in your tech grid but you should be experienced to the point where you wouldn’t need training or mentoring on that technology.

    Believe me, if you have a technology on your grid that the client cares about you will be asked about it. If you then say you’ve only had a whiff of experience with it you will not be taken seriously. Remember that a job interview is all about establishing trust. If the client doesn’t trust you they won’t hire you.

  • Describe how you directly affected the projects you worked on.

    One recent resume I read spent 4 pages advertising for the companies the guy worked at. Entries like: “Ford Motor Company is a large automotive concern whose annual earnings exceed xxx….” Your resume is supposed to be an advertisement for you - not a brochure for others. If anything list the company and the projects you worked on in one or two sentences. What the interviewer wants to know is what did you do at that position? Try to think of specific highlights. How did you positively affect the project’s outcome?

  • Use metrics Use specific metrics if you can get them.

Compare:

  • Team leader
  • Increased performance on data tier
  • Authored many articles on software process improvement
  • Helped bring in the project under budget.

to:

  • Lead team of 20 developers
  • Helped increase performance on data tier 150%
  • Wrote over 30 articles on company Wiki regarding software process improvement
  • Helped my team bring in the project $100K under budget.