Category: Programming

Running multiple instances of mysql on the same machine

24 August, 2010 (15:33) | Linux, SQL, Programming

There are a lot of ways to run two instances of mysqld on one machine. Generally all you need to do is specify different ports and data directories. The method I describe below is basically to copy the default configuration shipped with Ubuntu Server into a different directory and name everything associated with […]

Simple encryption and decryption of a string in c#

20 August, 2010 (12:32) | Cryptography, Security, Snippets, Programming, C#, Code

Here are some routines which are designed for simple use of Rijndael in C#. I’ve combined a test function in the class for simplicity of showing it’s use.

private static byte[] salt = Encoding.ASCII.GetBytes(”somerandomstuff”);

public static string Encrypt(string plainText, string […]

The Towers of Hanoi in Erlang

18 August, 2009 (22:34) | Programming, Erlang

I’m just playing with Erlang, below is my attempt at solving the Towers of Hanoi puzzle using it. Call it using hanoi:hanoi([1,2,3,4,5,6],[],[]) (a valid starting position is assumed).

-module(hanoi).
-export([hanoi/3]).

hanoi(A,B,C) ->
Disk=lists:max(A),
move(Disk,A,B,C).

move(Disk,[Disk|Source],Dest,Temp)->
[Source,[Disk|Dest],Temp];

move(Disk, Source, Dest, Temp) ->
[S1,T1,D1]=move(Disk-1,Source,Temp,Dest),
[S2,D2,T2]=move(Disk,S1,D1,T1),
[T3,D3,S3]=move(Disk-1,T2,D2,S2),
[S3,D3,T3].

Solving the Towers of Hanoi puzzle in C#

4 August, 2009 (18:45) | .Net, Programming, C#, Computer Science

I thought this would be a fun little exercise to try. This puzzle is generally used to teach recursion in CS classes, but I have never actually tried to implement it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TowersOfHanoiCs
{
class Program
{
static List […]

Sending an email with syntax hightlighting for your source code

2 August, 2009 (22:53) | Programming

I resisted the switch to HTML e-mail for as long as I could, I know there are some who have managed to succeed in not switching to an HTML enabled email reader. But I just couldn’t hold out due to the fact that there were so many non-computer savvy people I communicated with who […]

Turbo Pascal 5.5 is available for download for free

2 August, 2009 (22:23) | History, Programming

Firing up ole’ TP7 for the last post put me in a nostalgic mood, and I went looking to see where Turbo Pascal stands today. It doesn’t look like you can still buy it, and the only version available is Turbo Pascal 5.5 which you can download for free from: http://edn.embarcadero.com/article/20803
I believe my first […]

Statements in most languages can be empty

2 August, 2009 (19:31) | Programming

I was looking through some code that was posted for review when someone had pointed out a statement like the following:

int x=5;;

Note the two semi-colons. I initially thought “Great, someone has us reviewing code they didn’t even try to compile.” But to my amazement, it does compile, and it compiles in pretty much […]

Getting confused between closures and eval()

19 June, 2009 (23:51) | JavaScript, Programming

I just saw a question regarding closures in JavaScript regarding code similar to the following:

for (i=0;i<n;i++){
foo.bind( function() { bar(i); } );
}

The question was why does every closure execute bar(i) with i as the value of n for every instance, rather than whatever the value of i was when the closure […]

The difference between window.setTimeout() and window.setInterval()

1 August, 2008 (12:49) | JavaScript, Programming

From what I’ve seen, the problem most people have with the difference between these two JavaScript functions isn’t knowing what they do, but it’s knowing that they both exist. I’ve seen lots of people constantly call setTimeout() calling the same function over and over where the last line of the function calls setTimeout(), but […]

Programming vs. Engineering vs. Mathematics.

20 June, 2008 (17:28) | Programming, Humor, Computer Science

An experiment was conducted in order to study the differences between programmers, engineers, and mathematicians. One programmer, one engineer, and one mathematician were all locked in separate classrooms for one week. Each classroom contained all of the normal things you’d find in a classroom: chalkboard, chalk, desks, etc. In addition to that […]