Skip to content

Instantly share code, notes, and snippets.

Alexandru Vlăduţu alessioalex

Block or report user

Report or block alessioalex

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View custom-transform-stream.js
// http://codewinds.com/blog/2013-08-20-nodejs-transform-streams.html
"use strict";
var crypto = require('crypto');
var stream = require('stream');
var util = require('util');
var Transform = stream.Transform;
function ShaSum(options) {
View inheritance-0.js
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.getInfoCard = function() {
return this.name + ', ' + this.age + ' years old';
};
var johnny = new Person('John', '25');
View http-debugging-proxy.js
var fs = require('fs');
var http = require('http');
var httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createProxyServer({});
//
View 0-cache-args.js
// our own in memory database
var users = {
'alex': { user: 'alex', age: 27 },
'john': { user: 'johndoe', age: 34 }
};
// async function
var getUserFromDb = function getUserFromDb(id, callback) {
var min = 1000;
var max = 2000;
View inheritance-2.js
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.getInfoCard = function() {
return this.name + ', ' + this.age + ' years old';
};
// function Student(name, age, university) {
View async-cache-0.js
// TODO: create a cache mechanism for asynchronous functions
// the async functions should look like this:
//
// function getSomething(id, callback) { .. }
//
// Our caching function should take 2 args: the original function and an
// async function that tries to grab the data from cache.
// This async function should return another function that we will use instead of
// the original one.
@alessioalex
alessioalex / example.js
Created Nov 22, 2014
CSV-streaming-parser
View example.js
"use strict";
// CSV data downloaded from the following url:
// http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv
var fs = require('fs');
var csv = require('csv-parser');
var FilterStream = require('./filter-stream');
var Table = require('cli-table');
var bubbleError = require('bubble-stream-error').bubble;
View custom-writable-stream.js
// example from http://codewinds.com/blog/2013-08-19-nodejs-writable-streams.html
"use strict";
var stream = require('stream');
var util = require('util');
// use Node.js Writable, otherwise load polyfill
var Writable = stream.Writable;
var memStore = { };
@alessioalex
alessioalex / heavy-computation-settimeout.js
Created Nov 22, 2014
heavy-computation-settimeout.js
View heavy-computation-settimeout.js
// dividing it into chunks
var getSum = function getSumOfEvenNumbers(opts, cb) {
var sum = opts.sum || 0;
var i = opts.i || 0;
var stopAt = opts.stopAt;
var CHUNK_SIZE = 1000000;
var nextStop = (stopAt < (i + CHUNK_SIZE)) ? stopAt : (i + CHUNK_SIZE);
for (; i < nextStop; i++) {
@alessioalex
alessioalex / configurable-logger-example.js
Created Nov 22, 2014
configurable-logger-example.js
View configurable-logger-example.js
// TODO: given the log function previously created, create a prefixed logger
// function that takes a {String} as an argument.
// That string should be used as the first argument to the regular `log` function.
var log = function log() {
var args = Array.prototype.slice.call(arguments);
console.log(args.join(' '));
};
// log('hello', 'world', '!');
You can’t perform that action at this time.