Run out of memory? (Cannot allocate memory)

If composer shows proc_open() fork failed on some commands:

PHP Fatal error: Uncaught exception ‘ErrorException’ with message ‘proc_open(): fork failed – Cannot allocate memory’ in phar

This could be happening because the VPS runs out of memory and has no Swap space enabled.

free -m

total used free shared buffers cached
Mem: 2048 357 1690 0 0 237
-/+ buffers/cache: 119 1928
Swap: 0 0 0

To enable the swap you can use for example:

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1


Forward/Change your Node.js app port from port 3000 to port 80

I redirect port 80 to port 3000 with this command:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Then I launch my Node.js on port 3000. Requests to port 80 will get mapped to port 3000.

You should also edit your /etc/rc.local file and add that line minus the sudo. That will add the redirect when the machine boots up. You don’t need sudo in /etc/rc.local because the commands there are run as root when the system boots.


Install any version of Node.js on CentOS 6 using NVM

I’m not sure if the ‘yum’ install works on other CentOS or not. But I come across the problem that I get some problems with upgrading NodeJS from v0.10 to v5.4.0 on CentOS. I don’t know what I should do so I started clean, and found that install nvm is super easy then install NodeJS itself. (And the perk is that you can have multiple versions of Node.js that you want!)

I don’t know about the perf though. Feel free to share if you do!

How to do:

Follow the instruction here:

(Section “Install Node Using the Node Version Manager”)

For short:

curl | bash
source ~/.bash_profile
nvm list-remote
nvm install v5.4.0 # or whichever version you'd like
nvm list # must have v5.4.0 show in the list
nvm use v5.4.0 # use it
nvm alias default v5.4.0 # set default node
node --version # there should show v5.4.0


Install Virtualenv with Wrapper for OSX and zsh

Get necessary lib

sudo easy_install pip #probably don't need to sudo
sudo pip install virtualenv #probably don't need to sudo
sudo pip install virtualenvwrapper #probably don't need to sudo

Append this to ~/.zshrc (the file is hidden)

# set where virutal environments will live
export WORKON_HOME=$HOME/.virtualenvs
# ensure all new environments are isolated from the site-packages directory
# use the same directory for virtualenvs as virtualenvwrapper
# makes pip detect an active virtualenv and install to it
if [[ -r /usr/local/bin/ ]]; then
    source /usr/local/bin/
    echo "WARNING: Can't find"

You might need to restart your zsh.

Creating env

mkvirtualenv testenv

it will access the env automatically

Feel free to ‘pip’ anything now

pip install rq

more at:

Compile .less file in Sublime Text for nvm

This works on Sublime Text 3 only.

1. Install sublime-less2css package.
(Package Control: Install Pagekage -> sublime-less2css)

2. Make sure you have node & npm. Then install the following package globally

npm install less -gd
npm install -g less-plugin-clean-css
npm install -g less-plugin-autoprefix

3. If it doesn’t work (less2css error: `lessc` is not available):
– Go to Preferences > Package Settings > Less2Css > Settings – Default and copy the default settings
– Paste default settings to Preferences > Package Settings > Less2Css > Settings – User and edit the lesscCommand property to your lessc path:

"lesscCommand": "/Users/vee/.nvm/v4.2.1/bin/lessc",

– Save and try again

4. If you get env: node error (env: node: No such file or directory):
Find your node path:

which node

Create symlink your node path to /usr/bin/node
sudo ln -s /Users/vee/.nvm/v4.2.1/bin/node /usr/bin/node

^ The above solution isn’t working anymore in OXS El Capitan (source). I solved by installing a sublime package named Fix Mac Path. Restart and it should work!

5. (Bonus) If you’re using nvm. Don’t forget to set the default nvm:

nvm alias default 4.2.1


How to get/create “Release Key Hash” for Android’s Facebook API

After digitally signed and created an apk, remember your 1) Key store path, 2) Key alias, and 3) Key password. Then enter this on the command:

keytool -exportcert -alias KEY_ALIAS_HERE -keystore KEY_STORE_PATH_HERE | openssl sha1 -binary | openssl base64

For example,
Key alias: DistributionKeyStoreAlias
Key store path: /Users/vee/androidkeystore.jks

keytool -exportcert -alias DistributionKeyStoreAlias -keystore /Users/vee/androidkeystore.jks | openssl sha1 -binary | openssl base64

And copy the code and enter it in Facebook developer’s setting page > Android section > Release Key Hash.