language-agnostic

N-Grams for sequence correction

Sorry for the difficult question. I have a large set of sequences to be corrected by either/or adding digits or replacing them (never removing anything) that looks like this: 1,2,,3 => 1,7,4,3 4,,5,6 => 4,4,5,6 4,7,8,9 => 4,7,8,9,1 4,7 => 4,8 4,7,1 => 4,7,2 It starts with a padded original sequence, and a sample correction. I'd lik...

Fast average without division

I have a binary search loop which gets hit many times in the execution path. A profiler shows that the division part of the search (finding the middle index given the high and low indices of the search range) is actually the most costly part of the search, by a factor of about 4. (I think) it is not critical for efficient binary search...

How to deal with setUp() addiction when writing tests?

I'm somewhat new to writing tests. I've find myself struggling with keeping my setUp's clean and concise, instead trying to accomplish too much with an uber-setUp. My question is, how do you split up your testing? Do your tests include one or two lines of independent step code? def test_public_items(): item1 = PublicItem() it...

Should it be "Arrange-Assert-Act-Assert"?

Regarding the classic test pattern of Arrange-Act-Assert, I frequently find myself adding a counter-assertion that precedes Act. This way I know that the passing assertion is really passing as the result of the action. I think of it as analogous to the red in red-green-refactor, where only if I've seen the red bar in the course of my...

Handcoded GUI application Design & Visualization

We've tools like Netbeans/Visual studio to do the GUI app for our project in java/C#. But when we're creating apps by writing code on Text-editor/IDE without using components. then how to visualize the GUI app project ? I mean let's say i want to build a contact manager app in C#/java. now with GUI builder tools i can manage multiple fil...

What is a class interface?

I'm currently working my way through Code Complete and the word "interface" keeps popping up! I'm trying to get my head round what an interface is. Can you define the term? Also what actually makes up a "class interface"? ...

RS232 serial snoop tools for protocol development / debugging

I develop a wide range of relatively simple firmware devices. Every one of these ends up talking to the PC (or another device) via the RS232 port in one way or another, so I spend a lot of time implementing and debugging their communication protocols. My most common use case is to snoop on a program running on my PC that is communicatin...

Human name comparison: ways to approach this task

I'm not a Natural Language Programming student, yet I know it's not trivial strcmp(n1,n2). Here's what i've learned so far: comparing Personal Names can't be solved 100% there are ways to achieve certain degree of accuracy. the answer will be locale-specific, that's OK. I'm not looking for spelling alternatives! The assumption is...

Can a test class become a "God object"?

I'm working on a backend for an open source Python ORM. The library includes a set of 450 test cases for each backend, all lumped into one giant test class. To me, that sounds like a lot for one class, but I've never worked on a project that has 450 test cases (I believe this library has ~2000 test cases not including the test cases fo...

Java Reflection and the pain in Refactoring

Java Reflection provides a mechanism to introspect an Object at runtime. No second thoughts, this is a great feature, but it breaks all the Refactoring conventions! There is no easy way (other than File Search) even in modern IDE's to know which attribute is referenced and where. This makes Refactorings much more complex (tiresome!) and...

The benefits and advantages of being a jack of all trades programmer?

I've been doing web dev for 10 years now, mostly the MS stack but some LAMP as well. There are so many choices these days for programmers and the job market seems to be all over the place. Before I dive into some new technology once again I was hoping to get some perspective from others in regards to additional benefits of being a ja...

Comparison method for sorting that shuffles equal elements randomly

Here's a puzzle for you. I want to change the following comparison method, so that when two items are considered equal, they will be shuffled randomly. myList.Sort( (x, y) => x.Score.CompareTo(y.Score) ); I could imagine that this scenario would be useful when ordering search results if you didn't want to give preference to one resul...

Is there an algorithm for converting quaternion rotations to Euler angle rotations?

Is there an existing algorithm for converting a quaternion representation of a rotation to an Euler angle representation? The rotation order for the Euler representation is known and can be any of the six permutations (i.e. xyz, xzy, yxz, yzx, zxy, zyx). I've seen algorithms for a fixed rotation order (usually the NASA heading, bank, rol...

Evaluate dice rolling notation strings

Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive number], "d", positive number entity ::= roll | positive number expression ::= entity {...

Begin+End given - how many "transactions" at the same time

I have couple of data, which includes the beginning of a transaction and its end in a DateTime format. I want to figure out how many transaction are running at the same time. Is there any algorithm that could solve my problem? ...

Methods for modular customization of locale messages?

There many levels for the customization of programs. First of course is making it speak your language by creating i18n messages where tools like gettext and xgettext do a great job. Another comes when you need to modify the meaning of some messages to suite the purpose of your project. The question is: is it possible to keep customize...

what LIFO means and which data structure follows the LIFO strategy ?

what LIFO means and which data structure follows the LIFO strategy ? ...

When is a do-while appropriate?

When is a do-while the better choice over other types of loops? What are some common scenarios where its better than others? I understand the function of a do-while, but not when to use it. ...

Will it ever be possible to run all web traffic via HTTPS?

I was considering what would it take (technologically) to move all the web traffic to HTTPS. I thought that computers are getting faster, and faster, so some time from now it will be possible to run all traffic via HTTPS without any noticeable cost. But then again, I thought, encryption strength will have to evolve to counter the loss o...

How do I visualize audio data?

I would like to have something that looks something like this. Two different colors are not nessesary. I already have the audio data (one sample/millisecond) from a stereo wav in two int arrays, one each for left and right channel. I have made a few attempts but they don't look anywhere near as clear as this, my attempts get to spikey...