Skip to content

Instantly share code, notes, and snippets.

View picpoint's full-sized avatar
:octocat:
<html> .less {js} <?php?> "mysql"

rmtar picpoint

:octocat:
<html> .less {js} <?php?> "mysql"
View GitHub Profile
@picpoint
picpoint / IO to Nodejs
Created April 28, 2019 09:14
simple code to IO in Nodejs
const stdin = process.stdin;
const stdout = process.stdout;
stdout.write('Enter you name -> ');
stdin.on('data', function (data) {
stdout.write('Your name is -> ');
var name = data.toString().trim();
stdout.write(name + '\n');
stdout.write('Your name to reverse -> ' + name.toString().split('').reverse().join('') + '\n');
@picpoint
picpoint / script to loading
Created April 28, 2019 10:41
script to show loading process
const stdin = process.stdin;
const stdout = process.stdout;
const waitTime = 6000;
var currentTime = 0;
var loadsec = (waitTime - 1000) / 1000;
stdout.write(`loading ${loadsec} seconds...\n`);
var tm = setInterval(function () {
stdout.write((currentTime += 1).toString() + '\n');
@picpoint
picpoint / script to show process loading
Created April 28, 2019 12:07
script to display the download process updated
const stdin = process.stdin;
const stdout = process.stdout;
const waitTimeout = 6000;
const waitInterval = 1000;
var currentTime = 0;
var percent = 0;
function print (percent) {
stdout.clearLine();
stdout.cursorTo(0);
@picpoint
picpoint / core
Last active April 29, 2019 15:40
tasks from theme core
// ДЗ Ядро
/*
+++Задание 1
Реализовать программу, которая принимает на вход один или более аргументов и выводит их
сумму в консоль(stdout)
*/
/*
const stdout = process.stdout;
const argv = process.argv;
@picpoint
picpoint / create and append file
Created April 30, 2019 11:21
This programm create file and write to file text. To create and write file need key-command in console
const fs = require('fs');
function getValue(flag) {
const index = process.argv.indexOf(flag);
if (index > -1) {
return process.argv[index + 1];
} else {
return null;
}
}
@picpoint
picpoint / create and append file
Created April 30, 2019 11:21
This programm create file and write to file text. To create and write file need key-command in console
const fs = require('fs');
function getValue(flag) {
const index = process.argv.indexOf(flag);
if (index > -1) {
return process.argv[index + 1];
} else {
return null;
}
}
@picpoint
picpoint / watcher Nodejs
Last active April 30, 2019 11:48
simple watcher Nodejs and event err
const fs = require('fs');
const watcher = fs.watch(__dirname, function (event, filename) {
console.log('Event: ', event, ' ', 'filename: ', filename);
});
watcher.on('error', function (err) {
console.log(err);
});
@picpoint
picpoint / fs
Last active May 7, 2019 09:48
task 3 to fs
//Файловая система
/*
+++Задание 1
Реализовать программу, которая синхронно читает файл и выводит количество строк(\n) содержащихся в файле в консоль
*/
/*
const fs = require('fs');
var file = fs.readFileSync('test.txt', 'utf-8');
file = file.split('\n');
@picpoint
picpoint / events
Last active May 12, 2019 15:16
module Events
const EventEmiter = require('events'); // подключаем модуль
const myEE = new EventEmiter();
myEE.on('ready', function () { // создаём событие ready
console.log('is ready ...');
});
myEE.on('start', function () { // создаём событие start
console.log('is start ...');
});
@picpoint
picpoint / tick EventEmiter
Last active May 12, 2019 15:20
Events EventEmiter
// Н Ё Х
const EventEmiter = require('events');
class Timer extends EventEmiter {
constructor(total) {
super();
this.total = total;
this.ticks = 0;
}