language-agnostic

Did MS change something about keyboard hooks in Windows Vista or 7?

I've implemented keyboard hooks in several languages (AutoIt, C#) using SetWindowsHookEx and WH_KEYBOARD_LL. I also know of a couple of C++ programs that have the same issue. I didn't post any code because they work perfectly in Windows XP. However, under Windows 7, at some point the hooks become "unloaded" or stop processing any furt...

non-function operator based one-liner for magnitude of an int

I was wondering if there is any way to get the magnitude of an integer without using function calls and only using operators (no control structures). In case I'm using the term magnitude incorrectly here, what I mean is basically how many digits are occupied. eg. 2468 has a magnitude of 4. Otherwise, what is the most efficient way to d...

Algorithm to find fewest number of tags that encompass all items?

I'm thinking this might be NP-complete, but I'll ask anyway. Greedy algorithms don't seem to work in my head. Given a set of items, each with 1 or more tags, I want to find the smallest set of tags that cover all the items. Edit: See my "solution" here. ...

is it possible to check if someone is trying to vote from the same computer

Hi! From my knowledge the answer to this question is no, but i might be missing something. There are some polling sites which claim that voting from the same computer is forbidden and will result in a ban. How can they detect that? A cheater may use routable IPs, different operating systems, different browsers, proxies etc. ...

Multiple parameter optimization with lots of local minima

I'm looking for algorithms to find a "best" set of parameter values. The function in question has a lot of local minima and changes very quickly. To make matters even worse, testing a set of parameters is very slow - on the order of 1 minute - and I can't compute the gradient directly. Are there any well-known algorithms for this kind o...

How to Convert Long to Guid and Vice Versa?

Is this even possible? I don't even think it is, but I saw some code that was trying to do it. However, my unit tests showed that it was not working. I did see some similar thoughts: http://stackoverflow.com/questions/401480/converting-guid-to-integer-and-back http://stackoverflow.com/questions/3563830/converting-system-decimal-to-s...

What are the crucial key items in recording technical debt?

I'm setting up a technical debt register at The Office and want to make it a fairly comprehensive tool. What are the key pieces of information that we should be recording? ...

How do they search inside a string

What is the most efficient way to do this? There must be some better method other than brute force. ...

What is this type of copy called and is it bad pratice?

Shallow copy is when i write new List<List<ClassA>>(lsA) which just copies the member ls. So shallow copies the first list while the inner list is not. Since MyList has access to each T being put in (which its just piping through with C#'s List in this example) it can do a shallow copy each of those. So now all the members of MyList is b...

Online algorithm for calculating absolute deviation

I'm trying to calculate the absolute deviation of a vector online, that is, as each item in the vector is received, without using the entire vector. The absolute deviation is the sum of the absolute difference between each item in a vector and the mean: I know that the variance of a vector can be calculated in such a manner. Va...

Designing a generic DB utility class

Time and again I find myself creating a database utility class which has multiple functions which all do almost the same thing but treat the result set slightly differently. For example, consider a Java class which has many functions which all look like this: public void doSomeDatabaseOperation() { Connection con = DriverManager.ge...

Optimal median of medians selection - 3 element blocks vs 5 element blocks?

I'm working on a quicksort-variant implementation based on the Select algorithm for choosing a good pivot element. Conventional wisdom seems to be to divide the array into 5-element blocks, take the median of each, and then recursively apply the same blocking approach to the resulting medians to get a "median of medians". What's confusi...

Code Golf: Morris Sequence

The Challenge The shortest code by character count that will output the Morris Number Sequence. The Morris Number Sequence, also known as the Look-and-say sequence is a sequence of numbers that starts as follows: 1, 11, 21, 1211, 111221, 312211, ... You can generate the sequence infinitely (i.e, you don't have to generate a specific n...

Optimal way to pass system values to javascript

What is the most effective way to pass object and category ids or other system variables which shouldn't be presented to the user, from server to the browser? Let's say I have a list of items where I can do something with each of them by javascript, for example show tooltip html or add to favorites by ajax, or display on a map. Where is...

Where do I get "junk" data to help test my code?

For my C class I've written a simple statistics program -- it calculates max, min, mean, etc. Anyway, I've gotten the program successfully compiled, so all I need to do now is actually test it; the only problem is that I don't have anything to test with. In my case, I need a list of doubles -- my program needs to accept between 2 and 1,...

Is there a pseudo-random number generator simple enough to do in your head?

Are there are any pseudo-random number generators that are easy enough to do with mental arithmetic, or mental arithmetic plus counting on your fingers. Obviously this limits to fairly simple math - it needs to be something someone of average mathematical ability can do, or maybe average ability for a programmer, not a math prodigy. The...

What is the runtime difference between different parsing algorithms?

There are lots of different parsing algorithms out there (recursive descent, LL(k), LR(k), LALR, ...). I find a lot of information about the different grammars different types of parser can accept. But how do they differ in runtime behavior? Which algorithm is faster, uses less memory or stack space? Or to put this differently - which ...

Language Choice for Multi-Tier/Multi-Threaded/Event-Based Container

I would like to start a new project that consists of multiple tiers, the web tier, event-driven business logic, data processing, etc. I had worked on PHP and Java-based projects for the past few years and speaking from experience, Java (and given the open source libraries to achieve scheduling, ORM, AOP, etc.) is usually a good choice - ...

how do you convert a double to a string?

I know that most programming languages have functions built in for doing that for you, but how do those functions work? ...

How to generate all possibilities of a string with X tokens and Y values for each token

So, I have a template string with X amount of tokens in it. Hypothetically it could look like this: template = "render=@layer0@-@layer1@-@layer2@-@layer3@-@layer4@" The tokens, obviously, take the form of @tokenname@. In this hypothetical case it has five tokens. Each token has a different set of possible values. For example: token0V...