language-agnostic

What is the expected period of a repeating event that has a random (but limited) interval between each occurrence?

Okay, so we've got this event. Awesome, right? We've also got a timer with a fixed maximum duration, like one of those rotary kitchen timers. Not exactly awesome, but definitely handy. When the timer goes off, the event occurs, and the timer is reset to some random value between zero and the maximum duration (every value has an equal c...

What are common file extensions for web programming languages?

What file extensions are used most commonly by different languages? Please don't put source file names (like .java) but rather extensions that would be present in a URL for rendered pages. Here is my (alphabetized) list so far ASP Classic asp ASP.NET aspx axd asx asmx ashx CSS css Coldfusion cfm Erlang yaws Flash swf HTML ...

Should query languages have priority of operator OR higher than priority of AND ?

Traditionally most programming languages have priority of AND higher than priority of OR so that expression "a OR b AND c" is treated as "a OR (b AND c)". Following that idea search engines and query/addressing languages (css,xpath,sql,...) used the same prioritization. Wasn't it mistake ? When dealing with large enough data, that prior...

What are the differences between running an executable straight from the command line and from a cron job in Linux?

I have this executable that queries a remote server for a command, executes it on the local machine and returns the stdout (and also possibly stderr) from it back to the server. This executable runs just fine if called from the command line (as root), but I found it's failing for some commands when executed automatically by the cron job...

What should happen when a generator function is assigned?

If I have a programming language with first class functions. What should the semantics be when a generator function is shared? For example: var f = function() { foreach (i in 0..42) yield i; } int a = f(); // 0 int b = f(); // 1 // Assigning the generator function var g = f; int c = g(); // ?? int d = f(); // ?? I can i...

Which regular expression api would you emulate?

Most programming languages have apis for regular expression searching and replacing. In my experience the apis can be quite clunky, probably due to the number of actions available and efficiency considerations. If you were going to implement an api, which one would you emulate? Of particular interest is the methods and objects of the a...

Programmatically obtaining the number of colors used in an image

Question: Given an image in PNG format, what is the simplest way to programmatically obtain the number of colors used in the image? Constraints: The solution will be integreted into a shell script running under Linux, so any solution that fits in such an environment will do. Please note that the "color capacity of the image file" ...

Qt Widget Overlays

How do I overlay widgets in Qt? I want to create some widgets and place them out-of-layout, but rather tweak their size and position when some other widget's geometry is changed. Something like the buttons on the screenshot: ...

How do I name this simple method?

First of all, this is not really a programming question. It's more a question of "how do I satisfy McConnels naming conventions?" I have this Delphi-application that manipulates word-documents. One of the things I need to do is run through all the bookmarks in the document and delete some of them based upon a simple rule: If I currently...

CPU bound applications vs. IO bound

For 'number-crunching' style applications that use alot of data (reads: "hundreds of MB, but not into GB" ie, it will fit nicely into memory beside the OS), does it make sense to read all your data into memory first before starting processing to avoid potentially making your program IO bound while reading large related datasets, instead ...

Advanced chroma key code samples

I'm working on an application that needs to key out the background from an image taken by a webcam in front of a green screen. I figured this would be a very common task, but to my surprise i'm having trouble finding code samples for anything more advanced than a simple color-threshold and those do not quite cut it quality wise. I've f...

Design pattern for a class that works on a collection of other objects?

I have a User model that can hold 1-n UserGroup models, each of which holds data about the user's relationship with a specific group (for example, if they're the admin of the group, when they joined the group, etc.). I'd like to provide some helper methods like isGroupUser() and isGroupAdmin() that work on the entire set of UserGroup mo...

Is there a programming language that allows variable declaration at call site?

Update 2: examples removed, because they were misleading. The ones below are more relevant. My question: Is there a programming language with such a construct? Update: Now when I think about it, Prolog has something similar. I even allows defining operations at definition line. (forget about backtracking and relations - think about ...

When to INSERT or UPDATE with composite primary key models in ORM?

I've got a homemade ORM system that currently only supports auto-incrementing primary keys. This has worked well, but the time has come to support composite primary keys. I'm aware of the holy war between surrogate vs. composite primary keys, and I personally think there's a place for each. Anyway... :) With an auto-incrementing primary...

Is-a, extends, 'inherits': What is your preferred term for "inheritance" and why?

A subjective question, hence if there are complaints I'll wiki, but I'd like to know what people's takes are on the different terms that are used for inheritance almost interchangeably. We have "is-a", "extends", "derives", "subclasses" and simply "inherits" The words we choose have a lot of meaning packed into them. What is your pref...

What algorithm can I implement to speed up some Cellular Automata simulations?

I am writing a ncurses based C.A. simulator for (nearly) any kind of C.A. which uses the Moore or Neumann neighborhoods. With the current (hardcoded and most obvious [running state funcs]) the simulation runs pretty well; until the screen is filled with 'on' (or whatever active) cells. So my question is: Are there any efficient alg...

How should I answer a client when they ask when something will be done?

I'm presently doing about 10 programmers jobs, this is typical recession type fun. I have many clients asking me "When? When will you have my request completed?" Considering the other requests that I have to fulfill it's a real balancing act. So how should I answer these clients questions, when the real answer is "When I get to you"...

computer vision: extracting info about a shape given a contour (e.g. pointy, round...)

Given the 2D contour of a shape in the form of lines and vertices, how can I Extract Information from that? like: Pointy, round, straight line. Shape similarities with a given shape. Code is not necessary, I am more interested in concepts and the names of techniques involved to guide my search.... Thanks in advance. ...

What is a good community run venue for finding programming competitions?

The closure of a recent entertaining 'question' got me wondering what would have been a better forum for the challenge presented. I know there is a similar question, but most of the responses are pointers to infrequent and or hierarchical style challenges. I don't see any where the programming community creates both the challenges and ...

What to log/trace in a Production environment

Hi All, I'm wondering what kind of information should be logged to a file once an application has moved into a Production environment? Besides the logging of exceptions and errors... Should the start and end of each method be logged? The start and end of a running service? Each time the application saves data to a database or calls an ...