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

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:

}	% 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:

}	% 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.

File and folder access management in Apache

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

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

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

Windows XP Customization

Most of the following customizations work on Win2K also, but I’m not anymore sure which do and which don’t.

Enable-Disable Task Manager

Key: Software\ Microsoft\ Windows\ CurrentVersion\ Policies\ System
Name: DisableTaskMgr
Value: 1 = Enable this key, that is DISABLE Task Manager
Value: 0 = Disable this key, that is Don’t Disable = ENABLE Task Manager

Customization of Start Menu

Continue reading

Simple Add-On Wait Dialog in MFC

Despite the prediction of fast end of MFC due to release of .NET framework, it seems MFC is not about to leave us anytime soon. Personally, in many cases, I prefer it to .NET.

Some time ago I found this jewel I’d like to share with you. The original article has been posted by Jeff Prosise, in Microsoft Systems Journal, February 1997 – Vol 12 No 2, article Wicked Code.
If you wanna know about all the magic hidden behind the code, read the article.

Unfortunately, the article is not any much clear about how to make it all work, so I decided to write this.

Continue reading

BZip2 – Gotta Love It :)

I’ve never been much of a friend of commercials and recommendations, but there simply are stuff that have to be recommended.

Like Woody Allen’s 1975 movie “Love and Death“. 😀

Or like BZip2.

It’s free, it’s even patent free, it’s great, it’s almost unused in Windows world… Why? I have really no idea. The compression ratio is typically twice as good as that of zip. The only “down-side” is, that it can store only 1 file per archive… But then again, there’s tar to take care of this, and e.g. total commander can handle both pretty well.

But that’s not what I wanted to talk about. Yes, I wanted to talk to all you geeks who love programming just as much as I do – about the bzip2 API. And what’s more – it also has a nice documentation! Wow, yes!

I used to use many different compression formats throughout my programming carrier – zip, rar, lzo, minilzo, arithmetic, freearc, … – but never I used library so simple to learn and use. Plus, again, that has such a good ratio at reasonable speed and memory requirements (of course, if you want the best, there’s always PAQ in flavour of your choice, but who can afford to wait 10 hours for 1 file to be compressed?).

But enough talking, more coding. As an example, here’s how to do file-to-file compression (leave out error handling and comments, and whole code is 18 lines long, including declarations, etc.):

bool PackFile(const char* file_name)
    // open the input file
    FILE* file = fopen(file_name, "rb");
    if (0 == file)
        return false;

    // open the output file
    std::string out_file_name = file_name;
    out_file_name += ".bz2";
    FILE* out_file = fopen(out_file_name.c_str(), "wb");
    if (0 == out_file)
        return false;

    int bz2error;
    BZFILE* out_bz2 = BZ2_bzWriteOpen(&bz2error, out_file, 9, 0, 0);
    if (BZ_OK != bz2error)
        return false;

    // load file data into buffer, and store them to bzip2-out stream
    char buffer[1024];
    uint loaded_len;
    while ((loaded_len = fread(buffer, 1, 1024, file)) > 0)
        BZ2_bzWrite(&bz2error, out_bz2, buffer, loaded_len);
        if (BZ_OK != bz2error)
            BZ2_bzWriteClose(&bz2error, out_bz2, 1, 0, 0);
            return false;

    // close in file

    // close out bzip2 stream and the file
    uint total_in, total_cmp;   // how many bytes we read, and resulting compressed size
    BZ2_bzWriteClose(&bz2error, out_bz2, 0, &total_in, &total_cmp);

    return true;

Sending e-mail using pure WinSock

I’ve spend quite a bit of time these days searching for a simple way to send email from C++.

There sure is a lot of stuff on this on the Net, but there was one trouble – the program I’m writting is an NT service. Thus, all those MAPI-based solutions didn’t work for me (there are simply too many small things you have to take care of, that disable simple installation of software).

So, I just looked up “SMTP” on Wikipedia, and believe it or not, it was enough. I just wrote the whole thing as a pure plain-text communication with SMTP server, at it worked at first shot, haha!

Continue reading

Tips on ICS on Windows XP

If you’re not in mood to read all I have to say, and want just simple plain tips, feel free to skip to the end of post. 🙂

About a month ago, I was trying to set-up ICS (Internet Connection Sharing) between my computer and my wife’s laptop.

There sure are many guides on the Net about how to set all up, and what to do or not to do. Unfortunately, many of them are contradicting each other (or sometimes even themselves, haha!).

All I needed to set up was the ICS itself, no disk/file/printer sharing. Thus, most of stuff that follows won’t be useful for anyone who needs also any other kind of sharing, except of the connection to the internet. To be precise, switching off all other kinds of sharing helped me to achieve much higher stability of service.

Continue reading