<file_sep>// imports
var mergeTrees = require('broccoli-merge-trees');
var concat = require('broccoli-concat');
// var compileSass = require('broccoli-sass');
var compileES6 = require('broccoli-jstransform');
var pickFiles = require('broccoli-static-compiler');

// trees

// grab my styles in sass module
// var styles = compileSass(['app/scss/'], 'style.scss', '/assets/styles.css');  
var styles = concat(
	'app/scss',{
		inputFiles: ['*.scss'],
		outputFile: '/brocoli/assets/style.scss'
	});

// grab my scripts
var scripts = compileES6('app/scripts', [    
	'es6-arrow-function',
  	'es6-class',
    'es6-destructuring',
    'es6-object-concise-method',
    'es6-object-short-notation',
    'es6-rest-param',
    'es6-template',
    'es7-spread-property',
    'reserved-words']);

// grap any static assets
var public = pickFiles('app/html', {  
  srcDir: '.',
  destDir: '.'
});


// merge all trees:
module.exports = mergeTrees([scripts, styles, public]);  <file_sep># trynode
npm install

Brocoli:
# to get node_modules
npm install broccoli-cli --global
npm install --save-dev broccoli
<file_sep>// #1 - 10 octets
var buf = new Buffer(10);
// #2
var buf2 = new Buffer([10, 20, 30, 40, 50]);
// #3
var buf = new Buffer("Simply Easy Learning", "utf-8");

// json
var buf = new Buffer('Simply Easy Learning');
var json = buf.toJSON(buf);

console.log(json);

// string buffer
var buffer1 = new Buffer('TutorialsPoint ');
var buffer2 = new Buffer('Simply Easy Learning');
var buffer3 = Buffer.concat([buffer1,buffer2]);
console.log("buffer3 content: " + buffer3.toString());


// STREAMS

var fs = require("fs");
var data = '';

// Create a readable stream
var readerStream = fs.createReadStream('input2.txt');

// Set the encoding to be utf8. 
readerStream.setEncoding('UTF8');

// Handle stream events --> data, end, and error
readerStream.on('data', function(chunk) {
   data += chunk;
   console.log("wyciagam dane chunk: " + chunk);
});

readerStream.on('end',function(){
   console.log("koniec danych: wypisuje");
   console.log(data);
});

readerStream.on('error', function(err){
   console.log(err.stack);
});

console.log("Program Ended");

/// Jest jeszcze piping i inne nudne operacje na systemie plikow

// __ o z tym są globalnymi zmiennymi
console.log( __filename );
console.log( __dirname );

// oczywiscie to wcyaiagnie plikow jest callbackami wiec pojawi sie zawsze w kolejnce na koncu :/

// jakby te callbacki jeszcze wziac w taka funkcje to do tego wszystkiego mozna spowolnic 
// wszystko, tak aby nie dosc ze bylo ostatnie to jeszcze wywolalo sie po wszystkim :/
function printHello(){
   console.log( "Hello, World!");
}
setTimeout(printHello, 2000);

function dawajPozniej(){
	var data = fs.readFileSync('input.txt');
	console.log(data.toString());
	console.log("Sync");
}

console.log("Bez timeoutu");
fs.readFile('input.txt', function(err, data){
	console.log(data.toString());
	console.log("ASync");	
});
dawajPozniej();
console.log("Koniec bez timeoutu");

console.log("Z timeoutem");
setTimeout(dawajPozniej, 2000);
fs.readFile('input.txt', function(err, data){
	console.log(data.toString());
	console.log("ASync");	
});
console.log("Koniec z timeoutem");

// Ok czyli mozna synchroniczne przlozyc "ZA" asynchronicznymi za pomocą timeoutu

//A jakby usunac ten timeout

console.log("Z timeoutem");
var t = setTimeout(dawajPozniej, 2000);
fs.readFile('input.txt', function(err, data){
	console.log(data.toString());
	console.log("ASync");	
});
clearTimeout(t);
console.log("Koniec z timeoutem");

// To sie nic nie wypisze <file_sep>var EventEmitter = require("events").EventEmitter;
var domain = require("domain");
var child = domain.create();

var emitter = new EventEmitter();

child.on('error', function(err){
	console.log("child handled an error: " + err.message);
});

// explicit binding
child.add(emitter);

emitter.on('error', function(err){
	console.log("listener on emitter shows error: " + err.message);
});

emitter.emit('error', new Error('Will be handled by listener'));

emitter.removeAllListeners('error');

emitter.emit('error', new Error('Will be handled by child'));

var child2 = domain.create();

child2.on('error', function(err){
   console.log("domain2 handled this error ("+err.message+")");
});

child2.run(function(){
   var emitter2 = new EventEmitter();
   emitter2.emit('error',new Error('To be handled by child2'));   
});

child.remove(emitter);

emitter.emit('error', new Error("Crash!"));<file_sep>var events = require('events');

var eventEmitter = new events.EventEmitter();

var eventHandler = function connect(){
	console.log("Connection succesful");
	console.log('INSIDE CONNECTION HANDLER');
	eventEmitter.emit('data_received');
}

//Binding
eventEmitter.on('connection', eventHandler);

//
eventEmitter.on('data_received', function(){
	console.log('INSIDE DATA R HANDLER');
	console.log('data received succesfully');
});

console.log('EMITING CONNECTION');
eventEmitter.emit('connection');
console.log('End');<file_sep>var fs = require("fs");

// synchroniczne otwieranie plików
var data = fs.readFileSync('input.txt');
data.toString();
console.log("Nara 1");

// asynchroniczne otwieranie plików
// callback - asynchroniczna wersja synchronicznej funkcji
fs.readFile('input2.txt', function(err, data){
	console.log("2file");
	data.toString();
});

fs.readFile('input.txt', function(err, data){
	console.log("1file");
	data.toString();
});

// wniosek nie wazne ile synchronicznych polecen w glownych watkach mamy
// to i tak one zawsze przejdą jako pierwsze chocby wypadalo aby asynchroniczne
// dzialania zostaly wywolane w miedzyczasie 
// -- suabo --