David's blog

Regex Escapees

November 22, 2011 00:00

Sometimes when one writes regexes, Its hard to know what needs to be escaped and what doesn't. But I've solved that problem while I was writing a program that generated my regexes for me. Now I have a snippet that both humans and programs can use to write regexes!

This is for the .NET flavor of Reg...

Read post

Making Color From Alpha, Hue, Saturation and Brightness

November 22, 2011 00:00

I find myself wanting to do this sometimes, so here's a bit of code (I'm sure I stole this code from somewhere else);

public static Color ColorFromAhsb(int a, float h, float s, float b) {

    if (0 > a || 255 < a) {
        throw new ArgumentOutOfRangeException(&quot;a&quot;);
    }
    if (0f > h || ...
Read post

OpenGL weirdness

October 06, 2011 00:00

Try this:

        dispList = glGenLists(1);

        glNewList(dispList, GL_COMPILE);

        for(int x=-768; x<768; x++)
        for(int y=-768; y<768; y++)
        {
            glBegin(GL_QUADS);
                glColor3f((double)(rand() % 100) / 500, 
            (double)(rand() % 100) / 100, 0...
Read post

Help! GLEW compiles but doesn't link!

October 06, 2011 00:00

When you compile the glew_static project from glew on Visual Studio and link it with your program, you may get something like this:

app_init.obj : error LNK2001: unresolved external symbol __imp__glewInit
worldscene.obj : error LNK2001: unresolved external symbol __imp____glewBufferSubData
worl...
Read post

Why I Prefer Initialization Through Constructors

September 18, 2011 00:00

I always prefer initializing my class through the use of a constructor like this:

class Apple
{
    Color color;
    Taste taste;
    List<string> countries;
    public Apple(Color color, Taste taste, List<string> countries)
    {
        this.color = color;
        this.taste = taste;
        this.countries = countries...
Read post