Sunday, February 23, 2014

Source Code Browing Tools

I found someone struggling to understand a large code base, and I wanted to solve the problem. I've had the same issues too. Thank you Slashdot.

Source code browsing tools:
http://beta.slashdot.org/story/68967

Saturday, February 22, 2014

Hello World with Git

I was going through create a repo on GitHub, and these were a few link that I used:

https://help.github.com/articles/create-a-repo

Installing Git on Ubuntu 12:04:
https://www.digitalocean.com/community/articles/how-to-install-git-on-ubuntu-12-04

Error from Gnome keyring:
http://askubuntu.com/questions/243210/why-do-i-get-this-warning-from-gnome-keyring-in-xubuntu

Generating ssh keys for github:
https://help.github.com/articles/generating-ssh-keys

Errors with ssh keys:
https://help.github.com/articles/error-agent-admitted-failure-to-sign

Also some notes:

make sure you register the public key with github!

For some reason it helped to remove the git repository and start over.

KDE

I updated my OS to Ubuntu 12.04 LTS and my desktop to KDE. Unfortunately, Salome 6 does not work, and my desktop categories are a bit different. Otherwise it is good. I love KDE.

Conditionals in Node.js

// Okay, I will need this later.
if (5 < 4) {
   console.log("The math is weird here");
} else
   console.log("Math may be right here");

Reading from the User and Writing to a File in Node.js (part 3)

// Thanks for the encouragement Micah Alcorn! I wrote to a file using node.js.
// Now I am embedding the write in a function within readline. Due to variable
// scope, I have two outputs for the variable answer. One is 'the wrong answer'
// and the other is what I choose.

readline = require('readline');

var fs = require('fs');

var answer = 'the wrong answer';

var rl = readline.createInterface({

  input: process.stdin,

  output: process.stdout,

});

rl.question("What do you think of node.js?", function(answer) {

  // TODO: Log the answer in a database
  // Hmm ... I wonder what happens if I write to the file here...

write(answer);
//  fs.writeFile('read_write_node_embed.txt', answer, function(err) {
 
//    if (err) throw err;
  
//    console.log('It\'s saved!');

//});

// The end of the writing to the file

  console.log("Thank you for your valuable feedback:", answer);

  rl.close();

})

function write(answer) {
fs.writeFile('write_answer.txt', answer , function(err) {

  if (err) throw err;

  console.log('It\'s saved!');

});
}

fs.writeFile('wrong_answer.txt', answer, function(err) {

  if (err) throw err;

  console.log('It\'s saved!');

});

Reading from the User and Writing to a File in Node.js (part 2)

// I get different output when I embed! Thank you Micah!

readline = require('readline');

var fs = require('fs');

var answer = 'this answer';

var rl = readline.createInterface({

  input: process.stdin,

  output: process.stdout,

});

rl.question("What do you think of node.js?", function(answer) {

  // TODO: Log the answer in a database
  // Hmm ... I wonder what happens if I write to the file here...

  fs.writeFile('read_write_node_embed.txt', answer, function(err) {
 
    if (err) throw err;
  
    console.log('It\'s saved!');

});

// The end of the writing to the file

  console.log("Thank you for your valuable feedback:", answer);

  rl.close();

})

fs.writeFile('read_write_node_not-embed.txt', answer , function(err) {

  if (err) throw err;

  console.log('It\'s saved!');

});

Reading from the User and Writing to a File in Node.js (part 1)

Thanks for the encouragement Micah Alcorn! I wrote to a file using node.js.

var fs = require('fs');

fs.writeFile('message.txt', 'Hello Node', function (err) {
if (err) throw err;
console.log('It\'s saved!');
});

*source: http://nodejs.org/api/fs.html

I can also append data to the same file, through something like this:

var fs = require('fs');

fs.writeFile('message.txt', 'Hello Node', function(err) {
  if (err) throw err;
  console.log('It\'s saved!');
});

fs.appendFile('message.txt','data to append, function (err) {
  if (err) throw err;
  console.log('The "data to append" was appended to a file!');
});

If I want to instead take imput from the user and save it to a file all I have to do is:

var readline = require('readline');
var fs = require('fs');
var answer = 'this answer';

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.question("What do you think of node.js?", function(answer) {
  // TODO: Log the answer in a database
  console.log("Thank you for your valuable feedback:", answer);

  rl.close();
})

fs.writeFile('message.txt', answer , function(err) {
  if (err) throw err;
  console.log('It\'s saved!');
});

*source: http://nodejs.org/api/readline.html

Except this does not work, maybe because answer in rl.question does not appear to be local in scope...because the output of fs.writeFile is 'this answer'.

Friday, February 21, 2014

Text input into the console in Node.js

I have been trying to find out how text input from the console works in node.js. Apparently there is something called read line that does the trick. Here is the link: http://nodejs.org/api/readline.html. It is described in the Node.js manual. There are also methods to prompt users for input, as described in the Nodejitsu documents: http://docs.nodejitsu.com/articles/command-line/how-to-prompt-for-command-line-input.