Friday, June 25, 2010

Groovy tip: initialise ArrayList












Q I have an ArrayList of known length, each element containing a comma separated string, some list members may be empty, the list starts empty and is built up. But the list elements start null, is there a way to initialise them?
A def myArrayList = (0..99).collect { '' }



Eclipse tip: switch/change tab

Tuesday, March 30, 2010

Git tip: add to comments












Q I have done a git commit but want to append to the comments I have added.
A In the root of your repository directory you will find a .git folder. In there there is a file "COMMIT_EDITMSG" which contains the comments for the current commit. To bring up the default editor (VIM, unless you have your custom editor specified in the [core] section of .gitconfig - located in the home directory - e.g. "editor = e:\\JGSoft\\EditPadPro6\\Editpadpro.exe, you can do git commit --amend



Eclipse tip: switch/change tab

Wednesday, March 24, 2010

Eclipse tip: switch/change tab












Q I have looked at a lot of the Eclipse keyboard shortcut cheat sheet lists but I can't find a shortcut to change tab in the editor?
A Use ctrl+e to pop up a list of the open tabs which you can scroll though to change focus. Alternatively, you can use ctrl+page-up / ctrl+page-down to navigate to the right/left tabs respectively.

Tuesday, March 23, 2010

Git Tip: unstaging













Q In Git you have your working tree and your repository but the necessary in-between state is the staging area. Files get staged by doing a git add. What's the opposite of a git add, i.e. how can I "unstage" a file?
A As the handy command line help on a git status shows, files can be unstaged with git rm.

    To wipe any changes you have made since the last commit, do a git reset HEAD <file name with complete path>

    Monday, March 22, 2010

    Cygwin tip: copying text












    Q How can I copy text in a cygwin window?
    A In the system menu, select properties and then Options | Edit Options | QuickEdit mode. You can then highlight text in the window and press enter to copy it to the clipboard.

    Sunday, March 21, 2010

    Eclipse tip: code completion shortcut












    Q In Eclipse, ctrl+spacebar is not bringing up code completion?
    A Check for any shortcut collisions. On my machine I discovered that Dexpot's task switcher default shortcut is the same, it can be changed in configuration. I use Dexpot for Virtual Desktopping and it is a vital component of my toolkit.


    Monday, March 8, 2010

    Eclipse tip: editing class header












    Q How can I change the class header in Eclipse to add a company copyright blurb?
    A The menu option Window | Preferences | Java | Code Style | Code Templates | Code | New java file shows:

      ${filecomment}

        ${package_declaration}

          ${typecomment}

            ${type_declaration}

              The text that gets substituted for ${filecomment} can be edited via Window | Preferences | Java | Code Style | Code Templates | Comments | Files. When editing the template you have the option in the GUI to insert variables and you can see which ones are available.

                This header will only shows up in new classes after choosing "Generate comments" in the new Java class wizard.

                Subscribe with a reader