language-agnostic

Test Driven Design - where did I go wrong?

I am playing with a toy project at home to better understand Test Driven Design. At first things seemed to be going well and I got into the swing of failing tests, code, passing test. I then came to add a test and realised it would be difficult with my current structure and that furthermore I should split a particular class which had t...

An algorithm to space out overlapping rectangles?

This problem actually deals with roll-overs, I'll just generalized below as such: I have a 2D view, and I have a number of rectangles within an area on the screen. How do I spread out those boxes such that they don't overlap each other, but only adjust them with minimal moving? The rectangles' positions are dynamic and dependent on us...

Is it feasible to create a NullObject for every class? ( with a tool of course )

The NullObjectPattern is intended to be a "safe" ( neutral ) behavior. The idea is create an object that don't do anything ( but doesn't throw NullPointerException either ) For instance the class defined as: class Employee { private String name; private int age; public String getName(){ return name; } public int get...

How to model this kind of artificial intelligence?

Hello, while playing to this game I wondered how an AI controlling either the detectives either the criminal could work. For lazy people the aim of the game is simple: the board game is an undirected graphs that has 4 kinds of edges (that can also overlap for same pair or vertices), each kind is a type of transport that requires a sp...

What's the best design pattern for PHP when Class_a only occasionally needs Class_b information?

This project is in PHP, but is fairly language agnostic. I'm building a project that has the following MVC format Main_Class Main_Class_Common --> Class_A --> Class_B --> Class_C --> Class_... --> Class_K Original requests go to the Main_Class which then includes the appropriate main sub class. The majority of a request will...

Do I have to manually remove all event handlers for each instance??

Consider this class: Class Item : Inherits ItemBase Public Sub New AddHandler MyEvent, AddressOf MyEventHandler End Sub Private Sub MyEventHandler() End Sub Private Sub MySecondEventHandler() Handles MyBase.MyEvent End Sub End Class Do I have to manually remove the handlers on destruction of thi...

Whats wrong with these beginner style codes?

I'm a beginner and I was reading http://stackoverflow.com/questions/237241/what-coding-mistakes-are-a-telltale-giveaway-of-an-inexperienced-programmer. I didn't get few things. 1.Why writing something like this is frowned up on? if (IsAManMan == true) { Console.WriteLine("It's a MAN, man!"); } 2.what about this? if (test) { r...

Reliable way to wait for another Windows process to redraw its main window

I am moving a window (belonging to another process) to the front in order to take a screenshot of it. I am able to do this using SetForegroundWindow, however that function returns immediately. The other process takes a varying amount of time to redraw its main window (which requires it to access a database) so I cannot be sure that whe...

Is the use of machine epsilon appropriate for floating-point equality tests?

This is a follow-up to Testing for floating-point value equality: Is there a standard name for the “precision” constant?. There is a very similar question Double.Epsilon for equality, greater than, less than, less than or equal to, greater than or equal to. It is well known that an equality test for two floating-point values x and y s...

Resource(s) for learning bitwise operation?

I was recently asked a question, "how do you multiply without using the multiplication operator, without any sort of looping statements or explicit addition" and realized I wasn't familiar with bitwise operation at all. There is obviously wikipedia but I need something with more of an explanation geared toward a newbie. There's also thi...

TopCoder algorithm problem - how to make progress on this one?

I've recently joined TopCoder and have been practicing in the Practice Rooms for the last few days. I came across this problem which I cant seem to solve. Any help will be appreciated. The problem The product value of a string is the product of all the digits ('0'-'9') in the string. For example, the product value of "123" is...

Pattern for website content that updates periodically?

I often find myself designing simple little web projects that are serving up aggregate content or doing a 'mashup'. Typically this involves running a script to scrape/parse/manipulate some data periodically, then serving that as 'static' content. I run the 'refresh' script as a cron job that generates HTML that is served up to the end-...

clear all but the two most significant set bits in a word

Given an 32 bit int which is known to have at least 2 bits set, is there a way to efficiently clear all except the 2 most significant set bits? i.e. I want to ensure the output has exactly 2 bits set. What if the input is guaranteed to have only 2 or 3 bits set.? Examples: 0x2040 -> 0x2040 0x0300 -> 0x0300 0x0109 -> 0x0108 0x5040 -> ...

Is there a way to stop users from downloading an image from your website?

I'm using asp.net but open to using any language for doing this. I've seen some javascripts that does this but they seem pretty easy to get around. Is there a reliable way to keep users from downloading an image? ...

What is a "tagged DFA"?

I came across a regular expression library http://laurikari.net/tre/ and also http://hackage.haskell.org/package/regex-tdfa , but I could not find anything about this "tagged DFA" approach that they are using: neither on the pages of these libraries, nor in google (incl.scholar). Anyone know what it is about? ...

Great tools which help in development?

Apart from all the IDE's and their features or plugins (and lets skip version control systems too), what tools do you use which help you with development? This can be almost anything, but please keep it computer related. Not that i have something against your dog being very helpful with bug-fixing, but i do like cats more ;) ...

Finding the optimum column and row size for a table with n elements and a given range for its proportion

I am looking for an optimum way to create a table from n elements so that ideally there are no empty cells, but at the same time the proportion of the table dimensions colums / rows becomes as close to 1 as possible. Of course if n is a square number it is easy since then cols = rows = sqrt( n ); If n is a prime number it is also cle...

How to use transposition tables with MTD(f)

I'm writing an AI for a card game and after some testing I've discovered that using MTD(f) on my alpha beta algorithm - a series of zero-window searches - is faster than just using alpha-beta by itself. The MTD(f) algorithm is described well here http://people.csail.mit.edu/plaat/mtdf.html The problem I have is that for each pass in th...

Managing the "jack of all trades" concept : not focused on one thing, professional in a limited number of things

This may be closed, a couple of minutes from now, but I think I should still ask this. As I have seen in the industry, it really helps if you know more languages than just one; if you can work with a number of SQL engines than just one, and in rare cases, if you know both software engineering and programming (etc, etc, and the list goes ...

Perform atomic array modification in memcache

Suppose you want to keep an list of the last 10 visitors to your site in memcache. Every time that someone accesses your site, you want to push them onto an array and shift off the first visitor in the array. Of course, a potential problem is that multiple visitors could be overwriting and reading this array at the same time, possibly ...