spass 1.1 – Secure Password Generator

This is a new version of my /dev/random based secure password generator – spass. The new version doesn’t have new features, it’s mainly a bug-fix release. The package now uses autotools, which means it has the standard configure script and makefile. I also fixed some typos in the help message. Overall the new version doesn’t offer anything new compared to the old one, except for easier installation.
Continue reading spass 1.1 – Secure Password Generator

mctext 0.2 – A Markov Chain Text Generator

This is the second release of my Markov Chain text generator – mctext. This text generator takes existing sample text, and generates a new text using Markov Chains.

The main new thing in the version in that it allows the users to specify via the command line how many words should be considered when generating the next one. The bigger the step number the closer the generated text is to the original one. The value used in mctext-0.1 was 2, and this is also the default in this one. The number of steps can be set using the --steps command line switch.
Continue reading mctext 0.2 – A Markov Chain Text Generator

Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

I use Vim as my main IDE for C/C++ related development (as well as for almost all other development). If you use (or thinking about using) vim as as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by the OmniComplete, which is available since Vim 7.0. Just having the OmniComplete is a nice thing, but it’s much more helpful if configured properly to work with the libraries you use, such as wxWidgets. In this post I will show you how to get working the OmniComplete for wxWidgets, however, the procedure I will show can be easily adapted to almost all libraries.
Continue reading Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

C’s “Goes To” Operator

Well it isn’t really an operator but this is a nice C code construct I ran into. It doesn’t seem to have any benefit except as a nice way to create a reverse loop:

int count = 100;
while (count-->0) {
        //some work
}

As I said I don’t think I’ll find any performance benefit for using this code snippet. On the other hand it is always fun to see the puzzled face other programmers have the first time they see the code.

Optimizing for Loops: Reverse Loops

for loops are basic language constructs in many languages. One of the first thing to look at when optimizing code is the loops, as they do considerable amounts of work (like going through a very large amount of data), in very little code.

If you go use for loop, but you don’t really care about the order in which the loop is executed, to be more precise, if you can afford reversing to loop, you can save quite some time. By reversing the loop I mean instead of giving the index values from 0 to 10 for example, you go from 10 downward to zero. This doesn’t seem like a big change, but when being carefully implemented this can easily upgrade the performance of your for loops.
Continue reading Optimizing for Loops: Reverse Loops

The Revised String Iteration Benchmark

In this post I’m going to discuss again the string benchmark I did before to find out what is the fastest way to iterate over an std::string. If you haven’t read the previous post on this subject go a head and read it as it covers the basic idea behind this benchmark. As I did the last time I did the benchmark, I check 5 ways of iteration:
Continue reading The Revised String Iteration Benchmark

Profiling Code Using clock_gettime

After raising the issue of the low resolution problem of the timer provided by clock() in Resolution Problems in clock(), I’ve ended the post by mentioning to two more functions that should provide high-resolution timers suitable for profiling code. In this post I will discuss one of them, clock_gettime().
Continue reading Profiling Code Using clock_gettime

Random – A Random Number Generator Class

After dealing with the seeding of srand(), I’ve realized that rand() just doesn’t give strong enough random numbers for some of my needs (e.g. strong password generator), so I decided to find a better solution. The solution came in the form of Random, a cryptography strong pseudo-random number generator class.
Continue reading Random – A Random Number Generator Class

Resolution Problems in clock()

While playing recently with clock() in order to time the performance of different kinds of code and algorithms, I found an annoying bug. clock() just can’t register work that has taken less than 0.01 seconds. This is pretty unexpected as clock() should return the processor time used by the program. The man page for clock() states:

The clock() function returns an approximation of processor time used by the program.

Continue reading Resolution Problems in clock()

Introduction to C++ CGI – Processing Forms

In this post I will show you how to process HTML forms easily using CGIs in C++. I assume you have already basic knowledge of writing CGIs in C++, if you don’t go a head and read Introduction to C++ CGI.

Processing forms is the basic function of any CGI script and the main purpose of CGIs. As you probably know there are two common ways to send form data back to the web server: “post” and “get”. When form data is sent with the “get” method it is appended to the URL string of the form submission URL. The “post” method is much like the “get” except the data is transmitted via http headers and not via the URL itself. When a form uses “get” it allows the user to easily bookmark the query created by the form as the data is transmitted in URL itself, on the other hand the “post” method allows to send much more data and spares to user from seeing the data in the URL.

Getting the “post” and “get” data is relatively easy. To get the data sent by “get” you can just call getenv("QUERY_STRING") and you will receive a pointer to null-terminated string containing the “get” data. Reading the “post” data is a bit more complicated. The data needs to be read from the standard input, but the program won’t receive an EOF when it reaches the end of the data but instead it should stop reading after reading a specified amount of bytes, which is defined in the environment variable “CONTENT_LENGTH“. So you should read getenv("CONTENT_LENGTH") bytes from the standard input to receive the “post” data.

Continue reading Introduction to C++ CGI – Processing Forms