Thursday, April 28, 2005
script command
You start by typing script filename ( in the absence of filename the default filename is typescript)
The script command ends when you exit the forked shell by typing control-d.
more info on man script ofcourse ;)
Wednesday, April 13, 2005
commandline arguments in perl
$#ARGV is the subscript of the last element of the @ARGV array
Monday, April 11, 2005
latex row height in tabular
\renewcommand\arraystretch{MyValue}% (MyValue=1.0 is for standard spacing)
Thursday, March 17, 2005
Common C++ error
error:return type specification for constructor invalid
This mainly happens when you forget to end the class declaration with a ';'
Thursday, December 09, 2004
gengetopt
If an option is given multiple times
If an option is specified as multiple, then it can be specified multiple times at command line. In this case, say the option is called foo, the generated foo_given field in the args structure contains the number of times it was specified and the generated field foo_arg is an array containing all the values that were specified for this option.
Notice that if a default value is specified for a multiple option, that value is assigned to the option only if no other value is specified on the command line (and the corresponding _given field will be set to 1), i.e., a default value IS NOT always part of the values of a multiple option.
for (i = 0; i < args_info.string_given; ++i)
printf ("passed string: %s\n", args_info.string_arg[i]);
Sunday, December 05, 2004
C++
fs.open(filename.c_str());
The above line attempts to open the file with the given filename (searching in the current directory). Note that open member function takes in a char* argument and not a C++-style string, so you must use c_str to convert it. (Sigh, this is just a weird artifact of the stream libraries being completed before the string library). Opening the file may or may not succeed (depending on whether the named file exists, what permissions it has, etc.), so before you proceed, you should check the state of the stream.
if (fs.fail()) return;
The call to fail checks if the state of the stream is unhappy, in this case, it will determine if the file was properly opened. This is essential before we start trying to output to the stream (in the same way that we check if a FILE* is NULL in C).
Thursday, December 02, 2004
Emacs
M-/ autocompletion. It's based on the tokens in the currently open buffers.
ESC-u change a word into uppercase
ESC-c capitalise a word
C-x C-u upcase region
Sunday, November 28, 2004
GNU Build system
Makefile.am in the top directory should have the subdirs where Makefiles need to be created.
e.g Makefile.am for toplevel
+++++
SUBDIRS = src
+++++
and in the directory "src" you can possibly have the following Makefile.am
++++++++++++++++
bin_PROGRAMS = hello
hello_SOURCES = hello.cpp
++++++++++++++++++
Next you need to have a configure.in in your toplevel directory
following is just a template , read and understand on your own , i have no explanations
++++++++++++++++++
AC_INIT(src/hello.cpp)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(hello, 0.1)
AC_PROG_CXX
AC_PROG_INSTALL
AC_OUTPUT(Makefile src/Makefile)
++++++++++++++++
you are pretty much done with the files at this stage ,
$aclocal
$autoconf
$touch AUTHORS NEWS README ChangeLog
$autoheader
$automake --add-missing
Thursday, October 28, 2004
Installing perl modules
perl -MCPAN -e shell (to get an interactive CPAN shell)
perl -MCPAN -e 'install Time::JulianDay' (if you know the name of the module, you can install it directly without interacting with the CPAN shell)
Within the CPAN shell:
i /expression/ will search for a Perl module containing expression, and
install module will install the module.
Example:
perl -MCPAN -e shell
i /JulianDay/
install Time::JulianDay
Note: if you are behind a firewall, you may wish to use passive FTP with Perl's Net::FTP module. Set the environment variable FTP_PASSIVE 1 (or any non-zero value) to use passive FTP when downloading Perl modules through CPAN.
To manually install a Perl module:
1. Download the Perl module from CPAN or other site.
2. Extract the tarball.
3. Run perl Makefile.PL
4. Run make
5. Run make test
6. Run make install
Tuesday, October 05, 2004
fflush(stdin)
How can I flush pending input so that a user's typeahead isn't read at the next prompt? Will fflush(stdin) work?
fflush is defined only for output streams. Since its definition of ``flush'' is to complete the writing of buffered characters (not to discard them), discarding unread input would not be an analogous meaning for fflush on input streams.
There is no standard way to discard unread characters from a stdio input stream, nor would such a way be sufficient unread characters can also accumulate in other, OS-level input buffers.
References: ANSI Sec. 4.9.5.2
ISO Sec. 7.9.5.2
H&S Sec. 15.2
dired to open new directories in same buffer
Pasting the entire mail
- To: X@XXXXXX.XXX
- Subject: reusing dired buffer
- From: samuel padgett <XXXXXXX@XXX.XXX>
- Date: Thu, 29 Jun 2000 01:34:58 -0400
- Message-ID: <20000629013458.B2915@durham4-099.dsl.gtei.net>
Recently, there was some discussion in the comp.emacs newsgroup
regarding dired and the way `dired-find-file' handles directories.
`dired-find-file' will always create a new buffer for each directory.
If you work in many directories, these dired buffers can accumulate
and quickly become unwieldy.
The original post asked for a way to reuse the same dired buffer when
changing directories. Someone suggested using 'i',
`dired-maybe-insert-subdir', instead of 'RET'. This isn't ideal,
however, because it simply inserts the contents of the subdirectory
into the current dired buffer and doesn't remove the old directory's
contents. It also forces users to use two different keys to navigate
through directories and select files, 'i' and 'RET', instead of just
being able to use 'RET'.
I would really like to have the new directory contents replace the old
in a dired buffer. If my cursor is positioned over a file, however, I
want dired to do the normal thing: open the file in a new buffer.
This seems to me like the most intuitive behavior. I hacked out some
lisp code that does this:
(defun dired-follow-file ()
"In dired, visit the file or directory on this line.
If a directory is on the current line, replace the current
dired buffer with one containing the contents of the directory.
Otherwise, invoke `dired-find-file' on the file."
(interactive)
(let ((filename (dired-get-filename)))
;; if the file is a directory, replace the buffer with the
;; directory's contents
(if (file-directory-p filename)
(find-alternate-file filename)
;; otherwise simply perform a normal `dired-find-file'
(dired-find-file))))
Now, I simply need to remap the dired keys
(add-hook
'dired-mode-hook
(lambda ()
(local-set-key "\C-m" 'dired-follow-file)
(local-set-key "e" 'dired-follow-file)
(local-set-key "f" 'dired-follow-file)))
and (abracadabra) dired replaces the old directory with the new one in
the same buffer when I press 'RET'. (Note that it's always easy to
get back to the parent directory because you can just select '..' in
the new directory listing.)
I posted this lisp snippet to comp.emacs and was asked to also send it
toand . Here it
is. I hope this is helpful.
Regards,
Samuel Padgett
Friday, September 24, 2004
Thursday, September 23, 2004
perl error
-- you get this error when you try to initialize a hash like below
%hash_name = {};
from http://linux.about.com/library/cmd/blcmdl1_perl5005delta.htm
Reference found where even-sized list expected
You gave a single reference where Perl was expecting a list with an
even number of elements (for assignment to a hash). This usually means
that you used the anon hash constructor when you meant to use parens.
In any case, a hash requires key/value pairs.
%hash = { one => 1, two => 2, }; # WRONG
%hash = [ qw/ an anon array / ]; # WRONG
%hash = ( one => 1, two => 2, ); # right
%hash = qw( one 1 two 2 ); # also fine
Curly brackets are used to construct anonymous hashes. Their result is
a reference to that hash. So with %f = {} you're trying to assign a
reference (one item) to a hash. However, hashes are initialized with
lists which must have an even number of elements. Hence the warning.
The proper way to initialize an empty hash is with an empty list, which
is why %f = () works.
Tuesday, September 21, 2004
scanf
>>I'm having a problem using scanf. After I enter the username, the following scanf reads the "enter" I clicked. What should I do?
Instead of writing scanf("%c") you can write scanf(" %c") (with a space before %c), and it should work better. The space before the "%c" will read all white spaces (newline, tab and space) and the first non-white space will be read into the "%c". Using the scanf this way will prevent the scanf from reading the "ente