Skip to content

Instantly share code, notes, and snippets.

View a0viedo's full-sized avatar
🌯
no burrito no code

Alejandro Oviedo a0viedo

🌯
no burrito no code
View GitHub Profile
@a0viedo
a0viedo / gsonTest.js
Last active August 29, 2015 14:01
Complex example of Gson serialization to JSON and then back to an Object from JS
// you should have java npm package installed and arapi81_build001.jar and gson-2.2.4.jar in the same folder where you run this code
var java = require("java");
java.classpath.push('arapi81_build001.jar');
java.classpath.push('gson-2.2.4.jar')
var Arrays = java.import('java.util.Arrays');
var gson = java.newInstanceSync('com.google.gson.Gson');
java.newInstance('com.bmc.arsys.api.RegularForm', function(err, result){
var form = result;
@a0viedo
a0viedo / tryCatch.js
Created July 10, 2014 18:00
Why is not that good idea try/catch
try{
setTimeout(function(){
throw new Error('kaboom'); // be my guess to throw outside the setTimeout function
}, 4000);
}
catch (err){
console.log(err);
}
function sumar(parametro1, parametro){
return parametro1 + parametro;
}
console.log(contarvocales("coderhouse"));
function contarvocales(string){
var totaldevocales = 0;
@a0viedo
a0viedo / npmCommand
Created September 4, 2014 17:40
using npm programmatically
var npm = require('npm');
npm.load(function(err, npm){
npm.config.set('loglevel', 'silent');
npm.commands.show(['npm'], function(err, result){ /* not using any result on purpose*/});
console.log(npm.config.get('loglevel')); // this is printing 'silent'
});
@a0viedo
a0viedo / asyncQuiz.js
Last active January 26, 2021 19:54
Can you guess what the console will print? Extracted from the book Mastering Node.js
var fs = require('fs');
var EventEmitter = require('events').EventEmitter;
var pos = 0;
var messenger = new EventEmitter();
messenger.on('message', function(msg) { console.log(++pos + " message:" + msg);
});
console.log(++pos + " first");
var http = require('http');
http.get("http://www.google.com/index.html", function(res) {
console.log("Got response: " + res.statusCode);
res.on('data', function(){
console.log('data');
}).on('end', function(){
console.log('end');
})
}).on('error', function(e) {
@a0viedo
a0viedo / test.js
Last active August 29, 2015 14:07
describe('test something', function(){
it('should return correct value', function(done){
server.connect(cs , function(err, data) {
expect(err).to.be.null;
expect(data.connected).to.be.true;
done();
});
});
})
//cuentaRecursiva recibe un número y cuenta cuantas veces lo tiene que decrementar por uno para llegar a cero (caso base)
function cuentaRecursiva(numero){
if(numero === 0) {
return 0;
}
return 1 + cuentaRecursiva(numero - 1);
}
@a0viedo
a0viedo / info.md
Created November 14, 2014 16:33
Lo que deberían tener los tutores en pendrives

Cada pendrive debería contener:

  • Windows Installer (.msi) de Node tanto para x86 cómo x64.
  • Mac OS X Installer (.pkg).
  • Binarios de Linux (.tar.gz) tanto para x86 cómo x64.
  • Worshoppers core empaquetados (.tgz)

Cómo empaquetar un workshop

Si agregamos las dependencias a bundledDependencies dentro del package.json, al ejecutar el comando npm pack se debería crea el archivo con extensión tgz que contiene a su vez todas las dependencias. Por ejemplo el package.json de javascripting:

var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);