Author Archive

Pizza box chassis

Pizza box chassis

Pizza box chassis

The top is a screenshot of a document from work outlining different chassis sizes and their byte value to set for programming. I thought it was a joke because engineers have the weirdest joke. The bottom is a picture of an actual pizza box computer. And it’s running Linux. *shudders* I’m not surprised though. Needs moar bell peppers.


Formatting and Styling Strings (C#)

We’ve discussed different ways to format a string using printf for C++ and string.format for Java/Android and since I’ve been working with C# recently I would add that to the blog as well.

In C#, it’s just like Java/Android: use string.Format(). Instead of dollar signs, you would use curly brackets with the parameter number. What’s nice is that you don’t really need to worry about the type. For example:

int foo = 9000;
string bar = "sparta";

string fubar = string.Format("This is {0}! It is over {1}!", bar, foo);

Would result with:

This is sparta! It is over 9000!"

See how I didn’t need to tell it {0} was a string and {1} was an integer? You can also add the format inside the curly bracket if you wish such as:


Where index is the index of the value to use; length is the amount of spaces you want this variable to take up; and formatString is a standard or custom string that can be used to do more formatting (such as setting up a date in US or EU format).

As usual, if you’d like to know more about the details, visit MSDN for more reading.

Crypto++ and Linux

This week I’ve re-acquainted myself with Linux at work in order to port an app from Windows to Linux. Besides the aggravation of setting up the OS, IDE, and workflow, I had to use a 3rd party library called Crypto++. Well, it wasn’t obvious to set up or figure out so I’d put this out there in case someone has the same problem.

Basically I was able to include the files, but I got a linker error despite including the files in the project file in Qt. This is the error:

g++ -o encrypter -L/usr/lib -Lcryptopp -lcrypto++ -lQtGui -lQtCore -lpthread
encrypter.o: In function `CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)':
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x2b): undefined reference to `CryptoPP::AlignedAllocate(unsigned int)'
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x38): undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)'
encrypter.o: In function `CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)':
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x25): undefined reference to `CryptoPP::AlignedDeallocate(void*)'
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x32): undefined reference to `CryptoPP::UnalignedDeallocate(void*)'
collect2: ld returned 1 exit status
make: Leaving directory `/home/alex/projects/encrypter'
make: *** [encrypter] Error 1
Exited with code 2.
Error while building project encrypter
When executing build step 'Make'

The proper way to include crypto++ is NOT to download it from the website. Use terminal to get the library:

sudo apt-get install libcrypto++8 libcrypto++8-dbg libcrypto++-dev

Then check if installed on system:

apt-cache pkgnames | grep -i crypto++

Which should result with:


If the information above is different (which is possible if it becomes out of date), check the Crypto++ Linux wiki for instructions.

Now add the library to project with the following linkage (written as a makefile macro, but just put the -L and -I parts in the command line if you’re compiling manually):

LIBS += -L/usr/lib/crypto++ -lcrypto++
INCS += -I/usr/include/crypto++

While is is rather specific, someone out there is probably searching for this so here ya go!

If Linux was a car

Really? But your car still runs with Windows

Linux enthusiasts are scary

Shameless cross-post from my car blog:


If Linux was a car, you’d have to build it from scratch just to go to the store to buy some milk. You’d start by compiling an engine and put it on a chassis. That’s fine and dandy and it’ll get you where you need to guy, but it sure is a pain in the ass to turn with a socket wrench on the rack and pinion. So let’s put in a steering column and steering wheel.

It’s not very comfortable so let’s add some seats. Now you realize there are different flavors of seats. Bench, bucket, velour, cloth, leather, etc. Bench sounds nice which is great for cuddling with a significant other! Oh wait, you use Linux. Scratch that, let’s go with buckets for the sportier feel.

Great, but it’s not that great looking. It needs a body. Those damn Apple cars look so sleek and sexy with their glossy exterior, but we all know you can’t modify them. Fk the sheeple and their pretty cars. Those Windows cars actually look pretty good now unlike a few years ago when the Fisher Price Cozy Coup called them out on plagiarism. What can I do with the Linux car? Well, there’s not much to choose from out of the box. Fkr looks cartoony. Meh, fk it, let’s roll.

It drives just as well as the Apple car because they’re almost identical under the hood. You’re feeling pretty smug because you built your own car for free. Well, let’s keep adding mods. You want lib-vtec-honda, but it won’t work in your car. You hack it to work instead. You’re somewhat successful, but you needed another obscure library to get it to work: lib-jdm-bolts. Ok, it works fine, but not perfect.

Oh no, the radio stopped working! Ok, don’t panic, just use another antenna. Crap, it’s not compatible with Linux and you just paid out the butt for it. To the Googles! So many people have the same issue, but with different hardware. WTF?! Grrrr! Ok, this guy says to download ndis-radio-wifi-2.6.1 and compile it for my specific car. Ok. Fk! I need another obscure library: lib-am-fm-cassette. Don’t I already have that?! Jebus H. Chrysler this is retarded.

Wheee, got the radio working. Let’s roll. Going to Taco Bell for some chalupas and Baja Blast. Oh muffin fudger, it doesn’t have a fkn cupholder. Google it. Cupholders aren’t available to Linux due to it being proprietary technology developed by Adobe?! GD it to hell! You end up burning the car and buying a Windows car.

Want to learn C#?

I’ve been wanting to learn C# for a while so I finally started learning it a few weeks ago. I lightly touched C# back in the fall of 2009. We had a quick crash course trying to get a XNA game working thinking that was the best way to make a game in two weeks. That was a very terrible learning situation and I haven’t thought much about C# since then. Once I decided to take a shot at it again, I was definitely a lot wiser than I was 1.5 years ago. Now that I’ve got some good C++ programming, MFC UI development, and Visual Studio usage skills down, jumping into C# was not as hard as it was when I first came across it. Actually, working with C# in Visual Studio is so much easier than C++ and MFC that I feel like I’ve been converted to a new religion. Seriously, how did I live without this all my programming life?! String conversions, getting file paths/names/extensions, and capturing events are just one call away instead of some hackjob conversion and string parsing! C++ and MFC is like driving a Volvo 240: solid, reliable, and old, but hard to work on and possibly relies on hackjob repairs to make things work. C# with .NET is like a brand new Volvo S60: new, easy to use (from the driver’s seat), and safe with all the electro-nannies, but it’s a lot more complicated under the hood, but you’re not likely to go that deep anyways. I followed the tutorial at Home and Learn and got a nice primer on C#. The tutorials are very easy to read and understand so I recommend checking it out if you’re a beginner. It’s nice that Microsoft offers Visual Studio Express for free to play around with also. Get Visual Studio Express and start making some programs!

How to shoot yourself in the foot in any programming language

Searching through the documents on my hard drive this weekend I came across a document containing the joke of how to shoot yourself in the foot in any programming language. Well, not literally, but it does relate how the different languages behave by using the analogy of shooting one’s self in the foot. I forgot where I found this so if someone knows, post the link in the comments!

* * *

How to Shoot Yourself in the Foot in Any Programming Language

The proliferation of modern programming languages (all of which seem to have stolen countless features from one another) sometimes makes it difficult to remember what language you’re currently using. This guide is offered as a public service to help programmers who find themselves in such dilemmas.

You shoot yourself in the foot.

You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”

After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes and methods of those classes needed, you’ve forgotten what the hell you’re doing.

Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it.

You shoot yourself in the foot with a gun made with pieces from 300 other guns.

Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.

SELECT @ammo:=bullet FROM gun WHERE trigger = ‘PULLED’;
INSERT INTO leg (foot) VALUES (@ammo);

You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.

You’ve perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.

You shoot your right foot with one hand, then switch hands to shoot your left foot but you realize that the gun has turned into a banana.

You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception-handling ability.

After realizing that you can’t actually accomplish anything in this language, you shoot yourself in the head.

Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER. on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be retied.

You shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds ….

Shoot yourself in the foot with a water pistol. On big systems, continue until entire lower body is waterlogged.

Foot in yourself shoot.

You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.

The compiler won’t let you shoot yourself in the foot.

If you succeed, shoot yourself in the left foot.
If you fail, shoot yourself in the right foot.

Concurrent Euclid
You shoot yourself in somebody else’s foot.

Put the first bullet of the gun into the foot of the left leg of you.
Answer the result.

You spend days writing a UIL description of your foot, the trajectory, the bullet, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.

% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm: .o: No such file or directory
% ls

Not only can you shoot yourself in the foot, your users can too.

You’ll be able to shoot yourself in the foot just as soon as you figure out what all these bullets are for.

Visual Basic
You’ll shoot yourself in the foot, but you’ll have so much fun doing it that you won’t care.

You tell your program you want to be shot in the foot. The program figures out how to do it, but the syntax doesn’t allow it to explain.

After correctly packaging your foot, you attempt to concurrently load the gun, pull the trigger, scream and shoot yourself in the foot. When you try, however, you discover that your foot is of the wrong type.

You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot. After that’s done, you pull the trigger, the gun beeps several times, then crashes.

370 JCL
You send your foot down to MIS with a 4000-page document explaining how you want it to be shot. Three years later, your foot comes back deep-fried.

You try to shoot yourself in the foot but you just keep hitting the whitespace between your toes.

Dividing an array

Even if you don’t care about the practical applications of it in modern programming, it offers a look back when programming was more of a pain in the ass because shit needed to be set up properly as well as having a good algorithm. Actually it is still relevant in deeper technical programming that is closer to the hardware level. Probably not so much for app developers.

So let’s say you have an array using 16-bit integers. So you would have something like this:

unsigned short *myArray = new unsigned short[1024];

So you fill it up with data and all is good right? Well now your next requirement is that you want to divide each element into two parts, the lower byte and upper byte because the upper byte indicates the flashing pattern of the red LED and the lower byte indicates the flashing pattern of the green LED. Well FML, right? No!

We make a new byte pointer (a char in this case) and make it point to the typecasted main array:

unsigned char* birchPointer;
birchPointer = (unsigned char*) myArray;

Now because a char is a byte in size, when you advance the index it will point to the next 8-bit position. So let’s say myArray contains the following information:

myArray[0] = 0xBEEF;
myArray[1] = 0xCAFE;
myArray[2] = 0xBABE;

Now if you use the char pointer to access myArray, you’ll get the following information (providing your system is big endian):

birchPointer[0] = 0xBE;
birchPointer[1] = 0xEF;
birchPointer[2] = 0xCA;
birchPointer[3] = 0xFE;
birchPointer[4] = 0xBA;
birchPointer[5] = 0xBE;

If you’re using a machine that’s little endian (which most PCs are), then the byte values will be swapped like so (due to little endian storing the lower byte first in the memory sequence):

birchPointer[0] = 0xEF;
birchPointer[1] = 0xBE;
birchPointer[2] = 0xFE;
birchPointer[3] = 0xCA;
birchPointer[4] = 0xBE;
birchPointer[5] = 0xBA;

So there you have it: splitting a 16-bit array into an 8-bit array and learning something about how endians affect it.

Read more:
Size of C++ Datatypes
Big endian vs. little endian