language-agnostic

Which regex flavors support captures (as opposed to capturing groups)?

As I just learned from this question, .NET regexes can access individual matches within a repeated capturing group. I. e., if I apply a regex like \b(\w+\s*)+ to a string of words, only the last word will be stored in \1 or Match.Groups(1).Value, but using Match.Groups(1).Captures I get access to all the individual matches the regex it...

calculating parameters for defining subsections of quadratic bezier curves

I have a quadratic bezier curve described as (startX, startY) to (anchorX, anchorY) and using a control point (controlX, controlY). I have two questions: (1) I want to determine y points on that curve based on an x point. (2) Then, given a line-segment on my bezier (defined by two intermediary points on my bezier curve (startX', start...

Easiest way to find the correct kademlia bucket

In the Kademlia protocol node IDs are 160 bit numbers. Nodes are stored in buckets, bucket 0 stores all the nodes which have the same ID as this node except for the very last bit, bucket 1 stores all the nodes which have the same ID as this node except for the last 2 bits, and so on for all 160 buckets. What's the fastest way to find wh...

Is using the break statement bad practice?

I've been told by professors and peers at my university that using the break statement is bad practice, but through my coursework haven't come up with a great reason why. Those who claim that it is bad say that it's a "get out of jail free card" and that you can always avoid using it. My guesses for why its considered bad would be ...

Choice of programming language for learning data structures and algorithms

Which programming language would you recommend to learn about data structures and algorithms in? Considering the following: Personal experience Language features (pointers, OO, etc) Suitability for learning DS & A concepts I ask because there are some books out there that are programming language-agnostic (written from a Mathemati...

How to design a database where the main entity table has 25+ columns but a single entity's columns gets <20% filled on average?

The entities to be stored have 25+ properties (table columns). The entities are pretty diverse, meaning that, most of the columns are empty. On average, I'd say, less than 20% (<5) properties have a value in any particular item. So, I have a lot of redundant empty columns for most of the table rows. Almost all of the columns are decimal ...

How 'terse' is too terse? -- Practical guidelines for expressing as much intent in as few characters

First, I love writing as little code as possible. I think, and please correct me, one of the golden rules of programming is to express your code in as few of character as possible while maintaining human readability. But I can get a little carried away. I can pack three or four lines into one statement, something like $startDate = $...

Raytracing (LoS) on 3D hex-like tile maps

Greetings, I'm working on a game project that uses a 3D variant of hexagonal tile maps. Tiles are actually cubes, not hexes, but are laid out just like hexes (because a square can be turned to a cube to extrapolate from 2D to 3D, but there is no 3D version of a hex). Rather than a verbose description, here goes an example of a 4x4x4 map...

Using regex to add leading zeroes

I would like to add a certain number of leading zeroes (say up to 3) to all numbers of a string. For example: Input: /2009/5/song 01 of 12 Output: /2009/0005/song 0001 of 0012 What's the best way to do this with regular expressions? Edit: I picked the first correct answer. However, all answers are worth giving a read. ...

Does knowing a Natural Language well help with Programming?

We all hear that math at least helps a little bit with programming. My question though, does English or other natural language skills help with programming? I know it has to help with technical documentation, but what about actual programming? Are certain constructs in a programming language also there in natural languages? Does knowing ...

Compiler Construction course

I'm looking for a course (preferably video, much preferably) like MIT's video course on Compiler Construction. Can someone point me to some decent resources or help material (preferably video)? ...

Is it a good practice to suppress warnings?

Sometimes while writing Java in Eclipse, I write code that generates warnings. A common one is this, which I get when extending the Exception class: public class NumberDivideException extends Exception { public NumberDivideException() { super("Illegal complex number operation!"); } public NumberDivideException(Stri...

If I'm using a 1d array to represent a square board, how can I take my index and check the sqaures above, below and to its sides?

If I have a 4x4 gameboard which I'm representing in my program as a 1d integer array of size 16. How can I get the indexs of the squares above, below, to the left and to the right any given index? So, for example: A = { 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 } Which represents this board 0 1 2 3 4 5 6 7 8 9 10 11 ...

How Does Modulus Divison Work

I don't really understand how modulus division works. I was calculating 27 % 16 and wound up with 11 and I don't understand why. I can't seem to find an explanation in layman's terms online. Can someone elaborate on a very high level as to what's going on here? EDIT: Thanks for all your answers. You guys are incredibly quick. It all ma...

writing a program to ban a user (by MAC address) from a network

I'm not sure if this is possible at the application layer. Can a program be written to read and analyze packets (maybe interfacing with wireshark through it's lua api) and ban MAC addresses with suspicious network traffic? (defining suspicious network traffic as packet injection patterns similar to known attacks) ...

A database of questions with unambiguous numeric answers.

I (and co-hackers) are building a sort of trivia game inspired by this blog post: http://messymatters.com/calibration. The idea is to give confidence intervals and learn how to be calibrated (when you're "90% sure" you should be right 90% of the time). We're thus looking for, ideally, thousands of questions with unambiguous numerical an...

Issuing multiple requests using HTTP/1.1 Pipelining

When using HTTP/1.1 Pipelining what does the standard say about issuing multiple requests without waiting for each request to complete? What do servers do in practice? I ask because I once tried writing a client which would issue a batch of GET requests for multiple files and remember getting errors. I wasn't sure if it was due to me ...

How to write an algorithm to check if the sum of any two numbers in an array/list matches a given number?

How can I write an algorithm to check if the sum of any two numbers in an array/list matches a given number with a complexity of nlogn? ...

How should I add multi language support to my web app across PHP, JS and Template Files?

I'm building a website that needs to support different language translations. I have strings in PHP, JavaScript and Smarty Template files that need to translated. I want to use something like PHP's gettext() function and have a single language file for each locale. This is easy when the translatable strings are in the PHP files but I ...

How much abstraction is too much?

In an Object Oriented Program: How much abstraction is too much? How much is just right? I have always been a nuts and bolts kind of guy. I understood the concept behind high levels of encapsulation and abstraction, but always felt instinctively that adding too much would just confuse the program. I always tried to shoot for an amoun...