Skip to content

Instantly share code, notes, and snippets.

View kshirish's full-sized avatar
👨‍💻

k kshirish

👨‍💻
View GitHub Profile
@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:pass@host.com: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'));
@kshirish
kshirish / os.js
Created February 14, 2015 12:29
node api
// all of exposed methods in os
// are basically informations about OS
var os = require('os');
//console.log(os);
console.log(os.platform());
console.log(os.arch());
console.log(os.type());
@kshirish
kshirish / sexy-part-two.js
Created February 14, 2015 11:24
javascriptissexy
// Careful with arrays
function Class(){
this.array = [];
}
Class.prototype.anotherArray = [];
var obj = new Class();
var anotherObj = new Class();
@kshirish
kshirish / sexy-part-one.js
Created February 14, 2015 08:20
javascriptissexy
// immutable strings
var person = 'xyz';
var anotherPerson = person;
person = 'abc';
console.log(person);
console.log(anotherPerson);
// functions and other variables
var fun = function(){
@kshirish
kshirish / wsnode.js
Last active August 29, 2015 14:13
Websocket and Node
//////////////////////////////////////Server////////////////////////////////////////
var WebSocketServer = require("ws").Server;
var http = require("http");
var express = require("express");
var app = express();
var port = process.env.PORT || 5000;
var server = http.createServer(app);
server.listen(port);