Archive for the ‘tutorial’ Category

SSH tunneling in Ubuntu

June 3rd, 2011

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?

Customizing The Ubuntu Terminal

May 31st, 2010

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?!

Grails active page navigation menu

March 26th, 2010

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.

layout testing – browser resizing

March 11th, 2010

If you want to test a flexible or elastic site layout in Ubuntu you will be doing some window resizing. In MS Windows and Mac OSX window contents dynamically resize. It is a feature that makes it nice for seeing how CSS floats and positioning are behaving. I don’t know if it is a consequence of Compiz or what, but Ubuntu doesn’t do this be default. It only redraws the contents one you are finished resizing. Dynamic resizing is something you can enable in Ubuntu, though it is certainly not an area where Ubuntu shines.

To enable you will have to open CompizConfig Settings Manager (install it first if you don’t have it, obviously), open the “Resize Window” settings go to the “General” tab and from the “default  resize mode” drop down choose ‘normal’

You should now see window contents redrawn during the resize process, but chances are it is really laggy and crappy. To avoid the majority of this annoying crappiness on the rest of your desktop you can reset the default resize mode to rectangle or outline, and on the line that says “Normal Resize Windows” click the “+” icon. In the dialog that appears use the “grab” feature to pick the browser you want to have dynamic resizing on then click “add” to finish. That’s it! Close the settings Manager and you should be set.

UPDATE: A little more research turned up that this was in fact more an issue with Compiz. So I installed Compiz Fusion Icon , started that up and selected Metacity as the window manager. Dynamic resizing works in all the windows I tested and pretty fast/smooth. The downside is all my Compiz effects are gone, but it’s relatively easy to flip back and forth between Metacity and Compiz, so this is probably a better solution to this issue. I also noticed my javascript animations got much smoother with Compiz off.

Really if the only significant piece of compiz animation I would actually miss is the desktop switcher and zoom functionality.

Also, just tried it and this Metacity fix all goes away if you turn on Metacity’s compositioning feature as well. Compositioning is the problem, so it seems…

IE6 or IE7 on Jaunty with Wine

July 22nd, 2009

IE6 (Internet Explorer 6)  is dying and with every month that goes by I give less and less effort to supporting it, but IE7 is still relatively popular. I have been relying on other machines to test IE7 but that gets kinda old. Running Windows in virtual environment or dualbooting have been other ways I have tried to solve the problem of testing Microsoft’s troublesome browsers. Today I managed to figure out a relatively simple way of getting IE7 running with Wine on Ubuntu 9.04.

The first step is to go to the Wine download page which will walk you through installing the latest Wine.  For me it was 1.1.26.

You will also want to get winetricks.

Here is where it gets just a little technical. I tried a couple different methods and this is way I finally got things to work.

  1. From a terminal, navigate to where you downloaded the winetricks file and type “sh winetricks”.
  2. In the window that appears check the box for “ie6″ and click OK.
  3. Follow the prompts for the IE6 installer.
  4. Test IE6 by opening Applications->Wine->Browse C:/ Drive … Program Files->Internet Explorer — right click on “IEXPLORE.EXE” and select “open with ‘Wine…’” .

IE6scrnsht

Getting IE6 running is just a preliminary step that I found to be necessary in order to get to IE7. If you wanted to stop here you could. If you are on a 32bit version of Juanty you can go farther and get IE7 running – I wasn’t able to get it running on 64bit systems:

  1. download IE7.
  2. Close any running IE windows.
  3. Right click on the .exe and select “open with ‘Wine…’”
  4. Follow the prompts as per a normal windows install except that you should uncheck the updates option
  5. start IE7 the same way you previously started IE6

Screenshot here…

Have fun!!!