Lint only touched files with Webpack

Recently I had to add a linter on a project in which the codebase was never linted before. I am talking about a big codebase in which a team have worked on it for years already.

Obviously, the amount of errors thrown from the linter, was such a big number to become an useless information.

With my team mates, we agreed on run the linter only on the “touched” files: the behaviour we wanted was to get the linter parsing every file that gets changes.

Continue reading

Posted in Javascript | Tagged , , , , , | Leave a comment

Be careful with your fix!

I think many times the code grows wrong (also) because of some wrong solutions… Little example: yesterday I was sending an email by Gmail, an attachment was included to the mail.

Correctly, I wasn’t able to send the mail (clicking the “send” button) until the attachment wasn’t completely uploaded.

Continue reading

Posted in Uncategorized | Tagged , , | Leave a comment

Code readibility: little zoom on Implements from MooTools

I would like to spend a few lines about the Implements feature, from MooTools.

Like many other frameworks / toolkits, MooTools provides utilities for DOM manupulation, effects, etc… but what i really enjoy is the way it provides writing code, by its Class function. From Wikipedia:

Every JavaScript framework has its philosophy, and MooTools is interested in taking full advantage of the flexibility and power of JavaScript in a way that emphasizes greater modularity and code reuse.MooTools accomplishes these goals in a way that is intuitive to a developer coming from a class-based inheritance language like Java with the MooTools Class object.

It is not the goal of this post to write about how i see the code readibility improved by using Class; just click here for my own Class clone to know more.

What i would like to talk about here is the Class’s feature called Implements: it is a tool to reuse code, many times confused with Extends, and it is considered confusing from many sources.

Continue reading

Posted in Code readibility, Javascript, MooTools | Tagged , , , , , , , | Leave a comment

Vim hot stuff: marks

In the (new) “vim hot stuff” section, i would like to post about those Vim’s features that, when you meet them the first time, you think: “UAO! That is cool! How did i survive without it so far?”. The best example, for me, is the option “:set relativenumber” (from the 7.3); i think i was waiting for it from my beginning with Vim and i have realized how much i was waiting for it the first time that i have met it!

About the feature i am going to introduce here, i was googling for “how to select multi line in visual mode quicker” and i was led to this solution:

… I know that some people use marks extensively to make visual selections. For example, if I’m on line 5 and I want to select to line 35, I might press ma to place mark a on line 5, then :35 to move to line 35. Shift + v to enter linewise visual mode, and finally `a to select back to mark a.

Continue reading

Posted in Tips, vim hot stuff | Tagged , , , , , , , , | Leave a comment

Git: how to rewrite the branch history

Quick tip for those git users that, like me, make a lots of commits in their working branch and want to keep only the last one, before send the branch to production. Yes, the idea is to use this method before send the branch to production: it is not a good idea, to change the history of a project that has many persons working on it!

It is true that, by this method, I resetted the GitHub history of some personal projects, when they were already pushed: i didn’t get any problems, because i was the only person to commit on those projects!.

Continue reading

Posted in Programming, Tips | Tagged , , , , , | Leave a comment

Coding tips: accessing the data structure

I think it is really important keep the code more general and flexible as possible; one rule, that i would like to introduce here, is to use the right level of abstraction when accessing the data structure elements, trying to centralize the read / write operations on them.

Many times i saw pieces of code that work directly on the data structure: that is a problem when that data structure, at some point, gets changed and then the developers are forced to manually update every line of code involved with it.

Continue reading

Posted in Javascript, jQuery, Programming, Tips | Tagged , , , , , , , | Leave a comment

A “Class” function to define classes in Javascript with MooTools like syntax

Updated the 08/02/2013

I really enjoy to organize my Javascript code as objects and get profit by using inheritance.

“Approaching Javascript as Javascript and not as Java”, i read that so many times; Javascript is / can be OOP and i always thought about OOP as something good for code reusing.

I think the OOP nature of Javascript is all around the prototypal chain; a constructor function is the only way to define objects that achives these two points:

  1. members on the prototypal chain
  2. the constructor property and the instance of operator working as intended

What i am going to introduce here is a function Class that uses another syntax to achieve the same, native result than the constructor functions; i am avoiding closures as class pattern because they don’t store members on the prototype (but they are a good way to define private members).

I think that the Class function makes the syntax less redundant and verbose, moving the focus from the function to the prototype. Also, it provides tools for code reusing: Javascript has native inheritance but not native tools to use it.
A more expressive syntax to write objects in OOP approach, as Class function tries to provide, is in my opinion a good way to help the development.

Continue reading

Posted in Javascript, jQuery, My code, Programming | Tagged , , , , , , | 7 Comments

A quick digression about the constructor property in Javascript

When i think about the constructor, i think about the function called when a class is instantiated. Well, that is true about Java but i would like to write about the constructor in Javascript.

For me is a challenge write about the constructor; after years of Javascript i still see it as something confusing; anyway recently i had the opportunity to go through it and i would like to write here some considerations.

Continue reading

Posted in Javascript, Programming | Tagged , , , | Leave a comment

jPaginator as paginator for the jQuery Datatable plugin

Recently, at work,  i had to include the jPaginator as default paginator for the jQuery Datatable .

The way to add a custom paginator to the Datatable is really clean: you can write your own paginator as stand alone module and integrate it with the grid, as plugin, by extending the object $.fn.dataTableExt.oPagination (documentation here).

My goal was to get two paginators on the screen, one on the top (as jPaginator) and one on the bottom (the default one) of the grid. The jPaginator on the top is an interesting solution: if the user wants to jump over many pages, the jPaginator will perfectly fit that. When the user goes to the end of the page, the searched item is probably supposed to be on the same page or in a close one.

The full screen demo here:

The code behind the demo:


Foot note

Looking for an already written plugin, i have found this one: jPaginator plugin for Datatable . It works good but it didn’t match my goal, because it is designed to show the jPaginator only.

Some links

Thanks for reading

Posted in Javascript, jQuery, My code, Programming | Tagged , , , , , | Leave a comment

Fix the eee 1001px microphone issue for Ubuntu

Some months ago i have installed Ubuntu 12.04 on my eee 1001px; all was right but the microphone didn’t work. Checking on the web, it seemed to be an annoying problem for many people.

Continue reading

Posted in GNU/Linux, Tips | Tagged , , , , | Leave a comment