Skip to content

Instantly share code, notes, and snippets.

@salmanx
salmanx / timers.js
Created October 15, 2018 07:48
code example of setTimeout() and setInterval() for node js
var readline = require('readline');
var waitTime = 3000;
var currentTime = 0;
var waitInterval = 500;
var percentageWaited = 0;
function writeWaitingPercentage(p){
readline.clearLine(process.stdout);
readline.cursorTo(process.stdout, 0)
@salmanx
salmanx / readline.js
Created October 15, 2018 10:16
code example for readline module in node js
const readline = require('readline');
const rl = readline.createInterface(process.stdin, process.stdout);
const realPerson = {
name: "",
sayings: []
};
rl.question("Who is real person? ", function(answer){
realPerson.name = answer;
rl.setPrompt(`What would ${realPerson.name} say? `);
@salmanx
salmanx / event.js
Created October 15, 2018 11:19
simple code example how EventEmitter() works in node js
// Basic events functionality
// const EventEmitter = require('events');
// const emitter = new EventEmitter();
// emitter.on('messageLogged', function(args){
// console.log(`${args.name} : ${args.age}`)
// console.log("Listener called");
// });
@salmanx
salmanx / child_process_exec.js
Created October 15, 2018 14:12
explanation how child process works in node js
const exec = require('child_process').exec;
exec("open https://facebook.com");
exec('ls', function(err, stdout){
if(err)
console.log(err)
console.log("Listing finished..")
console.log(stdout);
@salmanx
salmanx / callback.js
Created October 18, 2018 05:20
an example how javascript callback works
console.log('Before');
getUser(1, displayUser);
console.log("After");
function getUser(id, callback){
setTimeout(() => {
console.log("Reading a user from database!");
callback({ id: id, name: "salmanx" })
@salmanx
salmanx / promise.js
Created October 18, 2018 05:22
an example how promise work in javascript
const p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1);
// reject(new Error('message'));
}, 2000)
});
@salmanx
salmanx / callback_to_promise.js
Created October 18, 2018 05:23
an example for callback to promise conversion in javascript
console.log('Before');
// callback approach
// getUser(1, displayUser);
// promised based approach
// getUser(1)
// .then(user => getRepositories(user.name))
// .then(repos => getCommits(repos[0]))
import { createStore, combineReducers} from "redux";
import uuid from 'uuid/v1';
// NOTE:
// to create store we need to pass reducer in createStore() method
// reducer is a function with state and action params - testReducer(state = demostate, action)
// reducer will return result based on action.type
// we need to pass demoState in params
// state of the application would look like this demoState
@salmanx
salmanx / docker-help.md
Created March 31, 2019 08:37 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

# Ruby wrapper for UglifyJS JavaScript compressor
gem "uglifier", ">= 1.3.0"
#Search Engine Optimization (SEO)
gem "meta-tags"
# Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
gem "sucker_punch"