language-agnostic

How to cluster objects (without coordinates)

I have a list of opaque objects. I am only able to calculate the distance between them (not true, just setting the conditions for the problem): class Thing { public double DistanceTo(Thing other); } I would like to cluster these objects. I would like to control the number of clusters and I would like for "close" objects to be in t...

Owning Up Bad Code

I am moving out of my current company to other opportunities elsewhere. As I was looking at my code base, there were some portions which I had written when I started programming. These screamed 'LOW QUALITY' (not that I write excellent code now, but certainly better code). After I leave, the code would be taken up by my colleague who w...

Code Samples to go with a Resume?

So I've been building up my website with my resume, and it occurs to me that I should post (as I've heard other people talk about) code samples. Unfortunately, I'm not entirely sure what kind of code I should post. Should I post entire projects? Should I just post a neat class with some implementation? Currently my focus is on graphics...

Can a webserver determine if its the active node of an HA failover system without hard coding anything on the server itself?

I can think of a few hacks using ping, the box name, and the HA shared name but I think that they are leading to data leakage. Should a box even know its part of an HA cluster or what that cluster name is? Is this more a function of DNS? Is there some API exposed for boxes to join an HA cluster and request the id of the currently act...

Is there any solution to know the similarity of two pdf without detail content compare

i want to know the similarity of tow pdf files, but i don't want to do the detail content compare . is there any solution just from its external structure .is it possible ?thanks! ...

Distinguishing instruments in a music file

Given a music file, is it possible to split out each instrument that is being played? I.e. let's say I have someSong.mp3, and in that song there's vocals, guitar, bass and drums. I'd want to get 4 "tracks" - one for each distinct instrument. I'm guessing that it's almost impossible to do this, given that instruments can overlap, and it'...

Detecting misspelled words

I have a list of airport names and my users have the possibility to enter one airport name to select it for futher processing. How would you handle misspelled names and present a list of suggestions? ...

Should I "retire" the old trunk of a newly-rewritten project?

Recently I've been revisiting an old project, which I last worked on about two years ago. Obviously, during this time I've learned new habits about how best to program, and I've got the itch to keep the tests, scrap the implementation, and re-implement the entire project. It's not a large project, and I believe I'll not be losing much by...

Should functions that only output return anything?

I'm rewriting a series of PHP functions to a container class. Many of these functions do a bit of processing, but in the end, just echo content to STDOUT. My question is: should I have a return value within these functions? Is there a "best practice" as far as this is concerned? ...

Generate File Names Automatically without collision

I'm writing a "file sharing hosting" and I want to rename all the files when uploading to a unique name and somehow keep track of the names on the database. Since I don't want two or more files having same name (which is surely impossible), I'm looking for an algorithm which based on key or something generates random names for me. Moreo...

Detecting a (naughty or nice) URL or link in a text string

How can I detect (with regular expressions or heuristics) a web site link in a string of text such as a comment? The purpose is to prevent spam. HTML is stripped so I need to detect invitations to copy-and-paste. It should not be economical for a spammer to post links because most users could not successfully get to the page. I would...

What optimizations are OK to do right away?

One of the most common mantras in computer science and programming is to never optimize prematurely, meaning that you should not optimize anything until a problem has been identified, since code readability/maintainability is likely to suffer. However, sometimes you might know that a particular way of doing things will perform poorly. W...

Divide amount by characters present in string, found via regex

Suggestions for an updated title are welcome, as I'm having trouble easily quantifying what I'm trying to do. This is a web-based form with PHP doing the calculations, though this question probably has an algorithmic or language agnostic answer. Essentially, there is an Amount field and a Charge Code field. The Charge code entered r...

Asymtotic run time needed to compute the transitive closure of a graph?

The transitive closure of a graph is defined e. g. here: http://mathworld.wolfram.com/TransitiveClosure.html It is easily possible in O(n^3), where n is the number of vertices. I was wondering if it can be done in time O(n^2). Thanks in advance ...

Uniquely identify IPhone on a web application

I have a website and I would like to open it to some of our corporate IPhone users, but without their intervention : I enter their IPhone "serial #" into our webapp When they connect to the webapp, if their "serial #" is recognised they can pass, otherwise, access denied. Is there such a "serial #" ? I've thought about a SMS with a...

What is the Speed Difference Between Database and Web Service Calls?

All things being equal, and in the most simple form, which is faster? 1.) A call to a web service method 2.) A call to a database For example, assume that you have a simple web service that just returns an integer that is calculated in X time. You also have a database that, when queried in th right way, also takes X time to calculate ...

Syntax highlight design pattern

I'm looking for some good overviews of best practices and common patterns for enabling syntax highlighting in a textbox. It seems like a very common exercise almost all languages have a UI control that enables syntax highlighting in different languages. I'm just curious to see if there is a common pattern of implementation. Is everyon...

Is a good idea to build in-memory indexes and circumvent the DB when operating intensively on a small subset?

I'm working on a program to automatically find optimal shift assignments, subject to lots of constraints. I'm using grails, i.e. the data about workers, shifts and assignments will be kept in a DBMS. For the optimization itself, I'll have to work very intensively on a small subset of the data (about 600 rows total from about 5 differen...

How to preserve build environment during product lifecycle

What are best practices in recording build/test machine(s) setup during the life time of a project? If you need to provide a patch for previous version of your product, you likely need to reload the same compiler and support tools to re-issue the patched release. What and how do you record? The obvious things are:the OS version and pa...

How to find a similar code fragment?

Does anyone has some tool or some recommended practice how to find a piece of code which is similar to some other code? Often I write a function or a code fragment and I remember I have already written something like that before, and I would like to reuse previous implementation, however using plain text search does not reveal anything,...