language-agnostic

How to check if current OS is Windows 7?

I'm developing a windows app (it depends on DirectShow, so no Linux, etc). It will run, for now, in XP and Windows 7 (no Vista support). However, there's a piece of code that behaves very differently in XP or Windows 7, so I need to know in which system I am, to make a workaround. As I don't support Vista -and even if I did, I guess th...

What are some uses of closures for OOP?

PHP and .Net have closures; I have been wondering what are some examples of using closures in OOP and design patterns, and what advantages they have over pure OOP programming. As a clarification, this is not a OOP vs. functional programming, but how to best use closures in a OOP design. How do closures fit in, say, factories or the obse...

Elegant way to handle "impossible" code paths

Occasionally I'll have a situation where I've written some code and, based on its logic, a certain path is impossible. For example: activeGames = [10, 20, 30] limit = 4 def getBestActiveGameStat(): if not activeGames: return None return max(activeGames) def bah(): if limit == 0: return "Limit is 0" if len(activeGames)...

Reliable way to (programmatically) compare PDFs?

I am in the classic scenario where the business gives you a bunch of new pdf forms for the new year with no revision notes whatsoever and you are supposed to figure out what's different from the previous year ones. I am talking loads of forms here, so I am trying to find a way to compare PDFs to outline differences without having people...

Find largest number with all contiguous triples being unique primes

Find largest number with all contiguous triples being unique primes If the digits of the answer are pqrstu...xyz then pqr, qrs, rst ... etc are all unique primes. As expected, extra points for speed, conciseness, and other good things. I can run Python/C/C++/Java on my comp and will try to update the answers with the running time of...

joining two tab-delimited files by column with same identifiers in ONE step (command)?

Very often I want to join two ascii-files, which are both tables in the sense that they consist of columns separated by tab, like this: file 1 FRUIT ID apple alpha banana beta cherry gamma file 2 ID FOOBAR alpha cat beta dog delta airplane and I want to join them like this with an inner join: FRUIT ID FOOBAR appl...

Architectural decisions: main site, forum, blog

I've been consulted with on the setup of a project and would like to bounce my ideas off of someone for extra opinions. The main part of this website is very complex and has very customized functionality, so from what I saw it's more of a webapp. However a blog is needed and also a forum is needed. This is the general overview of this ...

Computational cost of trig functions

Possible Duplicate: How do Trigonometric functions work? What actually goes into the computation of trig functions like Sin, Cos, Tan and Atan? I think I've found an optimization in my code where I can avoid using any of these functions and base the problem around slope instead of angles. So that means a couple division oper...

Can message-oriented middleware be used instead of MPI to coordinate distributed computation?

By message-oriented middleware I am referring to technologies such as Advanced Message Queuing Protocol. Obviously AMQP is a different beast than MPI, but I would think distributed-memory computations that operate in a master-slave manner could be trivially implemented using AMQP, letting AMQP handle equitable work distribution to sla...

Algorithm for sorting loosely comparable data?

Let's say I have an unsorted list of four objects: [B, C, A, D]. All four objects are of the same type, and: (A > B), (C > D), (A != C or D) (B != C or D) (C != A or B) (D != A or B). By "!=", I mean that they are neither less-than, equal-to, or greater-than the other objects. I need to "sort" the list such that A will alway...

Reproducing images with primitive shapes. (Graphics optimization problem)

Based on this original idea, that many of you have probably seen before: http://rogeralsing.com/2008/12/07/genetic-programming-evolution-of-mona-lisa/ I wanted to try taking a different approach: You have a target image. Let's say you can add one triangle at a time. There exists some triangle (or triangles in case of a tie) that maxi...

General purpose open source taxonomy database

I am looking for a database which could help me group thousands of English-language keywords to few general disciplines. For example: I HAVE THIS => I WANT TO HAVE THIS cat => animal chair => household wine => drink deer => animal beer => drink glass => household, drink total 50 000 keywords => total <100 disciplines I guess that orga...

Convert pixels into relative cm from a clickable image?

Hi, Having a bit of a brain freeze on how to do this. I have an image of an area of a soccer field which the user clicks on to indicate where something occured. I want to store the coordinates in real world units in my database so that I could change the image at a later time. However, I can't figure out the formula to do this (ignori...

What is rc stands for

Hi, I saw a lot of times code where return status of function was set to *rc * variable (e.g. int rc = foo();). I though it some sort of convention and blindly used it all over my code. Recently was asked by colleague what *rc * stands for and discovered that I indeed don't know the answer. Thanks ...

Position N circles of different radii inside a larger circle without overlapping.

Given n circles with radii r1 ... rn, position them in such a way that no circles are overlapping and the bounding circle is of "small" radius. The program takes a list [r1, r2, ... rn] as input and outputs the centers of the circles. I ask for "small" because "minimum" radius converts it into a much more difficult problem (minimum ve...

What is an opaque value?

What is an "opaque value" in C++? ...

What should your transaction management strategy be for an e-commerce system?

What is the general pattern or approach to managing transactions in a web-based e-commerce system? How do you handle the situation where more than one user tries to buy the last item, for example? ...

Finding overlapping sets

I'm writing a Digital Fountain system in C#. Part of this system creates me sets of integers, I need to find the combinations of sets which create can leave me with a set of just one item. What's the fastest way to do this? Set A: 1,2,3,4,5,6 Set B: 1,2,3,4,6 Set C: 1,2,3 Set D: 5,6 Solutions: A - B => 5 A - (C + D) => 4 I don't need...

Most underestimated development tool?

What is, in your opinion, the most underestimated development tool? With that I mean a tool that can be immensely useful, but rarely gets used? Reasons might be because the tool is so little-known, or that the use case is so obscure that people don't realize it could be used this way? (The purpose of this question, of course, is to get...

Fix bugs in library code, or abandom them?

Assume i have a function in a code library with a bug in it i've found a bug in a code library: class Physics { public static Float CalculateDistance(float initialDistance, float initialSpeed, float acceleration, float time) { //d = d0 + v0t + 1/2*at^2 return initialDistance + (initialSpeed*time)+ (acceleration*P...