hacks

C++ experts: is the offset of a member variable to its class constant under these conditions?

Given a variable foo of type FooClass* and a member variable in that class named bar, is the distance between foo and &(foo->bar) the same in any situation with some constraints: FooClass is a non-POD type. We know that foo will always point to an instance of FooClass, and not some subtype of it. We only care about behaviour under a si...

What really happens in a try { return x; } finally { x = null; } statement?

I saw this tip in another question and was wondering if someone could explain to me how on earth this works? I mean, does the finally clause really execute after the return statement? How thread-unsafe is this code? Can you think of any additional hackery that can be done w.r.t. this try-finally hack? Update 1 well, it seems as though a...

Is it possible to predict a stack overflow in C on Linux?

There are certain conditions that can cause stack overflows on an x86 Linux system: struct my_big_object[HUGE_NUMBER] on the stack. Walking through it eventually causes SIGSEGV. The alloca() routine (like malloc(), but uses the stack, automatically frees itself, and also blows up with SIGSEGV if it's too big). Update: alloca() isn't f...

Can you nest C preprocessor directives?

For instance, is the following possible: #define definer(x) #define #x? Thanks. ...

How Do I Import CSS With Safari and Opera When Using CSS Hacks?

I have a tough one here, but I think the benefit will be great... I'm using the following CSS hack with PHP. The U variable in the file below is a constant, previously defined (before I include this file) as the URL such as http://example.com/. The P constant variable is defined as the physical file path like /var/www/example.com/. (The...

Enumerate or list all variables in a program of [your favorite language here]

A friend asked me last week how to enumerate or list all variables within a program/function/etc. for the purposes of debugging (essentially getting a snapshot of everything so you can see what variables are set to, or if they are set at all). I looked around a bit and found a relatively good way for Python: #!/usr/bin/python ...

Best practice against password-list-attacks with webapplications

Hello, i'd like to prevent bots from hacking weak password-protected accounts. (e.g. this happend to ebay and other big sites) So i'll set a (mem-) cached value with the ip, amount of tries and timestamp of last try (memcache-fall-out). But what about bots trying to open any account with just one password. For example, the bot tries a...

What Healthy Tricks Do You Use to Stimulate Your Brain and Increase Code Output?

There have been a few posts around the place as to what is the best music for coding, etc. While music can certainly make coding more enjoyable, I don't believe it actually makes me more productive and in fact probably distracts me more as I want to mess around with iTunes playlists, ratings and find good music to listen to. I find that...

Specifying Compatibility Modes on a Per-Page Basis for IE8

I have a strange issue with a Telerik RadWindow that only occurs in IE8. It works fine when I force the browser to use Document Mode: IE7 Standards. I am trying to specify IE7 compatibility mode on a Per-Page Basis for just one page in my site. using <head> <!-- Mimic Internet Explorer 7 --> <title>My Web Page</title> <me...

Register DLL in GAC without Assembly Manifest

I have a DLL I wish to register with my GAC. I enter the command: gacutil /i c:\temp\msvcr100.dll and I get the error: Failure adding assembly to the cache: The module was expected to contain an as sembly manifest. All I have is the DLL. Is there a way to create / fake / bypass it? For those interested, I am attempting to extrac...

What is the scope of the * CSS hack?

I have been looking at a hack to solve a CSS problem I have. I haved used one to create a custom rule for Internet Explorer. margin-top:45px; *margin-top:0px; Does this hack apply to all IE browsers? Does this hack appear in any versions of Firefox or Safari? ...

Modify HttpServletRequest body

I'm working on legacy code and need to make a patch. The problem: an ancient application sends bad HTTP POST requests. One of the parameters is not URL encoded. I know that this parameter always comes last and I know it's name. I'm now trying to fix it on the server side which is running inside tomcat. This parameter is not accessible ...

Is there a quick and easy way to dump the contents of a MacOS X keychain?

I'm looking for a way to dump (export) the contents of an OS X keychain into a file that I can easily process elsewhere, such as tab-delimited plaintext or something of the sort. The Keychain Access app does not offer any such functionality, and getting a key's data involves opening each in turn, and having to type in the keychain's pas...

What is the biggest/ugliest hack you've used?

Duplicate: What programming hack from your past are you most ashamed of? What is the ugliest hack you've used in your code? You've not proud of using it, but it works, and you haven't found another way to do it? The ugliest one that I've done was writing some music in Lilypond. I wanted a horizontal bracket over my notes, so I hac...

C#: How to send keyboard scan codes manually?

I'm working on a project that needs to emulate a keypress of the Windows key. I've tried SendKeys.Send to no avail. Specifically, the windows key needs to come in concert with a button. That is, I want to send Windows Key and plus / minus. ...

Automatic log-in in Linux

What is the easiest and most elegant way to log into a fluxbox session automatically (with no action necessary, no keypress or anything) on system startup as a certain user. [Edit 2] Not even a shell login should be necessary for the user, always the preset user should be logged in graphically. [/Edit 2] There are some setups where this...

Is there any way to modify the value of a `private static final` field in java from outside the class? (Or, I need to monkey patch an external library).

I know this is normally rather stupid, but don't shoot me before reading the question. I promise I have a good reason for needing to do this :) It's possible to modify regular private fields in java using reflection, however Java throws a security exception when trying to do the same for final fields. I'd assume this is strictly enforc...

Why would you write something like this? (intentionally not using delete [] on an array)

I came across this kind of code once in a while - I suspect the creator is/was afraid that table delete would iterate over the table and "cost performance" (which imho will not be done either way)... is there any real benefit one might get/consider/imagine from not using the the table delete here? myClass** table = new myClass* [size]; ...

read javascript source

In my html file I put as <script src='http://otherdomain/file.js' ></script> When I run my webpage, that other javascript creates some html content using docuemnt.write command. How can I dynamically read that dynamic html using the javascript on my html page? Is it possible? ...

Concurrency Checks in MSSQL (Alternatives to TSEQUAL)

I am working in development under SQL 2008, however I have a SQL 2000 database (in compatibility mode). There are several queries that are using the "TSEQUAL" function to do concurrency checks. It seems however that this function has been completely removed in SQL 2008 and these statements (sitting in SPROCS) no longer compile. What i...