Skip to content

Instantly share code, notes, and snippets.

View kshirish's full-sized avatar
👨‍💻

k kshirish

👨‍💻
View GitHub Profile
@kshirish
kshirish / firebase.html
Created August 7, 2015 08:02
firebase go through
<!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/');
@kshirish
kshirish / promise.js
Last active August 29, 2015 14:22
Promises in native Javascript
var asyncFun = function(someUrl, resolve, reject) {
$.get(someUrl)
.done(function(response) {
if(response) {
resolve(response);
} else {
@kshirish
kshirish / es6.js
Last active August 29, 2015 14:18
// 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:
// 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
// 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!');
@kshirish
kshirish / customEvents.js
Last active August 29, 2015 14:15
node api
var EventEmitter = require('events').EventEmitter
, util = require('util')
;
function Animal(){
this.nose = 2;
this.ear = 4;
}
util.inherits(Animal, EventEmitter);
@kshirish
kshirish / http.js
Created February 15, 2015 13:32
node api
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
@kshirish
kshirish / console.js
Created February 15, 2015 09:15
node api
// 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'
@kshirish
kshirish / process.js
Created February 14, 2015 13:58
node api
// global object
console.log(process);
process.on('uncaughtException', function(err) {
console.log('Caught exception: ' + err);
});
setTimeout(function() {
console.log('This will still run.');
}, 500);
@kshirish
kshirish / url.js
Created February 14, 2015 12:44
node api
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'));