Jump to content
MrHoatzin

quaint hacky solutions that we're proud of or amused by

Recommended Posts

I tend to be wary of hacks, generally. Sometimes they are the best solution, tho, when they effectively save time and drudgery in a special case situation.

Yesterday I had to queue up something to go live this morning at seven thirty. To make the thing live, I had to run two lines of sql. I could've changed the way the frontend works, inserted some timestampes into the tables and made a robust queuing mechanism—which would be overkill. Alternatively I could've, made a cron job, but I had never messed with cron so I would've had to learn to cron, test it and spend a bit of time playing with it, and I didn't have the time, so I inserted this bit of PHP into the head of the site's template:

$fancySqlTimerHack = mktime(7,30,0,9,15,2009);

if(time() > $fancySqlTimerHack && time() < $fancySqlTimerHack + 18000){	//give it a five hour window for a stray visitor to trigger stuff
mysql_query ("UPDATE `spot_location` SET `retired` = 1 WHERE `id` IN (522,523)"); 
mysql_query ("UPDATE `spot_location` SET `retired` = 0 WHERE `id` IN (525,526,527,528,524,533)");
}

And then I cleaned it up this morning when I got to work, so that it would stop rewriting the database every time someone came to the site.

I think this proves that the tree falling in the jungle in fact does not make a sound if no one is around to hear it. Or, um, that it doesn't fall until someone comes around to listen to it fall. Or something like that.

So, share your fun hack anecdotes!

Share this post


Link to post
Share on other sites

[edit]oh, didn't read the title completely. the hack I posted was not really amusing or something I'm proud of.

my favourite is increasing a number in the name of a CSS or JavaScript file whenever the file changes: to force Internet Explorer to not use the cached version.

Edited by Erkki

Share this post


Link to post
Share on other sites

About 4 years ago, deciding that the internet was more important than bathing for a few days:

441328514_cb05e5fc77.jpg

Our ISP went down, and the only nearby open wifi could only be picked up in the bathroom, so we had a wifi dongle on a piece of wood sticking out of the window, and a machine in the bath feeding the connection to a router for rebroadcast.

Share this post


Link to post
Share on other sites

Hmm... I can't think of any hacky solution I'm proud of or amused by. I have made some hacky solutions which are quite complex, but I'm not really proud of it.

Share this post


Link to post
Share on other sites

I'm embarrassingly novice at this sort of thing, so I'm sure this is obscenely trivial, but I was fairly pleased with it anyway. Basically, we're using some software to create templates that generate HTML. Unfortunately, some of the values we're pulling in are boolean, and we've been told there's no conditional logic possible with the templates' macros. Our design guy was wondering how to avoid simply printing the "Yes" or "No" to the page (as that's all the boolean variables served), so I suggested surrounding the possible output with a span or div, then embedding the macro into the class name, with the following CSS:

.classYes { display : inline }
.classNo  { display : none   }

Or something to that effect. Not particularly ground-breaking, I know, but it did the job and was (to me, at least) an amusing work-around. Of course, it turned out that we could do conditional logic with the macros, after all, and the person who'd told us otherwise just didn't know what he was talking about. I suppose that's the price of using software whose documentation is a work-formerly-in-progress wiki.

Share this post


Link to post
Share on other sites
my favourite is increasing a number in the name of a CSS or JavaScript file whenever the file changes: to force Internet Explorer to not use the cached version.
Yeah, I generally don't care about stupid caching of IE. Google Maps api, however, simply refuses to refresh an xml file of geocodes more than once a day no matter what. I had to do some .htaccess trickery there and while testing I had it throw out a random huge number every time the page is refreshed.

RewriteRule ^geomarkers([0-9]+).xml$ lego/_executeMapXml.php?junkyTimeyStampyVar=$1&%{QUERY_STRING} [PT,L]

But there is only a fixed number of unique queries google lets your site have per day or something, so I changed that huge mystery number to default to the timestamp of the last db edit, and presto! Now it will only refresh when needed, and let google keep its cache without it messing up my end.

Share this post


Link to post
Share on other sites
About 4 years ago, deciding that the internet was more important than bathing for a few days
That is a shockingly clean bathroom considering you're a revolting icky person who easily sacrifices hygiene to technology addiction, apparently.
I'm embarrassingly novice at this sort of thing, so I'm sure this is obscenely trivial, but I was fairly pleased with it anyway.
Every time I have to edit someone else's ASP site or a yahoo store, or any other platform that I don't care to learn about, I will invariably have to resort to those kinds of solutions. They can get quite crazy.

Working in what is essentially marketing can be wearying. I get to do so much patchwork on so many weird ancient sites (initially built sloppily, to impossible deadlines) that no one wants to spend money on to properly rebuild. I wish I worked on more sites that were the end product, rather than a single tool of many available tools for hocking crap. ;(

Share this post


Link to post
Share on other sites

Not being a programmer I don't have any hacky tricks, however I did read a good article about them on Gamasutra that I found pretty amusing.

...someone noticed that the game didn't crash if you rotated the camera 90 degrees to the right. Initially, the programming team correctly waved this off as some kind of fluke that was masking the underlying bug. This isn't the type of "fix" that would repair the root cause of a crash. That didn't stop us from shipping it though!

Share this post


Link to post
Share on other sites

That Gama article was in Game Developer earlier this year, and is absolutely hilarious.


That is a shockingly clean bathroom considering you're a revolting icky person who easily sacrifices hygiene to technology addiction, apparently.

We lived with a fascist cleaner.

Share this post


Link to post
Share on other sites

ok, I recently created a hacky solution I'm sort of proud of:

http://wiki.beyondunreal.com/UE3:Insertion_Sort_Macro

It's basically an preprocessor marco that implements insertion sort of a dynamic array. And you might thing this is a terrible solution, but it isn't. UnrealScript (the scripting language used in the UnrealEngine) doesn't optimize code, and certain things are quite expensive. For example, function calls are quite expensive. A normal quicksort is very heavy on it's function calling. It's usually better to implement a selection or insertion sort. This hack provides an easy way to perform inline sorting of any dynamic array of any type, by the simple use of 2 macros.

This is a hacky solution because it's implemented as a preprocessor macro. Preprocessors is a hack to begin with. But also, this isn't the way you should implement functionality like this. But due to certain limitations and/or considerations, this quite a nice hack.

ps, I'm considering optimizing this routine, but I need to resolve a semantic issue first. i.e. does !(A>B || B>A) mean A==B? I'm considering to say yes, but == is much stronger in its meaning than the other construction.

Share this post


Link to post
Share on other sites
This thread scares me... (sorry)

I'm the same. It sounds like the future. Lines like this -

"It's basically an preprocessor marco that implements insertion sort of a dynamic array."

- make me question whether I really do know how to use computers.

Share this post


Link to post
Share on other sites

Nearly everything I end up putting in a Telltale game is a quaint hacky solution that I'm proud of or amused by, (un?)fortunately.

Share this post


Link to post
Share on other sites
whether I really do know how to use computers.

I don't know much about signal processing and multiplexing of multiple channels through a single piece of copper. But I can still watch TV.

I don't understand how "Law" is supposed to work, but I can still break it.

Share this post


Link to post
Share on other sites
does !(A>B || B>A) mean A==B? I'm considering to say yes, but == is much stronger in its meaning than the other construction.

Could someone, in theory, define a funky custom data type where == is calculated with a different level of accuracy than to < or > in UnrealScript? That's the only pitfall I can think of.

Share this post


Link to post
Share on other sites
Could someone, in theory, define a funky custom data type where == is calculated with a different level of accuracy than to < or > in UnrealScript? That's the only pitfall I can think of.

Was purely talking semantically.

And in any language you'll be able to define comparators for >, <, == and have a case where !(A > B || B < A || B == A) could be true. Because equals might not always live on the same plane of meaning.

A example would be NaN for integers, and mathematically there's also infinity.

For example when A = ∞, B = ∞ the previously mentioned statement is true (or should be).

Anyway... I concluded that if !(A > B || B > A) is true it doesn't matter of B == A or not. It doesn't matter in case of sorting the results, because it's ambiguous anyway.

Share this post


Link to post
Share on other sites

Somewhat off topic, but I was thinking about UnrealScript earlier today... Java is quite similar to UnrealScript: in design principles, syntax (at least the last time I used it -- in the Deus Ex version of the engine), in performance (actually Java probably performs better thanks to the JIT compiler, and occasionally even better than C++ code). Why isn't there an engine built like the Unreal Engine, but with Java taking the place of UnrealScript (or instead of Java it could be any language for the Java VM, such as Scala, Groovy, JRuby, etc.). There's so much research done on the Java VM and it keeps getting faster and better with each release. Why don't game developers take advantage of that?

Ogre and other C++ engine wrappers for Java are something like that, but they don't seem to be used much. One factor is probably the awkward mapping between Java and native code, but some newer tools can do that much easier.

Another factor could be Sun's licensing issues (although there are other VM's of course, they generally are not as good) and the fact that the design of the Java VM is more focused on "enterprise" server applications, not games (you could probably throw out 90% of Java when using it for a game). Still, the constant improvements benefit games as well, and I'm sure such an engine would easily beat XNA performance-wise.

Then there are engines written purely in Java (only using OpenGL natives and such), but not much comes to mind that has combined native code for performance-critical engine stuff with Java for game code.

Share this post


Link to post
Share on other sites

The problem you always have with using an existing language and VM with your engine is that you need to create a mapping. UnrealScript is build around the unreal object system. So there is a direct mapping from native code to unrealscript. No level of indirection.

Share this post


Link to post
Share on other sites

The mappings between Java & C should be easier now with JNA and various new tools such as http://code.google.com/p/jnaerator/ (haven't used them myself, though). But yeah I guess that has been (or still is) one of the problems why this hasn't happened yet.

Share this post


Link to post
Share on other sites
The mappings between Java & C should be easier now with JNA and various new tools such as http://code.google.com/p/jnaerator/ (haven't used them myself, though). But yeah I guess that has been (or still is) one of the problems why this hasn't happened yet.

But you would still have 2 instances of the object, instead of just one 1 object with 2 interfaces. You would need to use JVM as the base for your engine in order to get a similar integration as the UnrealEngine solution.

Doesn't have to be a bad thing, actually... would be quite nice. All you have to do is implement java native interfaces for certain features which sucks in Java: hardware graphic, physics middleware, audio (middleware), ...

Share this post


Link to post
Share on other sites

Yeah, and that's what existing Java engines (JMonkeyEngine, Ardor3D) do basically. So maybe there isn't much point to what I said.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×