I’m a PHP Developer, why I should use Javascript & Node.js to write my server-side code.

If you are a PHP Developer maybe you are used to write your server-side code in PHP and then you make run your code on a web server like Apache. Javascript, from your point of view, it’s simply a client-side scripting language and you use it to handle the front-end client business logic on a web page. A front-end developer might argue that with javascript is possible to manipulate the DOM via a library such as JQuery. You can do more than this. With one language you could code client-side and server side of a web application. Your brain context-switching will say “Thank you”. This is actually a benefit, for both developers and other company’s stakeholders (Search on google “the cost of context-switching for developers”).

So, it may sound strange to hear “Write your server-side code in Javascript using Node.js techonology“.

Anyway, you are here because you don’t understand why you should use Node.js to develop web applications.

Take a rest, drink a coffee and continue to read this article.
Continue reading “I’m a PHP Developer, why I should use Javascript & Node.js to write my server-side code.”

Asynchronous Javascript with Promises

Promises are an alternative way to the callback system for javascript asyncronous event. Instead of calling a callback, we call a function that returns immediatly a promise. Thus we can exit very soon from the function and continue with our code as in synchronouse code style.

Promises are a way to avoid the Callback hell and they are typicaly used for Ajax Requests (jQuery returns promises by default from Ajax requests) and UI animations. With promises you can easily synchronize tasks or execute tasks sequentially.

Continue reading “Asynchronous Javascript with Promises”

Rule Based Expert System

Definition

An expert system is a type of software that after a training session, it is able to make deductions or choices itself by reading a set of initial informations called facts.

On an expert system the competence of an human expert is coded in the knowledge base (for instance as a rule) updatable in base of the experience.

Rule based expert systems are software composed of rules in the form “IF condition THEN action”.

Given a set of facts expert systems, thanks to the rules which are composed, are able to deduct new facts.

Continue reading “Rule Based Expert System”

How to write your own JQuery Plugin

Dont repeat yourself – DRY – and write your own JQuery plugin for that piece of code that you reuse a lot of time in your projects.

Creating a simple Highlight Plugin

In this small example we are going to create a plugin that highlight an element. It simply changes the background and font-style css properties.

The first thing we have to do is to be sure that our plugin runs inside a local scope by wrapping out all your code inside of an Immediately Invoked Function Expression (IIFE):

// Plugin basic structure
(function($) {

    $.fn.yourMethod = function() {

        // Your Method code

    }

}(jQuery));

Continue reading “How to write your own JQuery Plugin”