language-agnostic

PathFinding Algorithm: How to handle changing Weights Efficiently

So, I have a simple pathfinding algorithm which precalculates the shortest route to several target endpoints, each of which has a different weight. This is somewhat equivalent to having one endpoint with a node between it and each endpoint, though the edges there have different weights. The algorithm it uses is a simple spreading algor...

What is Shadow Memory?

What is Shadow Memory? Can SO briefly shed light on how memory profiling tools use it? ...

Maintaining message integrity

I have a message that I am passing to myself which will be subject to man-in-the-middle attacks. Because of that, I am concerned about the integrity of the message being maintained between the time I send it, and the time that I receive it back. It should be assumed that once I send the message to myself, no information about the messa...

How to model "products" in an online store application

I'm building an online store to sell products like "Green Extra-large, T-shirts". I.e., the same shirt can have many sizes / colors, different combination can be sold out, different combination might have different prices, etc. My question is how I should model these products in my Rails application (or really how to do it in any applic...

A copyright / license comment for common utility apps while do contract work

I'm doing some contract work who need the source code for the application I'm writing. For the new files I'm writing for the customer, I'm giving them the copyright. However, there are some utility files (for OS abstractions like threading) I'm using that I've developed on my own (not on the customer's dime). I want to keep the right ...

Plain, linked and double linked lists: When and Why?

In what situations should I use each kind of list? What are the advantages of each one? ...

Is there a tool for software engineers to track their Requirements -> Design Docs -> Source?

So I recently finish my 3rd year software engineering project. The project was a game. It was not easy in the least. The most challenging project I have done. After some reflection I noticed that the major problem our group had was: Our SRS rarely matched our Design Diagrams Our architecture was not well defined And Lastly our c...

Beginning 3d Programming: Book/Website Suggestions?

First an overview of myself: Graduated almost 5 years ago w/ degree in Computer Engineering, minor in Math Currently attending grad school for MS in Computer Science. Work experience since college has been primarily VB.Net, ASP, SQL, etc, "business apps" Preferred C/C++, ASM, and other "lower level" languages in college, but haven't ha...

How do you implement a dispatch table in your language of choice?

A dispatch table is a data structure that associates an index value to an action. It's a rather elegant replacement for a switch-type statement. Most languages have support for dispatch tables, but the support ranges from do-it-yourself to built-in and hidden under a layer of syntax. How does your favorite language implement dispatch ...

How do you handle different character encodings?

I'm trying to understand the basics of practical programming around character encodings. A few things to consider: I know how to read a file whose encoding is different, and convert it to the console's encoding. But when I try to convert literal strings that appear in source code, for some reason, it doesn't always work: In IntelliJ'...

Probability Question

I have x items and y <= x special items. Out of these I pick z <= x items. Given s where 1 <= s <= y, what is the probability that the z items I picked contain s special items? The particular case I want to apply it to: I have 70 items, 14 are special. I pick 5 of them. What's the chance that 1 is special, 2 are special, etc... up to 5...

Longest Simple Path

So, I understand the problem of finding the longest simple path in a graph is NP-hard, since you could then easily solve the Hamiltonian circuit problem by setting edge weights to 1 and seeing if the length of the longest simple path equals the number of edges. My question is: What kind of path would you get if you took a graph, found t...

Best way to display default image if specified image file is not found?

This is NOT a duplicate of this question even though they have the same title. I've got your average e-Commerce app, I store ITEM_IMAGE_NAME in the database, and sometimes managers MISSPELL the image name. To avoid "missing images" (red X in IE), every time I display the list of products, I check the server for the image related to th...

How many units should there be in each generation of a genetic algorithm?

I am working on a roguelike and am using a GA to generate levels. My question is, how many levels should be in each generation of my GA? And, how many generations should it have? It it better to have a few levels in each generation, with many generations, or the other way around? ...

Best bugfixing/errorfinding strategy - all languages

Hi! I found out, while shoulder surfing some other - much more experienced programmers - that they all have different strategies in finding (their) errors in (their) code. And I don't mean understanding compiler error messages, but understanding the reason why the error message occurs - immediately by following the code-flow and locat...

Behavior of connect() with TCP

I call connect() on the client. The client enters the SYN_SENT state and sends a SYN. Now it gets a SYN with no ACK in it, so the client enters the SYN_RCVD state. Does connect() return at this point? Technically you have enough information to be able to call send() and recv() on the socket. The RFC itself says, if you call SEND on a s...

How do you normalize a zero vector

Suppose you have a function 'normalize' which takes a list of numbers (representing a vector) as input and returns the normalized vector. What should the result be when the vector is all zeros or the sum of its components is zero? ...

Implementing sort and/or search algorithms - where and why

From time to time have I come across manually implemented sort and/or search algorithms, instead of using language implemented algorithms. Most source code I've been looking into is written in Java, C# or PHP - but I'd guess this phenomenon is language agnostic. Regarding regular data structures such as lists; Why and where do you imple...

Print two-dimensional array in spiral order

How do I print a 5×5 two-dimensional array in spiral order? Is there any formula so that I can print an array of any size in spiral order? ...

How can I generate a file of random negative and positive integers in serial?

I want a file of randomly generated positive or negative serial integers. For now, I ask the file contain roughly (no guarantee required) equal numbers of negative and positive, but make it easy to change the proporotions later. By "serial", I mean the kth random negative is equal to -k, and the kth random positive is equal to +k. Thi...