Archive for the ‘Linux’ Category

h1

Simple guide to basic Doxygen usage

July 20, 2008

This is a simple guide to basic use of Doxygen-compliant commenting of source code. The guide is written from my point - C/C++ - but it’s valid for all supported languages, except of Python. See Doxygen documentation for use for Python. Doxygen is very flexible when it comes to the form of how the documentation is written, the layout presented here is simply my preference.

Read the rest of this entry ?

h1

How to create table in MSSQL only if it does not exist

March 1, 2008

Often you wanna make sure some tables in database exist, but you want to avoid getting the error message “There is already an object named ‘yourtable’ in the database.”, that you would get by simply issuing the CREATE TABLE command.

For these cases, MSSQL offers keyword EXISTS (most SQL engines provide similar facilities; e.g. MySQL C API allows you to directly check for the existance of database and/or table).

All you have to do in MSSQL is make sure the table is not yet registered in the sysobjects table, using the following SQL command:

IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N’[dbo].[tablename]‘)
AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
CREATE TABLE [dbo].[tablename] ( columns specification );

where “tablename” is name of table you want to create, and “columns specification” is the usual definition of table’s columns. Feel free to extend the table definition to your liking.

Or you might want to DROP the table before re-creating it:

IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N’[dbo].[tablename]‘)
AND OBJECTPROPERTY(id, N’IsUserTable’) = 1)
DROP TABLE [dbo].[tablename];
CREATE TABLE [dbo].[tablename] ( columns specification );

Yes, that’s all. Good luck!

h1

Get rid of page number on 1st page of ToC in LaTeX!

February 28, 2008

LaTeX, or more generally TeX, is undoubtly the best typesetting tool available, and what’s more, it’s for free (for Windows users - check out MiKTeX!). Yet, there are few things that should work in a certain “obvious” way, yet they don’t (fortunately, there’s very few of them).

One of them is quite a surprising thing - pagestyle{empty} command does not affect first page of the table of contents. Yet, all the other pages of ToC it does! The same holds for list of figures and list of tables.
This is quite an annoyance, especially if you put ToC at the beginning of the document, and want to have all the pages, before the real contents starts, without the page numbering.

So, how to get rid of the page number on the first page of table of contents in LaTeX? You have to dig into the header and footer setting for this.

First thing is to use fancyhdr package - put usepackage{fancyhdr} command anywhere before the begin{document}.

Second, right before issuing the tableofcontents command, redefine the “plain page style” to an empty one, like this:

fancypagestyle{plain}
{
    fancyhead{}
    fancyfoot{}
}	% clear header and footer of plain page because of ToC

And after the ToC, just get back to the “classical” plain page style (this is important - even if you use your “fancy” page style, each page containing first page of chapter is “plain”, unless you redefine this behaviour), like this:

fancypagestyle{plain}
{
    fancyhead{}
    fancyfoot[C]{thepage}
}	% re-define plain page after the ToC

This block has to be “on a new page” - either after you issue newpage or cleardoublepage command, or after your first chapter{…} command.

h1

File and folder access management in Apache

February 11, 2008

Restricting to localhost Access Only

To restrict access globally, all you have to do is to restrict access in httpd.conf in Apache’s conf directory.

First, locate the Directory settings for your htdocs directory (under Windows it’s e.g. C:/Apache2/htdocs, C:/Program Files/xampp/htdocs, etc., under Linux it’s e.g. /usr/htdocs, /usr/local/htdocs, /usr/local/www/htdocs, /usr/share/htdocs, etc.).

Then, you have to edit the Order subsection as follows (comments left out for readability):

<Directory "htdocs_path">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All</directory>

Order deny,allow
Deny from all
Allow from localhost
</Directory>

Note: Order of the Deny and Allow lines is important! - just guessing, but I think that Apache simply applies the rules one after another, and the output of last rule that applies to the IP is used.

It can be also sometimes useful to disallow overrides of settings; if needed, simply change AllowOverride All to AllowOverride None, to disallow override of settings using .htaccess files.

See Apache documentation for complete list of options; just like with Options, it’s recommended to list the settings explicitely in AllowOverride to know what exactly is allowed.

Restricting Access to Certain Files

Great example of how to do this is contained in the httpd.conf itself, but many people seem to somehow miss it there, so here it is:

# The following lines prevent .htaccess and .htpasswd files
# from being viewed by Web clients.
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>

Of course, don’t forget to restart Apache after each edit of httpd.conf file, so it reloads the settings. Good luck!

h1

Network patch for Linux systems under VMWare

February 10, 2008

If you’re experiencing problems with networking under Linux in VMWare (e.g. loosing connection after switching out and back in the virtual machine, after Pause-Resume, or after your host (A)DSL connection “restarts”), try the following simple patch (tested on FC4 and Ubuntu; you can always simply revert the changes to get to where you were).

Read the rest of this entry ?

h1

How to install VMWare Tools on Ubuntu/Debian

February 9, 2008

VMWare Tools are ready-to-install or ready-to-compile on most of the supported guest systems; on Ubuntu/Debian, you have to do a bit more to be able to compile them, since the system doesn’t come with necessary headers and tools.

Read the rest of this entry ?