Array.fill method in JavaScript

We are used to create arrays with loop.

A better way to create a long array with around 10,000,000 entries is to use the fill method which is fast and reliable.


Var a = new Array(10000000);

Fill can take two extra parameters as well.

a.fill(“satya”, 0, 100);
this will fill the array starting from 0th index till 100th index.


How about an application which suggest where more plantation is needed

Hello World,

Once I got an idea about making an app which can suggest the parts of the city, region, ares which need more plantation. The source for the nearest possible water body to make the plants grow properly.

The data must be shared with one of the Government agency who will analyse the temperature of a particular area and the type of plantation suitable in that area based on water resource availability.

Many times we plant trees which does not produce food items and just for clean air. Once I suggested to plant a fruit tree which will be beneficial for air as well it can produce some food for someone in need. People laughed at me and said if they plant a fruit tree, kids will throw stones and they will suffer from damages.

We eat fruits and throw the seeds. Why not plant them and grow a tree out of it.

Vulnerability with Google Chrome Extension

Hey Google,

Chrome extension is insecure. It allows developers to collect login information from any website without user’s knowledge.

When a chrome extension is installed, It is on for your browser in every session if there is no background script or page.

One can easily inject a piece of JavaScript code to any site and can collect the login details of any user.

A person who understand a bit of JavaScript, can read all the values entered into the input fields. When you read the value of a password field, it will give you the actual password.

From there on click of submit button making an ajax call to your server to store the page URL, username and Password is like cake walk.

Injecting JavaScript to any website from Chrome Extension must be restricted.

Give your thoughts.

Phaser bow and arrow game, trajectory

The most popular phaser framework is very helpful to create html5 and javascript games.

I have come up with a simple trajectory code for a bow and arrow game.

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', {
  preload: preload,
  create: create,
  update: update

var bow, bag, arrow, angle;
var score=0;
var x;
var y;
var oldx, oldy;
var xVel;  // calculate this based on distance
var yVel;  // 
var g = 0.25;
var arrowCreated = false;
var shot = false;

function preload() {
  game.load.image('bag', bagURI);
  game.load.image('bow', bowURI);
  game.load.image('arrow', arrowURI);


function create() {, 0, 800, 600);
  bow = game.add.sprite(100, 250, 'bow');
  bag = game.add.sprite(650,300,'bag');
  arrow = game.add.sprite(bow.x, bow.y, 'arrow');
  arrow.angle = bow.angle;
  x = oldx = arrow.x;
  y = oldy = arrow.y;
  //game.input.onDown.add(createArrow, this);
  game.input.onUp.add(shootArrow, this);

function update() {
  if (!shot) {
    angle = Math.atan2(game.input.mousePointer.x - bow.x, -(game.input.mousePointer.y - bow.y)) * (180 / Math.PI) - 180;
    bow.angle = arrow.angle = angle;
  } else {
    x += xVel;
    y += yVel;
    yVel += g;

    arrow.x = x;
    arrow.y = y;
    arrowAngle = Math.atan2(x-oldx, -(y-oldy)) * (180 / Math.PI);
    arrow.angle = arrowAngle;
    /* need to write new arrow code */
     oldx = x;
     oldy = y;
    if(arrow.y>600) {
    var intersects = Phaser.Rectangle.intersection(arrow, bag);
    if(intersects.width>0) {
function resetArrow() {
  shot = false;

function createArrow() {
  arrowCreated = true;

function shootArrow() {
  if(!shot) {
    shot = true;
    xVel = - (game.input.mousePointer.x-bow.x)/6;
    yVel = - (game.input.mousePointer.y-bow.y)/6;


When Bootstrap should be avoided

Bootstrap has a lot of excellent features when it comes to responsive design. But it makes the work difficult some times because it works on classes.

For an example, to achieve responsive images one has to apply img-reponsive class to all image tags.

This can be avoided by adding a simple style in your custom style sheet as below

img {
width: 100%;
height: auto;

Usefulness of bootstrap Jumbotron

As the name suggest this component can optionally increase the size of headings and add a lot of margin for landing page content. To use the Jumbotron −

  • Create a container
    with the class of .jumbotron.
  • In addition to a larger h1, the font-weight is reduced to 200px.

A jumbotron indicates a big box for calling extra attention to some special content or information. A jumbotron is displayed as a grey box with rounded corners. It also enlarges the font sizes of the text inside it. Tip: Inside a jumbotron you can put nearly any valid HTML, including other Bootstrap elements/classes.

Hello, world!

This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique. Learn more »