Saturday, October 22, 2016

Energy saving issues with Lubuntu (and how to fix it with powertop)

I'm a big fan of Lubuntu (Light Ubuntu), the Ubuntu without all bloated software since, on average, it saves up to 1 or 1.5 Gigas or RAM when compared to standard Ubuntu will of the fancy (and useless) 3D effects.

Something that annoys me anyway is that the default setup in Lubuntu (I ignore if that's the case in Ubuntu) is quite energy-hungry.

I use a Dell XPS 13 laptop equiped with brand new hardware that "theoretically" must work in silence most of the time, but when I just boot up Lubuntu and a couple of apps (Firefox, Eclipse) the fan starts to run at max speed.

The easy (patch) solution is to run next command:

sudo powertop

then go to the "Tunables" tab, and switch all from "Bad" to "Good", except most probably for the USB keyboard and mouse and the wifi or ethernet. (For those really concerned with the integrity of their HD data, don't swith also al SATA related stuff).

Actually, activating the power saving for the PCI Intel Core processor Graphics Controller is usually "good enough" to make the fan settle down, but switching on all the others makes no harm and our computer will be happier with us (don't forget that sooner than later IA equiped macro-computers will punish those poor humans that through the years tortured their indefense CPUs, so it's better to get friends as soon as possible before it's too late).

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!).