Tag Archives: javascript

Node n permission denied without sudo

Each time I do a fresh install of the Node Version Management tj/n I end up getting the permission denied when running npm install. If you also ran into this issue, well, there’s a quick fix. The issue is caused by the Node Version Management for which the owner is the root. The two following Continue Reading »

Convert seconds to Days, Hours, Minutes, Seconds

Learn how to convert number of seconds into days, minutes, hours and seconds. That’s it. You can now create a countdown timer, display the difference between two dates or just print  the time until something great happens. You now have 4 variables with values as follows: Bonus! Learn how to pad the values with 0 Continue Reading »

Socket.IO AngularJS Wrapper

I’ve been playing around with Socket.IO and AngularJS. To make things easier I created this service which can be used for transferring data between the client (which could be a web page) and a NodeJS server. The app is served by NodeJS so the Socket.IO server is listening on same location. ‘use strict’; angular .module(‘APP’) Continue Reading »

Google Maps JavaScript Wrapper

Some of the projects I’ve implemented required some dynamic or static maps. Of course most powerful maps library at that time was Google Maps. The wrapper allows the insertion of markers with custom icon, circles, polylines and setting the center and zoom of the map. Here’s one version of the JavaScript Google Maps Wrapper that Continue Reading »

Senior JavaScript Interview Test

A few weeks ago a team that I collaborated with asked me to create a JavaScript Interview Test for seniors. The third part of the interview test also contains answers. My opinion is that if you ever use this test and the candidate can answer correctly to  1/3 of the questions, well you should definitely Continue Reading »

JavaScript Prototypal Inheritance Pattern

This is pretty basic stuff but I’ll just place it here in case someone searches for a way to achieve inheritance in JavaScript.   // JavaScript doesn’t have classes but same behavior can be easily obtained using functions // Let’s consider a class Person function Person() { this.name = ”; this.birth = { ‘year’: -1, Continue Reading »

AngularJS Input Max Length Directive

In case you need to set a max length to a model binded input, well check this directive: ‘use strict’; angular .module(‘APP’) .directive(‘uiMaxlength’, function() { return { require: ‘ngModel’, link: function(scope, el, attrs, model) { var max_length = parseInt(attrs.uiMaxlength, 10); var input_value_parser = function(value) { if(value.length > max_length) { value = value.substring(0, max_length); model.$setViewValue(value); model.$render(); Continue Reading »

AngularJS Ng-Repeat In Range

AngularJS does not provide a way to create multiple copies of an element. Still this behavior is easy to achieve. Check the bellow filter which solves this problem: ‘use strict’; angular .module(‘APP’) .filter(‘range’, function() { return function(input, total) { total = parseInt(total, 10); for(var i=0; i<total; ++i) { input.push(i); } return input; }; }) ; Continue Reading »

NodeJS AES256 Encryption/Decryption

In one of my projects I needed to encrypt some data. I decided to use AES256 symmetrical encryption algorithm. So this is what I’ve come to (aes_encryption.js): var crypto = require(‘crypto’), cipher_seed = ‘some_random_characters’; var encrypt = function(text) { var cipher = crypto.createCipher(‘aes-256-cbc’, cipher_seed), crypted = cipher.update(text, ‘utf8’, ‘hex’); crypted += cipher.final(‘hex’); return crypted; }; Continue Reading »

Finalize – JavaScript Asynchronous Requests Queue

Most web apps send lots of asynchronous http requests. Sometimes you need to know when some selected requests are finished so that you can pass to the next step. The following function can be used for creating a queue with asynchronous requests using JavaScript and be notified when the queue is empty again (all selected Continue Reading »