Friday, 13 May 2016

How to create .bat file ?

I graduated in Mechanical Engineering. 
So I do not know: Why bat files are used? How are they created?

Hence I thought of writing below post.

BATCH file is way of getting things done on any computer.
These files mainly automate everyday tasks to save time.


 Step 1.Create blank text file on your computer.
 Step 2.Rename it as test.bat


I assume you know how to run commands from Command Prompt.
We type command in cmd prompt and run whenever we want. Instead typing on our own  these commands are put in  .bat file to get executed.


It has 2 main benefits -
1. To implement your own logic
2. To save time.

Also,Commands are not CASE Sensitive. 













Let us understand some basic commands -
TITLE - used for displaying title of command window.
ECHO - This is print statement of .bat file.

Anything following the word ECHO will be displayed in the command prompt as text.
ECHO OFF –It means that the program won’t show the command that you told it to run while it’s running – it’ll just run the command.
PAUSE – This outputs the “press any key to continue…” message.
 It’s helpful because it pauses the BAT file execution until the user tells it to go again. If you don’t put this in your program, everything will speed by and end before you can see it.
CLS – Clears the command window.
IPCONFIG -gives network information about your connected machine.
PING - To check if any machine can be contacted.

Let us write program to check the computer’s network/internet settings with an “ipconfig /all” command, and then review that info. Afterwards, we want to ping google.com to figure out if we really truly have access to the internet. We’ll pause the program after this as well, because we want to know for sure that they saw it.

Step 3. Open created test.bat in notepad.
Step 4. Write below steps to in it.
 

TITLE TEST BAT FILE 
 ::Add Title to command window.
ECHO OFF ::CMD will no longer show us what command it’s executing(cleaner) ECHO THIS IS PRINT :: Print some text IPCONFIG /ALL :: Outputs tons of network information into the command prompt PAUSE :: Lets the user read the important network information PING www.google.com :: Ping google to figure out if we’ve got internet! ECHO All done pinging Google. ::Print some text PAUSE :: Give the user some time to see the results. Because this is our last line, the program will exit and the command window will close once this line finishes. 

Step 5.
Open your command prompt.
Navigate to folder where test.bat is located.
then use command "test.bat" and it will run successfully.


Output:
 
 
 
Hope this will help you.



Wednesday, 11 May 2016

npm ECONNREFUSED error

If you face error which says ECONNREFUSED while doing npm install <<package name>>, you are probably behind a proxy which is not allowing you to connect to the server and download the packages required.

Just follow the below steps:

npm config set proxy  http://your_proxy_name:port
npm config set https-proxy https://your_proxy_name:port

And then try npm install

How to get npm config?

npm get proxy

will do the work :)

How to run ol3-cesium on desktop using NodeJs

I was trying to run ol3-cesium as a desktop application. I downloaded the latest code with examples from the official site : http://openlayers.org/ol3-cesium/.

When I tried opening the main.html (from examples folder) in my web browser..........


 And as soon as I hit the enable/disable button view the map in 3D looks like this.......



Debug and you will get an error similar to this:
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

How did I solve it?
Its a CORS issues and can be solved by using a web server. I used nodejs server to host the directory.

Create a server.js file in your ol3-cesium root directory.
The content of my server.js:

===========

var http = require('http');
var fs = require('fs');
var url = require('url');


// Create a server
http.createServer( function (request, response) {
   // Parse the request containing file name
   var pathname = url.parse(request.url).pathname;
 
 
   // Read the requested file content from file system
   fs.readFile(pathname.substr(1), function (err, data) {
      if (err) {
         console.log(err);
      }else{
console.log("Server responding");
         response.writeHead(200, {'Content-Type': 'text/html'});
         response.write(data.toString());
      }
      response.end();
   });
}).listen(8081);

// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');


===========

run server.js as
> node server.js

Server is running at http://127.0.0.1:8081/

You can now hit:
http://127.0.0.1:8081/examples/main.html

And...

Its now running from your file system.

Prerequisites:
1. Nodejs installed on your machine

PS: I have changed the raster layer in the example