Skip to content

Instantly share code, notes, and snippets.

View nickylimjj's full-sized avatar
💭
loves itacho sushi

Nicky Lim nickylimjj

💭
loves itacho sushi
View GitHub Profile
import csv as csv
filename = '<FILENAME>'
data = []
f = open(filename)
reader = csv.reader(f)
for row in reader:
data.append(row[5])
@nickylimjj
nickylimjj / server.js
Last active July 22, 2016 08:53
Nodejs: simple json server
// server.js
var http = require('http')
http.createServer( function (req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' })
var obj = {
firstname: 'John',
lastname: 'Lee'
}
@nickylimjj
nickylimjj / classes.js
Created July 22, 2016 06:09
Nodejs: Classes - Syntactic sugar for function constructors and prototypal inheritance
// classes.js
'use strict'
var Person = class Person {
// function Person (args) {}
constructor (firstname, gender) {
this.firstname = firstname
this.gender = gender
}
@nickylimjj
nickylimjj / emitter.js
Created July 21, 2016 08:21
Nodejs: understanding Events and Emitters
// emitter.js
// returns a Function Constructor
function Emitter () {
this.events = {}
}
// Listener is the code that responds to an event
// analogy: a person taking a cue from an event to execute his task
// @type : type of event. Ie, onClick
// @listener: code to be executed
@nickylimjj
nickylimjj / greet1.js
Last active July 22, 2016 06:10
Nodejs: module.exports vs exports
// module.exports
module.exports = function greet () {
console.log('greet1 [module.exports]')
}
console.log(exports)
console.log(module.exports)
@nickylimjj
nickylimjj / restaurant.js
Created July 1, 2016 15:19
NodeJS: non-blocking I/O
// understanding the Event Loop and async nature of nodejs
// resource help from : https://www.codeschool.com/blog/2014/10/30/understanding-node-js/
function submitOrder(orderNumber){
console.log('Submitted order and cooking: ' + orderNumber)
cookingFood(function afterEvent(){
console.log('food is cooked and ready to be delivered')
})
}
// 5s operation