This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>firebase</title> | |
</head> | |
<body> | |
<script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script> | |
<script> | |
// var ref = new Firebase('https://test231.firebaseio.com/'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var asyncFun = function(someUrl, resolve, reject) { | |
$.get(someUrl) | |
.done(function(response) { | |
if(response) { | |
resolve(response); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Arrows | |
// A function shorthand that binds `this` value. | |
// Arrow functions are always anonymous. | |
// | |
// // Basic syntax: | |
// (param1, param2, paramN) => { statements } | |
// (param1, param2, paramN) => expression | |
// equivalent to: => { return expression; } | |
// Parentheses are optional when there's only one argument: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Airnb's style guide for writing better javascript | |
// Reference: https://github.com/airbnb/javascript | |
// Primitives | |
const foo = 1; | |
let bar = foo; | |
bar = 9; | |
console.log(foo, bar); // => 1, 9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://www.html5rocks.com/en/tutorials/es6/promises/ | |
// `Promises` have been introduced natively as a part of ES6 now. In this blogpost hopefully I will | |
// try to explore all the aspects of `Promises`. | |
// So what is a Promise? | |
// `Promises` are merely a prettier way of writing code which makes an asynchronous code look like synchronous. | |
// Usual way of XHR | |
$.get("script.php", function(data) { | |
console.log('Your account has been created successfully!'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EventEmitter = require('events').EventEmitter | |
, util = require('util') | |
; | |
function Animal(){ | |
this.nose = 2; | |
this.ear = 4; | |
} | |
util.inherits(Animal, EventEmitter); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
// list all status codes | |
http.STATUS_CODES | |
var server = http.createServer(function(req, res){ | |
// get header info | |
console.log(req.headers); | |
//get method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// writes to stdout, same as info | |
console.log('hello %d', 2015); | |
//writes to stderr, same as warn | |
console.error('hello %d', 2015); | |
console.dir({ | |
name: 'John doe', | |
address: { | |
city: 'NY', | |
state: 'DC' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// global object | |
console.log(process); | |
process.on('uncaughtException', function(err) { | |
console.log('Caught exception: ' + err); | |
}); | |
setTimeout(function() { | |
console.log('This will still run.'); | |
}, 500); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = require('url'); | |
var str = 'http://user:[email protected]:8080/p/a/t/h?query=string#hash'; | |
// parse and format | |
var obj = url.parse(str,true); | |
console.log(url.format(obj)); | |
// resolve the browser will do | |
console.log(url.resolve('http://www.google.com/users','user')); |