Skip to content

Instantly share code, notes, and snippets.

View chaiwa-berian's full-sized avatar

Berian chaiwa-berian

View GitHub Profile
@chaiwa-berian
chaiwa-berian / index.html
Last active February 18, 2017 19:11
MichaelChilufyaSata
<nav class="navbar navbar-toggleable-md navbar-inverse bg-inverse">
<figure class="figure">
<a class="navbar-brand" href="#">Michael Chilufya Sata</a>
<figcaption class="figure-caption">Tribute Page</figcaption>
</figure>
</nav>
<div class="container">
<div class="row container">
<div class="col-sm-6">
<figure class="figure">
@chaiwa-berian
chaiwa-berian / README-Template.md
Created June 26, 2018 18:31 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@chaiwa-berian
chaiwa-berian / one_line_of_code_server
Created August 2, 2018 18:28
Nodejs Server in one line of code
require('http').createServer((req,res)=>res.end("Hey!")).listen(3000,'127.0.0.1');
@chaiwa-berian
chaiwa-berian / i_o_blocking_code_sample.js
Last active August 13, 2018 17:11
Nodejs Blocking Code Example
console.log('Step: 1');
var startTime = Date.now();
console.log('Start time: ', startTime);
for(let i=1;i<10000000000;i++){
//Do Nothing
}
var endTime = Date.now();
console.log('Step: 2 started!');
console.log('End Time: ', endTime);
@chaiwa-berian
chaiwa-berian / nodejs_events_demo.js
Last active August 13, 2018 18:28
Nodejs Events Demo
var events = require('events');
var emitter = new events.EventEmitter();
emitter.once('knock', function(){ //subscribe to the event
console.log('Who\'s there???');
});
emitter.on('knock', function(){ //subscribe to the event
console.log('Leave us in peace, please!!!');
});
//We are triggering start but we are catching done
var Job = require('./nodejs_inherit_events_main_job'); //inherit from main Job
var job = new Job();
job.on('done', function(details){ //Subscribe to the main job's done event
console.log('Job was completed at', details.completedOn);
job.removeAllListeners();
});
job.emit('start'); //Fire-up the main job
//We emit done and catch start events
var util = require('util');
var Job = function Job(){
//we will use it later to pass this to a closure
var job = this;
job.process = function(){
//emulate the delay of a job async
setTimeout(function(){
var obj ={
prop: (() => { return ( 3 > 4 ? 'yes' : 'no' );})();
}
console.log(obj.prop); //output: no
const http = require('http');
const fs = require('fs');
var server = http.createServer((req, res)=>{
var stream = fs.createReadStream(__dirname + '/data.txt');
stream.pipe(res);
});
server.listen(3000);
const http = require('http');
const fs = require('fs');
var server = http.createServer((req,res)=>{
fs.readFile(__dirname + '/data.txt', function(err, data){
if(err){
res.end(err);
}
res.end(data);
}