Connecting to USC Secure Wireless on Linux

Dec 23, 2014
Tested on: Ubuntu 14.04, Linux Mint 17, Linux Mint 17.1

USC (Univ. of Southern California) updated its wireless service to have an encrypted and faster connection available to USC faculty, staff, and students with name 'USC Secure Wireless'. Unfortunately for students like me, USC did not document how to use Linux computers with this service.

Following configuration has worked for me to connect to USC Secure Wireless during past couple of months. The basic idea is to use 'WAP2' or 'WAP Enterprise' security and use Protected EAP (PEAP) authentication along with GTC as secondary authentication. Same idea works on Android phones as well.

Create a new connection by right-clicking on 'Network connection' icon in notification area and choosing 'Edit Connections...' It will pop a 'Network connection' window. Click on the 'Add' button on the right side and choose 'Wi-Fi' as connection type. Then follow the settings described in the images below (click on the images to enlarge them). Note that the USC-id must be entered without

And here is how the connection information looks like after being connected to USC Secure wireless.

Read more ...

A simple approach to reference and PDF management

Sep 5, 2014

Managing references and citations is essential for academic publishing and reproducible research. However, managing large volume of references and citations over years is no easy task! A number of softwares have been developed specially for the task and been discussed many times. In this post I will briefly describe my own approach, which I have been using over 4-5 years now, to manage references, notes and corresponding files including PDFs. In particular, my approach aims to be:

  • Scalable - Manage hundreds of references and related files; It should be easy to add new reference/notes and should require no/little maintenance.
  • Easy formatting - References should be accurate and should be able to handle different character encoding, accents and should adapt to any reference-style based on the publisher specification.
  • Portable - Easy synchronization of whole setup (files, notes etc.) to a new computer/laptop/device.
  • Searchable - Search through titles, authors, previous notes etc.
  • Cross Platform - Same method should work across different operating systems (Linux, Windows, Mac) with no/minimal changes.
  • Work offline - Because Internet access is never as reliable as one wants it to be (also see 'Portable' above).
  • Free and Open - "Free as in beer" and, preferably, as "free speech" as well (no proprietary format). Being "open" also make it possible to port the data to some-other format/method, if required.

Note that the described method relies on BibTeX, mainly because it can achieve all the above goals and because BibTeX (& LaTeX) is de facto standard for writing in my discipline (Engineering). Use of BibTeX also makes bibliography dead simple in LaTeX - absolutely no export/import required! If BibTeX is not acceptable, skip to last section below for some alternatives.


The approach itself is fairly simple and is motivate by The Unix philosophy of small tools. The approach has three components:

  1. A directory on our computer/device, say with name "papers", which will contain all the files related to the references. Basically, this directory is the self-contained repository of all our information.
  2. JabRef for managing the BibTeX (.bib) file which manages all information, and
  3. A file synchronization tool, like Dropbox or Unison, to synchronize the papers directory to other devices, if required.

So, basically we save our files (PDFs etc.) in a directory, open/read/edit the files using our favorite software, add/edit the reference information via JabRef, and sync to other devices using our favorite sync-software. (In theory one could also use any other BibTeX manager, but JabRef is absolutely the best BibTeX manager I know.) For ease of file management, we can create 2-3 sub-directories to organize files, but it is completely optional as JabRef allows more advanced categorization. The image on right shows a sample directory structure. reference.bib is the BibTeX file which contains all the information related to references and lies at the heart of this approach. The sub-directories contain PDF and other files related to references. In my approach, I use one single .bib file for managing all reference, which in my experience works in a much better unified-way than multiple .bib files.

Next, I will outline some bare-minimum steps to get started with this approach. However, feel free to explore JabRef options and make your own customizations.


  1. Create a papers directory with 1-2 relevant sub-directories. Optionally, throw in few PDF files of your references in sub-directories. Avoid spaces in file and directory names; use underscore instead.
  2. Download and install latest version of JabRef for your platform.
  3. Open JabRef and create new database (File->New database). Save database as a reference.bib in papers directory.
  4. In JabRef, go to the menu Options->Preferences and set following:
    • In Files tab, check "Open last edited databases at startup" and "Backup old file when saving".
    • In External programs tab, check "Allow file links relative to each bib file's location" and "Use the bib file location as primary file directory"
  5. Optionally, setup your synchronization/backup for the papers directory.

Adding references

This step is the most important step, as we want our reference to be accurate. Let us assume that we have read this paper from Einstein and have saved a copy of the PDF file in appropriate sub-directory. Next, we would want to add it to our refernce list and add some notes from our reading. The idea here is that we will be very careful with all the details while adding the references the first time and then we can use it confidently life-long (almost) without any changes. If you are entirely new with JabRef then go through this short tutorial to familiarize yourself.

  • Open reference.bib using JabRef. Go to BibTeX->New entry and then select Article from entry type dialog.
  • Fill in the details of the paper starting from "Required fields" tab. You need not fill in all the fields in other tabs. You can find more about fields in BibTeX Help and wikibooks.
  • You can also copy-paste the details of field from the paper, publisher website, or listing on Google Scholar. But make sure that the details are correct. For example, the author details of the Einstein paper is wrong on Google Scholar!
  • While selecting Bibtexkey be sure that it is unique as you would never want to change it in future (Bibtexkey is the key which would refer from LaTeX). I typically follow the format: firstAuthorLastName_year_four_word_paper_summary for my Bibtexkey (& PDF filenames).
  • To link the PDF (or any other file), go to "General" tab and add the link to file. You can add as many files as you want to an entry. This allows easy access to the files from JabRef. See help section for more details and options.
  • You can also add your review of the paper in "Review" tab. I prefer adding some "Keywords" and write my notes in "Comment" in "General" tab. Also, I prefer to use my favorite 3rd party tools to annotate/highlight the PDF itself.
  • JabRef also supports groups (which are somewhat similar to labels in Gmail) and marking for more advanced categorization. However, I never felt any need of such categorization because the search in JabRef works well and use of keywords pretty much categorizes all the references.

While adding new entries, JabRef will autocomplete author names and words and can also autogenerate Bibtexkey. Once you have added enough references, you can directly link to the reference.bib from LaTeX file for bibiliography. You can also put the .bib file in some sort of version control for enhanced security and control. I prefer to create weekly backup of the entire papers directory to external hard-drive for peace of mind.


JabRef is written in Java which makes it cross-platform by design. I frequently use it on desktops (Linux, Windows and Mac). The method also works well with portable android devices with RefMaster. Basically, RefMaster replaces JabRef on andriod and it supports Dropbox integration. There should be similar apps for managing BibTeX on iOS platform.


The only feature which I miss in this approach is the ability to search inside the linked files when searching in JabRef. However, it is not a show stopper, especially in presence of various desktop search tools.

Also, this approach will not parse your computer for PDF files and auto-magically generate "correct" references. This method is geared towards accuracy and, in my experience, the auto-magical metadata extraction from PDF do not work well frequently and have rather large error rate. Careful verification of reference data while entering data is important and fruitful in long run.

Another drawback could be the steep learning curve required for getting comfortable with LaTeX (& BibTeX). It is assumed that people from my discipline (Engineering) are already using or will be using LaTeX. See next section for alternatives.


If LaTeX (& BibTeX) is not your cup of tea then following are some alternatives (but one should consider why should they not use LaTeX and who else uses LaTeX). I ended up with JabRef because most of the following did not had upto-the-mark BibTeX management, atleast by my taste, when I was trying them.

  • Mendeley is a good alternative and specially works well with office documents and can search inside linked PDFs.
  • citeulike is an online service and works well for collecting references while browsing over internet.
  • Zotero used to be a browser-plugin which offers good features, but I never tried it seriously. The standalone version came much later but looks good.

There are several other softwares which can be used for refernce management. Here is a popularity context of different softwares and here is an irony post comparing them. Everyone has their own preferences and a solution may not be the 'best' solution for everyone. The described approach works for me and could be helpful to others.

Read more ...

Moving remote Git repository

Jul 11, 2014
It is surprising that most of the search results related to moving Git repository is targeted towards moving repositories to and alike. I was trying to move my git repository from, say, to These servers are Linux servers and are accessible via SSH. However, using the common set of instructions i.e. git clone --bare followed by git push --mirror kept throwing me following error: $ git push -v --mirror ssh:// Pushing to ssh:// fatal: '/home/user/Repo.git' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Some posts suggested to first initialize a git repository on server. This sounded odd to me as per my understanding, all we need is SSH access to the server in order to setup as a remote Git repository.

And it turns out that the answer is very simple and is actually explained on Git documentation. Just perform a local --bare clone of the repository then scp or rsync it to server and update origin of the repository. Thats it! All push/pull would work as expected after that with new server. Here are steps I followed (notice server1 and server2 in the commands): # Check current remotes $ cd /home/user/Repo $ git remote -v origin (fetch) origin (push) # Temporary --bare clone in /tmp $ cd /tmp $ git clone --bare file:///home/user/Repo Cloning into bare repository 'Repo.git'... remote: Counting objects: 4389, done. remote: Compressing objects: 100% (4349/4349), done. remote: Total 4389 (delta 3138), reused 3 (delta 0) Receiving objects: 100% (4389/4389), 45.46 MiB | 15.28 MiB/s, done. Resolving deltas: 100% (3138/3138), done. Checking connectivity... done. # Transfer the new bare repository to new server using scp or rsync $ scp -r Repo.git # Update origin url in local repository $ cd /home/user/Repo $ git remote set-url origin # Check the updated remotes $ git remote -v origin (fetch) origin (push) # Delete the temporary clone in /tmp $ rm -rf /tmp/Repo.git
Read more ...

Matlab's cryptic error messages

May 17, 2014
Sometimes MATLAB's error messages can be very cryptic and misleading. Following are examples of error messages which I encountered while trying to solve \(\mathbf{A}x=b\) in least square sense using MATLAB's lsqr function. %% Error 1 Error using iterapp (line 60) user supplied function ==> @(x,transp_flag)transform_X(x,transp_flag, ...) failed with the following error: Not enough input arguments. Error in lsqr (line 180) u = u - iterapp('mtimes',afun,atype,afcnstr,x,varargin{:},'notransp'); %% Error 2 Error using * MTIMES is not supported for one sparse input and one single input. Error in iterapp (line 29) y = afun * x; Error in lsqr (line 180) u = u - iterapp('mtimes',afun,atype,afcnstr,x,varargin{:},'notransp'); For an experienced MATLAB user, error 2 may be easier to locate because of the message: "Error using *". However, when I was actually working, I got error 1 which said "Not enough input arguments". It took me sometime to figure out that both the errors were related to mismatching datatypes in input parameters. Both the situations were actually identical, except that in first case I was using function handle Afun in place of matrix representation of \(\mathbf{A}\). Here are the actual statements which raised errors: x = lsqr(Afun, b, 1e-9, 100, [], [], x0); % Raises Error 1 x = lsqr(A, b, 1e-9, 100, [], [], x0); % Raises Error 2
And here is the code snippet for Error 2 above. The code can be modified easily to create function handle Afun (see Example 2 here). Notice the statement x0 = single(rand(size(b))*5); in the code snippet which changes the datatype and causes error. n = 50; on = ones(n,1); A = spdiags([-2*on 4*on -on],-1:1,n,n); b = sum(A,2); x0 = single(rand(size(b))*5); x = lsqr(A,b,1e-9,100,[],[],x0);
The take-away message: Always check datatypes when MATLAB's error messages don't make sense!
Read more ...

LaTeX to word document

Jan 24, 2014
Tested on: Linux Mint 13 (Ubuntu 12.04), Microsoft Office 2010, LibreOffice 3

It is common to typeset scientific documents in  \(\LaTeX\). However, few people may like to still read and edit the document in word processors like Microsoft word (.doc or .docx)or LibreOffice (.odt). Here are quick (& dirty) steps to produce reasonably looking "office" documents from .tex files. The idea is to exploit HTML output as intermediate format which is readable by word processors. This ideas is shown below and has been explored and reported widely.
  1. Convert \(\LaTeX\) to .html: There are various ways to achieve this, but htlatex from TeX4ht worked best for me. First install TeX4ht and then then run following on the \(\LaTeX\) document. Note that htlatex runs latex three times before calling TeX4ht programs and it would write out all the outputs in the same directory as the .tex file (see below for handling PDF images). The generated files would include one .html file (paper.html for command shown below). $ sudo apt-get install tex4ht $ htlatex paper.tex
  2. PDF images: If the .tex file uses PDF files as images, then htlatex (or latex) may not be able to go along with correct conversion. Some discussions on Stack Exchange were very help for this issue and provided the solution. First create a configuration file, say myxhtml.cfg, with following content: \Preamble{xhtml} \Configure{graphics*} {pdf} {\Needs{"convert \csname Gin@base\endcsname.pdf \csname Gin@base\endcsname.png"}% \Picture[pict]{\csname Gin@base\endcsname.png}% \special{t4ht+@File: \csname Gin@base\endcsname.png} } \begin{document} \EndPreamble Then run htlatex as shown below. Note that the .tex file should use correct extension for every included image (or else use \DeclareGraphicsExtensions{.pdf}). $ htlatex paper.tex myxhtml
  3. Fix HTML: Sometimes TeX4ht will not write out clean html files i.e. the html tags may not be aligned properly. This may prevent html to import into word processors. Online editors like Fix My Html and HTML Tidy Online did the trick for me. Use the .html file generated by htlatex as input to these online editors and save the fixed html file for next step.
  4. Import HTML in word processor: Usually most word processors would support importing HTML files. If that does not work (like in my case), you can just open the HTML file in a browser then copy-paste the whole page into the word processor (check if your word processor also supports Paste Special for formatted text. It everything works out then you should be able to just save the pasted document in .doc, .docx or .odt format. 
The above set of steps produced good looking single column document for me with correct bibiliography references. The math equations are embedded as images in the documents, which may not be optimal but the process works for reviewing and editing the text by someone who prefers word processors.
Read more ...

Parent directories in tar archives

Jan 3, 2014
Tested on: Linux Mint 13 Maya (based on Ubuntu 12.04 LTS)

It is common to see full directory tree or . (dot) in tar archives. Sometimes, it may be unnecessary hassle to remove all parent directories after extracting or to look for the extracted file which merged with other files in extracted directory. In some situations, it may be desirable to create a tar archive with top directory (with informative name). There has been many discussion about the same. Here is quick summary with an example for future reference.

Test setup

We will create a test directory with some files in it with following commands (outputs are also shown): $ mkdir -p /tmp/path/to/test/dir_archive $ touch /tmp/path/to/test/dir_archive/file{1..10} $ ls /tmp/path/to/test/dir_archive/ file1 file10 file2 file3 file4 file5 file6 file7 file8 file9 $ tar --version tar (GNU tar) 1.26 Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by John Gilmore and Jay Fenlason.

Full parent directory

Following command creates tar archive with full parent directory structure as shown by --list command. $ tar -caf /tmp/test.tar.gz /tmp/path/to/test/dir_archive $ tar --list -af /tmp/test.tar.gz tmp/path/to/test/dir_archive/ tmp/path/to/test/dir_archive/file3 tmp/path/to/test/dir_archive/file10 tmp/path/to/test/dir_archive/file1 tmp/path/to/test/dir_archive/file8 tmp/path/to/test/dir_archive/file4 tmp/path/to/test/dir_archive/file2 tmp/path/to/test/dir_archive/file7 tmp/path/to/test/dir_archive/file5 tmp/path/to/test/dir_archive/file6 tmp/path/to/test/dir_archive/file9

Dot (.) as parent directory

Following command creates tar archive with dot (.) as parent directory. Note that the tar command ends in a dot (.). $ tar --directory /tmp/path/to/test/dir_archive -caf /tmp/test.tar.gz . $ tar --list -af /tmp/test.tar.gz ./ ./file3 ./file10 ./file1 ./file8 ./file4 ./file2 ./file7 ./file5 ./file6 ./file9

Directory name as parent directory

The trick to get dir_archive as parent directory in tar archive is to use --directory to change directory to one level up as shown below. Note location of dir_archive in the command. $ tar --directory /tmp/path/to/test -caf /tmp/test.tar.gz dir_archive $ tar --list -af /tmp/test.tar.gz dir_archive/ dir_archive/file3 dir_archive/file10 dir_archive/file1 dir_archive/file8 dir_archive/file4 dir_archive/file2 dir_archive/file7 dir_archive/file5 dir_archive/file6 dir_archive/file9
Some more notes about tar command:
  • Above commands can be combined with used along with exclude directive to by using --exclude='dir_archive/dir_exclude' after the --directory option.
  • Do not mix absolute and relative path in tar command for pathname and exclude option. --directory is an exception and can be absolute path while others paths can be defined relative to it.
Read more ...