Documentation is like sex!

Documentation is like sex.

When it’s good, it’s very good.
When it’s bad, it’s better than nothing.

You might also like:

Batchography: Polyglot Batch files and C++ – Self compiling C++ script

This article is part of the Batchography articles series and today, I am going to show you how to write a valid Batch file that is also a valid C/C++ file. The Batch file part of the source can do anything, however in this article, its sole purpose will be to compile itself and run the compile C++ program.

Let’s get started with the Polyglot source code:

Continue reading

Programming with Emojis

I ran into the EmojiCode website. Emojicode is an open-source, full-blown programming language consisting of emojis.

I personally did not like that language, but it is worthwhile mentioning:

No idea what that code does…I don’t care 😉

Meanwhile, if you are a C++ programmer, enjoy the following, legitimate, piece of code that redefine keywords into emojis and then the fun starts:

You might  also like:

Zipping all files in a Git repository


This is a quick / reference post illustrating how to archive (zip format) all the files in a branch in a Git repository.

From the command prompt, type:

git archive --format=zip -o master


  1. The “–format” argument lets you specify the archive type. I used the zip file format
  2. The “-o” argument lets you specify the output file name
  3. master” is the name of the branch to be archived.


flower separator
batchography-good-resDo you want to master Batch Files programming? Look no further, the Batchography is the right book for you.

Available in print or e-book editions from Amazon.
flower separatorYou might also like:


Futurama: Bender – Robot Grace – or the Geek’s prayer

If you are a fan of Futurama, and Bender the bending robot in particular, you might like this audio clip where Bender says grace before eating:

In the name of all that is good and logical, we give thanks for the chemical energy we are about to absorb. To quote the prophet Jerematic, one zero zero zero one zero one zero one zero one zero one… [Time lapse.] Zero zero one… zero one one zero zero one…two.

You might also like:

strtok() C++ wrapper

In this article, I share with you a simple C++ class that wraps the string tokenization function strtok(). The QuickTokenizer class makes it easy to tokenize and enumerate the tokens in a thread-safe manner.

The class code

class QuickTokenizer
  char *buf;
  char *token;
  char *ctx;

  void FreeBuffers()
    if (this->token != NULL)
      this->token = NULL;
    if (this->buf != NULL)
      this->buf = NULL;

  QuickTokenizer() : buf(NULL), token(NULL)


  const char *Tokenize(
    const char *str,
    const char *tok)

    this->buf = _strdup(str);
    this->token = _strdup(tok);

    return strtok_s(buf, token, &ctx);

  const char *NextToken()
    return strtok_s(NULL, token, &ctx);


Continue reading

Detect executable format using Python

In this article, I am sharing with you a small Python script that lets you detect if a file is an executable file and what platform the executable is targeting.

The following formats for 32 bits and 64bits processors are supported:

  • Mach-O files: both regular and universal formats
  • Windows PE files
  • Linux ELF files

The script

EXEFLAG_NONE        = 0x0000
EXEFLAG_LINUX       = 0x0001
EXEFLAG_WINDOWS     = 0x0002
EXEFLAG_MACOS       = 0x0004
EXEFLAG_32BITS      = 0x0010
EXEFLAG_64BITS      = 0x0020

# Keep signatures sorted by size
    ("\x4D\x5A", EXEFLAG_WINDOWS),
    ("\x7F\x45\x4C\x46\x01", EXEFLAG_LINUX | EXEFLAG_32BITS),
    ("\x7F\x45\x4C\x46\x02", EXEFLAG_LINUX | EXEFLAG_64BITS)

def get_exeflags(filepath):
        with open(filepath, "rb") as f:
            buf = ""
            buf_len = 0
            for sig, flags in _EXE_SIGNATURES:
                sig_len = len(sig)
                if buf_len < sig_len:
                    buf += - buf_len)
                    buf_len = sig_len

                if buf == sig:
                    return flags

    return EXEFLAG_NONE

Continue reading