2010/05/7
At work, we’re using mercurial for our source control. As we’ve released code to production we’ve needed to branch our repository to support what’s in production as well as ongoing development.
By default, grails uses ~/.grails as the working directory. If you’re doing branchy development, you can run into problems with this if you’ve got plugins installed in one branch that aren’t in the other. Having a unique directory per branch prevents you from having to run grails clean all the time.
Here’s a quick shell script that changes the grails working directory to have the branch name as a suffix if your source is contained in a mercurial repository (ex: the default branch would be ~/.grails_default and the 1.0 branch would be ~/.grails_1.0). If your application is not in a repo, it just uses the regular ~/.grails directory.
#!/bin/sh
HG_BRANCH=`hg branch 2>/dev/null`
GRAILS_SCRIPT=$GRAILS_HOME/bin/grails
if [ $HG_BRANCH ]; then
GRAILS_WORK_DIR=`echo ~`/.grails_$HG_BRANCH
echo "** grails working directory: $GRAILS_WORK_DIR"
$GRAILS_SCRIPT -Dgrails.work.dir=$GRAILS_WORK_DIR $@
else
echo "** default grails working directory"
$GRAILS_SCRIPT $@
fi
Just save this script as “grails” and put it in your PATH before the $GRAILS_HOME/bin directory (also make sure that you’ve defined $GRAILS_HOME). I have a ~/bin directory that’s the first thing in my PATH.
If you use the grails-debug command, you can repeat these steps for that, just change GRAILS_SCRIPT to $GRAILS_HOME/bin/grails-debug.
This same technique could easily be modified to be used for other source control systems such as git or subversion.
2009/11/3
A while ago I blogged about my grails testing aliases and how much time they save me.
I’ve made some enhancements to them in the interim that have made them even easier to use.
The most important alias is gtaf, which is short for “grails test-app” for failed tests.
It will search through your test output directory and look for any tests that failed. If it finds any, it will rerun only those tests. Otherwise, it will rerun all tests. That makes it easy to just use gtaf all the time. If any tests fail, it will open them up using Console.app.
If you’re not on OSX, or would like to use something else to view the failed test logs, just modify the testlog alias to do something different.
Read the rest of this article »
2009/11/1
I’ve had problems since installing snow leopard with sharing my printer with my wife’s macbook pro.
Whenever she’d try to print, the job would say “On Hold: Authentication Required”. After some fiddling around I found a solution:
- Go into System Preferences and go to the Print & Fax panel.
- Right click on the printer and choose “Reset Printing System…”. This will remove all of your printers.
- Hit the “+” and add the printer back, it should now be reset and have fixed whatever was fubar before.
- Click on the “Sharing Preferences” button (or go to the “Sharing” System Preference panel)
- Make sure that “Printer Sharing” is checked and that your printer’s name is also checked and that “Everyone” is set to “Can Print”
- On the remote machine you want to remove the printer and add it back in through the System Preferences Print & Fax panel
(This is on 10.6.1, not sure if this works in 10.6.0 (where I first had the problem), you should update to the latest).
After doing all that, I was able to print from my remote computers without any problems or any issues around authentication.
2009/06/18
I’m currently working at a startup that’s small enough that we don’t have a dedicated DBA and I’ve been doing a lot of mysql maintenance work recently. I wanted a quick dashboard for which commands were currently running and how long they’ve been running for. Sort of like top but for mysql.
Combining the unix “watch” command with the mysql “show processlist” command gives me what I’m looking for. A quick, self-updating status of the current state of the database.
watch -n 5 --differences "mysql -u username -psekrit -e 'show processlist'"
Shows something like this:
Every 5.0s: mysql -n 5 -u username -psekrit -e 'show processlist' Thu Jun 18 05:25:14 2009
Id User Host db Command Time State Info
3141 admin localhost mydb Query 34978 freeing items SELECT id, type, active, email FROM user WHERE email
3146 admin localhost mydb Sleep 0 NULL
24876 root localhost NULL Query 0 NULL show processlist
Where the “time” column is the number of seconds the query has been running, and Info holds the actual query (you can use “show full processlist” to see the full query).
Watch is a nice little linux util that runs a command every “n” seconds (it defaults to 2 seconds). If you use the –differences switch, it will highlight the differences between one update and another. I use watch for all kinds of monitoring activities, such as watching a directory to see a file grow in size as it gets transfered.
Here’s a quick shell function that you can add to your .bashrc/.bash_profile/.zshrc to use on arbitrary hosts:
function mysqltop() {
MYSQL_OPTS=$@
watch -n 5 --differences "mysql $MYSQL_OPTS -e 'show processlist'"
}
Then just pass in any creds/host info you need like a normal mysql command:
mysqltop -u ted -psekrit1 -h example.com -P 3307
If you’re on linux, you probably already have “watch” installed. If you’re on OSX, you probably don’t, but you can get it quickly through macports. Install macports, make sure “port” is in your path and run:
There is also a command called mytop that you can get which looks like the same thing, but prints out the processlist details with some nicer formatting and a little extra information. It’s in macports, but it has a number of dependencies including mysql so if you didn’t install mysql through macports, you might want to stick with what I have above or get it another way.
(EDIT: updated with bash function)
2009/05/26
On my MacBook pro, I’ve got 4 removable hard drives (2 physical in 2 partitions each) and a JungleDisk mount.
I found it painful to manually eject each individual drive in the finder so I threw together this quick AppleScript to eject all the disks.
tell application "Finder"
eject (every disk)
end tell
Just open up /Applications/AppleScript/ScriptEditor.app and paste that in. Then choose “Save As” and pick “Application”. That will compile the script and create a .app file that you can click on to run, or you can put it in your path and execute it there.
I think the same kind of script could be created with the command line “diskutil eject” command, but this seemed cleaner as I wasn’t able to come up with a generic way to figure out which disks were “ejectable” and which weren’t. AppleScript is able to figure that all out for you.
2009/05/13
Over the years, I’ve had a number of requests for me to share my zshrc file with friends and coworkers. In the past, I’ve normally trimmed out the sensitive parts by hand and then e-mailed the most useful stuff. I’ve always intended to make this an easier process and I’ve finally gotten around to it.
I’ve created a new bitbucket repository to hold my shared zshrc configuration. You can get it for yourself by cloning the repository:
cd ~
hg clone http://bitbucket.org/tednaleid/shared-zshrc/
Read the rest of this article »
2009/03/16
I ran into an issue today when trying to use curl to post something to an https endpoint on one of my Grails applications. Apparently, recent macports versions of curl don’t have full ssl support enabled by default (I have no idea why, this seems like one of the basic use cases of curl).
This is what I was seeing:
% curl -k https://www.google.com
curl: (1) Protocol https not supported or disabled in libcurl
After a bunch of fiddling around looking at the Portfile (located at /opt/local/var/macports/sources/rsync.macports.org/release/ports/net/curl/Portfile), I saw that there was something called a variant that seemed to talk about ssl support.
I’d never needed to install a variant of a port before, but it’s actually pretty easy to do. Just add a “+” with the variant name at the end of the install command.
sudo port install curl +ssl
Read the rest of this article »
2009/03/8
I work on a couple of different grails projects that use a variety of versions of groovy and grails. I’ve thrown together a quick shell script that makes it easy to create a new alias to switch between different versions depending on what project you’re working with.
function switchGrails() {
echo "Switching to groovy version: $1"
echo "Switching to grails version: $2"
sudo rm /usr/local/{groovy,grails}
sudo ln -s /usr/local/$1 /usr/local/groovy
sudo ln -s /usr/local/$2 /usr/local/grails
echo "Done!"
ls -latr /usr/local/{groovy,grails}
}
alias g104='switchGrails "groovy-1.5.7" "grails-1.0.4"'
alias g11rc2='switchGrails "groovy-1.6.0" "grails-1.1-RC2"'
You can create your own aliases like the ones above to switch to the groovy/grails combinations that you happen to be working with.
Just stick the code above in your .profile/.bashrc/.zshrc file and restart your shell to make the aliases available.
This function assumes that you’ve got you’ve got groovy and grails installed in your /usr/local directory and that you use a symlink at /usr/local/groovy that $GROOVY_HOME is pointed to and /usr/local/grails that $GRAILS_HOME is pointed to. If those assumptions aren’t correct for you, you’ll have to tweak the script.
It also uses “sudo” as it assumes that /usr/local is owned by root and not by your logged in user. If you’ve chowned the directory to yourself, you can remove the sudo (and the need to enter your password).
Now it’s easy for me to switch between different projects by just typing the appropriate alias:
pollux% g104
Switching to groovy version: groovy-1.5.7
Switching to grails version: grails-1.0.4
Done!
lrwxr-xr-x 1 root wheel 23 Mar 8 19:55 /usr/local/groovy -> /usr/local/groovy-1.5.7
lrwxr-xr-x 1 root wheel 23 Mar 8 19:55 /usr/local/grails -> /usr/local/grails-1.0.4
pollux% g11rc2
Switching to groovy version: groovy-1.6.0
Switching to grails version: grails-1.1-RC2
Done!
lrwxr-xr-x 1 root wheel 23 Mar 8 19:56 /usr/local/groovy -> /usr/local/groovy-1.6.0
lrwxr-xr-x 1 root wheel 25 Mar 8 19:56 /usr/local/grails -> /usr/local/grails-1.1-RC2
2008/12/9
In my current project, I’ve been doing a lot of tweaking of the default grails scaffolding templates. Because of this, I need to run the new uber generate-all command quite a bit to recreate things.
The one problem with this script is that if the files already exist, a prompt will come up after ~10 seconds or so (after the grails environment bootstraps) asking you if you want to Overwrite everything:
grails generate-all "*"
...
~10 seconds pass
...
Generating views for domain class Baz ...
File /foobar/grails-app/views/baz/list.gsp already exists. Overwrite?y,n,a
This was a bit of a pain as I’d often kick the script off, get distracted and then come back to the shell with that prompt still waiting for me to tell it what to do. I’d rather just start working with my shiny new scaffolding.
The easy solution to this is simply to pipe the answer you want into the grails command:
echo "a" | grails generate-all "*"
Doing that will pipe the “a” into the grails command so that when the prompt finally comes up, it knows that it can continue regenerating all of my scaffolding.
It seems simple enough after I figured it out, but I thought it could save some other people time when they’re hacking around with templates and know they want to regenerate all of them.
Read the rest of this article »
2008/11/25
In his book, The Productive Programmer, Neal Ford talks about using shims or jigs to help productivity. Jigs and shims are quickly created little snippets of code that automate repetitive tasks or make them easy enough that they’re worth doing. They’re little tools that help make your job easier and let you avoid using brute force to solve all of your problems.
My home directory has a bin folder in it that’s continually getting new jigs added to it, and my zshrc file is an ever-expanding list of quick shell functions.
Recently, I’ve been doing a lot more work with Mercurial as the team that I’m on switched from Subversion a couple of months ago on our Grails project. The initial transition was a little difficult for some people, but I think just about everyone is pretty happy with the transition now that we’ve made it.
Something that has helped everyone get comfortable with more complex Distributed Version Control System like Mercurial has been the distribution of shims and jigs amongst the team. I thought these tips might be useful to others as well.
Read the rest of this article »