Friday, December 4, 2015

Swift got it closer, but still fails

Continuing my religious and long war against null beings.

I just read about Swift improvements to avoid null pointers. In Swift a variable can not be assigned a null (nil in Swift nomenclature) unless it's declared optional. And this nil is actually an object of a defined type with a presence in memory, not a pointer to a forbidden memory address (0 in practice).

Still, while Apple's guys got closer to a solution, they didn't get the point.While the solution proposed by Swift fixed the Null pointer exception, it doesn't fix all the semantic inconsistencies of using Nulls. A nil object in Swift is still something empty of information, and so the "information lost" is still present.

The solution to fix the problem was much, much simpler and much, much more effective:


See more about it

Tuesday, June 30, 2015

Downloading youtube Videos with VLC (command line)

Ladies and gentlemen, we present you the fast and easy way to download Youtube videos using VLC and a shell script:

The script:

  # INPUT is the URL as seen in the browser
  # OUTPUT is any arbitrary file.
  vlc --intf dummy "${INPUT}" --sout=file/ts:${OUTPUT} vlc://quit

A problem appears if there are many related videos to download (for example a 50 video tutorial).
 Using Firefox I just select them all on the "right column" (related videos), right-click to select "see source code selected" and then clean the html to let only the input URL and the video title. 

Then a few Vim macros is all that needed to convert them in a shell script.

World Domination is an step closer now!

Saturday, May 23, 2015

Tuesday, January 20, 2015

Science is not Politics

“Let’s be clear: the work of science has nothing whatever to do with consensus. Consensus is the business of politics. Science, on the contrary, requires only one investigator who happens to be right, which means that he or she has results that are verifiable by reference to the real world. In science consensus is irrelevant. What is relevant is reproducible results.” – Michael Crichton

Looks unfortunate that most software developers have forgot this point.
Many modern programming languages just try to reach a consensus instead of doing things right. Let's observe how Javascript, the most widely used language today still keeps "null" and "nondefined" types around even if science says they must be dropped (backward compatibility is just an excuse, not a reason).

(Edit 2015/02/13: ECMAScript 5 Strict Mode will throw a ReferenceError when trying to evaluate a non-existing variable). 

Thursday, December 11, 2014

Is that good or bad?

This is the type of achievement to hide in a CV :(

Edit (2015-01-05): New hit on Stackoverflow!

Friday, December 5, 2014

Obfuscating Python code

Obfuscating code is probably a bad idea. It can have unpredicted consequences. Think twice before continuing

The script:
Next shell script will serve as reference to obfuscate Python code by compiling original files to .pyo while hiding the original source from py files.

# DIR_L: directory list (module list)

DIR_L="pythonModule1 pythonModule2 pythonModule3"

for dirA in ${DIR_L}; do
    cd ${CWD}/${dirA}
    rm -f *pyc *pyo
    python -OO -m compileall .
    ls *py | while read f ; do
        # Create empty "file".py with same modification time
that tmp (the renamed original "file".py used to
        # create the pyo file)
        mv $f tmp && touch -r tmp $f && rm tmp

 Python will *always* compare the modification date of the *py file with the one hardcoded in the *pyo object. If it doesn't match, the pyo will be recreated.
Creating a pyo file and then removing the code in the original *py file will not work since once the code is removed (echo -n "" > the modification date is updated. Next run will update the pyo file from the empty py file.
 Removing the py file leaving only the pyo file will not work either, since python will ignore the pyo file if the matching py file is not present.

The quick-and-easy solution then is to use "touch" with the -r option. This combination will create an empty file and update the creation/modification timestamp of the new file taking as reference the file passed to "-r".  Since moving a file doesn't modify its modification timestamp a line similar to:

  mv tmp && touch -r tmp && rm tmp 

will create the empty with a modification timestamp matching that of the myfile.pyo (created previously using python -OO -m compileall .)

While not shown in the script it's pretty clear that we must be working with a copy of the original sources. Otherwise they will be lost after obfuscation. Is up to the reader to choose its favourite way to do the copy. As a hint I use something like the next one-liner:

tar -C src_dir -cf - * | tar -C working_dir -xf -

pyminifier  provides utilities to minify, obfuscate and compress Python code as well as a Python API to use it inside other Python code. Unfortunately in my own tests it was buggy with many cryptic errors about missing modules.

touch is just available on UNIX-POSIX friendly systems. Probably it will also work on Windows with the help of cygwin, but it's not tested at all (and it will never be!).

Thursday, May 29, 2014

How much time does it takes to scan the entire Internet?

One week?, One month?

Extracted from

"This is the fastest Internet port scanner. It can scan the entire Internet in under 6 minutes, transmitting 10 million packets per second."

All you need is some good idea to start hacking the Internet and a 10Gbit/s symmetric link. Just ask your local carrier about it.