Grails datePicker magic

Been working much more on the frontend side of web development lately, but found a nice trick in Grails that seemed good to throw out there.

Maybe this is documented somewhere and I just always missed it. I knew the datePicker tag in gsp’s worked nicely for binding to domainClass objects through dataBinding, but didn’t know it could also be used as a super convenient way to get a date object in a controller. This is in grails 2.3 line BTW.

Example:

My use case was a simple report that needed to be run for a given month.

in the gsp:

	
		
		
	

Sweet. That is a really quick way to generate the HTML I want.

Now, here is the really slick part I didn’t know about. In the controller I can access the params.report object and it will be a Date!

def report() {
	def forwardMonth = params.report.toCalendar()
	forwardMonth.roll(Calendar.MONTH, 1)
	forwardMonth  = forwardMonth.getTime()
	flash.message = "${params.report.toString()} -- ${forwardMonth.toString()}"
	...

Flattr this!

trying out zsh and oh-my-zsh on ubuntu

Using the terminal all day I figured I should ‘sharpen the axe’ a bit. I have played around with configuring bash, but mostly I don’t know what I am doing in that .bashrc file. I tried a few ways to get the terminal tab titles to be something shorter so they would actually be usefull for example. no luck there. Tried customizing the prompt to include git status if I was in a git repo. Got that one to sorta work, but screwed up some other stuff in the process…

Noticed zsh is a alternative that has a vocal fan base, thought I’d see if it lived up to the hype. I’ve been using it for a couple months now but so far I think I like it, and I am sure I have only scratched the surface of what it is capable of. which was probably true of bash as well…

Anyway, installing isn’t to hard, but not very obvious so I thought I would document how I did it to see if anyone wanted to chime in on how I did it wrong, or possibly would find it usefull.

First install zsh package from Software Centere or using apt-get install zsh
Use bash terminal one last time to install oh-my-zsh (https://github.com/robbyrussell/oh-my-zsh)
open edit>profile preferences in the terminal menu
on the second tab ‘Title and Command’ check ‘Run custom command instead of my shell’ and enter ‘zsh’ in the text input.
Restart Terminal
Viola!

edit .zshrc as desired.

RESTfullness and web-frameworks

After working on an offline mobile web app that integrated with a Grails backend, and after that being prompted to explore options for a new some green field development, which lead me to re-evalutate things like REST to NoSQL to MVC frameworks in general to mobile frameworks, to front-end frameworks in general. I feel like I have started to form a more robust comprehension of where web-app development is headed in general, and most of the web-frameworks I know of seem to be missing it so far. This would be hard to articulate briefly, but blogs are good for taking a wild stab at that sort of thing, right? Disclaimer: this is just me sort of thinking out loud, so take it for what it is.

I am coming to the conclusion that I don’t think I want to use Grails anymore. Either that or I want to gut it of a lot of what it does. Sitemesh, don’t need it. Hibernate, don’t really want SQL database anymore, schema’s are so restricting/un-agile, so don’t need it. GORM, dislike it about as much as I find it useful, so could really take it or leave it. if you end up working with a object DB then it is pretty much an unnecessary abstraction anyway. Groovy, well I like it better than Java, but honestly Scala seems like it might be the most promising language on the JVM, and for that matter other non-JVM languages have plenty of appeal too. Resources plugin, Tablibs (built in or customizable), Scaffolding and Templates, i18n… better handled by a front-end framework.

Or…  RESTfullness and MVC are beautifully simple things, and these plus the idea that next generation web applications can no-longer count on consistent and/or high-speed connectivity, but can count on robust javascript engines on the client side means that pushing as much of the application to the client as possible is now something to strongly consider. . Grails (and lets not just pick on Grails, most web-frameworks I know of) is still stuck in the paradigm where views are generated server-side .

Grails, again, to be fair, this seems to be a pattern for web frameworks in general, has been advancing in ways that make it more powerful and thus more complex, not less. True it does a decent job of hiding that complexity away most of the time, but even so, what if  its being there is all unnecessary in the first place? The trend in the way people are using their computers/devices would seem to me to drive rich apps working on the client-side with relatively simple storage and syncing services that they connect to. Maybe what it means for web-frameworks to evolve at this point means to specialize, simplify, and strip down.

Flattr this!

SSH tunneling in Ubuntu

I wanted to work with a PostgreSQL DB remotely with PgAdmin, but I didn’t really want to figure out how to allow the DB to accept external connections in a secure way. Since I have SSH access this should be very doable. I have seen co-workers use putty for SSH tunneling before, and had previously used Putty on Ubuntu to copy that, but setting up my Natty workstation I figured there had to be a more native way to do it. Of course I could do tunneling straight from the command line. If I could ever remember the steps for it that approach would work great. Instead I found a tool called Gnome SSH Tunnel Manager (gSTM) and installed that from the Ubuntu repos. It is pretty straight forward to configure if you understand the concept of tunneling, which I only barely do, so I needed a little help getting set up, but after that it is dead simple.

  1. Install gSTM and start it up.
  2. Click ‘Add’ for a new tunnel bookmark, and name it.
  3. Add IP and user login for remote machine.
  4. Leave port and privatekey as default (unless you know what they are used for in which case you probably know what to put in there).
  5. In the port redirection section click ‘Add’, a new dialog will appear.
  6. Type is ‘local’.
  7. ‘Port’ is the port on your local machine you want to assign the tunnel to (I did 5666).
  8. ‘To host’ can be set to ‘localhost’.
  9. ‘To Port’ is the port used on the remote machine. default PostgreSQL is 5432.
  10. Click ‘OK’ and all the settings are done for gSTM so click ‘OK’ again to close the settings dialog.
  11. Highlight new tunnel, and click ‘Start’ – it should prompt you for the ssh password.
  12. Ta-da!
  13. Now use pgAdmin, or  another application to connect to the DB at localhost:5666 (or whatever port you set in step 7 above..).

Now I just need to make sure my tunnel is running in order to have access to the DB locally. Very cool! Probably where I got most confused was with the ‘To host’ and ‘To port’ settings, the wording seems backwards. Is that just me?

Flattr this!

Jan 2010 Ubuntu Browser Benchmarks

A follow-up of this.

Note: I am just comparing Javascript. This is no longer a good way to benchmark a whole browser, if it ever was… but it is just interesting to me, and gives one metric that is an important one.

Environment is Ubuntu 10.10 64bit on Core2Quad@2.66Ghz

Browser Version Sunspider result
Chromium 10.0.634.0 277.2ms +/- 1.8%
Midori 0.2.9 388.5ms +/- 1.0%
Epiphany 2.30.2 382.0ms +/- 2.4%
Opera 11.00 352.6ms +/- 1.8%
Firefox 3.6.14pre 1883.8ms +/- 2.6%
Swiftfox 3.6.12 1068.2ms +/- 2.3%
Firefox 4b10pre 283.6ms +/- 5.0%

All the browsers have advanced pretty well. Once Firefox 4 finally ships I’d say the playing field is pretty level for javascript performance in browsers on Linux. In real world usage I just don’t know that anyone would be able to distinguish a speed difference between the browsers when it comes to javascript. The next pieces browsers need to keep working on are HTML5 and CSS3 implementations, Hardware acceleration for 2D and 3D rendering, and additional browser features, like extensibility and ‘installable’ web apps.

As a web developer I am excited about where things are going, and how the web as a platform is advancing. Native (meaning native to the OS/Desktop environment) applications aren’t gone yet, and probably won’t be for a long time yet, but they are needing a better and better excuse to not move into the browser. What would be the benefit of that you ask? The same that Java Swing, Adobe AIR and others have tried to achieve. OS independence. You write it for Firefox according to defined standards and it should work on all browsers that implement the same standards on all the OS’s. That is a big deal! I think a couple prime candidates for proof of concept browser apps would be all the little games normally included in Ubuntu. Mines, Solitaire, Tetris clones etc. and maybe the social networking client like Gwibber. If only I had more time to play…

Update: I played some with Tetris in a browser idea

Flattr this!

Customizing The Ubuntu Terminal

The Obvious:

With a terminal open select Edit -> Profile Preferences.

In here you can set background color, transparency, font, font-size, text colors and more.

A couple not-quite obvious things I like to do.

Uncheck the ‘show menubar by default in new terminals’ – it just isn’t very useful and a right click in the terminal gives you some of those options anyway and if what you need is not there you can easily bring back the menubar from there.

Increase the number of scrollback lines – personally I at least double it to 1024 lines as Grails errors are long and ugly and that is the framework I spend a lot of my time working with. Your mileage may vary.

Advanced:

The .bashrc file in your home directory is where extra configuration options lie.

Colors:

Ubuntu disables the prompt being a different color. but simply uncomment the proper line in .bashrc and you’ll undo that. Look in the vicinity of line 36-40. The comment says the goal is to avoid distraction… just doesn’t make sense to me. A colored prompt helps me distinguish certain pieces of text from others, so for me, it is essentially the opposite of a distraction helping me focus on the pieces I need to read from the pieces I don’t.

Aliases:

Many Linux command line gurus expect “ll” or certain other common aliases to work. Uncomment a couple more lines in Ubuntu’s .bashrc file and they will. Look in the vicinity of line 80-83.

you’ll also see just a couple lines down:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
So if you’d like to add extra aliases create a .bash_aliases file and fill it in. Sweet right?!

Flattr this!

Grails active page navigation menu

A Common feature found in many CMS’s or web-apps is a navigation menu with a highlighted active page, or the parent of the current page in a hierarchy. The trick is getting the proper element with an added CSS class of ‘selected’ or ‘active’. There are a number of ways to do this, but I just found a new way to do it in Grails using a Sitemesh’s pageProperty.

In my main layout gsp I have the nav menu

 
  

then in the head section of a view gsp’s where I want the appropriate element to have a ‘selected’ or ‘active’ class. I include:

    

Then in the css have something to deal with the applied class:

  #mainMenu li > a.selected { .... }

Pretty simple! I don’t know if this is very efficient in terms of performance. I can think of other ways to do this with Javascript, or params passed from the controller, but I wanted to find something that used Sitemesh as that seemed like the component that ought to handle this sort of feature. So while this is working for me, and gives a pretty good level of control, I am still wondering if it is really the ‘right’ way to do it.

For a more comprehensive explanation of Sitemesh in Grails visit this blog.

Flattr this!

2010 breakout year for Linux (as in Android)?

Yeah, i know not another “year of Linux” prediction. So lame, but eh, whats the harm really 🙂

I have been thinking for a while now that Android is really the up and coming platform. This article about the android market reaching the 20,000 app milestone seems to agree, but is pretty conservative about it. Things it doesn’t consider is that the Android Market is just one place that apps are released. Apps can be made available other ways, such as a simple download available on the web that you then drop onto your device, or accessed directly through specific URL’s.

Also in contrast to native apps there are web apps. Web-apps developed for iPhone’s mobile safari browser also run on other mobile webkit browsers like the one found on Android (and Palm’s WebOS) and vice-versa. There is no count on those that I know of, but they are definitely growing in numbers and I suspect their popularity will be increasing dramatically. Less platform lock in is a big draw for developers. Additionally, existing tools make developing mobile apps relatively easy. For example, Android benefits from already existing tools like JqTouch, xUI, iUI and others

Then there is the fact that Android is starting to show up on things other than phones, like e-readerstablets, and amazing looking reader-tablet hybrids

With 2010 just around the corner some people are sure to claim (yet again) that this will be the year for Linux to break out, and they might be right as 2010 is really shaping up to be a big year for Android.

Flattr this!

Gedit snippets

Call me slow, but for whatever reason I never was aware of how cool the snippets plugin for gedit was. It comes as part of the gedit-plugins package in the repositories. It basically works by using a key phrase like “if” or “link” and then hitting Tab will insert the code block specified. Placeholders are also included so hitting tab subsequently will move the cursor to those spots. It makes for rather fast coding once you get used to it – a really great productivity tool in a lightweight editor! You can also define your own snippets pretty easily and share them since they get saved as a simple xml file. I just put some I created for Groovy and Grails up on Github.

Flattr this!