Javascript HTML Fun

December 18th, 2013

Here are some useful Javascript snips for working with form data.

How to get the name of the HTML tag for an element:

This code will see if we have a map set of inputs (somename[]):
[code]// See if we have a map here
var mapFound = 0;
if (thisName.indexOf(‘[]’) != -1) {
mapFound = 1;
thisName = thisName.replace(/[\[\]’]+/g, ”);

How to take a map of inputs and turn them into a Javascript map type var, and toss the empty ones:
[code]var map = $(thisName).map(function(){
if (this.value != ”) {
return this.value;
} else {
return null;

Fun With Automated GIF Generation

October 29th, 2013

Trolling around on the web, found a fun little process for generating animated GIFs:

Codility And Candiate Testing

July 28th, 2013

Tonight, I tested through a series of tests on Codility. Well … kind of.

Codility, for those of you who haven’t heard, is a automated test tool used to filter interview candidates, or for developers to show off their chops. A great idea in practice, what this leads to in reality is testing that is geared to math, because it’s easy to evaluate automatically.

Case in point, the tests I was presented with were:

  • Movement/path overlap detection
  • Rectilinear space intersection/area calculation
  • Binary period location (P [P ≤ Q / 2] and [S[K] = S[K+P] for 0 ≤ K < Q − P])

Of these three questions, I managed to complete one and started trying to understand the other two before I said “Screw this”.

No, you didn’t read that wrong. I had a 33% success rate, and then I just didn’t care enough to keep going. I didn’t consider the problems relevant enough to my ability to bother taking them. I would not consider myself a poor programmer (in fact, a few colleagues have told me the opposite). I have been programming for over ten years, and have developed some really complex projects. I am highly creative, analytical and a good problem solver.

Maybe I’m just cranky because I didn’t complete their testing, but I would not use Codility if I ever needed to hire. Many self-taught developers are in the same boat as I am (lacking the comp-sci math background), but end up being stuck without the luxury of bailing out on the testing, because they need to test for some job they’ve applied for.

Reddit hiring is a much more useful test of ability and problem-solving.

Which Framework?

July 21st, 2013

Learning a framework is an investment of time. You have to work out how this one structures its files, wants you to template, what levers to pull.

This is why people build their own so often. At least then it works the way you want it to.

Globally Scoped

July 14th, 2013

Global variables are a code smell. This statement is both true and false. What is true is that they are a problem when they are no longer the right variables to be global.

Today I had to re-factor a function to be able to use multiple servers inside one script instance. Initially, the server connection was created and stored in one variable that was then referenced. This worked well, because the code that called this function didn’t have to worry about what server connection was involved.

Of course, the problem started when I added a second server into the mix. Now, this function had to be able to access either server, selected by the code in some of the places that called it. The easiest way to solve this would have been to keep the global and add a second optional parameter to override it, but that would not be as clean a fix as just fixing the global.

And so I re-factored the function call to pass in the server connection to use. This makes the function more flexible, because I can add new servers to the mix and just pass in the variable for the one I want to use. The other benefit is that in eliminating the global, this function is now finally completely self-contained, making it that much easier to test and fix.

Lesson Learned
Globals can be useful, but will make it harder to properly test a function, and complicates matters if the function that uses them is widely used and has to be changed.

Choose carefully how to use them.

WordPress - Entries (RSS) and Comments (RSS) - © 2011 Ben Dauphinee