Tuesday, April 21, 2015

Promises

"Jo vaadaa kiya voo nibhana padegaa"

How people explain things in simple words so that many others can understand? I am really thankful to Sandeep Panda for explaining JavaScript Promises in simple English!

Couple of lines from this site "If you use the Promise API to make an asynchronous call to a remote web service you will create a Promise object which represents the data that will be returned by the web service in future...".

Read more...

http://www.sitepoint.com/overview-javascript-promises/



Sunday, April 5, 2015

module.exports in Node.js

Suppose you want to write a module, say a functions module and access it in another module, say main.js, how are you going to do it in Node.js?

Real simple!

Create two .js files under C:\nodetest folder: functions.js, main.js

functions.js
module.exports = { addNumbers : function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }, findArea : function(r){ return 3.142 * r * r; } };


or 


functions.js:
this.addNumbers = function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }; this.findArea = function(r){ return 3.142 * r * r; };

main.js
var functions = require('./functions.js'); console.log(functions.addNumbers(1,2)); console.log(functions.findArea(2));

Run the main.js from command prompt!

C:\nodetest>node main

Reference:

http://www.sitepoint.com/understanding-module-exports-exports-node-js/

Friday, February 20, 2015

Using NodeJS, express, and MongoDB

Using NodeJS, express, and MongoDB stack? The following web site gives an introduction about how to install and run a full stack using these technologies in easy steps. Cool!
http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/

Tuesday, January 27, 2015

Predefined JavaScript function methods: apply(), call()

I was searching online to find a way to explain JavaScript predefined function methods: apply() and call(). This site http://hangar.runway7.net/javascript/difference-call-apply explains in simple English. Thanks a bunch!

Monday, January 19, 2015

Sample Ajax using jQuery & PHP

I started searching for a simple example that covers "PHP, jQuery, Ajax" and I found this web site which is simple and awesome: http://brian.staruk.me/php/2013/sample-jquery-php-ajax-script/. Thanks to Brian Staurk!

Saturday, November 8, 2014

Things to learn if you want to learn Web Development

1. Responsive Web Design - Things that you need to focus on:

  • Media queries - for example: <link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="style480.css" />
  • Viewport meta tag - controls the dimensions of the mobile browser window
  • Flexible layout - Use percentages and third-party flexible grids
  • Flexible images - set max-width style for image as 100%; myimage { max-width: 100%;}
2. Cascade Style Sheets
  • inline styles, internal styles and external styles
  • id, class, element selectors and specificity
  • CSS positioning and display properties
  • Building navigation bars using CSS
  • Background images, sprites
  • Building simple grids
  • Playing with page CSS using Chrome developer tools, Firebug in Fire fox
  • CSS3 features
3. JavaScript
  • Capturing the DOM elements
  • Functions - creating and calling
  • Variables - globals, locals, hoisting
  • Loops and Conditionals
  • Form validations
  • Event binding and delegation, Event capturing and bubbling
  • Objects and constructor functions
  • AJAX
4. HTML Elements
  • Form elements
  • Layout elements
  • Special elements
  • Web Storage, Local Storage
  • HTML 4.01 and HTML 5



Wednesday, October 1, 2014

Learning PHP

PHP or Ruby on Rails? Which would be the easy server side language to pick up in no time? And how difficult to install it on Windows 8?

Well, these were the questions that I asked myself when I thought about a simple server side scripting language that I can use to explain some basics to a novice web developer.

I decided to go with PHP for the following reasons:

  • I read couple of chapters from a book (Head First PHP and MySQL) and went through couple of lessons in W3C Schools and felt it was easy.
  • I checked in dice.com and found more job opportunities for a PHP developer than a Ruby on Rails developers.
So....
  1. I followed this web site http://www.c-sharpcorner.com/UploadFile/47548d/how-to-install-wamp-server-on-windows-8-1/ and insalled WAMP (Windows, Apache, MySQL, PHP) server on my winodows 8.1 machine. Surprisingly, it was simple and straight forward. NOTE: Steps 1 through 8 were good enough for me and the WAMP server was up and running like an Arabian horse.
  2. From localhost index page, I opened the sqlbuddy and created a sample table in test database.
  3. I wrote the following simple program that talked to the database and provided me the response:

<?php // Connecting to a database using parameters... // mysqli_connect(hostname, username, password, database name) $dbc = mysqli_connect('localhost','root','','test') or die('Error connecting to MySQL server.'); // Select statement to get data from 'person' table $query = "select firstname, lastname from person"; // Executing the query $result = mysqli_query($dbc,$query) or die("Error querying database"); // Accessing the data that is obtained while($row = mysqli_fetch_array($result)) { echo $row['firstname'] . " " . $row['lastname']; echo "<br>"; } // Closing the database mysqli_close($dbc);
?>

So much for a day, huh? I am happy because I learnt something today!