Showing posts with label Projects. Show all posts
Showing posts with label Projects. Show all posts

Tuesday, 27 September 2016

Learning Node.js

Node.js has always looked interesting to me, yet I have never explored it properly.

Every time I hear people mention Node.js its almost always followed by the words "web-server", so naturally I assumed Node.jswas a light weight web-server. Turns out (by just Googling node.js) that it is in fact just a JavaScript Run-time.

Once I installed Node I realised I could just run the following in a console:

$ node
> console.log('Hello');
Hello
undefined

Undefined is returned because node returns the return value of each command. This command has no return value. 

The reason people always mention web-servers is because its incredibly easy to create a basic web-server with node:

web-server.js

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080);

console.log('Server running on port 8080.');

Now running $ node web-server.js will launch the web-server, going to http://localhost:8080 will show the text.

Node.js has a very large number of library's which can be used to do almost anything. One project I am quite keen on is a drag and drop page which will parse a CSV file and output relevant data. I'm going to be working on this over the next few hours and I will update this post once complete.

Thursday, 4 February 2016

Understanding VIM

Me and Vim have a complex relationship. I spent a lot of time loathing it, a small amount of time putting up with it and now all my time using it.

I was born in the late 80's. I grew up with graphic user interfaces, this was a good thing, it was easy to pick up and play with. I didn't have to worry about permissions,  .swp files and the like. I could use my mouse to highlight all the text, click where I wanted to start typing and just start typing.

Then when I got older and started using Linux I took my first step into the world of real programming, no more batch files for me!
I was told that Vim was an incredibly useful tool you could use to write code, I tried it, it did not make me happy.

"Why do you have to press 'i' every time you want to type?" I asked myself shortly after discarding it and using a more notepad-esque option.
I read that the reason for this is so you can execute useful commands such as a search and replace:

 :%s/foo/bar/g

"How is this better than CTRL+F?" I thought. My general opinion was that Vim was needlessly complicated and so I forgot about it.

After university I got a job at a company which provided Real Time information for buses. Each bus stop had a digital display which received information via GPS or Wifi. One of my jobs was to remotely access these digital displays and update the software within. The problem was that each display ran a headless version of Linux called TinyCore, this means it had no GUI. I watch a few of my colleagues editing config files using Vi or Vim and decided to give the editor another go (not that I had any choice). I learned a few basic commands and I got used to it, but I still didn't like it much.

Things stayed that way for a while, It's only been the last few years that I have realized what I have been missing with Vim.

I have downloaded Vim Improved text editor which I now use daily, hourly almost. The great thing about it is that it you learn the command line vim by using it. when you click file it gives you all the usual options, i.e. Open, Save etc, but just on the right it shows you the relevant command to preform that action on the command line.

Currently I do a lot of work on a Linux server running redhat. With Vim I can, remove duplicate records just by typing:

:sort u

I can column select by pressing 'SHIFT+V' or 'CTRL+V' and then select my column, then by pressing 'I' and typeing what I need, then pressing 'ESC' all rows have been updated.

I have misjudged Vim and i am now spending a lot of my time realizing how great this software actually is.