This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo nohup npm start & |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Date: Jan 19 2017 | |
| title: NodeJS enhanced CJS module pattern | |
| author: Shahzad Nawaz | |
| email: shahzadscs@gmail.com | |
| Description: | |
| This gist proposes an enhanced CommonJS module declaration pattern for nodeJS/express modules. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Reverse string in javascript. | |
| var str = "your string"; | |
| str.split('').reverse().join(''); | |
| //using ES6 is more easy. | |
| [...str].reverse().join(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let lsb = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'saven', 'eight', 'nine'], | |
| mid = ['', 'ten', 'tweenty', 'therty', 'fourty', 'fifty', 'sixty', 'saventy', 'eighty', 'ninty'], | |
| msb = ['', 'one hundred', 'two hundred', 'three hundred', 'four hundred', 'five hundred', 'six hundred', 'saven hundred', 'eight hundred', 'nine hundred'], | |
| num = 445; | |
| input = String(num); | |
| let msbBit = Number(input[0]), | |
| midBit = input.length > 1 ? Number(input[1]) : 0, | |
| lsbBit = input.length > 2 ? Number(input[2]) : 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let array = [{ id: 1, name: 'umair', age: 14 }, { id: 2, name: 'zubair', age: 16 }, { id: 3, name: 'owais', age: 20 }]; | |
| //get any field/key of obj using map. | |
| let idsArray = array.map( (obj) => obj.id ); | |
| //result ids = [1, 2, 3] | |
| //get special object from array using find. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Array syntax | |
| let promises = [promiseOne(), promiseTwo(), promiseThree()]; | |
| $q.all(promises).then((values) => { | |
| console.log(values[0]); // value One | |
| console.log(values[1]); // value Two | |
| console.log(values[2]); // value Three | |
| // do something |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var crypto = require("crypto") | |
| function encrypt(key, data) { | |
| var cipher = crypto.createCipher('aes-256-cbc', key); | |
| var crypted = cipher.update(data, 'utf-8', 'hex'); | |
| crypted += cipher.final('hex'); | |
| return crypted; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // set-up a connection between the client and the server | |
| var socket = io.connect(); | |
| // let's assume that the client page, once rendered, knows what room it wants to join | |
| var room = "abc123"; | |
| socket.on('connect', function() { | |
| // Connected, let's sign-up for to receive messages for this room | |
| socket.emit('room', room); | |
| }); |