Optimizing for Loops: Reverse Loops

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

If you use a 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 the loop – you can save quite some time. By reversing the loop, I mean that 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 carefully implemented, this can easily improve the performance of your for loops.
Continue reading Optimizing for Loops: Reverse Loops

Creating a Local SVN Repository (Home Repository)

In this tutorial, I will explain how to create a local Subversion (SVN) repository intended for a single user. I assume that you already know the benefits of keeping track of old revisions of projects or important documents such as a resume or a thesis you have been writing. Subversion offers you a very convenient yet powerful method to do so, and the easiest way to do so with Subversion (SVN) is to create a local home repository intended for a single user – you.
Continue reading Creating a Local SVN Repository (Home Repository)

spass – A Secure Password Generator Utility

spass is a secure password generation tool. spass was designed under the assumption that a password generator is only as good as its random number generator, so spass uses the Random class, a /dev/random-based cryptographically strong random number generator class. As always, I tried to make the command-line interface as user-friendly as possible (as much as a command-line interface can be friendly).
Continue reading spass – A Secure Password Generator Utility

Conditional Expressions in Python 2.4

Python 2.5 introduced a new syntax structure: conditional expressions. For programmers in languages such as C, these structures seem very basic and fundamental, but Python lacked them for many years. As I said, Python 2.5 introduced such a syntax structure; one may use it in the following form:

x =  a if condition else b

As you probably guessed, a is assigned to x if condition evaluates to true, and b is assigned otherwise. This is pretty much equivalent to the C conditional expression. But as I said, this structure was only introduced in 2.5. Previous versions of Python are still widely deployed and in use, so how do you achieve the same thing in older versions of Python?
Continue reading Conditional Expressions in Python 2.4

ssh-keygen Tutorial – Generating RSA and DSA Keys

In this post I will walk you through generating RSA and DSA keys using ssh-keygen. Public key authentication for SSH sessions is far superior to password authentication and provides much higher security. ssh-keygen is the basic way to generate keys for this kind of authentication. I will also explain how to maintain those keys by changing their associated comments and, more importantly, by changing the passphrases using this handy utility.
Continue reading ssh-keygen Tutorial – Generating RSA and DSA Keys

radio.py-0.4 – Listening to Radio the Easy Way

Update: radio.py 0.5 is available.

radio.py is a little script that makes it very easy to listen to radio under Linux (and maybe other OSs too) with mplayer. All you need to do is call radio.py with the name of the station you want to listen to. For example:

radio.py Radio Paradise
or
radio.py BBC3
To read more about radio.py, go to the first post discussing radio.py.

What’s New

Here are some of the things that have changed in radio.py-0.4 compared to the previous release (0.3). Continue reading radio.py-0.4 – Listening to Radio the Easy Way

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 ahead and read it, as it covers the basic idea behind this benchmark. As I did the last time I ran the benchmark, I checked 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 ended the post by mentioning 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 generate random numbers that are strong enough for some of my needs (e.g. a strong password generator), so I decided to find a better solution. The solution came in the form of Random, a cryptographically strong pseudo-random number generator class.
Continue reading Random – A Random Number Generator Class

Resolution Problems in clock()

While recently playing 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()