NodeJS
Today was the first day that I had no idea how to do algorithms. The second algorithm was to write a function that takes in a string and returns an array that gives all possible in-order combination. For example, str = "abc" should return [" ","a","b","c", "ab", "ac", "bc", "abc"]. I wrote yesterday that it makes life easier to first write the non recursive form of this and I did do that...except I couldn't translate it into a recursive function. When Kris showed us his solution, it completely blew my mind and I think it blew everyone else's mind. So far, we've only returned a function by itself once, with this problem, you have to call itself (but with slightly different parameters) again. Even as Kris showed us a feature on Chrome's debugging feature where it showed us everything that is happening line by line, it didn't make sense. Seriously, I've never been so out of depth with algorithms and it does scare me at how unprepared I am.
We went through all of Node today. NodeJS is a backend server that is very useful because of how lightweight and compact it is for very specific purpose of real time functions in a software or website. Imagine a chatroom with 100,000 people, when you write something, the message should show to everyone at the same time and immediately. With other servers, this is not possible without a refresh of the page or if it is possible, causes a high amount of server load so the users in the chatroom would be severely limited. One node in NodeJS can handle 200,000 connections. But Node does have drawbacks, namely working with relational databases, like MySQL and anything that requires heavy computation.
All in all, the assignments again weren't too hard but there was a lot of information to absorb. There is a way of doing routes that makes it easier than how it was done in Django but it was really repetitive to write a code for every static, image files. This is what I mean:
var http = require('http');
var fs = require('fs');
server = http.createServer(function (request, response){
response.writeHead(200, {'Content-type': 'text/html'});
console.log('Request', request.url);
if(request.url === '/'){
fs.readFile('views/index.html', 'utf8', function (errors, contents){
response.write(contents);
response.end();
});
} else if(request.url === '/dojo.html'){
fs.readFile('views/dojo.html', 'utf8', function (errors, contents){
response.write(contents);
response.end();
});
} else if(request.url === '/stylesheet/style.css'){
fs.readFile('stylesheet/style.css', 'utf8', function (errors, contents){
response.write(contents);
response.end();
});
} else {
response.end('File not found!!!');
}
});
server.listen(8000);
console.log("Running in localhost at port 8000");
Low and behold, our last assignment of the day was to find out how to write an import .js file that dynamically knows which folder to look in and render which file in the fold.er