Skip to content

Instantly share code, notes, and snippets.

View deleteman's full-sized avatar

Fernando Doglio deleteman

View GitHub Profile
@deleteman
deleteman / stringify.js
Last active March 28, 2019 02:18
stringify-serializer
let testObj = {
name: "Fernando",
age: 35,
speak: function() {
console.log("Hello world!")
},
address: undefined
}
let serializedObj = JSON.stringify(testObj)
testObj.speak()
@deleteman
deleteman / tojson.js
Created March 28, 2019 02:19
tojson serialization
let testObj = {
name: "Fernando",
age: 35,
speak: function() {
console.log("Hello world!")
},
toJSON: function() {
console.log("toJSON called")
},
address: undefined
@deleteman
deleteman / node-serialize.js
Created March 28, 2019 02:21
usong node-serialize to serialize objects
const serialize = require("node-serialize")
var obj = {
name: 'Bob',
say: function() {
return 'hi ' + this.name;
}
};
var objS = serialize.serialize(obj);
console.log(typeof objS === 'string');
@deleteman
deleteman / jsonstream.js
Created March 28, 2019 02:25
serialization using jsonstream
var fileSystem = require( "fs" );
var JSONStream = require( "JSONStream" );
var books = [
{name: "The Philosopher's Stone", year: 1997},
{name: "The Chamber of Secrets", year: 1998},
{name: "The Prisoner of Azkaban", year: 1999},
{name: "The Goblet of Fire", year:2000},
{name: "The Order of the Phoenix", year:2003},
{name: "The Half-Blood Prince", year:2005},
{name: "The Deathly Hallows", year:2007}
@deleteman
deleteman / argv.js
Created March 28, 2019 02:27
argv reading code
process.argv.forEach( (val, index) => {
console.log(index + ': ' + val);
});
@deleteman
deleteman / sliced argv
Created March 28, 2019 02:28
slicing the argv array
let args = process.argv.slice(2);
args.forEach( (val, index) => {
console.log(index + ': ' + val);
});
@deleteman
deleteman / iterating.js
Created March 28, 2019 02:33
Iterating over an object's properties
class Obj {
constructor() {
this.a = 1
this.b = 1
this.c = 1
}
method(st){
}
}
@deleteman
deleteman / object keys.js
Created March 28, 2019 03:13
object keys
let obj = {
a: 1,
b: 2,
test: function() { return 0}
}
for(m in obj) {
console.log(m)
}
console.log(Object.keys(obj))
@deleteman
deleteman / async-loop.js
Created March 28, 2019 04:08
async-loop.js
function asyncLoop(list, callback) {
let results = []
list.forEach( fn => {
fn( (err, result) => {
if(err) return callback(err)
results.push(result)
if(results.length == list.length) {
callback(null, results)
}
})
@deleteman
deleteman / async-loop2.js
Created March 28, 2019 04:10
using async-loop
const req = require("request")
let calls = [
function (cb) {
req.get('http://www.google.com', cb)
},
function (cb) {
req.get('http://www.yahoo.com', cb)
},
function (cb) {
req.get('http://www.msdn.com', cb)