Posted by alibad on June 4, 2008
Almost every item we buy or own has a barcode printed on it. We see those barcodes every day, but still we don’t understand what they really mean or how to generate them. That’s why I’ve created an article on Code Project that explains what barcoding is and details the design and implementation of a Java program that generates a barcode label from a given UPC code.

Enjoy!
Ali B
Posted in Java | Tagged: barcoding, barcode, UPC, UPC-A, Java | No Comments »
Posted by alibad on May 14, 2008
So you’ve been having some pain trying to put IntelliSense into your frequent CAML (Collaborative Application Markup Language) files. For every new XML file you create, you have to go to its properties and then point to the target schema located at ../TEMPLATE/XML/wss.xsd.
If you don’t know what I mean, usually, in order to display IntelliSense in an XML file opened through Visual Studio, we must link the XML file to an XSD. This is done by going to the file properties and linking to the XSD every time we open the XML file in Visual Studio.
One way to avoid having to link to the XSD every time, is to add the file(s) to a Visual Studio project. However, what if you create CAML files so frequently that you don’t want to add them to a Visual Studio project every time?
The best solution would be to load the XSD whenever a new XML file referencing it is opened; and I have the steps to do that!
Under the Schemas folder of the Visual Studio installation folder (Ex: C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas), there is a file named Catalog.xml.
Reference wss.xsd from it by adding the following tag:
<Schema href=”C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/TEMPLATE/XML/wss.xsd” targetNamespace=”http://schemas.microsoft.com/sharepoint/” />
Make sure that href is pointing to the correct location of the wss.xsd file.
Enjoy!
Ali B
Posted in .Net, SharePoint | Tagged: SharePoint, Visual Studio, XML, CAML, XSD, wss, Features | 1 Comment »
Posted by alibad on March 1, 2008
The purpose of this interactive program is to make it easier to learn OpenGL Geometric Primitives. There are ten geometric primitives in OpenGL, from a point to a polygon, and all are represented by vertices. This program will give you the flexibility to add and remove vertices in a certain order, and shows you how the choice of the primitive determines how the vertices are to be combined. It can be used in the following ways:
- Learn OpenGL Geometric Primitives through
- Interactive Program
- Source Code
- Documentation
- Learn some OpenGL functions designed to work with geometric primitives
- Draw primitives manually and generate their corresponding OpenGL C code
Here is a view showing Monalisa drawn with lines only…

Click here to download a video showing how the program can be used.
Enjoy!
Ali B
Posted in C, OpenGL | Tagged: OpenGL, geometric, primitives, point, line, polygon, vertex, primitive | No Comments »
Posted by alibad on February 21, 2008
This is pretty simple, but it does add some neatness to C code.
Suppose you define an enum for colors as follows:
typedef enum
{
BLACK,
BLUE,
CYAN,
DARK_GREY,
GREY,
GREEN,
LIGHT_GREY,
MAGENTA,
ORANGE,
PINK,
RED,
WHITE,
YELLOW
} Color;
You want to keep track of the number of colors you have in your program, so you can say
#define COLOR_COUNT 13
or
const int COLOR_COUNT = 13;
Now, suppose you added a new color to the enum. You have to remember to change the COLOR_COUNT value to 14.
The neater way to do this is to simply add the COLOR_COUNT at the end of the enum; it will take the size of the intended set.
typedef enum
{
BLACK,
BLUE,
CYAN,
DARK_GREY,
GREY,
GREEN,
LIGHT_GREY,
MAGENTA,
ORANGE,
PINK,
RED,
WHITE,
YELLOW,
COLOR_COUNT
} Color;
Enjoy!
Ali B
Posted in C | Tagged: C, enum | No Comments »
Posted by alibad on February 13, 2008
It’s really weird that the C math library (math.h) doesn’t support the round function. It only includes the floor function which rounds down a float to an integer (can also be done by implicit or explicit casting) and the ceil function which rounds the value up.
For example,
int x;
x = floor(1.2); // x is set to 1
x = floor(1.8); // x is set to 1
x = (int)1.8; // x is set to 1 (Explicit Narrowing Conversion)
x = 1.8; // x is set to 1 (Implicit Narrowing Conversion)
x = ceil(1.2); // x is set to 2
x = ceil(1.8); // x is set to 2
The round function is supposed to round the float value to the nearest integer.
x = round(1.2); // x is set to 1
x = round(1.8); // x is set to 2
This can be done adding a 0.5 to the value and then truncating it.
x = (int)(1.2 + 0.5); // x is set to 1
x = (int)(1.8 + 0.5); // x is set to 2
We also have to take negative values into consideration by adding -0.5 and then truncating.
x = (int)(-1.2 - 0.5); // x is set to -1
x = (int)(-1.8 - 0.5); // x is set to -2
Thus, here is the resulting C function:
int round(double number)
{
return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
}
Note that you might want to use long rather than int to include support for larger numbers and avoid integer overflow.
That’s it, pretty much primitive, but fun!
Enjoy!
Ali B
Posted in Algorithms, C | Tagged: C, ceil, floor, function, math.h, round | 3 Comments »
Posted by alibad on February 8, 2008
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated. The term is usually referred to as GUID (Globally Unique Identifier) when working with Microsoft technologies. Otherwise, it is referred to as UUID (Universally Unique Identifier).
Here are multiple ways to generate a GUID:
Visual Studio
Run guidgen.exe. There are two ways to run guidgen:
- Open Visual Studio IDE, go to Tool menu, and select the Create Guid menu item. More details here.
- Open Visual Studio Command Prompt (from start menu) and enter the following command: guidgen. More details here.
Using any of the methods above, you get the following:

You can use any of the 4 formats available, but usually the Registry format (currently selected) is the mostly used one. To generate a new GUID, click New GUID. To copy the GUID to the clipboard, click Copy.
.Net
You can generate a Guid using any .Net language. Here is how you can do it with C#. Click here for more details.
Guid myGuid = System.Guid.NewGuid();
SQL Server
A GUID is represented as type uniqueidentifier in T-SQL. It is generated as shown below. More details here.
SELECT newid()
Online
If none of the above methods are available for you, you can get one generated online at http://www.guidgenerator.com/.
Posted in .Net, Database | Tagged: guid, uuid, newid, uniqueidentifier, guidgen | 3 Comments »
Posted by alibad on February 3, 2008
Knowing that the Facebook Developers site has enough information to guide you through the process of writing a Facebook Application, my only intention here is to provide quick easy steps to get you done with your first application in 90 minutes. Go on with the below in the order specified.
- Skim through FAQ (10)
- Read Anatomy of a Facebook Application (5)
- If you don’t already have a web hosting server that supports PHP 4 or 5, then register for a free one at http://www.freeunmeteredhost.com. Joyent also provides Free Facebook Accelarator, but they usually take some time to sign you up (20)
- Create your first Facebook Application by going through the Guide to Creating an Application (45)
- Use Notepad++ to edit PHP files (5)
- Use an FTP Client (ex: SmartFTP) to transfer files between your local computer and web server (5)
Check the Facebook API documentation for more details. If anyone followed the instructions above, please leave comments on how much time it took you to be done.
Enjoy!
Ali B
Posted in Web | Tagged: PHP, Facebook, Joyent, SmartFTP, x10Hosting, FTP, application | No Comments »
Posted by alibad on February 1, 2008
It’s been some long time since I touched upon PHP, and I wanted to write a small web application using PHP and MySQL. It took me almost half a day just to setup my environment. I first started by individually installing each of PHP, Apache Web Server, MySql and PhpMyAdmin, and then modifying some configuration files to make them work together. This took some time, and I still had some problems. So I gave up on it and decided to use one of those integrated packages (WAMPs) that get everything setup for you, and it was well worth it.
Follow the below instructions to save yourself some research time and be ready in half an hour.
Preparing PHP Environment
Install latest version of XAMPP, which contains:
- Apache HTTPD Web Server + Openssl
- MySQL Database Server
- PHP
- phpMyAdmin for managing the MySql database Server
- FileZilla FTP Server
- Mercury Mail Transport System
Why XAMPP? Click here for a Comparison of the available WAMPs (Windows, Apache, MySQL, PHP).
Using XAMPP
- Run XAMPP Control Panel and start the Apache and MySql services.
- Open Url http://localhost.
- The main folder for all WWW documents is at \xampp\htdocs. To test for a PHP page, create new file phpinfo.php with only the following content <?PHP phpinfo(); ?> and place it under \xampp\htdocs. Then go to web browser, and type http://localhost/phpinfo.php in the address bar.
That’s all you need to know before you put yourself into development mode. Click here if you want to explore other installation methods.
Editing PHP Files
If you are already familiar with Eclipse, I suggest you download the Eclipse plugin for PHP in order to use Eclipse as your PHP IDE. Otherwise, Notepad++ is a nice multi-tabbed editor. Don’t worry, both are GREAT and FREE.
Enjoy!
Ali B
Posted in Web | Tagged: PHP, MySQL, Apache, Web, PhpMyAdmin, XAMPP, WAMP, Eclipse, Notepad++, PDT | No Comments »
Posted by alibad on January 27, 2008
This article shows you how to create GUI controls for your OpenGL application and organize them into GLUI subwindows. In this article, we will take the source code from the previous article GLUI Window Template, and modify it so that our GLUI controls will be laid out inside two subwindows rather than in a single window. The reason is that having a separate window to contain our GLUI controls could be sometimes annoying for the user, as she or he will have to lose the focus on the OpenGL context window every time she or he wants to do an action. A nice way to avoid this is to place the GLUI controls directly into the GLUT OpenGL window by embedding them into a GLUI subwindow.
This article can be used in the following ways:
- Learn how to use GLUI subwindows
- Understand the Viewport concept in OpenGl
- Use the program as a template for your OpenGL applications that require GUI controls
The image below shows how our controls were laid out into a single GLUI window in the previous article:

The image below shows how our controls will be laid out into two separate subwindows placed on the left and the bottom of our main GLUT window:

Check it out, and let me know your feedback.
Enjoy!
Ali B
Posted in CPP, OpenGL | Tagged: C, GLUI, GLUT, OpenGL, subwindow, template, viewport, window | No Comments »
Posted by alibad on January 25, 2008
This article describes in detail how to create your first GLUI window with some basic controls inside it, and provides you with a template for your OpenGL applications.
When OpenGL applications get more complex, we need something more than a GLUT mouse, keyboard, and\or popup menus to interact with our OpenGL objects drawn on the window. GLUI gives us more flexibility by allowing us to add GUI components to interact with our OpenGL objects, such as buttons, check boxes, radio buttons, spinners, list boxes, lists, trees, file browsers, text fields, text areas, and the special controls: rotation and translation.
This article can be used in the following ways:
- Learn how to add GUI components to your OpenGL application in a very straight-forward and simple manner, through
- Documentation
- Interactive Program that displays to the user how every event is handled and classifies these events into GLUT and GLUI events.
- Neat and commented Code that reflects the simplicity of the GLUI library
- Learn some totally new controls in the GLUI library created specifically for graphical manipulation, such as the rotation and translation controls.
- Use the code as a template for your OpenGL applications.
Click below for a screen shot of what the program would look like when its run.

Make sure you read the GLUT Window Template article as a prerequisite to this article. One important thing to note is that GLUI is a C++ library, which means that your code must be written in files with .cpp extension rather than .C, or otherwise the linker will complain.
Check it out, and let me know your feedback.
Enjoy!
Ali B
Posted in CPP, OpenGL | Tagged: C, control, GLUI, GLUT, graphics, GUI, OpenGL, template, window | 2 Comments »