language-agnostic

Determining the health/validity of an email address

Routine maintenance on a website often involves verifying that links are valid, flagging bad ones, etc. I know how to match email addresses via a script (especially in the context of a web page where they'd be in mailto: links). My question is how would I verify they're OK without spamming the address? Stripping-off the domain and veri...

Has anyone actually implemented a Fibonacci-Heap efficiently?

Has anyone of you ever implemented a Fibonacci-Heap? I did so a few years back, but it was several orders of magnitude slower than using array-based BinHeaps. Back then, I thought of it as a valuable lesson in how research is not always as good as it claims to be. However, a lot of research papers claim the running times of their algori...

Class design: entity ID vs entity reference

If I've got Foo with a property of type Bar. Both are persisted in a database which can be retrieved by an ID. (The IDs are actually used in the line of business by customer service claims. So they're not just index placeholders.) I could take the approach shown with b1 or b2. Chaining entities together scares me since if you push t...

Caching system like memcached but where I need to list what is in the cache

What's the best caching system/daemon that supports get, put, delete and list (memcached, I think, doesn't support list) An example I would like to use memcached for my caching solution but I'm stuck with the application design that I currently have which is that I cache the following 3 URLs I need to always have different cache keys...

Best Way For Back Button To Leave Form Data

I'm creating a web page based on user input from a form. After the user sees the generated page I want to allow them to press the back button and make changes to the form. I would like to display the form as they had filled it out previously. What is the best way to get this behavior (with cross browser support)? ...

Ideas for converting straight quotes to curly quotes

I have a file that contains "straight" (normal, ASCII) quotes, and I'm trying to convert them to real quotation mark glyphs (“curly” quotes, U+2018 to U+201D). Since the transformation from two different quote characters into a single one has been lossy in the first place, obviously there is no way to automatically perform this conversio...

Is it bad practice to use the system() function when library functions could be used instead? Why?

Say there is some functionality needed for an application under development which could be achieved by making a system call to either a command line program or utilizing a library. Assuming efficiency is not an issue, is it bad practice to simply make a system call to a program instead of utilizing a library? What are the disadvantages o...

How can I become better at realizing how to solve a particular problem?

I have become pretty fluent in a few different languages now, but I seem to have a hard time actually figuring out the best way to go about solving particular problems. What are some ways to go about getting better at the actual problem solving of programming. ...

Algorithm for Finding Redundant Edges in a Graph or Tree

Is there an established algorithm for finding redundant edges in a graph? For example, I'd like to find that a->d and a->e are redundant, and then get rid of them, like this: => Edit: Strilanc was nice enough to read my mind for me. "Redundant" was too strong of a word, since in the example above, neither a->b or a->c is considered ...

Documents with different "Filters" / Levels of information

I often have one document that needs different levels of depth for different "viewers". Typically we end up with different documents that need to be kept in sync, or color/format-marking relevance to different users. I wonder if there's another way to deal with that, if I am the only one stumbling over that, and how you deal with it. ...

Modified preorder tree traversal - determining the "top" when no parent is specified

I'm implementing a Modified preorder tree traversal class for a category tree on a Web site, but I'm having trouble with one scenario. Typically when inserting a new category a top-level parent is specified, whose left value in the tree is used in order to determine where the new category should go in the tree. However, there could be ti...

Is it a good idea to eliminate compiler warnings?

In the past I've worked with -Wall and other switches for gcc to eliminate every compiler warning for projects I've been involved in. Similarly, in Perl, I always program with use strict and use warnings (and often -T as well) to try to achieve the best code quality I can. I understand that a few years ago, the Perl porters group worke...

How do you determine if doing something the right way will handicap you?

I have a horrible habit, actually something I'm wrestling with right this moment, when I think of a better way to do something - either a refactor, or something that would just be SO MUCH COOLER LOOKING, or such a better UX, I just HAVE to do it. Even when it would cost me time and I'm in a time crunch. I never know when to say, "no, the...

How to pick bitflag values?

I have a set of options, some orthogonal (can be combined in any combination), some exclusive (only one from the set is allowed), and need to pick a set of enum values so that they can be combined with bit-wise or and extracted with bit-wise and. I would prefer that or-ing invalid combination would be detectable. Are there any tools for...

Intercepting the Fn key on laptops

Sometimes when I work on Thinkpads/MSI laptops, the Ctrl and Fn key are swapped (Fn being the leftmost key), and it drives me nuts - I keep hitting Fn instead of Ctrl. I was wondering if it's at all possible to intercept the Fn key. I'd like to write a hook that swaps the Ctrl/Fn keys, but it seems that Fn is not being processed by the ...

Commonly used keyboard shortcuts in web apps

I'm setting up keyboard shortcuts for a web app, and I'm wondering: What are the most commonly used keyboard shortcuts (in web applications)? For example, Google's gmail and reader uses j / k : previous/next o / Enter: open/expand which seems to have stuck, but they also use p/n: previous / next message ...which to me see...

Planning for efficiency early vs Premature optimization

I seem to notice two schools of thought emerging in regards to optimization: Premature optimization is the root of all evil. You should only optimize when you've written the most readable and simplest thing possible. If after profiling you determine that the software is too slow, you should optimize. Optimizations should be done earl...

Is there a "canonical" name for a function combining min() and max()?

I find that I frequently end up writing a function that I always call "clamp()", that is kind of a combination of min() and max(). Is there a standard, "canonical" name for this function? It always looks something like this: function clamp($val, $min, $max) { if ($val < $min) return $min; else if ($val > $max) return $max;...

Weird coding phase I'm going through

Lately, I've been going through a pretty weird phase. I feel the need to write/rewrite all the tools I use ( text editors,IDE's,libraries/modules ) and I don't know why . Even though this can be seen as a good thing ( because I learn alot of things in the process , and my software design skills are improving constantly ) , the weirdest ...

Have you ever created a fortunate accident in code?

Have you ever created code that didn't do what it was meant to do but ended up doing something cooler? A bug that (actually) was a feature or created something new by accident? For example when I was first learning to program. I started playing with demo graphics code from hornet.org in assembler and c. I was trying to change some code ...