I was studying (rev-eng) how does YouTube works when I’ve found this post about the get_video_info call.

After some digging and some trying I’ve made a node.js module to make the request and parse the response, without the need for the official API.

Here’s the link:

Leave a comment

Posted by on 2016/07/29 in dev


Tags: , , , ,

How-to handle app parameters in Node.js

Let say you have to handle one or more custom parameters in your Node.js app. There are many ways to do that, here are my fab 4.
In these examples I’ll read a debug (on/off) and a port (number) parameters.

keep an eye on these two modules:


Passing them to the interpreter

node app.js --debug --port 8080
var dbg = (process.argv.indexOf('--debug') >= 0);
var port = 0;
if (process.argv.indexOf('--port') >= 0 && (process.argv.indexOf('--port')  +1 < process.argv.length))
  port = process.argv.indexOf('--port') + 1;


Adding them to the package.json

 "config": {
   "port": 8080,
   "debug": "true"
var dbg = (process.env.npm_package_config_debug == 'true');
var port = process.env.npm_package_config_port || 0;

If you’re using PM2, you also need to create an ecosystem.json file ( to correctly handle the package.json stuff.

Using a local json file (params.json)

  "debug": "true",
  "port": 8080
var pars = require('./params.json');
console.log(pars.port, pars.debug);


Using an environment variable (not my preferred …)

export debug=true
export port=8080
var dbg = (process.env.debug == 'true');
var port = process.env.port || 0;
Leave a comment

Posted by on 2016/07/07 in dev


Tags: , ,

xsd quiz

I recently needed to solve an XSD problem. I needed to define a schema that allows this:


where FIRSTValue is not mandatory, SECONDValue is not mandatory but either one of them or both must exists.

I started using a “sequence”

<xs:complexType name="AltType">
      <xs:element type="xs:string" name="FIRSTValue" minOccurs="0" />
      <xs:element type="xs:string" name="SECONDValue" minOccurs="0" />

but this allows 0 children…

I then tried an “all”:

<xs:complexType name="AltType">
      <xs:element type="xs:string" name="FIRSTValue" minOccurs="0" />
      <xs:element type="xs:string" name="SECONDValue" minOccurs="0" />

and this also allows 0 children…

Ok let’s think about a “choice”:

<xs:complexType name="AltType">
      <xs:element type="xs:string" name="FIRSTValue" minOccurs="0" />
      <xs:element type="xs:string" name="SECONDValue" minOccurs="0" />

Ouch! I can’t have BOTH children …

Ok, the choice is surely the way:

<xs:complexType name="AltType">
      <xs:element type="xs:string" name="FIRSTValue"  />
      <xs:element type="xs:string" name="SECONDValue"   />
        <xs:element type="xs:string" name="FIRSTValue" />
        <xs:element type="xs:string" name="SECONDValue" />

but this is evalued as a “non deterministic” choice and doesn’t compile.

Finally the solution (because yes, it IS possible). Note: to avoid an empty node I defined a new type of string with minimum length = 1.

  <xs:simpleType name="notEmptyString">
    <xs:restriction base="xs:string">
      <xs:minLength value="1" />

  <xs:complexType name="AltType">
        <xs:element type="notEmptyString" name="FIRSTValue" />
        <xs:element type="xs:string" name="SECONDValue" minOccurs="0" />
      <xs:element type="notEmptyString" name="SECONDValue" />
Leave a comment

Posted by on 2016/06/30 in dev


Tags: , ,

tsql: give me 5! (and 6, 7, 8, …)

Sometimes on databases I’ve worked on there were “table of numbers”, i.e. to store Years.
Are you sure you really need that table? There are a lot of -funny- ways to get numbers from sql! C’mon!

0-999 numbers, using a Table Value Constructor (

;WITH tmp AS (
  SELECT * FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) AS X(y)
  a.y + (b.y * 10) + (c.y*100) as Value
FROM tmp as a, tmp as b, tmp as c

These are years from 1900 to 3947, is it enough?

select 1900 + number as [Year]
  from master..spt_values
  where type = 'P'

This is a more comprehensive list of numbers between 0 and 65535, aka (256 * 256) – 1

;with seed as (
  select number
  from master..spt_values
  where type = 'P'
  and number < 256
select n1.number + n2.number * (256)
  from seed n1
  full outer join seed n2 on 1=1
Leave a comment

Posted by on 2016/06/01 in dev


Tags: , , , ,

this.window (& friends)

Open a console in your browser, then verify these:

console.log(this === this.window); // true
console.log(this === this.window.window.window); // true
console.log(this === this.self); // true 
console.log(this === this.frames); // true (also when this.frames.length > 0)

When this.frames.length > 0 you can also:

for (i in this.frames) console.log(this === this.frames[i]) // true,false,true,true,false,.... (so many true because we have "self","window","parent","frames",... The others are $,jQuery,google stuff,...)

console.log(this.window[0] === this.window[1]); // false
console.log(this.window[0] === this); // false (obviously in my test)
console.log(this.window[1] === this); // false (obviously in my test)
console.log(this.window[1] === this.frames[1]); // true
Leave a comment

Posted by on 2016/04/07 in dev


Tags: , , ,

kodi & retrogaming

There are many ways to implement both Kodi and a retrogaming machine (RetroArch with EmulationStation) on your RPi.
The most common are:

  • OSMC with a EmulationStation launcher
  • RetroPie with a Kodi launcher
  • Recalbox with a Kodi launcher
  • a dual boot SD (OSMC, OpenElec, Recalbox, RetroPie, …)

There is no a ‘better’ one, you can choose what you do prefer =D. I actually am into the first one, and I’m going to explain how to do it.

1. install Kodi on the SD
2. open a terminal. Remember you can login locally with power button, select “exit”, press ESC on the splash screen or you have to enable the ssh service to login from remote (user:osmc / pwd: osmc).
3. download the retrosmc script from the mcobit repository github:

cd /home/osmc
chmod +x

4. launch it


5. choose “Install retrosmc” (disclaimer: it takes about 30 minutes or more!)
6. after all the setup, choose “Install Launcher Addon”
7. all you need is now under /home/osmc/RetroPie/ (roms folder, bios folder, …)

Now you can launch retrosmc within Kodi -> Programs

Leave a comment

Posted by on 2016/03/01 in sys


Tags: , , ,

alias ll=?

On Ubuntu the default alias for ll is:

alias ll='ls -alF'

but my favourite one is:

alias ll='ls -lrhat --group-directories-first'

(or “list sorted by modification time, reversed, in long format, human readable with folders first”).
To remember it I just remember “Linux Red HaT” (my firsto distro in nineties)

What’s yours?

Leave a comment

Posted by on 2016/01/28 in sys


Tags: , , ,