Saturday 6 September 2014

Vim support for Scala

mkdir -p ~/.vim/{ftdetect,indent,syntax} && for d in ftdetect indent syntax;
do curl -o ~/.vim/$d/scala.vim https://raw.githubusercontent.com/scala/scala-dist/master/tool-support/src/vim/$d/scala.vim;
done

Tuesday 5 February 2013

mp42avi

CONVERT MP4 to AVI:
ffmpeg -i source.mp4 -vcodec mpeg2video -b 5000k -acodec ac3 -ar 48000 -ab 384k -ac 2 -g 12 -top 1 -target ntsc-dvd -aspect 4:3 source.avi

pdfconcat

How to concatenate a large number of PDFS (for example, GroupOn vouchers):
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=groupon.pdf Groupon-*.pdf

rsync

RSYNC ENTIRE DIRECTORY:
rsync -avz local_dir remote_user@remote_machine:/remote_path
Recursively copies all files from local_dir to directory
/remote_path/local_dir on remote machine.
Note: trailing slash on source directory avoids creation of local_dir on
remote host

Tuesday 18 December 2012

Wonderful appreciation of my Dad

AN APPRECIATION

Finbar Costello, who died on October 31st, 2012, is deeply mourned not only by his family but by the numerous friends who considered him an important part of their lives. He was born on October 3rd, 1939, the son of the legendary Lieut Gen Michael Joseph Costello.

Following his education at Clongowes Wood College (of which he was later to become president of the union) he graduated from UCD with a commerce degree and went on to a successful career in advertising. In due course he became managing director of Irish International Advertising and held various other directorships. However it was his life more generally that left an indelible impression on so many.

Through the long and debilitating illnesses that were to dog his last 10 years he demonstrated the attributes that truly defined him as a remarkable man. His indomitable courage in the face of constantly recurring health crises was always combined with an optimism and an engagement with and love of life. It is no commonplace observation to say that he was truly a person whose identity was steeped in the values in which he profoundly believed. These included in particular great integrity and loyalty to his friends and country.

He was a man for all seasons and he read voraciously on a wide range of subjects. On any aspect of current events he invariably had an objective point of view that he never hesitated in expressing in pungent terms, even if he was swimming against the tide of popular sentiment of which he disapproved.

His institutional loyalties were deep and constant to his school and above all to UCD rugby club. There can have been no greater alickadoo in any club in the country than Finbar. He devoted countless hours, year after year, to developing UCD RFC and, more importantly, the young men who were members of it. He played for, was honorary secretary, honorary treasurer and trustee and, ultimately, president of the club in 1980, but no formal description of these roles adequately describes his engagement. He was the very soul of the club and his personal mentoring and support of the students who passed through may have had a greater influence on many of them than almost any other aspect of college life.

In 2005 he received from the National University of Ireland an honorary doctorate for his work with UCD Rugby Club which was a unique and richly deserved accolade.

Finbar married Jo in 1965. During the difficult years of illness she dedicated her life selflessly to helping him and throughout was an indispensable support and much more. Their relationship and that with his sons Barry and Gavin, was by far the most important element for him in a life that was truly fulfilled.

– PETER SUTHERLAND

Thursday 11 October 2012

Using rsync to back up a home directory

Having a laptop that's on it's last legs, I'm looking at backing up my home directory.

However, I don't want to backup all the cruft that has accumulated there.

Rsync has a useful option to exclude a list of named directories: --exclude-from file.txt, where file.txt contains the list of files and directories to exclude.

So this is the procedure:

1. Perform a dry-run to investigate which cruft should be removed (-n indicates a dry-run):

e.g., rsync -avzn --exclude-from exclude.txt $source_dir $destination_dir

2. Add crufty patterns to exclude.txt:

3. Repeat until satisfied

4. Run actual rsync, e.g. rsync -az --exclude-from exclude-txt $source_dir $destination_dir

e.g.


% cat exclude.txt
.m2
.adobe
.bak
.cache
.config/chromium
.config/evolution
.config/google-chrome
.config/.libreoffice
.config/libreoffice
.dbvis
.eclipse
.freerdp
.Foxit
.gconf
.gimp*
.git
.gitignore
.ies4linux
.ivy2
.java
.macromedia
.moc
.mozilla
.multimedia
.opera
.pki
.pulse
.rdesktop
.squirrel-sql
.Skype
.swt
.vim
.vimperator
.thumbnails
.thunderbird
.w3m
.wine32
.wine64
.wireshark
.zcompcache
Desktop
Maildir
tmp
workspace





Monday 5 December 2011

Paginated Lists

Extending Java List to create paginated lists for JSTL jsps

JSTL often need to display lists of Java Beans.

The Pageable interface can be used to display these lists with pagination:

package com.brewer.list.util;

import java.util.List;

/**
 * An extension of the {@link java.util.List} interface for use in JSPs,
 * to allow display of a paginated list.
 *
 * For example, the JSTL construct <c:forEach> can be populated with this type,
 * to allow simple instantiation of the necessary variables.
 *
 * @author gavin (gavcos@gmail.com).
 */
public interface Pageable<E> extends List<E> {

    /**
     * The number of pages in the list
     */
    public int getNumberOfPages();

    /**
     * Returns the currently selected page.
     *
     * @return int  The current page.
     */
    public int getCurrentPage();

    /**
     * Sets the current page.
     * On instantiation, this should be set to 1.
     *
     * @param   page    The page to set.
     */
    public void setCurrentPage(int page);

    /**
     * Sets the page size.
     *
     * @param   pageSize    The page size to set.
     */
    public void setPageSize(int pageSize);

    /**
     * Returns the current page size.
     *
     * @param int   The page size.
     */
    public int getPageSize();

    /**
     * Returns the index the first row of the current page.
     *
     * @return  int The index.
     */
    public int getFirstIndexOfCurrentPage();

    /**
     * Returns the index of the last row of the current page.
     *
     * @return  int The index.
     */
    public int getLastIndexOfCurrentPage();
}

The PagedList class implements the interface:

package com.ecomm.brewer.util.list;

import java.util.ArrayList;
import java.util.Collection;

/**
* @see {@link nsi.fonctionnel.partnens.technique.util.Pageable}.
* @author p127001
*/
public class PagedList<E> extends ArrayList<E> implements Pageable<E> {

    private static final long serialVersionUID = 3469596120762185396L;
    /** The page size */
    private int pageSize;
    /** Default page */
    private static final int DEFAULT_PAGE = 1;
    /** Default page size */
    private static final int DEFAULT_PAGE_SIZE = 20;
    /** The currently selected page, initially the first one. */
    private int currentPage = DEFAULT_PAGE;

    /** Default constructor, initialises page size to default. */
    public PagedList() {
        super();
        this.pageSize = DEFAULT_PAGE_SIZE;
    }

    /**
     * Calls super class and initialises page size to default.
     * @param initialCapacity   The initial size of the list.
     */
    public PagedList(int initialCapacity) {
        super(initialCapacity);
        this.pageSize = DEFAULT_PAGE_SIZE;
    }

    /**
     * Initialises the list with an initial capacity and a page size.
     * @param initialCapacity   The initial size of the list.
     * @param pageSize          The page size to set.
     */
    public PagedList(int initialCapacity, int pageSize) {
        super(initialCapacity);
        this.pageSize = pageSize;
    }

    /**
     * Calls super class and initialises page size to default.
     * @param c
     */
    public PagedList(Collection<E> c) {
        super(c);
        this.pageSize = DEFAULT_PAGE_SIZE;
    }

    /**
     * Returns the current page.
     *
     * @return int   The current page.
     */
    public int getCurrentPage() {
        return this.currentPage;
    }

    /**
     * Sets the current page.
     *
     * @param   int     The page to set as current.
     */
    public void setCurrentPage(int page) {
        this.currentPage = page;
    }

    /**
     * Sets the page size.
     *
     * @param   pageSize    The page size to set.
     */
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * Returns the current page size.
     *
     * @param int   The page size.
     */
    public int getPageSize() {
        return this.pageSize;
    }

    /**
     * Returns the number of pages in the list.
     * If the list is empty, returns zero.
     *
     * @return  int     The number of pages, based on the size of the list and the page size.
     */
    public int getNumberOfPages() {
        if (this.size() == 0 || this.pageSize == 0) {
            return 0;
        } else {
            int iDiv =  this.size() / this.pageSize;
            int iModulo = this.size() % this.pageSize;
            return iModulo == 0 ? iDiv : ++iDiv;
        }
    }

    /**
     * Returns the index of the first row of the current page.
     *
     * @return  int     The index of the current page's first element.
     */
    public int getFirstIndexOfCurrentPage() {
        if (getCurrentPage() < 2) {
            return 0;
        } else {
            return (getCurrentPage() - 1) * this.pageSize;
        }
    }

    /**
     * Returns the index of the last row of the current page.
     *
     * @return  int     The index of the current page's last element.
     */
    public int getLastIndexOfCurrentPage() {
        return getFirstIndexOfCurrentPage() + (this.pageSize - 1);
    }
} 

In the JSP, use a JSTL forEach tag to display the list:

<c:set var="noPages">
    <%= getList().getNumberOfPages() %> 
</c:set>
<c:set var="currentPage">
    <% getList().getCurrentPage() %> 
</c:set>
<c:set var="startIndex">
    <%= getList().getFirstIndexOfCurrentPage() %> 
</c:set>
<c:set var="endIndex">
    <% getList().getLastIndexOfCurrentPage() %> 
</c:set> 
<c:if test="${not empty people}">
    <c:if test="${noPages ne '1'}">
        <tr>
            <td>${currentPage}&nbsp;/&nbsp;${noPages}</td> 
        </tr>
        <c:forEach var="person" items="people" begin="startIndex" end="endIndex" varStatus="status">
            <tr>
                <td>${person.name}</td>
                <td>${person.firstName}</td>
            </tr> 
        </c:forEach>


        <c:if test="${pageNo ne '1'}">
            <tr>
                <td>
                <c:forEach var="i"  begin="0" end="noPages"> 
                    <c:choose> 
                    <c:when test="${currentPage eq i}">
                    </c:when>
                    <c:otherwise>
                        <a href="select-page-link">
                    </a>
                    </c:otherwise>
                    </c:choose>
                </c:forEach> 
                </td>
            </tr>
        </c:if> 
   </c:if>
</c:if>