A Simple Markov Chain Text Generator Example Implementation

There are plenty of articles describing what a Markov Chain is, so I won’t delve into the details there, but few actually show how to implement one. So this article will focus on a simple implementation of a Markov Chain text generator with a configurable block length. Example texts available as sample on this page is an excerpt of “Alice in Wonderland”. It is included as hidden PRE tag in the HTML below.

Overview

A Markov Chain text generator generates pseudo random text that, based on a certain block size, can produce natural looking text. For example, the letter “A” in English is followed by other letters with a certain probability. So, if the last letter printed was “A”, the generator will choose a random letter to follow it, but the randomness is weighted by previously analyzed text. If you have a larger block size, say three, the letters “Mar” are followed by three more letters with some other probability. For instance, if this article were analyzed, the generator would likely choose “kov” as the next three characters producing the word “Markov”. We will refer to these letters, or sequences of letters as nodes. It should be obvious that the longer the sequence used for nodes, the more natural looking the next will be, but also more memory will be used.

Implementation Steps

I’ll break the implementation down into a few steps as follows:

  • Choosing a block size.
  • Specifying the text.
  • Breaking the text into blocks.
  • Creating a list of transitions from one block to another.
  • Choosing a random starting node for the generation of text.
  • Choosing a weighted node to follow the current node.
  • Repeating the previous step as many times as desired.

Storing Node Weights and Selected Weighted Random Values

Two of the hardest problems are defining a method of storing the weights for the transitions between the nodes, and also selecting the next node based on those weights. We can solve both problems at the same time rather simply. To start, all of the nodes will be stored as an associative array, with the characters of the node serving as the index. Each element in that array will also be an array which contains all of the nodes which follow the initial node, including repeats. For example, the entry for the node “ah” is below (based on “Alice in Wonderland”):

nodes["ah"] = ["’l", " w", " m", ", ", ", ", ": ", " h", ", ", "’s", "!”", "! ", "’l", " s", " a", ", ", " o", " o", " i", " o"]

As you can see, the node “ah” is most often followed by a comma and a space, next most often is a space and the letter “o”. By storing the data this way we don’t have to compute weights individually at all, and selecting a weighted node is as simple as choosing a random value from the array. The downside is that it will use more memory than if we just stored the weights.

Block Size and Text

We’ll assume we have a class that implements the Markov Chain text generator. We can pass in both the text and the desired block size to its constructor:

function generateMarkovText(){
    const c=new MarkovChainTextGenerator(document.getElementById("aliceinwonderlandfull").innerHTML,2);
    document.getElementById("output").textContent=c.generateText(1000);
}

Analyzing the Text

constructor(text,blockSize) {
    this.nodes=new Array();
    this.buildChain(text,blockSize);
}

buildChain(text,blockSize){
    for(let i=blockSize;i<text.length-blockSize+1;i++){
        const last=text.substring(i-blockSize,i);
        const next=text.substring(i,i+blockSize);
        this.addTransition(last,next);
    }
}

addTransition(last,next,chain){
    if(this.nodes[last]==undefined){
        this.nodes[last]=new Array();
    }
    this.nodes[last][this.nodes[last].length]=next;
}

The constructor accepts the text to analyze and the block size as parameters, then hands that off to the buildChain() method. The buildChain() method just breaks all of the text up into it’s different blocks, and calls addTransition(). And the addTransition() method just checks to see if the node already exists, creating an empty array if it doesn’t, then appends the new node to the array.

The Text Generator

That handles everything for generating the actual Markov Chain. Next step is to actually use the chain to produce some random text.

First, we’ll choose a node at random to start with using chooseRandomNode(). Next we’ll choose a random value between 0 and the length of the array for the current node, append that to the text we’re generating, and just keep looping until we have all the text we want.

Dead Ends

It’s possible that there will be a node which is a dead end, meaning it has zero probability of transitioning to another node. What this really means is you’ve reached the end of the text. For example, the “Alice in Wonderland” text ends with “THE END”, which appears nowhere else in the text. So, for a node size of 7, there will be no node following it. There are multiple ways of handling this situation, for our purposes we will just choose another random node to start with and continue on. This is what the check for undefined in the generateText() method is for.

The completed class is as follows:

class MarkovChainTextGenerator{
    constructor(text,blockSize) {
        this.nodes=new Array();
        this.buildChain(text,blockSize);
    }

    buildChain(text,blockSize){
        for(let i=blockSize;i<text.length-blockSize+1;i++){
            const last=text.substring(i-blockSize,i);
            const next=text.substring(i,i+blockSize);
            this.addTransition(last,next);
        }
    }

    addTransition(last,next,chain){
        if(this.nodes[last]==undefined){
            this.nodes[last]=new Array();
        }
        this.nodes[last][this.nodes[last].length]=next;
    }

    chooseRandomNode(){
        const values=Object.values(this.nodes);
        return values[Math.floor(values.length*Math.random())][0];
    }

    generateText(textLength){
        let currentNode=this.chooseRandomNode();
        let text=currentNode;

        for(let i=0;i<textLength;i++){
            if(this.nodes[currentNode]==undefined){
                currentNode=this.chooseRandomNode();
            }
            const nextIndex=Math.floor(this.nodes[currentNode].length*Math.random());
            currentNode=this.nodes[currentNode][nextIndex];

            text=text+currentNode;
        }
        return text;
    }
}

Try It!!!

Node Size:
Generated text will appear here

Setting Manual Exposure in OpenCV

In OpenCV, you can set the exposure for your camera manually by using the VideoCapture::set method. What isn’t obvious is what value to pass in for it. I have experimented with various webcams and the below settings seem to be accurate enough. Not all cameras allow setting the exposure programatically, so if the code below doesn’t work, you might try a different camera, or experiment with different values. Once you’ve set a value manually, I haven’t found a way to switch back to auto-exposure without restarting the camera.

Below is an example of using this setting in Python

import cv2

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_EXPOSURE,-4)

while(True):
    ret, frame = cap.read()

    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Estimated exposure settings from Joan Charmant’s ‘Review of the ELP-USBFHD01M camera’

CAP_PROP_EXPOSURE Exposure Time
-1 640 ms
-2 320 ms
-3 160 ms
-4 80 ms
-5 40 ms
-6 20 ms
-7 10 ms
-8 5 ms
-9 2.5 ms
-10 1.25 ms
-11 650 µs
-12 312 µs
-13 150 µs

Android: Simple Example of Page Transition Using ViewPager

The ViewPager class built in to the Android SDK is a simple method of showing an animated transition between two views. For example, turning a page, or a calendar scrolling through months. This functionality can be added with only a few lines of code. Below I present an example containing pretty much the bare minimum of code and markup required to get a ViewPager up and running.

The steps are fairly straight foreward:

  • Edit your Activity’s layout to include a “ViewPager”. As in activity_main.xml below.
  • Define the layout for your “pages”. This will be a new .xml file containing a layout just like you define for an activity (pageritemview.xml below).
  • Create a new PagerAdapter class (e.g. ViewPagerAdapter below) which implements the display of your layout. There are a handful of methods you must override, but the bulk of the work is done in “instantiateItem()”.
  • In your activity’s “onCreate()” method, initialize the viewPager.

One likely question after getting this to work is “Can a ViewPager allow infinite scrolling?”. The simple answer is “No”. But there are some workarounds. There are a few people who have implemented their own ViewPager class modifications, but I haven’t used any of them, so cannot recommend any. The more common workaround is to return a count far higher than a user is likely to ever scroll (e.g. 10,000), and then in your Activity’s onCreate() method call the ViewPager’s setCurrentItem() method to set the current item to be the middle.

Below, I have chosen to just display the current position as a string for a simple example. In reality, you would use the position as an index into an array or a database to look up the information you want to display for a specific item.

MainActivity.java:

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


class ViewPagerAdapter extends PagerAdapter {
    Context context;
    LayoutInflater inflater;

    public ViewPagerAdapter(Context context) {
        this.context=context;
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = inflater.inflate(R.layout.pageritemview, container,
                false);

        /*
        Just as an example, we just display the current position as text.  In reality
         you would use the "position" variable to look up the current item to display
         in an array or a database.
         */
        ((TextView)itemView.findViewById(R.id.someText)).setText(Integer.toString(position));
        container.addView(itemView);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
    }

}

public class MainActivity extends Activity {
    ViewPager viewPager;
    PagerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager = (ViewPager) findViewById(R.id.pager);
        adapter = new ViewPagerAdapter(MainActivity.this);
        viewPager.setAdapter(adapter);
    }
}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:orientation="vertical"
    >

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>

pageritemview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/someText"
        android:textSize="50dp"
        android:gravity="center"
        />

</LinearLayout>

A Quick Snippet for Drawing Images in Java

Java does not have the best built-in tools in the world for drawing images, but it’s still useful for many purposes. Below is just a snippet on getting started drawing in Java. For more information on what’s available see the Java Graphics class reference.

BufferedImage i = new BufferedImage(500, 500,BufferedImage.TYPE_INT_RGB);
Graphics g=i.createGraphics();
g.setColor(Color.BLUE);
g.drawLine(0, 0, 500, 500);
g.drawString("This is a test", 20,20);
ImageIO.write(i,"jpg",new File("test.jpg");

A basic 3d to 2d projection

Developing an actual 3D engine is an incredible amount of work, and including a 3D library in your project can add a considerable amount of bloat to your project. Fortunately you can implement some very simple 3D projections in just a couple of lines of code, and they are not computationally intensive. There are limitations on using this particular method though:

  • This can draw wire frames only.
  • You need all of the coordinates of your “world” to be centered horizontally and vertically relative to your screen (or you need to convert them to be that way).
  • All of the lines must fit on the screen (e.g. you can’t have the edge of an object partially off-screen)

The basic algorithm is incredibly simple. For each given point (x,y,z) in your 3D model, you convert it to 2D screen coordinates (x’,y’) by the following equations:

x'=d*x/z
y'=d*y/z

Where (x,y,z) are the points in your 3D world, (x’,y’) are the x,y coordinates from the center of your screen. And d is the focal length of the camera (or scaling factor), if you’re not sure what to use you can get good results just by experimenting.

Below is C# code to demonstrate this concept. Notice that most of the code is for manipulating, offsetting, and scaling the box, the actual code projecting to 2D is only two lines.

        protected override void OnPaint(PaintEventArgs e) 
        {
            float[]  box = {
                            -1,-1,0,
                            1,-1,0,
                            1,1,0,
                            -1,1,0,
                            -1,-1,0,
                            -1,-1,2,
                            1,-1,2,
                            1,-1,0,
                            1,-1,2,
                            1,1,2,
                            1,1,0,
                            1,1,2,
                            -1,1,2,
                            -1,1,0,
                            -1,1,2,
                            -1,-1,2
                         };
            base.OnPaint(e);

            float scale = .2f;
            for (int x = 0; x < box.Length; x++) box[x] *= scale;

            for (int j = 0; j < 10; j++)
            {
                for (int k = 0; k < 10; k++)
                {
                    float zoffset = 10f;
                    float xoffset = 1f*(j-5);
                    float yoffset = 1f*(k-5);

                    float d = 500;
                    float lastX = d * (box[0] + xoffset) / (box[2] + zoffset);
                    float lastY = d * (box[1] + yoffset) / (box[2] + zoffset);

                    Pen p = new Pen(new SolidBrush(ForeColor));
                    int i = 3;
                    while (i < box.Length)
                    {
                        float x = d * (box[i + 0] + xoffset) / (box[i + 2] + zoffset);
                        float y = d * (box[i + 1] + yoffset) / (box[i + 2] + zoffset);
                        e.Graphics.DrawLine(p, translate(new PointF(lastX, lastY)), translate(new PointF(x, y)));
                        lastX = x;
                        lastY = y;

                        i += 3;
                    }
                }
            }
            

        }

        private PointF translate(PointF p)
        {
            PointF f = new PointF(p.X+this.Width/2, p.Y+this.Height/2);
            return f;
        }
    }

3D Projection example

This is a very useful technique for drawing diagrams and simple objects, and can be a starting point for adding more features like rotation, or solids.

Android: Accessing other views from inside a custom view using findViewById().

If you attempt to call findViewById() on the ID of a view that is not from the Activity that holds the view, findViewById() returns null. I’ve seen a lot of solutions posted for attempting to access a View from outside the activity that created it. Most of them involve inflating the original view and going from there. I can’t speak to whether or not that actually works (I do not believe they will), but I can offer an alternative, more attractive solution.

For this option, you will need a reference to the activity that holds the view you want to modify, this is usually given to you in the form of a Context object passed into your constructor. You can save that context in a member variable, and from there call context.findViewById(), which will return the view you want.

public class SomeClass extends View{
     Context context;
     ...

     public SomeClass(Context context, AttributeSet attrSet){
          super(context,attrSet);
          this.context=context;
          ...
     }

     public void someFunction(){
          TextView t=(TextView)context.findViewById(R.id.someTextView);
          ...
     }
}

In many cases, it will be preferable to not access the View directly, and instead add a public function to the Activity that actually holds the view. This way many other classes will be able to access the same function, which is very often necessary. Then, in order to access that function, you cast the Context to the Activity Class that holds the view:

public class SomeClass extends View{
     Context context;
     ...

     public SomeClass(Context context, AttributeSet attrSet){
          super(context,attrSet);
          this.context=context;
          ...
     }

     public void someFunction(){
          ((MyActivity)context).manipulateSomeViews();
          ...
     }
}

I would say the second example is a much more elegant solution as it keeps the logic controlling a View inside the class that holds it. But, as with everything, you’ll likely find many exceptions.

Why you should return “this” from your setter methods.

Fortunately most API designers know to use this technique, but it’s still pretty common to find some that do not. It’s generally good practice, that when writing a setter method for a class, that you return the object’s “this” rather than “void”. The reason is that it allows a user of your class to chain together setter methods and save some typing and screen space. For example:

SomeObject o=new SomeObject().setTextSize(5).setBackgroundColor(Color.BLUE).setSomeOtherProperty(true);

The alternative would look like:

SomeObject o=new SomeObject();
o.setTextSize(5);
o.setBackgroundColor(Color.BLUE);
o.setSomeOtherProperty(true);

The first example is much more concise and uses up much less screen real estate for someone reading the code, and also requires less typing. Granted the second example is much easier to read. But you should leave it up to the developer to determine which style they want to use.

In order to enable such a feature, all you need to do is return “this” from your class’ setter methods. For example:

public SomeObject setTextSize(Integer textSize){
     this.textSize=textSize

     return this;
}

Since almost all setter methods do not return a value, this can easily be added to a class.

An alternative in some situations, is where the developer is likely to want the old value (usually because they want to restore it when they’re done). For example:

public Integer setTextSize(Integer textSize){
     Integer temp=this.textSize;
     this.textSize=textSize;
     return temp;
}

If you have some methods that return the previous value of a setter, it’s generally not a good idea to mix returning “this” and previous values inside the same class. It would be difficult and cumbersome for a user to remember which functions return the object, and which functions return the previous value, and may try to chain together setters that aren’t possible. Such a situation would be particularly problematic if the object returned from your setter actually had a valid function that the user was trying to call.

There is also a small amount of overhead in returning an object that will just be ignored in many (or most) circumstances. But, in almost all circumstances, this small amount of overhead is negligible.

Resurecting a broken Android phone as a development sandbox for app development.

I had the unfortunate incident of cracking the screen on my fairly new Galaxy S5. Since most of the phone worked, I wanted to get all of my old data off, on to my new phone, and finally re-purpose the old phone as a development sandbox which I can dedicate to Android app development. Exactly which steps you’ll need to go through will depend on the functionality remaining in your device, what settings you’ve enabled, and the tools you have at hand. This details the method I used, which is possibly one of the worst case scenario that can happen, so you can probably use some of this info even if you aren’t in quite as bad of a situation.

My Situation

In my case, the screen was completely broken, it would not display information nor register touches. I had also not enabled developer options, and had a lock screen swipe pattern set. Fortunately, the new phone I bought was exactly the same as the old one, this allowed me to see what the screen would look like without being able to see the screen of my old phone. This was important for counting keystrokes needed to perform tasks in the blind, as well as tracing out the pattern for the lock screen. I had not yet paired the phone with any Bluetooth devices like a keyboard or mouse, nor had I rooted my phone.

Features that made it possible

The Galaxy S5, and many other phones have the build in ability to use a mouse, keyboard, and display through the USB port on the phone. You will need a USB host cable (apparently also called USB-to-go cable) to plug in a mouse and keyboard, you will also need an HDMI adapter for your phone to display the screen on an external monitor.

The Ultimate Goal

The bad thing is that you can’t have a mouse, keyboard, computer, and the display hooked up at the same time, and you need all of these to develop apps in a normal manner. Here is a small overview of the steps:

  • Unlock the phone completely in the blind
  • Pair the phone with a Bluetooth keyboard and mouse
  • Enable developer options
  • Disable the lock screen
  • Backup phone
  • Root the phone
  • Set up the phone to install APKs over the air

Unlocking the phone

This was undoubtedly the hardest part. There were many claims of being able to unlock the phone through USB hooked up to the computer, but required a rooted phone. If you have a password set rather than a swipe pattern, you can simply plug a USB keyboard into your phone using a USB Host Cable, type in your password, press Enter, and be done with it.

With a swipe pattern, it’s far more difficult as you need to know where the mouse pointer is, and if you attempt to swap between the mouse and HDMI display the pattern times out and resets, so the only way to do this is completely in the blind. What I did was set the same unlock pattern on my new phone, then taped a piece of paper to my desk, taped a pencil to my mouse, and traced out the pattern on the sheet of paper. After plugging in the mouse, I moved it to the lower left corner, to ensure I had a home location to start the pattern from, I then traced a line to where my pattern started, clicked the button and traced out the pattern. I then plugged the mouse into my new phone and retraced over the same line to unlock the phone. It is important to keep the mouse in a common orientation as well as trace the line, because if you rotate the mouse with your wrist, it won’t actually be moving in the same direction. For this I visually kept the side of the mouse square with the sheet of paper. It took me a good 15-20 minutes to finally unlock my phone. When it unlocks, it will play a sound, so there’s no need to keep switching back to the HDMI display to see if it worked.

Paring with a Bluetooth Keyboard and Mouse

After you have the phone unlocked, you can switch between the HDMI display, keyboard, and mouse to see where the cursor is and what’s on the display. In my case, I did not have a real Bluetooth mouse, the regular wireless mice work only with their specific dongle, and although you can use them as a mouse with the dongle plugged in, you cannot register them as a Bluetooth mouse. I did have a Bluetooth keyboard available, and fortunately this was enough to navigate around and take care of most of the work. You can move around the screen and select icons using the arrow keys, and in most apps you can use the arrow keys to select most fields, but in some cases the app only works with mouse clicks.

I never figured out how to get the menu to pull down with just they keyboard, but I was able to access the settings by navigating around with the arrow keys to select the “All Apps” from my quick launch, from there I made my way to the settings icon and managed to pair my Bluetooth keyboard. This was all done over the course of 10-15 minutes of swapping out the USB keyboard with the USB HDMI display and seeing where the cursor was and where it needed to go.

Enabling Developer Options

Once you have a Bluetooth keyboard attached, it’s fairly easy to navigate to the settings an enable the developer options (on the Galaxy S5 that’s done by going to “About” in the phone settings and clicking on the build number 10 times). But when you actually plug it into the computer, you’ll be prompted to give the computer permissions, and this prompt goes away if you try to unplug it from the computer and plug in the HDMI display. This issue was solved for me by following the same steps on my new phone, from there I was able to determine that to accept the prompt using the Bluetooth keyboard I just needed to click the down arrow once and the right arrow twice, then press enter.

Disable the lock screen

Without a Bluetooth mouse, I did not bother attempting to disable the lock screen. You have to draw the lock pattern again to disable the lock screen, and it does not play a sound when you do it correctly, making it a very time consuming process. The pattern is also slightly different on the disable screen than on the real lock screen which meant I’d have to trace out a new pattern again, making it take even longer. So, instead I went into the developer options and enabled the “Stay Awake” option which causes the phone to not re-lock while it’s charging. This was able to hold me over until I came across a Bluetooth mouse. An actual Bluetooth mouse is kinda hard to find, I finally found a combination small keyboard and touch pad at Best Buy near the tablet Bluetooth keyboards, after pairing that, I was able to use it as a mouse to disable the lock screen permanently.

Back up the phone and restore it to my new one

This was a lot harder than it should be. There is a backup service built into Android, but it is far from reliable, on my new phone only about 10 apps out of the hundreds were actually restored, and about only 5 of my contacts. If you try to search around, you’ll see a lot of very sketchy apps, and some legitimate ones that require root. The one that finally worked for me, not requiring root, was Helium. It does require that developer options are turned on. But it was able to back up and restore all of my apps and data except two of them which deliberately blocked being backed up.

Rooting the phone

I generally do not like to root my phones. I prefer that when I develop an app, that I can test it in a very similar environment that will be used by all of my customers, and I’ve never found a particularly good reason to do so anyway, at least until now. In order to install applications over the air, that is with the HDMI cable plugged in rather than plugged in to the computer, you’ll require a rooted phone. I was a bit concerned about having to do any work in the blind during the root process, but it went off without a hitch just following the “normal” instructions found pretty much everywhere.

Another option that might not require root is to connect the phone to the computer by USB and echo the screen to the PC. But this likely has performance issues, and the apps I have seen as of this writing either require root or don’t appear very mature.

Setting up the phone to receive APKs wirelessly

I used “ADB Wireless” from the play store for this. You run the app on a rooted phone, then you run “adb connect 192.168.0.1” from your PC. From then on, the remote phone appears just like a directly connected one, which you can verify using the command “adb devices”.

List of my favorite free/open source utilities 2012

While I’ve been a huge fan of Scott Hanselman’s Tool List, but was pretty disappointed in the 2011 list in that it lacked conciseness. Below is a short list of software I use on a very regular basis, install on pretty much every PC that I can, and are all tools I know very well. Of course there’s a lot of commercial software I use too, but below are the ones you can download freely.

  • Notepad++ This is the Notepad replacement for me, and makes a great code editor.
  • Cygwin This utility gives you many of your favorite *nix commands under windows like grep, head, etc, many interpreters like perl, python, bash, etc, and a wide range of many other utilities. Powershell, which is now bundled with Windows is often touted as an alternative, but does not have anywhere near the number of utilities/scripts available. Additionally Powershell gives significantly different names and parameter names to similar Linux utilities, forcing you to learn two different command sets if you work with Linux too. So, if you’re using Linux at all, Cygwin is the way to go.
  • Robocopy comes with Windows now. Beyond just copying files from one place to another, I use it to back up my important code/documents to a separate drive every night at 3am.
  • VirtualBox My favorite virtualization software. I no longer have any PCs dedicated to running Linux for testing or development work. There are lots of virtualization options out there, I chose VirtualBox mainly for it’s USB support.
  • Virtual PC This used to be my virtualization software of choice, I keep it around because I still have some old VMs I never converted over.
  • 7-Zip This has been my archive software of choice for many years now. Previously it was WinRar, which is a commercial program. Even though I own several licenses for WinRar, I no longer feel a need to use it as 7-Zip does everything I need now.
  • Foxit This is a PDF reader, an alternative to Acrobat Reader. I switched to this reader from Acrobat many years ago due to the fact that Acrobat was becoming so bloated. I also don’t like reading PDF files in my browser, and attempting to configure Acrobat to only open as a separate process wasn’t reliable, seems it would always somehow revert to opening in the browser.
  • Combined Community Codec Pack This is a codec pack that makes fairly certain you’ll be able to play almost any video you come across. Downloading videos is fairly rare now days, but I still install this on every fresh Windows install I come across.
  • Synergy allows you to use the same keyboard and mouse across several PCs. You just move the mouse off the edge of the screen on one computer and on to the screen of another.
  • Thunderbird I haven’t yet given up on a local e-mail client. But I do have all of my e-mail forwarded to GMail too. I actually still receive a lot of e-mail, and more than Google allows me to store. Not to mention I have 15+ years of e-mail history stored locally.
  • Arduino The Arduino IDE for working with electronics. Before the Arduino came along I was using SDCC for the PIC. Working with Arduinos is so much easier for me, and does pretty much everything I need.
  • Processing The Processing IDE. Uses a similar language as the Arduino, and is the de-facto language many people use to interface a PC to an Arduino. I can’t say I write a whole lot of programs using this, but mostly use it to run other people’s programs to interface with an Arduino.
  • CDBurner XP Software for buring CD/DVDs. The name makes it sound obsolete, but it works with Win7 and Vista, and burns DVDs too.
  • Dimension 4 A program to synchronize your PC’s clock with an atomic clock over the Internet. There is functionality built in to Windows to do the same thing, but this gives you more control. The Windows functionality is difficult to verify if it’s working properly without just changing the clock time and waiting an hour to see if it’s fixed. D4 also has the added feature in that it graphs all of the adjustments made, so you can see how (in)accurate your clock is.
  • Eclipse This IDE should need no introduction. I use it only for Java development, and often still use Notepad++ instead for small, one off programs.
  • Free Download Manager For downloading large files that may fail, or that you want to schedule to download at a later time.
  • Frhed A free and Open Source Hex editor.
  • Oracle Java JDK Needed to develop Java applications. I have no real reason for using the Oracle JDK over any other, other than it’s just what I’ve always used.
  • Linux in a virtual machine – Ubuntu Server Many things are just easier with Linux, especially if you work with other Linux servers. Every PC I have will have at least one “utility” Linux VM, this is in addition to any sandbox or development Linux VMs.
  • WinMerge A graphical version of the “diff” utility. It compares two text files and highlights the differences between them.
  • cmdhere.reg This adds a context menu to Windows Explorer allowing you to quickly open a command prompt at the location you’re viewing. Additionally, I also create a shortcut to CMD.EXE on my desktop, and assign the hot-key CTRL-ALT-D, to open a command prompt.
  • Putty An SSH client for connecting to the many Linux systems I use.
  • SpaceMonger A utility to visually show you what is using up all of the space on your hard drive. The old 1.4 version is free. Another purely free similar application is WindirStat, but not quite as good of a UI IMHO.
  • RealVNC Software that lets you remote control another Windows [or Mac, or Linux, etc] PC from anywhere you can open a TCP connection. There is Remote Desktop built in to Windows now, but Remote Desktop has a lot of limitations like the fact that it blanks out the screen on the host PC when it’s remote controlled, and you have to log out the current user if its an account with a blank password. I do use Remote Desktop when I log in to other Windows servers, where I don’t actually want to control what’s on the screen of another system, but I use VNC when I’m connecting to other desktop PCs.
  • Firefox My browser of choice. The only other browser I’ve spent much time with is Internet Explorer, which I feel hides too much information from developers. Other browsers like Chrome and Safari seem to lack the wide range of plugins Firefox has.
  • Visual Studio Express Well, I don’t actually use the Express version which is free, but if you don’t want to buy the whole thing [or your employer won’t buy it for you] then Visual Studio Express is a great way to program in C#.