1. Google I/O 2013 takeaway for the FEDs

    The Google I/O 2013 is over. This event is a treasure hunt for world of Front-end development as well. New trends and features are revealed. So, here’s a list of MustWatch videos and slides from Google I/O for the FEDs:

    Watching all those videos will take you probably the whole weekend, so here are some hottest stuff

    • Web Component and Polymer library 
    • DevTools Experiments: workspaces
    • DevTools Profile: Track allocation - continues snapshot of heap
    • DevTools Profile: JavaScript CPU profile - Flame Chart view
    • Dev Tools: Port Forwarding
    • Chrome ADBPlugin for Android remote debugging (super hot!).
      Not in store yet, so take from here(github).
    • Packaged Application: complete offline web app distributed via chrome web store
     


  2. Installing Tomcat on MacOS with homebrew

    Installing Apache Tomcat on MacOS became little more easy with homebrew. If you haven’t heard about it, it’s a missing package manager for MacOS. It allows you easily install any utilities that you might need with only one command in terminal.

    So, installing the Apache Tomcat would require from you the following steps:

    1. Update the brew repository
      brew update
    2. Install the tomcat (it will install the latest version by default)
      brew install tomcat
    3. Create symlink so it would be comfortable to launch it
      sudo ln -s /usr/local/Cellar/tomcat/7.0.39/libexec /Library/Tomcat
      Homebrew will install you tomcat under /usr/local folder. So, instead of writing the path all the type, we are going to create a symbol link
      /Library/Tomcat
      which will point to the same direction.
    4. Change the folder ownership so you could write there
      sudo chown -R bolshchikov /Library/Tomcat
    5. Make script in bin folder executable
      sudo chmod +x /Library/Tomcat/bin/*.sh

    So, now in order to launch the tomcat, open terminal and type

    /Library/Tomcat/bin/startup.sh

    Navigate to http://localhost:8080, you should see the welcome page of Tomcat.

     


  3.  


  4.  


  5. Why are you interested in front end development?

    This question pops up quite often from different people: friends, students, head-hunters, colleagues, etc. (feel free to add your own). 
    The real answer was crystalized after constantly giving some fuzzy replies, and here it is:

    I believe people are born to create. From the very childhood subconsciously I was trying to create something and express myself through different sphere: singing at high schools, 9 years of music school, 7 years of martial arts, but surprisingly the sphere of art, that fits me best, was close to my uni major of computer science - front end and web development. I don’t care that it might not be mature or serious enough for a developer with C++/Java knowledge. I love this world. I want to make it better, and create.

     


  6. Up-to-date guide of installing Node.js on *nix

    This is the clear, complete, and up-to-date guide of how to build the nodejs  in *nix OS.

    1. Install dependecies
      sudo apt-get install g++ curl libssl-dev apache2-utils
    2. Install git (unless you don’t have it already)
      sudo apt-get install git-core
    3. Clone git and install
      git clone https://github.com/joyent/node.git
      cd node
      git checkout v0.10.4
      ./configure
      make
      sudo make install
      
    4. Check the version
      node -v
      
     

  7. Compiling nodejs

     


  8. Mozilla Labs introduced a service for your website that makes it surprisingly easy to collaborate in real-time.

     


  9. Very useful series of articles about techniques and tools which were used while building Angry Birds game.

     


  10. By leveraging this new JavaScript optimization technology, Mozilla has been able to bring Epic’s Unreal Engine 3 to the Web.

     


  11. Jasmine tests in Node with mock dependencies

    We need unit testing for JavaScript files with mock dependencies without a browser.

    A simple phrase with a lot of meaning said to me by the head of R&D department. By that time I already  had a reasonably large code base of JavaScript files, interdependent and managed by RequireJS, and a tests folder with specs in Jasmine. But that wasn’t even close to the set  goal.

    Luckily for us, cases for which solutions do not exist yet are very rare. And that wasn’t one of them. Every component required to tackle the task existed separately - essential ingredients of success are straightforward:

    There are modules for node that allow running the require.js library and jasmine, but separately. However, the tricky part is to assemble them together. Two github repositories will help solving that:

    • AMD-Testing - A demonstration project of how to test async modules (AMD) both in the browser and in NodeJS.
    • Squire - A dependency injector for RequireJS users to make mocking dependencies.

    So, the bottom line is to build a testing system to run unit tests based on Jasmine specs, intended for JavaScript source code, using either real or mock dependencies in NodeJS environment.

    Project Structure
    The whole testing system is located in tests folder sitting inside the project folder, for which the unit tests are written. It has several folders and a bootstrapping file.

    image

    JavaScript files under unit test might contain some dependencies that are used for handy development, e.g. custom logging system instead of simple console.log function. Such files should always be substituted with mock dependencies while running a unit test. These plugs are stored in mocks folder.
    External libraries like jasmine, reporter, which come from amd-testing library for generating terminal suited report, require.js, and squire are under libs folder.
    Specs posses jasmine specification files for unit tests.
    Finally, runner.js is a launchable file for NodeJS that specifies the configuration for RequireJS, and loads Jasmine spec suits.

    Runner File
    Script runner.js is the heart of the testing system. Conceptually, it has 3 parts: RequireJS configuration object, global assignments of Jasmine methods, and lastly, specs launch.

    RequireJS configuration
    Since the original project is managed with RequireJS, we need to utilize it inside a unit test system as well. So the first thing we should do in runner.js is to specify the configuration for requirejs as well. It almost repeats the config object of the original project with paths to the original scripts with minor changes:

    • Original paths should be changed to mock objects that are located in the mock folder
    • Add paths to specification folders
    requirejs.config({
        nodeRequire: require,
        baseUrl: 'tests',
        shim: {
          'underscore': {
            exports: '_'
          },
          'backbone': {
            deps: ['underscore', 'dom'],
            exports: 'Backbone'
          },
          'modernizr': {
            exports: 'Modernizr'
          },
          'logger': {
            exports: 'log4javascript'
          }
        },
        paths: {
     
          // Mocks definitions
          logger: './mocks/logger',
          sys: '.././utils/sys',
     
          // Real definitions
          core: '.././core',
          sandbox: '.././sandbox',
     
          jquery: '.././libs/jquery-1.8.2',
          underscore: '.././libs/underscore-1.4.2',
          text: '.././libs/text-2.0.3',
          backbone: '.././libs/backbone-0.9.2',
          modernizr: '.././libs/modernizr-2.6.1',
         
          base: '.././managers/base',
          mediator_mngr: '.././managers/mediator',
          desktop_mngr: '.././managers/desktop',
          auth_mngr: '.././managers/auth',
          def_mngr: '.././managers/definition',
     
          // Specification definitions
          authMngrSpec: './specs/managers/auth',
          mediatorMngrSpec: './specs/managers/mediator'
        }
    });
    

    Globals
    Setting globals methods is required to expose RequireJS and Jasmine throughout the testing system, and specs in particular.

    // Make define available globally like it is in the browser
    global.define = require('requirejs');
    // Make jasmine available globally like it is in the browser
    global.describe = require('./libs/jasmine').describe;
    global.it = require('./libs/jasmine').it;
    global.expect = require('./libs/jasmine').expect;
    global.beforeEach = require('./libs/jasmine').beforeEach;
    global.jasmine = require('./libs/jasmine').jasmine;
    

    Runs
    The last part of runner.js file loads Jasmine specification suits that should run, and the script of the reporter for outputting test results into a console/terminal.

    /* Main function which loads and runs specification for unit test */
    requirejs(['authMngrSpec', 'mediatorMngrSpec'], function() {
      setTimeout(function () {
        var Reporter = require('./libs/reporter').ConsoleJasmineReporter;
        global.jasmine.getEnv().addReporter(new Reporter());
        global.jasmine.getEnv().execute();
      }, 50);
    });
    

     

    Unit test
    Unit tests can be written in two ways: using original dependencies and using mock dependencies. The former is not unique in any way from writing regular Jasmine spec.

    define(['.././managers/mediator'], function (mediator) {
      describe('Mediator', function () {
        beforeEach(function () {
          // before code goes here
        });
        describe('subscribe method', function () {
          describe('verify parameters', function () {
     
            it('should throw exception if all parameters are not specified', function () {
              // code
            });
          });   
        });
      });
      return 'Mediator Manager';
    });
    

    The define statement loads the script that should be tested. If the script has dependencies, they will be loaded as well either using relative path or paths, which were specified in the configuration object. The define callback function specifies the unit testing code.

    Writing unit test with mock dependencies requires little more coding.

    Unit Tests With Mocks

    Writing unit tests with mock dependencies consist of two obvious stages - creating mock deps and building unit test. The latter is no different from described above, so there is no need to detail it again.

    define(['./libs/squire'], function (Squire) {
      var injector = new Squire();
      injector.mock('base', {
        data: {
          ajax: function (params) {
            console.log('I did ajax request to ' + params.url);
          }
        }
      });
      injector.mock('mediator_mngr', {});
     
      injector.require(['.././managers/auth'], function (auth) {
        describe('Authorization manager', function () {
          beforeEach(function () {
            expect(auth).toBeDefined();
          });
          describe('login method', function () {
            it('should succeed', function () {
              auth.login(TEST_SUCCESS_CREDENTIALS, function (res) {
                expect(res.status).toBe('200');
              }, {});
            });
     
          });
          describe('logout method', function () {});
        });
      });
      return 'Authorization Manager';
    });
    

    Firstly, Squire lib should be loaded and instantiated. Its documentation page provides a good explanation of how to create mocks. What we need is squire.mock method(Object name, Mock object). After creation, the module in test will use mocks, which are identified by mock names, instead of real dependencies. Injector.require method loads the script which should be tested and injects our mocks.  The regular unit test code goes further.

    Conclusion

    image

    Now it’s all done. The only thing remaining is to launch the test. Open a terminal, navigate to the test folder, type `node runner.js`, and enjoy the results.

     


  12. DOM’s manipulations are expensive

    Well, yeah, every front-end dev knows it but why it is so? Knowledge of how browsers work, webkit (hello, chrome, safari, and now opera) in particular, might help to write more efficient code.

     


  13. Aas it turns out, not all JS developers can cope with such task as reversing linked list. Can you?
    Following the link above, you would need to implement reverse method of LinkedList class, such that, after printing, it will be vice versa.

    http://jsbin.com/ugojoq/3/edit

     


  14. Good, in-depth explanation of what asm.js is about. In short: asm.js defines a subset of JavaScript that can be compiled to fast executable. 

     


  15. I suppose, guys from jQuery used this resource to write their library taking into consideration all compatibility information among browsers