language-agnostic

Is there any self-improving compiler around?

I am not aware of any self-improving compiler, but then again I am not much of a compiler-guy. Is there ANY self-improving compiler out there? Please note that I am talking about a compiler that improves itself - not a compiler that improves the code it compiles. Any pointers appreciated! Side-note: in case you're wondering why I am ...

How to generate random 'greenish' colors

Anyone have any suggestions on how to make randomized colors that are all greenish? Right now I'm generating the colors by this: color = (randint(100, 200), randint(120, 255), randint(100, 200)) That mostly works, but I get brownish colors a lot. ...

Why don't I see pipe operators in most high-level languages?

In Unix shell programming the pipe operator is an extremely powerful tool. With a small set of core utilities, a systems language (like C) and a scripting language (like Python) you can construct extremely compact and powerful shell scripts, that are automatically parallelized by the operating system. Obviously this is a very powerful ...

Optimization! - What is it? How is it done?

Its common to hear about "highly optimized code" or some developer needing to optimize theirs and whatnot. However, as a self-taught, new programmer I've never really understood what exactly do people mean when talking about such things. Care to explain the general idea of it? Also, recommend some reading materials and really whatever y...

Bad Fairness with a ReadWriteLock / SharedLock under load

Hello, we are currently designing a multithreaded server application. To optimize performance, we decided to implement a ReadWriteLock, i.e. multiple threads can get a lock if they only want to read but just one thread may hold the write lock. This lock is used with a list and iterating over the list is the "read" operation. Now this...

Minimax algorithm

I have a simple question regarding the Minimax algorithm: for example for the tic-tac-toe game, how do I determine the utility function's for each player plays? It doesn't do that automatically, does it? I must hard-code the values in the game, it can't learn them by itself, does it? ...

Guidance for writing a wrapper for a REST API

I've written a few very casual wrappers around REST and less structured web interfaces, but all just for fun, with very little attention to error detection and handling, timeouts, etc. Can somebody please give me some pointers, either on practices, or to resources, for developing a solid, professional .NET (or other platform) wrapper fo...

Why 13 places in ROT13?

I understand the reasons for and against ROT13, but I'm wondering why specifically people have chosen 13 places to shift the alphabet? I understand it's halfway around, but is there an elegant reason to go -that- far, but not 12 or 14 spots? It seems to me like making each letter "as far away" as possible from its starting position only...

Access control lists

I've been reading up on (Role-Based) Access Control Lists for an upcoming project and am having some troubles figuring out how it will work for me. In the examples I've seen, they always talk about allowing and denying access to the particular actions of a controller/model. For example: the group "Visitors" can read posts, "Members" can...

Various ways of implementing bubble sort?

How should I implement the classic bubble sort algorithm? I'd particularly like to see a C++ implementation, but any language (even pseudocode) would be helpful. P.S. Not a homework. ...

Human inspector vs. programmer (was: Algorithm to detect if any circles overlap)

Problem This question actually came up at work today. We are planning an experiment where we will show a series of maps to users. Each map has 31 symbols on it. Each symbol also has a label. We noticed that, in a few cases, the labels overlapped, which rendered one of the labels unreadable. We ended up identifying the problem symbols t...

How do you stress test your own software?

I've been working on an app, by myself, and I am at a stage where everything works great--as long as the user does everything he or she is supposed to do. :-) The software needs more testing to see how robust it is, how well it works when people do things like click the same button repeatedly, try to open the wrong kind of files, put dat...

handling amorphous subsystems in formal software design

People like Alexander Stepanov and Sean Parent vote for a formal and abstract approach on software design. The idea is to break complex systems down into a directed acyclic graph and hide cyclic behaviour in nodes representing that behaviour. Parent gave presentations at boost-con and google (sheets from boost-con, p.24 introduces the ap...

GUI patterns to edit data with many-to-many relationship

Hi, I often run into a situation where I need to come up with a GUI to edit data that has a n:m relationship. I'm looking for user friendly GUI ideas. [table1] | /|\ [table2] \|/ | [table3] Usually the GUI resembles something like this: Grid that shows all items from table1 Add table3 item... (shows modal window with t...

Interfacing with the end-user's scanner from a webapp (web/scanner integration)

Consider the following scanning procedure in a typical document handling webapp: The user scans a document using a scanner connected to his/her computer The scanned image is saved locally on the user's computer as a BMP/JPG/TIF/PNG file The user hits a file upload "Browse.." button in the web application The user is presented with a fi...

Refactoring to Asynchrony?

I program ActionScript for the FlashPlayer. This means compiling a set of ActionScript files into a SWF file (a bunch of bytecode that gets executed by the FlashPlayer in your browser). Anything that is not compiled into the SWF file must be requested. Examples of this would include ANY textual content, media, or graphical content that w...

The ethics of using 'My Documents' as a dumping ground...

Something I've wondered about for a while now and would like to get a general opinion on: Advanced apologies if this has been asked previously, I did a search and couldn't find anything similar. This question is related to questions like, "Correct location to save a temporary file in Windows?" , but not quite the same. I've noticed ove...

Should a unit-test method exceed 200 lines?

Is it too bad to write a really long (more than 200 lines) test method? Or should I break it up into smaller-methods? ...

Code Golf: Playing Cubes

The challenge The shortest code by character count, that will output playing bricks tower series according to user input. The input will be a series of numbers (positive, negative and zero) that represents the height of the current cube tower following their index. A height of 0 means no tower and is spaced. A cube tower is composed o...

How many 1s in an n-bit integer?

An interesting problem I ran into today: what is the fastest way to count the number of 1s in an n-bit integer? Is it possible to beat O(n)? For example: 42 = 0b101010 => 3 ones 512 = 0b1000000000 => 1 one Clearly, the naive algorithm is to simply count. But, are there any tricks to speed it up? (This is merely an academic question;...