Tuesday, 28 March 2017

Ubuntu dev machine space management

Visualize filesystems usage:
df -h
Show disk usage of un/hidden folders
 du -sch .[!.]* * |sort -h


Find working kernel
uname -r
List installed kernels
dpkg --list | grep linux-image 


Sort and display packages size:
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
Completely delete a package
sudo apt-get purge packagename
Delete unused packages
sudo apt-get autoremove
Clean Apt cache
sudo apt-get clean


Brew cache cleanup
rm -rf $(brew --cache)
Brew uninstall
sudo ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

RVM
rvm uninstall ruby-2.3.3
Uninstall gems
gem uninstall -aIx

NPM cache cleanup
npm cache clean
Yarn (Node.js) cache cleanup
yarn cache clean

Monday, 27 March 2017

Wednesday, 15 March 2017

Javascript substack module pattern

Sup!?

So, we are using React to get a photo, send to an API and convert the response into a chart with ChartJS.

Our first attempt involved writing a DataConverter class like this:

This is nice but... we have a class (ECMAScript 2015 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) which has no state at all, wouldn't be better to have a module instead?

Cool uh?!
Hang on!
Take a look at the return call: when this module is called, it is not offering a series of methods.
It is returning a function instead, so this module can be called as a function:

This is nice but apparently the power of NodeJS let's us build more robust code, using the substack module pattern:

Using this pattern we don't have to use the weird module pattern syntax, the code is more elegant and clear... agree???
One catch though, is where this code will be executed: server side or client side with build tools is fine, other cases there is a chance that all this function will be available in the global scope.

This pattern has also ways to expand the behaviour of our modules: