language-agnostic

Convert light frequency to RGB?

Does anyone know of any formula for converting a light frequency to an RGB value? ...

Besides Logo and Emacs Lisp, what are other pure dynamically scoped languages?

What are some examples of a dynamically scoped language? And what are the reasons for choosing that design? Is it because it is easy to implement? ...

Getting Your Customer's Bills in to Bill Pay Sites

We are looking at ways to cut costs, and one idea I had was to push our customer's bills into the Bill Pay systems that banks (and other sites) use. Only thing is, I don't know how to do that? My searches in the past didn't turn up any information for the company side. Can anyone point me in a productive direction? Is there a single cle...

How to implement permissions in a blogging system?

I am rolling my own blogging system and I am wondering how to determine permissions and implement them in a blogging system? What should be the permissions for a commenter, a blogger and an admin? What is the best way to implement them? ...

Find common elements in two sorted lists in linear time

I have a sorted list of inputs: let x = [2; 4; 6; 8; 8; 10; 12] let y = [-8; -7; 2; 2; 3; 4; 4; 8; 8; 8;] I want to write a function which behaves similar to an SQL INNER JOIN. In other words, I want to return the cartesian product of x and y which contains only items shared in both lists: join(x, y) = [2; 2; 4; 4; 8; 8; 8; 8; 8; 8] ...

Code Golf: Lasers

The challenge The shortest code by character count to input a 2D representation of a board, and output 'true' or 'false' according to the input. The board is made out of 4 types of tiles: # - A solid wall x - The target the laser has to hit / or \ - Mirrors pointing to a direction (depends on laser direction) v, ^, > or < - The la...

uninterlace bits from 16 bit value

I have a 16 bit value with its bits "interlaced". I want to get an array of 8 items (values 0 to 3) that stores the bits in this order: item 0: bits 7 and 15 item 1: bits 6 and 14 item 2: bits 5 and 13 ... item 7: bits 0 and 8 This is a trivial solution: function uninterlace(n) { return [((n>>7)&1)|((n>>14)&2), // bits 7 and 15 ...

Where to put potentially re-useable helper functions?

This is language agnostic, but I'm working with Java currently. I have a class Odp that does stuff. It has two private helper methods, one of which determines the max value in an int[][], and the other returns the occurrences of a character in a String. These aren't directly related to the task at hand, and seem like they could be reus...

How are mutexes implemented?

Are some implementations better than others for specific applications? Is there anything to earn by rolling out your own? ...

Is it code-smelly to have empty classes in the middle of a class hierarchy?

I sometimes end up with a class hierarchy where I have an abstract base class with some common functionality and a couple of implementing classes that fall into two (rarely more) groups which I want to treat differently in some cases. An example would be an abstract tree node class and different branch and leaf implementations where I wa...

Subclasses causing unexpected behavior in superclasses — OO design question

Although I'm coding in ObjC, This question is intentionally language-agnostic - it should apply to most OO languages Let's say I have an "Collection" class, and I want to create a "FilteredCollection" that inherits from "Collection". Filters will be set up at object-creation time, and from them on, the class will behave like a "Collect...

How to handle different protocol versions transparently in c++?

This is a generic C++ design question. I'm writing an application that uses a client/server model. Right now I'm writing the server-side. Many clients already exist (some written by myself, others by third parties). The problem is that these existing clients all use different protocol versions (there have been 2-3 protocol changes over ...

How to name variables that represent thresholds or limits?

For example, say we have a ticketing system that can be configured to offer tickets at normal price, but once you're within X hours of the event, you offer them at a different price (it may be discounted or increased). We'll call this the 'rush price'. Moreover, once you're within Y hours of the event, you offer them at yet another price...

Code Golf: Banknote calculator

This question was posted by a C beginner and it was an exercise to calculate, given a dollar value input by the user, the minimum number of bills (or banknotes, depending on your locale) needed to reach that dollar value. So, if the user entered 93, the output would be: $20 bills = 4 $10 bills = 1 $5 bills = 0 $1 bills = 3 Finally su...

Design Pattern: managing a limited number of a resource

I am in the process of designing a feature for a system where I strongly feel that there must be a pattern for this out there, that I should know about before diving into the code. The scenario is this: I have a pool of resources of which I have a limited number. I have a variable number of consumers that use those resources; each c...

Can I ask for some guidance in solving this algorithm related problem?

Hello, In my free time I like polishing my algorithm / programming skills (well, my skills suck and I try to improve them) by solving problems on pages like topcoder.com or uva.onlinejudge.com. Usually I can write and code correct algorithm for simpler problems - I understand most of the basic concepts regarding things like recursion or...

Name for over-generalizing a function? Is this an anti-pattern?

What is the name for passing an argument to a function to select what the function does? For example: enum { DoSomething, ... }; void f(FunctionType a); f(DoSomething); .... f(DoSomethingElse); Vs: void DoSomething(); .... void DoSomethingElse(); ...

Coder's block: How to fire timer at intervals, compensating for early/late firing

I'm having a silly-yet-serious case of coder's block. Please help me work through it so my brain stops hurting and refusing to answer my questions. I want to fire a timer at intervals up to a final time. For example, if t = 0, my goal is 100, and my interval is 20, I want to fire at 0, 20, 40, 60, 80, and 100. The timer is not precise,...

Lookup structure for handling future events (time based)

Hi, I am looking for an efficient data structure, that'll allow me to cue events ... that is, i will be having an app, where at any time in execution, it is possible, that an event will be raised for a future point in execution ... something like: t=20: in 420 seconds, A occurs t=25: in 13 seconds, B occurs t=27: in 735 seconds, C occ...

Opposite of "Abstractor"

I have a function that takes object instances and reduces them down to an abstract/generic format. Like this: class Dog { id=0, awesome=1 } => [id:0, type:'dog'] //abstract, generic version class Cat { id=1, awesome=0 } => [id:1, type:'cat'] class Narwhal { id=42, epic=1 } => [id:42, type:'narwhal'] I call this an abs...