Rotation Transform

basic 2D Rotation

Rotation About an Arbitrary Axis

Homogeneous Coordinates

Four-Dimensional Transforms

Transforming Normal Vectors

Quaternion Mathematics

rotation with quaternion

Spherical Linear Interpolation

Most UBUNTU Commands

File System

cp originalFile newFile : copy original to new
rm file : remove file
rm -rf directory : remove non-empty directory
rm -r directory : clean directory
rmdir directory : remove empty directories
mkdir directory : create directory
mv fileFrom fileTo : move file from to
ls director : display all directory content
dir directory : diplay all directories inside directory
ls -l file : file create date and owner and mod
cat file.txt file2.txt : display file content
pwd : get current path
cd path: set the current path
chmod {options} filename : change permision of file
chown USERNAME:GROUPNAME path : change owner
chown -R USERNAME:GROUPNAME path : change owner recursive
chgrp group file1 file2 dir1 : change group of file
touch file : create file
zip|unzip file

cat ./file.txt | grep "^hello .*ld.*$"
user@host:/home/user$ chmod ugo+rwx file4 #add read and write and execute permision for owner and group and others


lspci : pci hardware info
inxi : hardware info more readable need to install
free : memory size and how much used and free
dmesg : debug all devices
lsusb : all serial devices connected
top : monitor all processors
kill -9 pid : force kill for proccesor


sudo : play command as root
sudo -i : always as root
adduser userName : add user
su : change user
usermod -aG group user : add user to group
deluser user group : remove user from group
groups : display groups of current user
exit : logout
passwd : change passward of current user
adduser –system userName : add system user
addgroup group : add new group


Table JoinEmbedded Documents
Primary KeyPrimary Key (Default key _id provided by MongoDB itself)
   _id: ObjectId(7df78ad8902c)
   title: 'MongoDB Overview', 
   description: 'MongoDB is no sql database',
   by: 'tutorials point',
   url: '',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 100, 
   comments: [	
         message: 'My first comment',
         dateCreated: new Date(2011,1,20,2,15),
         like: 0 
         message: 'My second comments',
         dateCreated: new Date(2011,1,25,7,45),
         like: 5

Embedded Data Model

In this model, you can have (embed) all the related data in a single document, it is also known as de-normalized data model.

For example, assume we are getting the details of employees in three different documents namely, Personal_details, Contact and, Address, you can embed all the three documents in a single one

	_id: ,
	Emp_ID: "10025AE336"
		First_Name: "Radhika",
		Last_Name: "Sharma",
		Date_Of_Birth: "1995-09-26"
	Contact: {
		e-mail: "",
		phone: "9848022338"
	Address: {
		city: "Hyderabad",
		Area: "Madapur",
		State: "Telangana"

Normalized Data Model

In this model, you can refer the sub documents in the original document, using references. For example, you can re-write the above document in the normalized model as:


	_id: <ObjectId101>,
	Emp_ID: "10025AE336"


	_id: <ObjectId102>,
	empDocID: " ObjectId101",
	First_Name: "Radhika",
	Last_Name: "Sharma",
	Date_Of_Birth: "1995-09-26"


	_id: <ObjectId103>,
	empDocID: " ObjectId101",
	e-mail: "",
	phone: "9848022338"


	_id: <ObjectId104>,
	empDocID: " ObjectId101",
	city: "Hyderabad",
	Area: "Madapur",
	State: "Telangana"
show dbs; //show all databases
use db;//select database
db;//current database{"name":"tutorials point"})//insert document to collection
db.dropDatabase()//remove database
db.createCollection("mycollection")//create collection
db.COLLECTION_NAME.drop()//remove collection
show databases // display all databases
use database //select or create database
show collections // display all collections[
		title: "MongoDB Overview",
		description: "MongoDB is no SQL database",
		by: "tutorials point",
		url: "",
		tags: ["mongodb", "database", "NoSQL"],
		likes: 100
	title: "NoSQL Database",
	description: "NoSQL database doesn't have tables",
	by: "tutorials point",
	url: "",
	tags: ["mongodb", "database", "NoSQL"],
	likes: 20,
	comments: [
			message: "My first comment",
			dateCreated: new Date(2013,11,10,2,35),
			like: 0
			{"First_Name": "Radhika"},
			{"Last_Name": "Christopher"}
		$NOT: [
			{key1: value1}, {key2:value2}
db.empDetails.find( { "Age": { $not: { $gt: "25" } } } )
OperationSyntaxExampleRDBMS Equivalent
Equality{<key>:{$eg;<value>}}db.mycol.find({“by”:”tutorials point”}).pretty()where by = ‘tutorials point’
Less Than{<key>:{$lt:<value>}}db.mycol.find({“likes”:{$lt:50}}).pretty()where likes < 50
Less Than Equals{<key>:{$lte:<value>}}db.mycol.find({“likes”:{$lte:50}}).pretty()where likes <= 50
Greater Than{<key>:{$gt:<value>}}db.mycol.find({“likes”:{$gt:50}}).pretty()where likes > 50
Greater Than Equals{<key>:{$gte:<value>}}db.mycol.find({“likes”:{$gte:50}}).pretty()where likes >= 50
Not Equals{<key>:{$ne:<value>}}db.mycol.find({“likes”:{$ne:50}}).pretty()where likes != 50
Values in an array{<key>:{$in:[<value1>, <value2>,……<valueN>]}}db.mycol.find({“name”:{$in:[“Raj”, “Ram”, “Raghu”]}}).pretty()Where name matches any of the value in :[“Raj”, “Ram”, “Raghu”]
Values not in an array{<key>:{$nin:<value>}}db.mycol.find({“name”:{$nin:[“Ramu”, “Raghav”]}}).pretty()Where name values is not in the array :[“Ramu”, “Raghav”] or, doesn’t exist at all
{"x":{"$exists":true}} // = {"x":{"$ne":null}}

update and Save()

db.mycol.update({'title':'MongoDB Overview'},
   {$set:{'title':'New MongoDB Tutorial'}},{multi:true})
> //for insert or update
      "_id" : ObjectId("507f191e810c19729de860ea"), 
		"title":"Tutorials Point New Topic",
      "by":"Tutorials Point"
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("507f191e810c19729de860ea")
{ "_id" : ObjectId("507f191e810c19729de860e6"), "title":"Tutorials Point New Topic",
   "by":"Tutorials Point"}
{ "_id" : ObjectId("507f191e810c19729de860e6"), "title":"NoSQL Overview"}
{ "_id" : ObjectId("507f191e810c19729de860e6"), "title":"Tutorials Point Overview"}
	{First_Name: 'Radhika'},
	{ $set: { Age: '30',e_mail: ''}}
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }
	{Age:{ $gt: "25" }},
	{ $set: { Age: '00'}}
db.mycol.remove({'title':'MongoDB Overview'})
WriteResult({"nRemoved" : 1})
{"_id" : ObjectId("507f191e810c19729de860e2"), "title" : "NoSQL Overview" }
{"_id" : ObjectId("507f191e810c19729de860e3"), "title" : "Tutorials Point Overview" }

limit and sort

{"title":"NoSQL Overview"}


db.members.createIndex( { "user_id": 1 }, { unique: true } )
backgroundBooleanBuilds the index in the background so that building an index does not block other database activities. Specify true to build in the background. The default value is false.
uniqueBooleanCreates a unique index so that the collection will not accept insertion of documents where the index key or keys match an existing value in the index. Specify true to create a unique index. The default value is false.
namestringThe name of the index. If unspecified, MongoDB generates an index name by concatenating the names of the indexed fields and the sort order.
sparseBooleanIf true, the index only references documents with the specified field. These indexes use less space but behave differently in some situations (particularly sorts). The default value is false.
expireAfterSecondsintegerSpecifies a value, in seconds, as a TTL to control how long MongoDB retains documents in this collection.
weightsdocumentThe weight is a number ranging from 1 to 99,999 and denotes the significance of the field relative to the other indexed fields in terms of the score.
default_languagestringFor a text index, the language that determines the list of stop words and the rules for the stemmer and tokenizer. The default value is English.
language_overridestringFor a text index, specify the name of the field in the document that contains, the language to override the default language. The default value is language.


MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  var dbo = db.db("mydb");
  dbo.collection("customers").find({}, { projection: { _id: 0, name: 1, address: 1 } }).toArray(function(err, result) {
    if (err) throw err;

aggregate() Method

   _id: ObjectId(7df78ad8902c)
   title: 'MongoDB Overview', 
   description: 'MongoDB is no sql database',
   by_user: 'tutorials point',
   url: '',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 100
   _id: ObjectId(7df78ad8902d)
   title: 'NoSQL Overview', 
   description: 'No sql database is very fast',
   by_user: 'tutorials point',
   url: '',
   tags: ['mongodb', 'database', 'NoSQL'],
   likes: 10
   _id: ObjectId(7df78ad8902e)
   title: 'Neo4j Overview', 
   description: 'Neo4j is no sql database',
   by_user: 'Neo4j',
   url: '',
   tags: ['neo4j', 'database', 'NoSQL'],
   likes: 750

//similar to count method
db.mycol.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}])
{ "_id" : "tutorials point", "num_tutorial" : 2 }
{ "_id" : "Neo4j", "num_tutorial" : 1 }

Following are the possible stages in aggregation framework −

  • $project − Used to select some specific fields from a collection.
  • $match − This is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage.
  • $group − This does the actual aggregation as discussed above.
  • $sort − Sorts the documents.
  • $skip − With this, it is possible to skip forward in the list of documents for a given amount of documents.
  • $limit − This limits the amount of documents to look at, by the given number starting from the current positions.
  • $unwind − This is used to unwind document that are using arrays. When using an array, the data is kind of pre-joined and this operation will be undone with this to have individual documents again. Thus with this stage we will increase the amount of documents for the next stage.
$sumSums up the defined value from all documents in the collection.db.mycol.aggregate([{$group : {_id : “$by_user”, num_tutorial : {$sum : “$likes”}}}])
$avgCalculates the average of all given values from all documents in the collection.db.mycol.aggregate([{$group : {_id : “$by_user”, num_tutorial : {$avg : “$likes”}}}])
$minGets the minimum of the corresponding values from all documents in the collection.db.mycol.aggregate([{$group : {_id : “$by_user”, num_tutorial : {$min : “$likes”}}}])
$maxGets the maximum of the corresponding values from all documents in the collection.db.mycol.aggregate([{$group : {_id : “$by_user”, num_tutorial : {$max : “$likes”}}}])
$pushInserts the value to an array in the resulting document.db.mycol.aggregate([{$group : {_id : “$by_user”, url : {$push: “$url”}}}])
$addToSetInserts the value to an array in the resulting document but does not create duplicates.db.mycol.aggregate([{$group : {_id : “$by_user”, url : {$addToSet : “$url”}}}])
$firstGets the first document from the source documents according to the grouping. Typically this makes only sense together with some previously applied “$sort”-stage.db.mycol.aggregate([{$group : {_id : “$by_user”, first_url : {$first : “$url”}}}])
$lastGets the last document from the source documents according to the grouping. Typically this makes only sense together with some previously applied “$sort”-stage.db.mycol.aggregate([{$group : {_id : “$by_user”, last_url : {$last : “$url”}}}])

Nodejs express

Express Overview

Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates the rapid development of Node based Web applications. Following are some of the core features of Express framework −

  • Allows to set up middlewares to respond to HTTP Requests.
  • Defines a routing table which is used to perform different actions based on HTTP Method and URL.
  • Allows to dynamically render HTML Pages based on passing arguments to templates.

Installing Express

Firstly, install the Express framework globally using NPM so that it can be used to create a web application using node terminal.

$ npm install express --save

The above command saves the installation locally in the node_modules directory and creates a directory express inside node_modules. You should install the following important modules along with express −

  • body-parser − This is a node.js middleware for handling JSON, Raw, Text and URL encoded form data.
  • cookie-parser − Parse Cookie header and populate req.cookies with an object keyed by the cookie names.
  • multer − This is a node.js middleware for handling multipart/form-data.
$ npm install body-parser --save
$ npm install cookie-parser --save
$ npm install multer --save


var express = require('express');
var app = express();

app.get('/', function (req, res) {
   res.send('Hello World');

app.get(/a/, function (req, res) {//any url contains a

app.get('/name/:name',function (req,res){//req.params={name:"mohammed"}
    res.send("hello world");

var server = app.listen(8081, function () {
   var host = server.address().address;
   var port = server.address().port;
   console.log("Example app listening at http://%s:%s", host, port)
  .get(function (req, res) {
    res.send('Get a random book')
  .post(function (req, res) {
    res.send('Add a book')
  .put(function (req, res) {
    res.send('Update the book')

static files

Express provides a built-in middleware express.static to serve static files, such as images, CSS, JavaScript, etc.
You simply need to pass the name of the directory where you keep your static assets, to the express.static middleware to start serving the files directly. For example, if you keep your images, CSS, and JavaScript files in a directory named public, you can do this −


upload file

var bodyParser = require('body-parser');
var multer  = require('multer');
let storage = multer.diskStorage({
    destination: (req, file, cb) => {
    filename: (req, file, cb) => {
        cb(null, file.originalname);

let uploadFile = multer({
    storage: storage,
    limits: { fileSize: config.fileMaxSize }

const UploadFile = [uploadFile,async (req, res) => {
    try {
        let file=req[config.fileQueryName];
    } catch (err) {

cookies management

var express      = require('express')
var cookieParser = require('cookie-parser')

var app = express()

app.get('/', function(req, res) {
   console.log("Cookies: ", req.cookies)


app.get('/example/b', function (req, res, next) {
  console.log('the response will be sent by the next function ...')
}, function (req, res) {
  res.send('Hello from B!')
var cb0 = function (req, res, next) {

var cb1 = function (req, res, next) {

var cb2 = function (req, res) {
  res.send('Hello from C!')

app.get('/example/c', [cb0, cb1, cb2])//multiple response
let config=require("./config");
let express=require("express");

let app=express();
app.get('/name',function (req,res){
let server=app.listen(config.port,()=>{
var express = require('express')
var router = express.Router()

// middleware that is specific to this router
router.use(function timeLog (req, res, next) {
  console.log('Time: ',
// define the home page route
router.get('/', function (req, res) {
  res.send('Birds home page')
// define the about route
router.get('/about', function (req, res) {
  res.send('About birds')

module.exports = router

Content-Type: application/json


Content-Type: application/x-www-form-urlencoded

  extended: true

and you can acess to it by


raw data

const express=require("express");
const bodyParser = require('body-parser');

let options = {
    inflate: true,
    limit: '100kb',
    type: 'text/plain'
let app=express();
    res.send(req.body);//body is string if type: 'text/*' else buffer

HTTP headers

app.get('/', (req, res) => {
app.get('/', (req, res) => {

Response Methods And Properties

The methods on the response object (res) in the following table can send a response to the client, and terminate the request-response cycle. If none of these methods are called from a route handler, the client request will be left hanging.

MethodDescription a file to be downloaded.
res.end()End the response process.
res.json()Send a JSON response.
res.jsonp()Send a JSON response with JSONP support.
res.redirect()Redirect a request.
res.render()Render a view template.
res.send()Send a response of various types.
res.sendFile()Send a file as an octet stream.
res.sendStatus(), res.status(code)Set the response status code and send its string representation as the response body.
res.apphold express app
res.cookie(name, value [, options])
res.set('Content-Type', 'text/html')
// => 'text/html'

// => 'text/html'

// => 'application/json'

// => 'application/json'

// => image/png:

for more visit this link

NODE.JS Introduction

Node.js = Runtime Environment + JavaScript Library

first application

install link
var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('Hello World!');
node myfirst.js

var job=require("./Job");

NPM (Node Package Manager)
Online repositories for node.js packages/modules which are searchable

//update npm 
$ sudo npm install npm -g

//to install npm module
$ npm install <Module Name>
$ npm install express

//to install module in globa
$ npm install express -g

//check all modules installed globally
$ npm ls -g

//uninstall module 
$ npm uninstall express

//update module 
$ npm update express

$ npm search express
var express = require('express');

Process Module

The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require()

process.stderr.write("hello world");
process.stdin.on("data", (data) => {
    const name = data.toString().trim().toUpperCase();
    if (name !== "") {
        process.stdout.write(`Hello ${name}!`);
    } else {
        process.stderr.write("Input was empty.");

fs and path Modules


// Returns: 'quux.html'

path.basename('/foo/bar/baz/asdf/quux.html', '.html');
// Returns: 'quux'

// Returns: '/foo/bar/baz/asdf'

// Returns: '.html'

path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf'

fs sync

const fs = require("fs");
const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
const contents = fs.readFileSync(filepath, "utf8");
console.log("File Contents:", contents);
const upperContents = contents.toUpperCase();
fs.writeFileSync(filepath, upperContents);
console.log("File updated.");

fs async

const fs = require("fs");
const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
fs.readFile(filepath, "utf8", (err, contents) => {
  if (err) {
    return console.log(err);
  console.log("File Contents:", contents);
  const upperContents = contents.toUpperCase();
  updateFile(filepath, upperContents);
function updateFile(filepath, contents) {
  fs.writeFile(filepath, contents, (err) => {
    if (err) throw err;
    console.log("File updated.");

fs promises

const fs = require("fs").promises;
const path = require("path");
const filepath = path.join(process.cwd(), "hello.txt");
async function run() {
  try {
    const contents = await fs.readFile(filepath, "utf8");
    console.log("File Contents:", contents);
  } catch (error) {
function printMetadata(file) {
  try {
    const fileStats = fs.statSync(file);
  } catch (err) {
    console.error("Error reading file path:", file);

Watching for file updates
Node.js’s fs module provides functionality that enables you to watch files and track when files or directories are created, updated, or deleted.
In this recipe, we’ll create a small program named watch.js that watches for changes in a file using the watchFile() API and then prints a message when a change has occurred.

const fs = require("fs");
const file = "./file.txt";
const moment = require("moment");, (eventType, filename) => {
    const time = moment().format("MMMM Do YYYY, h:mm:ss a");
    return console.log(`${filename} updated ${time}`);


var events = require('events');

let emitter=new events.EventEmitter();
emitter.on("click",()=>{console.log("call 1")});
emitter.on("click",()=>{console.log("call 2")});
emitter.on("click",()=>{console.log("call 3")});
emitter.emit("click");//call 1 call 2 call 3
var events = require('events');

function fun1(){
function fun2(){

let emitter=new events.EventEmitter();


Pure JavaScript is Unicode friendly, but it is not so for binary data. While dealing with TCP streams or the file system, it’s necessary to handle octet streams. Node provides Buffer class which provides instances to store raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap.Buffer class is a global class that can be accessed in an application without importing the buffer module.

var buf = new Buffer(10);
var buf = new Buffer([10, 20, 30, 40, 50]);
var buf = new Buffer("Simply Easy Learning", "utf-8");
buf = new Buffer(256);
len = buf.write("Simply Easy Learning");

console.log("Octets written : "+  len);//20
buf.toString([encoding][, start][, end]) 
Live Demo
buf = new Buffer(26);
for (var i = 0 ; i < 26 ; i++) {
  buf[i] = i + 97;

console.log( buf.toString('ascii'));       // outputs: abcdefghijklmnopqrstuvwxyz
console.log( buf.toString('ascii',0,5));   // outputs: abcde
console.log( buf.toString('utf8',0,5));    // outputs: abcde
console.log( buf.toString(undefined,0,5)); // encoding defaults to 'utf8', outputs abcde
var buffer1 = new Buffer('TutorialsPoint ');
var buffer2 = new Buffer('Simply Easy Learning');
var buffer3 = Buffer.concat([buffer1,buffer2]);

console.log("buffer3 content: " + buffer3.toString());
var buffer1 = new Buffer('ABC');

//copy a buffer
var buffer2 = new Buffer(3);
console.log("buffer2 content: " + buffer2.toString());
Live Demo
var buffer1 = new Buffer('TutorialsPoint');

//slicing a buffer
var buffer2 = buffer1.slice(0,9);
console.log("buffer2 content: " + buffer2.toString());


var fs = require("fs");
var data = '';

// Create a readable stream
var readerStream = fs.createReadStream('input.txt');

// Set the encoding to be utf8. 

// Handle stream events --> data, end, and error
readerStream.on('data', function(chunk) {
   data += chunk;

readerStream.on('end',function() {

readerStream.on('error', function(err) {

console.log("Program Ended");//call first
var fs = require("fs");
var data = 'Simply Easy Learning';

// Create a writable stream
var writerStream = fs.createWriteStream('output.txt');

// Write the data to stream with encoding to be utf8

// Mark the end of file

// Handle stream events --> finish, and error
writerStream.on('finish', function() {
   console.log("Write completed.");

writerStream.on('error', function(err) {

console.log("Program Ended");
var fs = require("fs");

// Create a readable stream
var readerStream = fs.createReadStream('input.txt');

// Create a writable stream
var writerStream = fs.createWriteStream('output.txt');

// Pipe the read and write operations
// read input.txt and write data to output.txt

console.log("Program Ended");