Finding the phone numbers in 50,000 HTML pages

How do you find the phone numbers in 50,000 HTML pages? ###Jeff Attwood posted 5 Questions for programmers applying for jobs: In an effort to make life simpler for phone screeners, I've put...

Recursion or Iteration?

Is there a performance hit if we use a loop instead of recursion or vice versa in algorithms where both can serve the same purpose? Eg: Check if the given string is a palindrome. I have seen many...

How to convert floats to human-readable fractions?

Let's say we have 0.33, we need to output 1/3. If we have 0.4, we need to output 2/5. The idea is to make it human-readable to make the user understand "x parts out of y" as a better way of...

Which, and why, do you prefer Exceptions or Return codes?

My question is what do most developers prefer for error handling, Exceptions or Error Return Codes. Please be language(or language family) specific and why you prefer one over the other. I'm...

What is the difference between a framework and a library?

What is the difference between a *framework* and a *library*? I always thought of a library as a set of objects and functions that focuses on solving a particular problem or a specific area of...

Solving "Who owns the Zebra" programmatically?

Edit: this puzzle is also known as "Einstein's Riddle" The Who owns the Zebra (you can try the online version here) is an example of a classic set of puzzles and I bet that most people on Stack...

What does the word "literal" mean?

What does the word "literal" mean when used in context such as literal strings and literal values? What is the difference between a literal value and a value?

What is a good network graph library for language X?

I have noticed that a recurring question is: “What is a good network graph library for language X”. I have played with quite a few of the libraries and I can share my experiences with...

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...

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...

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...

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...

Determine font color based on background color

Given a system (a website for instance) that lets a user customize the background color for some section but not the font color (to keep number of options to a minimum), is there a way to...

What is the best API in any language for Audio and MIDI music application development?

What is the best API to utilize in developing an application that handles both realtime MIDI and audio input and output? This would be for an application that is used in the process of making...

What is rc stands for

I saw a lot of times code where return status of function was set to ***rc *** variable (e.g. int rc = foo();). I though it some sort of convention and blindly used it all over my code. Recently...

ID Best Practices for Databases

I was wondering what the best practices were for building and storing IDs. A few years ago, a professor told me about the dangers of a poorly constructed ID system, using the Social Security...

What are the differences between PEGs and CFGs?

From this wikipedia page: The fundamental difference between context-free grammars and parsing expression grammars is that the PEG's choice operator is ordered. If the first alternative succeeds,...

ASCII + Numpad combination for power 10

I am writing an app and I need to use power numbers in strings. But I cannot for the life of me figure out how to type power 10 characters. I know that if I hold down ALT + 0178, the character...

Algorithm for diameter of graph?

If you have a graph, and need to find the diameter of it (which is the maximum distance between two nodes), how can you do it in O(log v * (v + e)) complexity. Wikipedia says you can do this using...

Can inheritance be replaced completely by composition?

This question is NOT question like "inheritence vs composition". I understand completely how inheritance differs from composition, I know the Liskov substitution principle, the diamond problem,...

How to check if line segment intersects a rectangle?

If you have 2 points, (x1, y1) and (x2, y2), which represent two opposite corners of a rectangle, and 2 other points, (x3,y3) and (x4,y4), which represent 2 endpoints of a line segment, how can...

Peak signal detection in realtime timeseries data

Update: The best performing algorithm so far is this one. This question explores robust algorithms for detecting sudden peaks in real-time timeseries data. Consider the following example...

How to install Julia in an anaconda environment?

One of the main features of Anaconda is that it is language agnostic as stated in their blog: You can create environments of any binary dependency tree (different versions of Python, R, Julia,...

Greedy algorithm: highest value first vs earliest deadline first

Assume we have a set of n jobs to execute, each of which takes unit time. At any time we can serve exactly one job. Job i, 1<=i<=n earns us a profit if and only if it is executed no later than its...

How to calculate index from row and column?

I want to calculate an index (base 0) for any given row and column where rows and columns are base 1 and the number of columns is known, e.g. 2 If max_columns is 2 and index is 5, then to...

Intuitive explanation of binary tree traversals without recursion

I have seen many articles and books (and Stack Overflow answers) that show how to do preorder, inorder, and postorder depth-first tree traversals iteratively, using an explicit stack instead of...

Human-like mouse movements via Selenium

The Story: One of the approaches to solve captchas, like Google ReCaptcha, is to try to imitate the human mouse actions: movements, hovering and clicks. Some users reported that making mouse moves...

solving the 2-sum algorithm in javascript

I'm trying to write a simple solution to the 2-Sum problem in Javascript. The problem goes: given an array of n integers and a target sum, determine what combinations of two integers will sum to...

Could you implement async-await by memcopying stack frames rather than creating state machines?

I am trying to understand all the low-level stuff Compilers / Interpreters / the Kernel do for you (because I'm yet another person who thinks they could design a language that's better than most...