My Ubuntu 14.04 LTS installation

Here’s how I install and configure Ubuntu 14.04 LTS. My main application right now is writing and running R programs. Additionally, I use Dropbox to share files across systems and Crashplan for off-site backup.

  1. Down the 64-bit CD, burn it to a disk, and install. Agree to use the proprietary software. Give the system a unique name.
  2. Install and configure Dropbox.
    1. Go to the Dropbox website, download the deb, and install it.
    2. Configure selective sync to sync only: github-clones, keepas, todo.
  3. Fix the ipv6 problem. This will cause software center and other apt-get operations to run slowly.
    1. Search for “connecting to takes too long”
    2. Follow the instructions to disable ipV6. You can copy and paste the commands into a terminal. Follow the directions to allow sites that prefer ipV4 to use ipV4. Also disable ipv6 (though that doesn’t seem to work).
  4. Use the Ubuntu Software Center to install
    1. KeepassX (not Keepass2)
    2. Chromium web browser
    3. vim
    4. git
  5. Install R. Visit and follow the instructions.
    1. Pick a repository; e.g., the one in Maryland
    2. set the deb. See instructions on r-project website.
    3. Install software r-base and r-base-dev using sudo apt-get install PACKAGE.
  6. Once the Dropbox sync completes,
    1. install the dot files in Dropbox/git-hub-clones/dotfiles/.
    2. start sync of other Dropbox files you want to work on.
  7. Install tmux: sudo apt-get install tmux
  8. Map CAPS LOCK key to another ESCAPE. This makes VIM much more usable.
    1. Install via ubuntu software center: gnome tweak.
    2. Use the “Typing” preference to map the CAPS LOCK to another ESCAPE.
  9. Install CrashPlan. Visit the website, download, install, configure.
  10. Configure Chromium to use my account.
  11. In System Settings > Software & Updates > Other Software, enable software from Canonical Partnersh.
  12. Auto hide the panel (on the left of the screen) and enable workspaces. System Setting > Appearance > Behavior.
  13. Install pathogen.vim. Search and follow directions.
Posted in Uncategorized | Leave a comment

Simple unit testing in C++

There are many complex frameworks available, include cxxtest and the Boost test frameworks. However, a simple approach can also be effective.

In our simple approach, we define a static public method for each class: static void unit_test(). This method runs all the unit tests associated with the class. It throws if it finds an error; otherwise it returns.

As the start of a main program that uses classes, I run a series of tests on each class. The tests look like

In writing the unit_test() methods, there is some repetitive code. For example, I do a lot of scientific computing, and its useful to test if two floating point values a and bare close enough. For this, I defined a function bool close(T a, T b, T tolerance). All these function are static methods in the class Unit_test.

Posted in C++ | Leave a comment

gnu screen how to’s

The GNU screen manual

Setup the ~/.screenrc file such that many lines of stdout are saved, because by default, screen throws away the output. Put these lines in .screenrc
defscrollback 10000

ssh to remote system

Either start a new screen session or reconnect to a prior session
screen #start new session and attach to it
screen -list #list all available session and whether attached or not
screen -dr [pid.sessionname] # connect attached session to me
screen -r [pid.sessionname] # connect detached session to me

Once you are attached to a session, never use the session command by itself, or you start yet another session. It’s easy to get confused.

Once attached to a session, you can open windows (= virtual terminals).

To create a new window and switch to it and start recording in a file everything that displays on the window:
C-a c  # create window and switch to it
C-a ” # list current window numbers for use in script command below
script window-N-MM-DD-HH-MM-PURPOSE.script #save stdout in unique file name

With a screen session, to switch to a different window
C-a N # switch to window N
C-a p  # switch to previous window
C-a n  # switch to next window

To scroll a window, switch to it and enter copy mode (which allows scrolling using the arrow keys)
C-a ESC #start copy mode
<scroll with arrow keys, if running Terminal, can copy to clipboard>
ESC #stop copy mode

NOTE: DO NOT create another screen session from within a screen session. If you do, then follow Marco’s advice

Problem with screen w/in a screen is that there is no way to send
the C-a to the nested screen.  The best way to sort out the problem
is to connect to the nested screen directly using

screen -rd <id of screen>

the ‘d’ parameter will detach the nested screen then in the other
‘nesting’ screen you will have the terminal back.

Posted in linux/unix | Leave a comment

Using the servers

Server names (partial list): juno, monk

To see load on servers, while on campus  browse to

From home, must login twice and its best to always run screen
screen [-r]

My ubunutu vm (or the mac os logon) has a script to sync the generated-data
rsync -aP repp-generated-data

Posted in linux/unix | Leave a comment

Git remote repositories

To clone a remote repository
git clone ssh:// repo.git

To retrieve changes from the remote and merge into a local branch

To send changes in current branch to the remove
git push

Posted in git | Leave a comment

Branching in git

To create a new branch from the current branch
git branch BRANCH_NAME

to list all branches
git branch

To work in a branch
git checkout BRANCH_NAME

To merge commits in BRANCH_NAME into the master branch
git checkout master
git merge BRANCH_NAME

To delete a branch
git branch -d BRANCH_NAME

To rename a branch

Posted in git | Leave a comment

Using git as a front-end for Subversion


Checking out a subversion repository to a git repository in your LOCAL_DIR

Edit and commit with git as normal. In particular, you can create a new git branch with
and later merge it back to the master with
git checkout master

To update and commit back to Subversion
git-svn rebase
git-svn dcommit

Posted in scm | Leave a comment

Skeleton C++ type polymorphism (virtual function)

Here is one recipe; there are others.

Plan to access the polymorphic function via a pointer, as in

Define the base class this way
struct Base {
virtual int func() { … };

Define the derived class this way
struct Derived : public Base {
virtual int func() { … };

Define objects this way
Base base_obj;
Derived derived_obj;
std::vector<Base*> mixed;

Call the virtual function this way
function do_it(std::vector<Base*> v) {
for (unsigned i = 0; i < v.size(); ++i) {>func();

Posted in C++ | Leave a comment

My bash configuration

Edit ~/.bashrc to set choices I like

  • Change the prompt (\W=base name of current directory)
    PS1=”\W $ “
  • Protect against clobbering a file
    alias cp=”cp –interactive –verbose”
    alias mv=”mv –interactive –verbose”
    alias rm=”rm –interactive”
  • Provide shortcuts
    alias emacs-help=”cat /home/roy/Dropbox/tracking/emacs-help.txt”
    alias lwr=”cd /home/roy/Dropbox/nyu-real-estate/repp-repo-svn/src/local-weighted-regression-2/src”
    alias todo=”emacs -nw /home/roy/Dropbox/tracking/”
    alias tracking=”cd /home/roy/Dropbox/tracking”
  • Start emacs in the terminal
    alias emacs=”emacs -nw”
  • Say changes were made
    echo “Ran roy’s .bashrc commands”
Posted in bash | Leave a comment

My emacs configuration

Edit ~/.emacs to enable org-mode

  • (add-to-list ‘auto-mode-alist ‘(“\\.org\\'” . org-mode))
  • (add-hook ‘org-mode-hook ‘turn-on-font-lock)
  • (global-set-key “\C-cl” ‘org-store-link)
  • (global-set-key “\C-ca” ‘org-agenda)
  • (global-set-key “\C-cb” ‘org-iswitch)
  • (global-font-lock-mode 1)

Set default font (method 1)

  • Start emacs in X windows
  • Pick front via menu Options > Set Default Font
  • Save options via menu Options > Save Options (this may not be necessary)

Set default font (method 2)

  • find a font you like and turn in on
  • in the buffer, enter M-x describe-font to find out the name of the font
  • in .emacs, add a line
    (if (eq window-system ‘X)(set-face-attribute ‘default nil :font FONT))
  • example
  • (if (eq windows-system ‘X) (set-face-attribute ‘default nil :font “-Misc -Fixed-Medium-R-SemiCondensed–13-120-75-C-60-ISO8859-1”))

Tell emacs to save the desktop (=its frames and windows) automatically when you exit, if you are running under X

  • (if (eq window-system ‘X) (desktop-save-mode 1))
Posted in Uncategorized | Leave a comment