The blog of Sebastián Gurin about software development. "A place to store those little things that time will erase if not written...."
sábado, 1 de julio de 2017
install dropal in ubuntu server
domingo, 25 de diciembre de 2016
https web server with ubuntu, letsencript and nodejs
sudo apt-get install letsencrypt
letsencrypt certonly --standalone -d example.com
Note: this will generate the following files in folder /etc/letsencrypt/live/example.com: cert.pem chain.pem fullchain.pem privkey.pem
Now you are ready to implement and execute your nodejs https server. Run the following program and then open https://example.com and it should be working without any browser warning, ready for production.
const https = require('https');
const fs = require('fs');
// cert.pem chain.pem fullchain.pem privkey.pem
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem')
};
https.createServer(options, (req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(443);
Or using http-server command line utility:
http-server . -p 443 --ssl --cert "/etc/letsencrypt/live/example.com/cert.pem" --key "/etc/letsencrypt/live/example.com/privkey.pem"
miércoles, 22 de junio de 2016
writing selenium in javascript node with webdriverio - instructions for impatients
First is about installing and running the selenium server. Second is a little webdriverio example.
Installing the selenium server
The following instructions are give in a shell script that was tested on mac:#install java # download selenium server: curl -O http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar #download googlechrome selenium drivers: curl -O http://chromedriver.storage.googleapis.com/2.22/chromedriver_mac32.zip unzip chromedriver_mac32.zip #Execute selenium server: java -Dwebdriver.chrome.driver=./chromedriver -jar selenium-server-standalone-2.53.0.jar
The Program
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome'
}
};
webdriverio
.remote(options)
.init()
.url('http://www.google.com')
.getTitle().then(function(title) {
console.log('Title was: ' + title);
})
.end();
Appendix: Technologies used
- http://www.seleniumhq.org/ - the infrastructure that talks to browsers (java)
- http://webdriver.io/guide.html - the selenium javascript api
- http://chromedriver.storage.googleapis.com/index.html - selenium driver to manage chrome browser.
- java and node
jueves, 19 de mayo de 2016
Minify JavaScript code with esprima and escodegen
var esprima = require('esprima'),
escodegen = require('escodegen');
function doUglify(s)
{
try
{
var ast = esprima.parse(s);
s = escodegen.generate(ast, {format: escodegen.FORMAT_MINIFY}) || s;
}
catch(ex)
{
console.log(ex);
}
return s;
}
lunes, 18 de enero de 2016
first steps with postgresql for inpatients
DATA_FOLDER=.data mkdir myproject cd myproject initdb -D $DATA_FOLDER #TODO DONT DO THIS IN PRODUCTION sudo chmod -R a+wr /run/postgresql/ postgres -D $DATA_FOLDER >logfile 2>&1 & createdb mydb
sábado, 7 de noviembre de 2015
jasmine for node: execute test files and set jasmine timeout globally
Also I had some difficulties guesssing how to set the timeout interval globally. Mainly my difficuly was not to now that jasmine was creating a global 'jasmine' object when requiring it.
The following code shows both things:
var
path = require('path')
, glob = require('glob').sync
, Jasmine = require('jasmine')
var jasmineRunner = new Jasmine();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 99999999;
jasmineRunner.specFiles = glob(path.join(__dirname, '*Spec.js'));
jasmineRunner.execute();
martes, 6 de octubre de 2015
Queue based on Q promises
So just that,I'm working with promises in JavaScript and at certain point I needed a queue for executing asynchronous tasks. My promises are implemented by q library and my particular requirements are as follows. I implemented this web service client without knowing that no concurrent operations are allowed. In some cases, if you request two operations at the same moment the server will return an error. In my case, an obvious quick solution was to en-queue the method that makes the requests in my client. Something like make it synchronous (similar as java methods can be declared as 'synchronous' when multi threads access it).
I research a little and there are plenty alternatives, most appreciated was the queue utility of async, a library that also use. Nevertheless instead learning how to use it, and because I know this problem can be solved w promises wanted to try something else
I very liked the solution proposed here because is simple so I adapted to use Q promises instead jQuery's. This is the result (working example in node, but should work also in the browser)
var Q = require('q')
var Queue = function ()
{
var lastPromise = null;
this.add = function (obj, method, args, context)
{
var methodDeferred = Q.defer();
var queueDeferred = this.setup();
if(context === undefined) { context = obj; }
// execute next queue method
queueDeferred.done(function ()
{
// call actual method and wrap output in deferred
setTimeout(function ()
{
obj[method].apply(context, args);
methodDeferred.resolve();
}, 100);
});
lastPromise = methodDeferred.promise;
};
this.setup = function ()
{
var queueDeferred = Q.defer();
// when the previous method returns, resolve this one
if(!lastPromise)
{
lastPromise = Q.defer();
lastPromise.resolve();
lastPromise = lastPromise.promise;
}
lastPromise.done(function ()
{
queueDeferred.resolve();
});
return queueDeferred.promise;
}
};
var queue = new Queue();
queue.add(console, 'log', ['one']);
queue.add(console, 'log', ['two']);
queue.add(console, 'log', ['three']);
setTimeout(function ()
{
queue.add(console, 'log', ['four']);
}, 2000);