Run NodeJS app as a service and make it start after reboot

The issue

If you are running all Node dependencies locally, as opposed to globally, using a package such as foreverjs will not work, since all your node modules will be inside of your folder, and not installed on your server.
The reason why I have this, and as such, many of you, it is because we use a web server such as Apache and we want to add NodeJS additionally in the server. The Node app will only run if you hit “node start test.js”, therefore this is a solution to make it run forever plus also restart it after reboot of the server. In my case, because of my setup the crontab solution did not work.
Here is my setup:
Apache installed on my server, and Virtual host pointing to located in /var/www/html/ folder
Main node file is main.js
Therefore, dependencies installed on node_modules

The solution

Install forever-service package. I used the option “–script” because my main Node app file was not named app.js (which is the default name assumed in forever-service).
$ sudo forever-service install test --script main.js
That will create a process called “test”. You will need to start it after that.
$ sudo start test

Why use Yahoo finance for your trading needs

As a follow-up post (see stock selection guide), I write this one to filter all the information that Yahoo finance provides when looking up for a company quote.

  • Summary: is a good place to make sense of the technical details of the shares. Ranges, volume and beta are useful indicators.
  • Historical prices, if can be plotted into a graph will be very useful to study the historical trend of the shares and compare it with an index.
  • Interactive chart of Yahoo finance updates in real time and it offers logarithmic scale (smooths spikes). As a recommendation I would calculate high and low prices in yearly intervals to see if the possibility of profit is empirically real (technical analysis).
  • Headlines and news should be quickly read (no need to read the details) and mark them as positive or negative impact.
  • The information in Key Statistics tab should be used to compare with other companies, therefore used in conjunction with Competitors and industry tab. The Beta provided can be used to calculate CAPM and have a degree of understanding of how it moves with indexes. If Beta of a company is over 2 it means that it moves a lot more if the index moves 1% (mathematically a Beta of 2 does not mean that the stock will duplicate its value if the index goes up) and it moves in synch with the index the closer Beta gets to 1.
  • Income statement, balance sheet and cash flow statements should be used to calculate increases in earnings (compare one year with another) but should not be taken for granted. For example, some costs may extend several terms so that profits at the end are waned not because of reduced income but because of expenses from previous terms. Therefore, book values are not consequently related to market prices, a profitable company may not have a good book value and vice versa.


Stock selection for small investors

This is a guide for selecting assets in the global financial environment (I assume you have access to any stock in the world). The whole purpose is to make profit in a medium term, with an aggressive (risky) profile with little investment. Throughout my years of investing experience I have come to a clear conclusion.

Buy stocks within world biggest indexes

Here are a few reasons why (updated over time).

  • SMEs are not listed in a stock exchange. It is true that we should not close any doors to ourselves, that we should buy any stock anywhere in the world as long as the business is good and makes profit. However, this is not possible in reality because we also deal with other economic costs such as travelling, signing complex contracts, wasting time on bureaucracy, getting cheated… and the list goes on. This assumption also includes OTC stocks.
  • Trading volume has to be high. There should be a threshold that the shares traded need to satisfy for you to invest. If the volume is low, which is what happens with OTC shares, they are completely unpredictable. A company with a lot of capital such as an investment bank, or a hedge fund can easily take over and buy an outstanding amount of shares and as a result manipulate the market. Big companies are harder to manipulate because there are so many investments that it is no longer possible to manipulate the market with a sole transaction, which in a sense, makes it less volatile.
  • Good representation of the economy. In order to get market efficiency to hold and be able to predict to some degree the future direction of the stock price, it needs to be listed in an index. Indexes are usually good measures of a country’s economy. From my research I’ve noticed that relevant indexes such as FTSE 100, IBEX 35, Nasdaq, Dow Jones and Nikkei are relevant because when there is a shock in one of these indexes or some kind of turmoil, the economy feels it and vice versa. Therefore, we try to accomplish ceteris paribus (all other things equal) by analyzing stocks that are listed in an relevant index.
  • Reputation of the company. Even though this statement mustn’t be true in all circumstances, it gives a a certain degree of trust if the company is public (listed in a stock exchange, which means financial statements are available to anyone and auditing is done), which conversely will provide us with as much information as possible about the company. In private companies that have little exposed information, our asymmetric information risk is much higher and the probability of our investment not being profitable will be more evident.
  • Predict investors’ reactions, not data. Today, investment companies are heavily relying on market data that are analyzed by quantitative analyst experts. However, according to this documentary, market movements and overall investment has an emotional component, since economics is based on too many assumptions that do not apply in many circumstances, we should still focus on investor’s expectations which includes information provided by media and possible scenarios of how investors may react. Therefore, we should also include in our analysis the news that come from media and categorize them as positive or negative impact.

With all these arguments, I found Yahoo finance the best solution for these needs. See Use Yahoo finance for filtering relevant info on Yahoo finance.

Cost of living in cities around the world

I found this website Numbeo:
Which uses aggregate data from users of the website who input the data to the website. It kind of follows the Wikipedia collaborative environment, so it is still an informal source.

Any user in any country can input data, which is data that may be biased. They seem to have labels for general products but still a specific model of the product is not cited, therefore prices may vary. As an example, labels like “Apples 1 Kg 2.06 dollars ” is not insightful because apples can be imported (Fiji apple) or it has different varieties (Golden apple) which may cause high variability in data input.

The good thing is that you can see the spread (variability) on the data on the right side “Range” column. Statistically, data with high spread means prices have big lows and highs. A price range of 0 – 30 has an average of 15, but still a price range of 10 – 20 is 15 too, but this last range has much lower spread. Therefore, looking at the range graph on the right, you should avoid big ranges, because data is not consistent nor representative of the product.

Obviously you cannot do a economic study with this website, however, this will give you a pretty good insight for an unknown destination, as long as you need how to avoid inaccurate data. Big cities will probably have more data, proportionally more people live in big cities, more people will go to big cities and this means more people will add more data, therefore data accuracy is based on amount of people contributed. Furthermore you can contrast data with other more legitimate websites such as:

This is a good source of information, which gathers economic data of different countries created by Michael Porter. You can contrast welfare using this website with Numbeo and see the differences, that will help you locate accurate data. If not enough, you can still search your destination using Wikipedia and contrast data against Social Progress Imperative and get a big picture with the information provided in all three websites.

Good luck on your travels!

Stop saying “Self-teaching”

I have learned web design, HTML, CSS, using Photoshop among other tools by watching videos, reading books, practicing tutorials available on the Internet. People call it these days “Self-teaching” or “I am self-taught”. I don’t know if it was a kid who created this expression, but I find it arrogantly childish, sounds like you are better than others just because you learned it without a teacher, and some Americans even call some of these kids “genius”. I think this is one of the worst words made popular by media. The main reason behind it is that you can’t possibly teach your self.

We all had a teacher when we were young, someone knowledgeable that has far more experience than you doing the things you want to learn and this is why that person is a teacher and teaches you, because he or she knows more than you, otherwise that person would not have the power to teach you, it would be useless. When you don’t know something, someone then teaches you, then how can you “self-teach” something you don’t know? If you don’t know how to play the piano, you can’t possibly teach yourself how to play it…

After all, I believe this expression is really wrong, but English-speaking people just accepted it, maybe as an answer to the questions that so many spoiler parents (always putting their kids on a pedestal) ask: “Where did you learn that?” or “Who taught you that?” Under this context, well… it makes sense that a kid jokingly with a cocky attitude says “I taught myself”, wow this ends usually with a “My son/daughter is a genius”.

For these and several other reasons I urge everyone who reads this post to avoid using this silly expression. You can’t possibly self-teach, better “self-learn“. Hereby I propose using this new expression, filtered, neat, no hard feelings, just a humble “self-learn”, because we learn everyday, babies do it when they walk, and pianists do it when they practice new melodies. Yet I still encourage those that have the means to learn through a teacher to do it in the traditional way, it will save you a lot of time and you’ll learn it much better and even reach skillful mastery —coming from a long-time “self-learned”.

Random number in javascript

The following snippet creates an integer (no decimals) between the range you choose starting from 1.

var range = whatever number you want;

var randomNumber = Math.floor(Math.random() * range ) + 1;

This means that if want a number between 1 and 6:

var range = 6
var randomNumber = Math.floor(Math.random() * 6) + 1;


Because Math.random will output a decimal under between 0 and 1 (never will be 1) we round it down, this means that Math.floor(0.5) = 0. We simply multiply the inside by the top number and add to the outside 1 to make it an integer between the specified range.

Remove /blog from multisite URLs


One of the issues of the multisite is that by default it appends /blog to the site’s URL, so no matter at which page you are, you’ll get something like

To avoid this follow these instructions

  1. At blog site set Settings -> Permalinks -> Common Setting -> Default (Must select default only and don’t touch any thing, If you need to change category base, tag base set at Network Admin only)
  2. At Network Admin -> Sites -> (root site) Permalink Sturcture -> /%category%/%post_id%

Use wkhtmltopdf in WordPress

The story behind this method

After tried several HTML to PDF engines such as TCPDF, MPDF, mostly had a common problem – they were not supporting most features of CSS. After some searching I stumbled upon wkhtmltopdf, which is based on webkit. However there wasn’t a plugin to convert WordPress posts to PDF using wkhtmltopdf, there were only wrapper classes for PHP, since wkhtmltopdf is a command line application in its essence. Hence, I had only one choice: to create my own method.
Because I am not a programmer, I came up with a very rudimentary method for converting the posts output by WordPress into PDF using wkhtmltopdf engine.

Installation steps

Steps for successful installation of wkhtmltopdf to avoid annoying errors such as “X server not found”, “no error display”…

1. Install composer

2. Install wkhtmltopdf.

3. URL:


4. After publishing post, execute the URL.

5. Automate using curl PHP function. Paste this in functions.php of your theme. Remember to substitute “example” to any other name you want.

For the $options see this link:
You can also user other wrappers such as
Other resources using PHP (not WordPress)
Video (French):

Cleaning up Ubuntu 14.05 log files


I am using a Digital Ocean 30GB SSD droplet, not for long, I realized that only installing a few scripts made it consume over 75% of the disk space. I realized that this was obviously consuming too much resources for what did so here is my cleanup procedure.

Finding out the large files

First run this command to see what percentage your disk is consuming.
df -h
This command will show you a list of folders in your root with their sizes. (don’t forget to run in sudo if you don’t have priviliges).
du -sh /*
You can recursively use it, so in my case
du -sh /var/log/*
The log folder was consuming over 12GB of space. Therefore, I opened this folder to find the log files that were consuming too much space obvioulsy you can’t delete most of the log files, those ending with .log can only be truncated with:
> var/log/mail.log
And if you do again:
du -sh /var/log/*
You’ll see the first size column turn to 0. If you want to truncate all log files
truncate -s 0 /var/log/*log
Or you can see what is writting the file with (there may be a good reason why the file is so large)
tail mail.log.1
And after you are done, check that the hard disk consumption has been decreased ().
df -h

Moreover, you could establish the size, time to purge and managing log files with logrotate.

Ubuntu cleanup commands

Additionally you can run these commands to cleanup any other files that are left orphaned or unused automatically by the system.
Run these scripts in that order.
apt-get autoclean
apt-get clean
apt-get autoremove
For further explainations:

See if your PC can run a 64-bit OS

I was thinking whether my hardware was capable of running a 64-bit (x64) Windows. However, a search on Google added more confusion to this issue. Most queries searching “Can I run 64-bit Windows”, “Is my computer a 64-bit or 32-bit” type of questions refered to methods to determine what type of Windows your are running, and they are summarized in these two methods:

  1. Go to Start > All Programs > System Tools > System Information
  2. Go to Computer > right-click select properties. Or you can hold Windows Key + Pause / break button

Both of previous options will show you the type of Windows Operating System you are running NOT what your CPU is capable of running. Even if you state in Google clearly, “check if my PC can run 64-bits” no relevant results will return.

The best article I’ve found explaining this 32-bit and 64-bit explained, says that you need a CPU capable of running 64-bit to run 64-bit applications (either Operating Systems such as Windows, Linux or software). Therefore, Google searches for this issue needs to be rephrased.

Yet, most of the results where still irrelevant. Among some of the solutions included more sophisticated ones this time. It turned out that the only way to find out whether your CPU is able to run 64-bit was to use a software tool and check the tasks the CPU can carry out (due to the nature of the 64-bit architecture). The best software I found for my purpose was 64bit Checker, basically because it clearly states the version of Windows installed and what can your CPU support, as opposed to other software such as CPU-Z, which has a lot of information but CPU support is not clearly stated.

64-bit checker