Endianness

grahams - - 2 mins read

We were having endianness issues reading in some binary data in the Windows version of my project at work… While we were able to use the network byte-ordering routines ( htons(), etc) to swap the integer values, byteswapping floats were a bit trickier… After beating my head against the desk for a few hours yesterday, I gave up and went home… When I got home I read the IEEE Floating Point spec (IEEE 754) until I understood how they were represented in memory, and this morning I wrote this code to properly do the swapping:

double fswap( float f ) {
union {
float f;
unsigned char b[4];
} u1, u2;

u1.f = f;

u2.b[0] = u1.b[3];
u2.b[1] = u1.b[2];
u2.b[2] = u1.b[1];
u2.b[3] = u1.b[0];

return u2.f;
}

When I first learned C a gojillion years ago I thought to myself “What the hell could you possibly use a union for?” Guess I found the answer… :)

You’d have to change it up a bit to swap a double… Here’s a stab at an implementation for doubles, although I haven’t tested it:

double dswap( double d ) {
union {
double d;
unsigned char b[8];
} u1, u2;

u1.d = d;

u2.b[0] = u1.b[7];
u2.b[1] = u1.b[6];
u2.b[2] = u1.b[5];
u2.b[3] = u1.b[4];
u2.b[4] = u1.b[3];
u2.b[5] = u1.b[2];
u2.b[6] = u1.b[1];
u2.b[7] = u1.b[0];

return u2.d;
}

Thought y’all might find it interesting, and it might be good to add to your toolchest in case you ever run into this same problem.

The Donkeys Wish You A Merry Christmas

grahams - - 1 min read

Here is the cover of my Aunt & Uncle’s Christmas Card:

You may notice that one of their donkeys has a bell around it’s neck. This is because the horse is blind, and follows the sound of the bell.

Soft Restart

grahams - - 1 min read

Had a dentist appointment this morning at 9:45pm, which provided me an excuse to sleep in a bit, which definitely aided in my sleep schedule adjustment.. Had the crown prepped and the mold taken, and will have to go back in a few weeks (after my trip to CA) to have it installed. Got into work around noon, went straight to lunch, and have been playing catch-up for the rest of the day. Looks like I will be working on a new project soon, which sounds pretty interesting…

This weekend I just lazed around, although I did come up with caching versions of my CD List and DVD List. The old versions would hit the database server every time, these new versions check the table modified time first and rebuilds the cached version if necessary. This wasn’t a huge deal at CSH, but it was at sean-graham.com, since it was hitting up the CSH database, which was slow over the net. Those pages now load much faster, unless you are the unlucky soul who hits it when the cache is stale… :)

Happy New Year!

grahams - - 2 mins read

Had a great time yesterday, after a bit of a rough start… Before landed in Boston I needed to get to the store to do some preparations for the party we were throwing… I headed down to the Alewife area to hit up TRU to get a copy of Outburst that Corinna wanted. There is a Hippie Mart over there, so I figured I would get my grocery shopping done as well. Well, it took me like 20 minutes of searching the store to FIND the game, then another 20 minutes to check out. I made my way through the parking lot over to the supermarket, but there were so many people in the lot that THIS took 20 minutes before I gave up, not having enough time to shop before I had to be at the Airport.

Corinna landed safely, and I was there in time… We got back to the apartment, after stopping at the River St. Hippie Mart, and pretty much instantly set about preparing for the party… I also received my awesome hand-made slippers from Corinna’s Stepsister, .. Holy crap are they comfortable… I have to shrink them a bit to fit right, which will require some laundromat maneuvers, but it shouldn’t be that bad even for a laundry gimp like myself. Everyone started showing up around 7:30pm last night, , , Michelle, Audra, and all came over, and stayed well into the night (Audra spent the night). We made way too large of a commitment to food and drink preparations, but it wasn’t too bad. There are lots of leftovers, but they hopefully won’t be leftover for long. We celebrated the arrival of the new year on the roof of the building, watching the Boston Harbor fireworks in the distance… The view up there is truly beautiful (if you like cityscapes, that is.. :P).

Woke up pretty late this morning, around noon, but I wasn’t even tired when I tried to sleep at 3am last night, so it took a long while to fall asleep. I did all the dishes this morning, which was surprisingly not as shitty as I had expected… Now Corinna and I are going to settle in and watch our first movie of the new year, The Last Samurai, which I’m not expecting to be great, but want to see anyway.

The Movies I saw in 2004

grahams - - 4 mins read

Series: Yearly movie lists

Here’s a list of the movies I saw this year… If you compare it to last year’s list, you’ll notice that I saw a few more films in the theatre this year, more than one a week on average (which isn’t surprising since I head up the Boston Sunday Night Film Club). You might also notice that I saw fewer films on video this year… I guess that’s what getting a job’ll do to ya… Damn employment! :)

My General Theory of Christmas Decorations

grahams - - 3 mins read

I have been observing trends in Christmas decorations for some time now, and I think I have developed a generalized theory to describe their trends.. There are four phases to the Christmas decoration product lifecycle, and the first three phases typically last one holiday season. They are as follows:

  1. Bleeding Edge - One or two people in your area have the decoration. These people are almost like the beta testers for the product… More accurately, they are like Patient 0 for the meme.
  2. Cutting Edge - A handful of people, perhaps 5% of your local population, have discovered this decoration and have purchased it and put it on display. What’s interesting about this phase is that if the product has made it to this phase, it will continue on through the subsequent phases. While a product might die on the vine at the first phase, once it’s “cool” enough for this handful of people to adopt it, it will achieve traction with the rest of the decorating community.
  3. Fad - A huge percentage of the decorating population has bought several of these decorations.. Things are completely out of hand, and headed for disaster. (i.e. 2004’s “Inflatable Decoration” craze)
  4. Passé - This is the endgame… The only people who continue using this decoration in their display are those who don’t realize how lame it has become. Sometimes this period is very brief, and only a few people try to perpetuate this decoration (i.e. the christmas lights with complicated, seizure-inducing blink patterns), but this period can also be drawn out and involve a reasonable swath of the population (i.e. “Icicle Lights” in 2004).

Now, applying this theory to the present, and I have made some predictions… We are comfortable saying that this year’s “Bleeding Edge” decoration is Orb Lights (strings of baseball sized orbs, similar to the Ambient Orbs, which either are a constant color or slowly cycle through many colors). We are also comfortable predicting that one of this years “Cutting Edge” decorations are animated light displays (featuring a set of lights that turn on or off to create a few “frames” of a jerky animated scene…).

It is important to note that I expect it to be possible, on the rare occasion, that a decoration mired in the “Passé” could circle back around to “Bleeding Edge” if it had become obscure enough and “rediscovered”. In fact, I suspect that the “Animated Light Display” has been around the block before. It is also important to point out that distinguishing between Bleeding and Cutting edge can be difficult at times, so it is possible that both the orbs and animated displays are still in their infancy..