RSS LJ

May 4, 2012

Some Mandelbrot rambles (, )

by fluffy at 9:04 PM

A lot of folks out there know about the Mandelbrot set. But that knowledge is often based on pretty abstract stuff, and is limited to the fractal as a two-dimensional thing that doesn't really make much sense. The other day I decided to screw around with some basic GPU programs, and I figured I'd finally write some stuff about this.

This is of course very basic to anyone who has studied fractals before, but the description of what's going on is largely secondary in this case.

(Warning: There are a lot of very large images in this post.)

May 3, 2011

Vala (, )

by fluffy at 8:24 PM

A while ago I learned about an interesting language called Vala, which is basically C++ if it were redesigned from the ground up with only the good parts of C++, plus useful parts of other more-modern languages like C# and JavaScript. Every now and then I look at the tutorial again and it's just getting better and better. And it is designed to maintain ABI compatibility with C, and actually is just a front-end that generates and compiles C code, meaning it's also perfectly-suited for embedded programming, especially on platforms where C++ has been stupidly hobbled (such as Android NDK).

I especially like the way it handles generics, the way all Vala references are equivalent to boost::shared_ptr (with a keyword to make a reference weak - without any need to explicitly lock it), the way that you can still do explicit memory management if you need to (only with a very nicely-implemented equivalent of std::auto_ptr to make even that stuff easier), it supports contract-based programming features (including requiring explicit nullability for object parameters), and that it supports true closures (unlike Java's quasi-closures) with a syntax that isn't ridiculously horrible (unlike in Javascript, C99, or C++0xB2011). It also has a very nice syntax for function pointers delegates, and also has some syntactic features that are there specifically to support asynchronous message handling.

It's a shame that people only seem to think that it's suitable for Gnome, probably because it grew out of GObject and is part of the Gnome project. It's not! It's a general-purpose language, that just happens to also provide GTK and Gnome bindings as part of its standard library. But it's also compiled, C-compatible (and therefore C++-compatible), and doesn't require a ridiculously large and fragile runtime library.

Maybe someday I'll have an opportunity to actually do a project with it. For now I just feel like I keep on staring through the window at the shiny toy that I wish I could use.

February 16, 2011

Any mod_rewrite gurus out there? (, , )

by fluffy at 10:50 PM

As an attempt at getting rid of some stupid spammers who are also trying to exploit nonexistent scripts on my site, I'm trying to redirect all requests that contain /../ in the original request URI (which are basically guaranteed to be an exploit attempt) elsewhere. However, it looks like mod_rewrite is only performing the substitution rule on the resolved path (i.e. it's treating /foo/../bar/ as /bar/) despite the fact that the REQUEST_URI environment variable still has the original /../-containing expression in it. I know my regexp is written correctly because the rule is working on other things (such as QUERY_STRING and HTTP_REFERER).

So, does anyone know if there's any configurations to mod_rewrite which might fix this behavior?

It's not a big deal but I've noticed a high correlation between the spammers who get through and the folks who are trying to find stupid CGI exploits and I figure anything that trips them up can only help.

February 14, 2011

C++ wishlist: Abstract-on-subclass (, )

by fluffy at 6:50 PM

In C++ you can mark a method as being abstract pretty trivially, e.g.:

class A {
  virtual foo() = 0;
};

which makes it so that you can't instantiate anything that derives from A until the method foo has an implementation. This is a very useful pattern.

What it's missing, however, is a way of insisting that every instantiable instance of A must provide its own implementation of foo; for example:

class A {
  virtual foo() = 0;
};

class B: public A {
  virtual foo() {}
};

class C: public B {
};

It would be nice if in this case, there were a way to make it so you can't instance C until it gets its own implementation of foo.

Of course, the situation I've run into where this would be exceptionally useful (having a complex DOM which needs per-class script bindings) is kind of nichey, and I can't really see it adding much value to the language as a whole. Still, I can dream...

March 19, 2010

Using inner classes to simplify complex cleanup in C++ ()

by fluffy at 5:55 PM
A lot of my work involves writing C++ code which uses fairly low-level C APIs which require stateful initialization and cleanup at various points (for example, binding a resource, performing an operation, and then unbinding the resource when it's done). The usual approach to this sort of thing is like this:
bool MyClass::useResource() {
    if (bindResource(mResource) != RESULT_OK) {
        //! Binding failed; return failure
        return false;
    }

    if (doSomethingComplex() != RESULT_OK) {
        //! Our complex operation failed; return failure (but first unbind the resource)
        unbindResource(mResource);
        return false;
    }

    if (doSomethingElse() != RESULT_OK) {
        //! Another complex operation failed; return failure (but first unbind the resource)
        unbindResource(mResource);
        return false;
    }

    // We were successful; unbind the resource and return success
    unbindResource(mResource);
    return true;
}
This is a bit annoying to deal with, especially if the unbind procedure is fairly complex. What's even worse is if you have multiple resources which get bound and need to be unbound, especially if there are multiple steps between those resource bindings. So here is a way to simplify this sort of thing.

October 10, 2009

Geometry Images ()

by fluffy at 7:52 PM
Back when I was in grad school I was doing a lot of research on graphics, and had come up with an obvious-in-retrospect geometry representation format, which I called an "NMMesh," for an NxM Mesh of points; at the same time, X. Gu at MIT had been working on a similar concept, which he called a "Geometry Image." Of course, I never got around to writing any papers, whereas Gu had, and so his (much better) name caught on. For a few years they were a darling concept in the graphics research community.

Recently I'd been messing around with my research 3D engine for various reasons (mostly of nostalgia), and I came to realize that even now there are several things I had been doing with geometry images that still don't appear to be well-known for them. So, I'd might as well write some of it up.

January 21, 2009

Exceptions vs. error returns, quantified ()

by fluffy at 4:05 PM
Today I got into a bit of a discussion regarding embedded programmers and their tendency to avoid exceptions in C++. The argument basically boils down to three things: code size, memory usage, and runtime. So, rather than continue on without actually putting my beliefs to the test (the discussion basically centered around whether engineers are making assumptions based on how things were 15+ years ago), I decided to construct a minimal test which I think shows where the tradeoffs may be.

August 14, 2008

Documentation (, )

by fluffy at 5:33 PM
Quick poll: when you see this documentation in a cross-platform image-handling API:
width: Specifies the width of the image. All implementations support images that are at least 64 pixels wide.
what do you think that means in terms of valid parameters to be passed into the width parameter?

August 10, 2008

Hash tables (, , )

by fluffy at 12:33 AM
Lately I've noticed that a lot of people are confused about what a hash table is and how one goes about implementing it. (This often comes up when I'm interviewing candidates and I ask them how they'd implement an associative array without the use of std::map.)

A hash table is not using a hash function to distill a key into a value which is used to order it in an associative array/sorted list/etc.

A hash table is using a hash function to distill a key into a value which is used to index into a linear, non-sparse array.

May 15, 2008

Virtual inheritance weirdness ()

by fluffy at 5:01 PM
I was trying to see if I could emulate something like Java's final by changing the scope of an inheritance. I got some weird results.

August 10, 2007

Finally set up SVN ()

by fluffy at 11:13 PM
The recent discovery of AudioCompress being actively used prompted me to finally set set up an SVN repository. (Dreamhost made it mad easy, as always. Though it might take a little while for DNS to propagate, of course.)

What else should I put into SVN? SOLACE maybe? (Cleaning that up for release would take a lot of work though, and it's not really that useful anymore, except as a general reference on how to do things with geometry images...)

How circuitous ()

by fluffy at 10:38 PM
Remember AudioCompress, which started life as xmms-compress before I made it generic? Someone's made a "new" XMMS plugin called xmms-normalize using the AudioCompress core.

Meaning they've ported an XMMS plugin to XMMS.

I would have preferred if they'd just submitted a patch to make it compatible with XMMS2 so it could be part of the core AudioCompress distribution, but whatever...

8/11 03:15 This has inspired me to go through the code and basically rewrite it. It's amazing how something I wrote as a quick hack as a grad student is still algorithmically-good but of course several years of professional software engineering have given me a completely different perspective on code quality.

January 17, 2007

HOWTO: launch a web browser from a win32 app ()

by fluffy at 12:01 PM
I needed to know this for a simple app at work and, not being a Win32 programmer, I couldn't find it documented, so to hopefully save someone else a wild goose chase:
ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
where url is an ordinary char* string.

February 9, 2004

Random silly puzzle ()

by fluffy at 8:57 PM
So, the friend who hosts this site for me popped online and gave me a little code snippet:
rc(char*ni){char*n=ni;while(n&&*n){if(*n>='A'&&*n<='Z'){*n+=32;if(*(n+1)){*(n+1 )-=32;return;}else{*ni-=32;}}n++;}}main(int c,char**v){if(c<2)exit();while(1){printf("%s ",v[1]);rc(v[1]);}}
Basically, compile it and run it with something like "./a.out Foobar" and it'll output the string repeatedly, rotating the capitalization to the right. (With the caveat that it doesn't work with more than one capital letter.)

But it seemed rather bloated to me, so I rewrote it...

July 5, 2003

New AudioCompress release ()

by fluffy at 11:12 PM
Grab v1.5 while it's hot.

Also, this is the 28th entry. (Yes, I know the archive file isn't numbered 256. But trust me anyway, this is the 256th entry.)

July 3, 2003

New AudioCompress feature ()

by fluffy at 9:05 PM
Hopefully I'll be making an AudioCompress release soon, since someone submitted a patch to let it act as an esd plugin (so all esd-speaking apps can be processed by it, which makes me very happy indeed).

The only reason I'm not releasing it yet is that for some reason, it keeps on blocking on write after 31 fragments are processed. Anyone have any ideas? The patch submitter doesn't have any idea what's going on for me.

June 30, 2003

Ooh, Mac stuff I missed ()

by fluffy at 9:17 PM
It was mentioned on various weblogs but I never paid it any mind, but XCode looks awesome. It might be the impetus for me to finally write the windowing abstraction layer in Solace, which will finally give it Ultra Super Portability (and not just "pretty good portability to systems which can run an X11 layer).

Namespace collision ()

by fluffy at 8:27 PM
Not really a "code" entry, but it's about Solace, so...

Basically, bt let me know about a slight namespace collision between Solace (my ongoing renderer project) and Solace (an online boardgame). Fwee.

Update: The situation has been resolved in a way agreeable to both. If only all trademark issues were so easily dealt with. :)

June 13, 2003

Hardcore lighting stresstest ()

by fluffy at 5:45 PM
Haven't posted about my graphics engine in a while, so here's some pictures of my dynamic shadow stresstest running at 20fps.

May 18, 2003

Idea: Directory transaction logs ()

by fluffy at 10:10 PM
Something I've been thinking about recently.

Concept: Take advantage of underlying UNIXisms to make a file system which has complete, or at least pretty good, undo recovery.

Older »