Unix/Linux – ICS printer name

May 26, 2007 by Rares Vernica

To get a list with all the printers in ICS, ssh to printserver and run:

lpstat | grep Printer

Emacs — Search/Replace new line

March 24, 2007 by Rares Vernica

In order to search/replace new line character (\n) in Emacs, instead of \n you need to type:

C-q C-j

C/C++ – _M_underflow_common

February 13, 2007 by Rares Vernica

When you define you own character traits (e.g., ignorecase_traits – to ignore the case when comparing strings) you might run into the following link error:

In function `std::basic_filebuf<char, ignorecase_traits>::uflow()'::
undefined reference to `std::basic_filebuf<char, ignorecase_traits>::
_M_underflow_common(bool)'

The solution is to add the following to one of your CC/CPP files:

struct cGet_M_underflow_common : std::basic_filebuf<char> {
  int_type mGet_M_underflow_common(bool b) {
    return _M_underflow_common(b);
  };
};

icfielbuf::int_type icfielbuf::_M_underflow_common(bool bump) {
  return reinterpret_cast<cGet_M_underflow_common *>(this)->
    mGet_M_underflow_common(bump);
};

Emacs – change case

February 6, 2007 by Rares Vernica

In order to change the case in Emacs you can use:

M + l to change to lowercase all the letters from the cursor to the end of the word
M + u same meaning, but upercase
M + c same meaning, but capitalizes

C/C++ – binary IO

February 1, 2007 by Rares Vernica

Here is an example of how we can write to and read from files in binary:

Write:
ofstream file(“foo.txt”, ios::out | ios::binary);
unsigned e =101;
file.write(reinterpret_cast<char*>(&e), sizeof(unsigned));

Read:
ifstream file(“foo.txt”, ios::in | ios::binary);
unsigned e;
file.read(reinterpret_cast<char*>(&e), sizeof(unsigned));

More info:
http://courses.cs.vt.edu/~cs2604/spring06/binio.html
http://www.codersource.net/cpp_file_io_binary.html

Unix/Linux — Bash — String seperator

November 6, 2006 by Rares Vernica

In Bash the default string separator is whitespace which means spaces, tabs, or blank lines. The string separator is used in various places, including when looping with for over a string. The string separator is stored in the IFS variable.

If you want to set the default separator to “:” you need to do:

IFS=:

If you want to set is to newline, you can do it like this:

IFS=$’\x0a’

‘\x0a’ is the hexadecimal notation for newline or Ctrl-J.

A common pattern is to save the old separator before changing and restore it when you are done:

IFS_OLD=$IFS
IFS=:

IFS=$IFS_OLD

or more simple, just unset it when you are done:

IFS=:

unset IFS

Emacs – file coding system

October 11, 2006 by Rares Vernica

In order to change the coding system for a file (i.e., DOS to Unix), you can use:

C-x RET f unix

Unix/Linux – ICS quota

October 11, 2006 by Rares Vernica

To view your quota, use the following command on a Sun OS system:

quota -v

The command will not display the correct information on the Linux systems.

The get the amount of free space on a shared disk, use, for example:

df -h /extra/rvernica0

LaTeX – Customize page numbering

October 4, 2006 by Radu Cornea

For changing the default, centered page numbering, use the fancyhdr package:

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{} % clear all header and footer fields
\fancyfoot[R]{\footnotesize Page \thepage\ of 2}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

This will print the page number on the right side of the footer, smaller font and in the format “Page % of 2″.

Unix/Linux – output the Nth line from a file

October 2, 2006 by Rares Vernica

In order to output the Nth line from a file you can use:

more +N file | head -n 1