Code Blog


In this section I collected some small programming projects that I have developed over the recent years, some are work-related but the most are just for fun.


Cellular Automaton

A cellular automaton (Wikipedia) is a two-dimensional, artificial space with physical laws which can be individually defined. A configuration which is set at the start develops in discrete and deterministic steps based on local interactions. Some configurations can move through space, reproduce or get trapped in infinite loops. Feel free to play around with different "natural laws" and draw your own starting configurations in the Cellular Automaton App.

Screenshot of Cellular Automaton


MP3 Tagger V1.2

A small app to remove or add ID3 tags to Mp3 files based on their file names.
With this tool you can easily remove all ID3 tags from an entire folder of Mp3 files and its subdirectories. Also, ID3 tags can be added based on the file names. Example: If all your files are named in the format "Artist - Title.mp3", these values can be automatically added as ID3 tags.

Screenshot of Mp3 Tagger

Credits: MP3 Tagger uses UltraID3Lib, an MP3 ID3 Tag Editor and MPEG Info Reader Library, copyright 2002 - 2010 Hundred Miles Software (Mitchell S. Honnert)


Memory V2

Version 2 of the browser-based Memory game I implemented earlier (see below in the code blog). This version has many improvements such as more card pairs, two player modes (single and multi) and a clock that records the time needed to find all pairs. On the code level, it makes use of many of the new ECMAScript 6 features.
As it only requires the jQuery library to run, it can be also downloaded and played offline on a PC, tablet or smartphone.

Screenshot of Memory


2D Color Graphs

I used the Bitmap object of the .NET framework to draw some 2D graphs with C#. The RGB color codes for every pixel are calculated by formulas that take the current x and y value as input. For example, the red component of a pixel could be calculated by r = x % 255.
By using a variety of different formulas, some very nice images could be created.

This is the core of the program code. Note that a Form must be available with a PictureBox (name = "pictureBox") on it:

´╗┐using System;
using System.Drawing;
using System.Windows.Forms;

namespace ImageProcessor
{
    public partial class FormMain : Form
    {
        Bitmap bm;

        public FormMain()
        {
            InitializeComponent();
        }

        private void FormMain_Load(object sender, EventArgs e)
        {
            bm = new Bitmap(pictureBox.Width, pictureBox.Height);
            int r, g, b = 0;
            for (int x = 0; x < bm.Width; x++)
            {
                for (int y = 0; y < bm.Height; y++)
                {
                    r = x % 255;         // Calculate red component
                    g = y % 255;         // Calculate green component
                    b = (x + y) % 255;   // Calculate blue component
                    bm.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            pictureBox.Image = bm;
        }
    }
}

Rot13

Rot13 is a simple method for encryption and decryption of texts which became mostly popular for its usage with Geo Caching. Here, hints for the location of a cache are oftentimes encrypted using Rot13, meaning that the position of a letter in the alphabet is shifted by 13 positions. Example: Position 1 in the alphabet is an A, shifted by 13 positions it becomes an N. So the word "above" becomes "nobir".
The Rot13 app is also optimized for smartphone usage.


PDF Splitter

A program to save all pages of a PDF document as individual PDF files. Texts from the contents of the pages can be used to name to result files (certain text lines can be used as variables to build the file names).

Credits: PDF Splitter uses PDFsharp, a .NET library for processing PDF.

Screenshot of PDF Splitter


7Bum

Basically a drinking game where a group of people counts from 1 onwards. Whenever a number includes the figure 7, can be divided by 7, is a repdigit, or its sum of digits is 7, the player has to shout "Bum!". If he misses to do so, he is penalized accordingly.
Find the 7bum app here.


Python Spaceship Game

A space game I implemented to get to know turtle graphics in Python. A ship is to be navigated to collide with all the asteroids flying through space in order to collect them (implementation of shooting is next on my todo list).
The spaceship is represented as a grey triangle. Use up and down keys to accelerate and decelerate, resprectively. Left and right key will change the flight direction.
Start the game by using the python game.py command.

Screenshot of Spaceship Game


Powerful PDB Web Viewer Using 3Dmol.js

Example of how to use the freely available JavaScript library 3Dmol.js to build a tailored web viewer of PDB structures. The library also allows loading other molecular file formats and creating user-defined objects.

Screenshot of PDB web viewer


Accessing PDB Header Information With Python

This code example demonstrates how PDB header information can be retrieved without importing any additional modules such as Biopython etc. The headers for the PDB codes 1atp, 3k2h, 5e8s and 4usk are downloaded and, subsequently, the title is being searched for the word "kinase". If the keyword is found, the PDB code and its corresponding title are printed.

import sys
import urllib

def get_pdb_header(pdbcode):
    f = urllib.urlopen("http://files.rcsb.org/header/" + pdbcode.upper() + ".pdb")
    lines = f.read().split("\n")
    return lines
    
def get_title_from_pdb(pdbfile):
    title = ""
    firstLine = True
    for line in pdbfile:
        if line.startswith("TITLE    "):
            add = line[9:]
            add = add.strip()
            if not firstLine:
                add = add[1:]   # remove title line number
            title += add
            firstLine = False
    return title

pdbcodes = [ "1atp", "3k2h", "5e8s", "4usk" ]    

for pdb in pdbcodes:
    pdbfile = get_pdb_header(pdb)
    title = get_title_from_pdb(pdbfile)
    
    # scan title for keywords:
    if "KINASE" in title:
        print pdb + " : " + title

Using Python's Argument Parser

By using the argparse module of Python it is very easy to create command line tools that require several arguments. This example demonstrates the usage of optional, required and multiple arguments. Note that a help text is automatically shown whenever the script is called with the option -h or not enough arguments are given.

import argparse

def get_args():
    parser = argparse.ArgumentParser(description='brief description of this script.')
    parser.add_argument(
        '-s', '--system', choices=['Windows', 'Linux'], default='Windows',
        help='Operating system to generate the output for'
    )
    parser.add_argument(
        '-f', '--file', nargs='+',
        help='Name of the file(s) to processed',
        required=True
    )
    parser.add_argument(
        '-d', '--directory',
        help='Optional name of output directory'
    )
    return parser.parse_args()

args = get_args()
print 'Going to process file(s) ' + args.file + ' for OS ' + args.system
# Do your actual work here ...

Memory Browser Game

A browser-based implementation of the game "Memory" using the JavaScript library jQuery. The game also provides time measurement for finding all pairs as well as a highscore list.

Screenshot of Memory



Last update: 2020-04-24