Ah grep you are a time saver

Posted on

Searching for a function valid_move that was made in one of my tttt dirs 

How to quickly find it with out manually going to each file?

grep -R “valid_move” ttt*

MONGODB: What is a projection?

Posted on Updated on

A projection is when you search for documents in MongoDB but only get back the fields that you request.

example records   {name: “Tom”, age: “35”, zipcode: “10003”,_id:778789754}

using projection for name and zipcode: {name: “Tom”,  zipcode: “10003”}


var mongo = require(“mongodb”).MongoClient;
var url = “mongodb://localhost/addressbook”;
var collectionName = “friends”;
if(err) console.log(err)//throw err;
var collection = db.collection(collectionName);
collection.find({},{name: 1, age: 0,_id:0,zipcode: 0}).toArray( function(err,documents){
if(err) console.log(err)//throw err;


node notes: require() caches module.exports

Posted on Updated on

if you are importing a file that instantiates a new object

when you import the file again as a 2nd object you would expect … a new object

but your 2nd variable will be the same object as the first variable, even though a “new” constructor was used. why?

Node caches module imports , it wont load the file again so no new instance!!!


// file greet3.js
function Greetr(){
  this.greeting=”Hello World from greet3″
module.exports = new Greetr();


var greet3 = require(“./greet3.js”);
greet3.greeting = “NEW GREETING!!!!”
var greet3a = require(“./greet3.js”);
Hello World from greet3
how to resolve??
in the file being exported, greet3.js, send the constructor not the new instance
module.exports = Greetr;
var Greet3a = require(“./greet3.js”);  //you capitalize greet3a to tell its constructor
var grtr = new Greet3a();

Node notes : on require with no js file in local path

Posted on

if you require, for example  “greet”, and greet.js is not found, node will look for folder called “greet” and then look for a file called index.js



Ubuntu: Install Visual Studio Code via apt-get

Posted on Updated on

Why fiddle with downloading from the browser when apt-get will do?

sudo add-apt-repository -y "deb stable main"
sudo apt-key adv --keyserver --recv-keys EB3E94ADBE1229CF
sudo apt update
sudo apt -y install code

If need upgrade

sudo apt -y upgrade
sudo apt -y dist-upgrade

great answer from zurfyx



Errors encountered on my way to install Node.JS v8 on ubuntu

Posted on

when running apt-get install nodejs

You might want to run ‘apt-get -f install’ to correct these:
The following packages have unmet dependencies:
libgail-3-0 : Depends: libgtk-3-0 (= 3.20.9-1ubuntu2) but 3.18.9-1ubuntu4 is to be installed
nodejs : Depends: libuv1 (>= 1.6.1) but it is not going to be installed
python3-gi-cairo : Depends: python3-gi (= 3.22.0-1) but 3.20.0-0ubuntu1 is to be installed E: Unmet dependencies. Try ‘apt-get -f install’ with no packages (or specify a solution).

to fix:  apt-get -f install

When trying to install nodejs again will only allow for node-legacy (v4)

to fix: 

# Using Ubuntu
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs


finally at v8 locally


io.emit vs socket.emit

Posted on

io.emit lets the server send an event to all the connected clients at once. This is useful when you need to send some data to everyone. This is something we want everyone to be able to see.

socket.emit sends an event to a single socket. This is great when you need to send an event to a single user. Example: This is why we use socket.emit when sending out a greeting message. It only needs to go to that one user. notes