Advanced Javascript: Introduction To Server Side Javascript Using Meteor

Server Side Javascript has come long way, and after launch of Node.js in July 2011 gained lot of popularity as idea of using same language on client and server bought in code and software architecture uniformity in software applications. Even though Brendan Neich‘s Netscape already had vision to use same programming language on client and server but at that time people were using Pentium I/II processors which were not powerful enough to support Javascript Interpreters. In case you don’t know Brendan Neich he’s creator of Javascript and co-founder of Mozilla. In present generation of more than 2 billion smartphones you can get Phone with 1.2 GHz processor for less than $40. Seeing boom in processing speed of devices software developers started integrating Javascript interpreters like SpiderMonkey & Rhino in their applications. Some started using Jaxter server that embeds entire Mozilla Firefox Browser Engine in web server giving access to Ajax and Javascript within application.

Now when we have brief history of Javascript let me explain how to setup Meteor and create a simple server side Javascript application.

Go to this link and install Meteor.

Once you are done with setup go to command like and create a directory named bluefish if you would like to follow remaining series of tutorial.

Nikhils-MacBook-Pro:bluefish nikhil$ meteor create bluefish
Created a new Meteor app in 'bluefish'.
Nikhils-MacBook-Pro:bluefish nikhil$ cd bluefish/
Nikhils-MacBook-Pro:bluefish nikhil$ meteor
Started proxy.
Started MongoDB.
Started your app.  
App running at: http://localhost:3000/

Screen Shot 2015-10-24 at 4.10.07 pm Screen Shot 2015-10-24 at 4.16.08 pm

Now navigate to http://localhost:3000/ and if everything if fine you will see following webpage-
Screen Shot 2015-10-24 at 5.07.16 pm

Now you can use your favourite code editor to change HTML and CSS and see if changes are getting reflected in your application without refreshing browser. If you can see updated HTML in your browser, congrats you deployed your first Javacsript Server Side Application. It’s called hot code push.

Now lets dig in a little and make our first bluefish list.

Edit your HTML and change it to

<head>
  <title>bluefish!</title>
</head>
 
<body>
  <div class="container">
    <header>
      <h1>bluefish!</h1>
    </header>
 
    <ul>
      {{#each fishes}}
        {{> fish}}
      {{/each}}
    </ul>
  </div>
</body>
 
<template name="fish">
  <li><img src={{imageurl}} height="80" width="100"/>{{text}}</li>

</template>

Change your Javascript to

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    fishes: [
      { text: "pygmy angelfish",imageurl:"http://www.seascapestudio.net/reference/fishes/centropyge_argi.jpg" },
      { text: "blue dot grouper",imageurl:"http://www.richard-seaman.com/Underwater/Egypt/Highlights/PeacockGrouper.jpg" },
      { text: "blue line grouper",imageurl:"http://www.aquariumdomain.com/images/fish_marine/grouper_blueline2.jpg" },
      {text:  "teira batfish",imageurl:"http://www.aquariumdomain.com/images/fish_marine/tieraBatfish8.jpg"},
      {text:  "convict blenny",imageurl:"http://www.roslyndakin.com/wp-content/uploads/2011/01/convictadult.jpg"}
    ]
  });
}

You can write your custom styling in CSS file.

Screen Shot 2015-10-24 at 5.02.14 pm

For further information, visit https://www.meteor.com/tutorials/ or wait for next chapter of tutorial. Happy coding!

Image credits-

http://www.seascapestudio.net/
http://www.richard-seaman.com/
http://www.aquariumdomain.com/
http://www.aquariumdomain.com/
http://www.roslyndakin.com/

References-
https://developer.mozilla.org/ja/docs/Web/JavaScript/Server-Side_JavaScript
https://www.meteor.com/

Advertisements

Stop Workplace Harassment in India

670px-Deal-with-Workplace-Bullying-and-Harassment-Step-5
6 of 8 people in India go through workplace harassment without knowing they are being harassed. Wanted to share this important piece of advice for wellbeing of employees as well as employers.

To employers- you don’t owe your employees, they just work for money and cause they trust in you.

To employees- Know your rights, be aware. Even if you make mistakes no employer/boss has right to harass you.

Labour inspector from the Labour Department are employed for the well-being of the employee issues and there is no fee as such. Following are some common example of workplace harassment:

  • Dispersion of malevolent and untrue rumours, scandal or innuendo at the workplace. Isolating an individual socially and professionally in the office.
  • Threatening a person or dominating him/her unfairly.
  • Deliberately discouraging one or hindering his/her job.
  • Physical abuse or intimidating someone with abusive languages.
  • Eliminating one from his roles and responsibilities without any reason.
  • Altering instructions and guidelines constantly.
  • Imposing unrealistic deadlines intentionally to make an individual fail.
  • Holding back important information or tenaciously providing wrong information.
  • Cracking offensive jokes verbally or in written, especially in front of or about female colleagues.
  • Sneaking into someone’s personal life, spying or pestering him/her.
  • Causing unnecessary pressure on a particular person by assigning heavy workload when others are free.
  • Making on sit idle without any work which is also a way to create mental pressure on a worker. Often companies take this way to make their employees surrender for voluntary retirement schemes.
  • Screaming or showing vulgarity to an employee.
  • Intentionally and unreasonably criticizing an individual on regular basis.
  • Ridiculing one’s opinions. Unjustifiable punishment for trifles.
  • Holding back deserved leaves, promotions and training.
  • Blocking applications for training, leave or promotion.
  • Meddling with one’s personal belongings behind his/her back.

When any of the above happens to an individual, it indicates that he/she is falling prey to employee harassment. Be it the employer or co-workers, there are legal terms via which the offenders can be punished.

Indian constitution guarantees gender, racial and religious equality as the Fundamental Right’ of the residents of the country in Part III, Articles- 14, 15, 16 which implies for the workplace as well. Hence one faces discrimination by the employer because of his/her race, complexion, gender, caste or origin; he/she can immediately seek legal advice by consulting with a lawyer.  The ‘Directive Principles of State Policies’ of Part IV encompasses the cultural and socio-economic rights of Indian citizens.

Image credits- www.wikihow.com

Android 6.0 to be named Milkshake, Muffin or Marshmallow?

Almost everybody expected Android 4.4 to be called ‘Key Lime Pie’ to be in mouth watering alphabetical sequence of world’s most popular smartphone OS. There were also rumours that next release of Android will be named ‘Kaju Katli’, which is most sought after Indian sweet, but Google named it Kitkat. Next and latest was ‘Lollipop’. Here’s mouth watering alphabetical sequence that Google followed-

Cupcake (1.5)
Donut (1.6)
Eclair (2.0-2.1)
Froyo (2.2-2.3)
Gingerbread (2.3-2.3.7)
Honeycomb (3.0-3.2)
Ice Cream Sandwich (4.0-4.0.2)
Jelly Bean (4.1-4.2.2)
Kitkat (4.4)
Lollipop (5.0+)
Milkshake? (Next release)

What will Android M be called? ‘Milkshake’, ‘Muffin’ or ‘Marshmallow’? Comment your point of view.