language-agnostic

minimizing overlap in random rectangles

Hi, I have a number of possibly overlapping rectangles, of random size and position within a fixed plane. Since these rectangles are random, some may not overlap: |----- | | |----| |----| | | |----| Some may overlap by just one corner: |-----| | |--|--| |--|--| | |-----| Some may be contained inside an...

How to improve maintainability of functions

I will expand here on a comment I made to http://stackoverflow.com/questions/2244860/when-a-method-has-too-many-parameters where the OP was having minor problems with someone else's function which had 97 parameters. I am a great believer in writing maintainable code (and it is often easier to write than to read, hence Steve McConnell(p...

Unit rotation in a game

I have a unit in a game which is pointing in a particular direction; when it turns to another direction it should take the shortest turn available. The scheme starts at a particular angle, and requires a given angle to lerp (linear interpolate) towards. For example, lerping from 10 degrees to 350 degrees should calculate a target angle ...

Tooltips with infinite timeout?

I'm thinking of setting the timeout on all my tooltips in a WinForms application to infinity (or an extremely large value). The motivation is that it's annoying for the user if the tooltip disappears while I'm still reading it, without providing any extra value whatsoever as far as I can tell. Normally I wouldn't ask something like this...

Writing a system to monitor all nodes in a cluster.

This is a semi-experimental thing for me. I have a cluster of over 100 (variable) nodes, and I want to write a monitoring application that would poll all the web nodes every n (eg 1 or 2) seconds, and record their response times. If the web node is already struggling, I may not want to bring it down by adding more requests. So it woul...

Should I store reference data in my application memory, or in the database?

I am faced with the choice where to store some reference data (essentially drop down values) for my application. This data will not change (or if it does, I am fine with needing to restart the application), and will be frequently accessed as part of an AJAX autocomplete widget (so there may be several queries against this data by one us...

Figure out acceleration to hit a target position with 0 velocity?

I'm trying to get my simulation to stop on a specific point. I have my starting position, an ending position, my current velocity and the time I'd like to take to get there. Since: d = vt + (at^2)/2 I was figuring that d = (end - start) a = 2(d - vt) / t^2 but my end point is way off when I run it. I've tried using two simple updat...

Regular performance tuning and maintenance

How often do you conduct regular maintenance such as stress test your application and/or tune your database indexes for your applications? E.G., Do you tune (defrag, reorganise or rebuild) your database indexes once a week, every six months or only after large volumes of data have been input and do you stress test your application afte...

Getting a response from the mailserver, if the email has been sent

We recently had the problem that important timed emails could not be sent by the mailserver but the Zend_Mail send() function didn't return false since the email was successfully delivered to the mailserver. In our situation the mail cue was jammed up due to some thousends of non sendable emails produced by a couple of cron jobs. How ...

Code Golf: Scrabble-able

Code Golf: Scrabble-able Input: a list of words Output: a legal arrangement for the words on a scrabble board (or false if impossible). Format of output is entirely up to you, as long as it is comprehensible. Bonus points for pretty printing. Scrabble board size is unbounded, no un-listed words should be found in solution. Examples: ...

How to calculate positions of holes in a game board?

I'm making a game with Python->PyGame->Albow and ran into a problem with board generation. However I'll try to explain the problem in a language agnostic way. I believe it's not related to python. I've split the game board generation into several parts. Part one generates the board holes. Holes are contained in a list/array. Each hole...

Monitor brands with common words

Let's say you should monitor the brand "ONE" online. What algorithms can be used to separate pages about the brand ONE from pages containing the common word ONE? I'm thinking maybe Bayes could work, but are there other ways to do this? ...

What is the fastest factorization algorithm?

I've written a program that attempts to find Amicable Pairs. This requires finding the sums of the proper divisors of numbers. Here is my current sumOfDivisors() method: int sumOfDivisors(int n) { int sum = 1; int bound = (int) sqrt(n); for(int i = 2; i <= 1 + bound; i++) { if (n % i == 0) sum = s...

Why use an array to implement a "list" instead of a hash table?

Consider an array versus a hashtable where the keys are just the integral indexes of a list. Their average-case insertion, lookup, and removal big-O bounds are all O(1) constant time. I understand that you may get some low-level wins in cache locality with an array, and there is a marginal (mostly-constant) overhead to the hashtable ope...

What features do you look for (or use most) in refactoring tools?

I'm familiar with the basics, such as "Extract Method." But that is about all that I use. What others are there? This can include refactoring tool features and also macros that you write yourself. ...

How can I get a full list of registered domains?

How can I get a full list of all the registered domains in the world? ...

How to format outgoing email - Create in code or use templates with replaceable values?

What is the best practice to create templates for outgoing email? Should I have each class create the html for the specific email? Should I have a text template with placeholders that are replaced by a common method? In the first option, I'd have a sendEmail method that takes the formatted html string and send the email. Multiple cla...

Parser Generator for changing file.

Hi, are there any Parser Generator which generated parsers are capable of the following: Parse a file and if you change line n then it only reparses the line or the lines which changed because of this. So that the parser don't need to reparse the full file. Greets, Mathias ...

How to deal with with programmers who refuse to indent their code?

The firm where I work has programmers who still don't seem to understand the importance of indentation and write all the code aligned to left margin. What arguments can I put to convince them of the importance of indentation? ...

How does one define and describe these different points in time?

Background: Eldridge asked me to explain what the difference is between the difference phases of time when it comes to writing and deploying code. He wants to know: 1) what is the difference between: 1) design time; 2) compile time; 3) run-time? 2) what are specific examples of things a programmer would not be able to hard-wire into ...