Completely removing Node.js and Npm

Apparently i needed to completely remove my node.js and npm installation in my mac mavericks because i have installed various version of node.js from brew and nodejs.org website. After removing node from Brew, i am still able to access my node on my terminal and decides to write this to help anyone who is looking into removing and reinstalling node altogether (either from source or brew)

Removing Node.js

Credit goes to Dominic Tancredi
To recap, the best way (I've found) to completely uninstall node + npm is to do the following:

  • go to /usr/local/lib and delete any node and node_modules
  • go to /usr/local/include and delete any node and node_modules directory
  • if you installed with brew install node, then run brew uninstall node in your terminal
  • check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there
  • go to /usr/local/bin and delete any node executable

You may need to do the additional instructions as well:

  • remove: /usr/local/bin/npm
  • remove: /usr/local/share/man/man1/node.1
  • remove: /usr/local/lib/dtrace/node.d
  • execute: rm -rf /Users/[homedir]/.npm

Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as wel

Node still isn't uninstalled!

If you have done the above and you can still execute node on your terminate by firing

node

then you might need to do the following. Download the source code from nodejs.org exactly like how you have installed your nodejs from source


git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install

Inside the source code, instead of hitting 'make' and 'make install', do the following

sudo make uninstall

This instruction will uninstall whatever the source has installed into your machine.

Node and Npm still not uninstalled

Well, if you did all the above and you can still use node on your machine. You might want to try using 'locate' and manually removing all the necessary npm and node files in your machine by using

locate node 
locate npm

after you remove anything from the above command, you should fire the following to update the latest locate database

sudo /usr/libexec/locate.updatedb

but you will have the fire the above command every time you successfully remove certain directory as 'locate' only update periodically at a specific time every day.

Removing Brew and Reinstalling it

I faced an issue with my brew installation which caused a lot of ruby error popping out every time i uses Brew. Therefore i needed a way to reinstall brew.

Uninstall Brew

A quick Google search lead me to Uninstalling brew (so I can reinstall) by Eneko Alonso and he has all the instruction listed to cleanly removing your brew installation. But make sure the first one (`brew –prefix`) returns the path where homebrew was installed properly. If not, you might ending up removing stuff from your computer you did not intend to remove.

cd `brew --prefix`
rm -rf Cellar
brew prune
rm -rf Library .git .gitignore bin/brew README.md share/man/man1/brew
rm -rf ~/Library/Caches/Homebrew

Reinstalling Brew

All you have to do is fire this on your terminal

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Sit back and relax until Brew is fully installed. Once its done, remember to use "brew doctor" to make sure it said  the following


$ brew doctor
Your system is raring to brew.

and we are good to go!

Varnish Error 418 I’m a teapot

Recently i installed varnish into our cPanel server on my web hosting company in Malaysia. The installation is pretty straight forward and simple but the only issue here is that my main website is getting an 'error' text rather than showing me my varnish website.  If you inspect element, it will gives you Error 418 in its http headache with the error "I'm a teapot" which makes me a little irritated with it.

I was getting this error because my main website has a dedicated ip which is different from the rest of the account. This also means that my varnish configuration is a little different from all other account in it. But getting 'error' isn't what i was after. Normally one will just skip varnish entirely because it doesn't work. However,  you shouldn't be worry too much on it. Apparently the error was caused by varnish cached and if you plunge it, your website should be showing up fine. Below you can find purge command for varnish 3.0

sudo varnishadm "ban req.http.host ~ www.mydomain.com"

or

sudo varnishadm "ban req.http.host ~ /"

The only thing you might need to take note is the browser cache showing on your browser which might mislead you and makes you panic for a bit. If it still showing error 418, all you need to do is wait a little bit and it should show up nicely.

Get WordPress Custom Post Taxonomy Categories and Tags

Here's another problem with WordPress post where you want to know whether a particular custom post has a particular taxonomy categories or tags. In a normal post cast, you will highly likely used either get_categories or get_terms but for custom post type you might need to use another method which is what i am using currently as well. In order to determine whether a post category or tag is used by your custom post type, try the following

$terms = wp_get_object_terms($post->ID, 'review_category');

The first parameter is obviously the post id but the second parameter here is actually the custom post type taxonomy which you can find on your custom post type 'categories' section (on the url). Once you have determine your taxonomy name, getting post taxonomy categories or tags should be a piece of cake.

Check Whether a page is using WordPress Custom Taxonomy Category

Well, today i faced a little problem on checking whether a page displaying on WordPress site is using a custom taxonomy post type. I need to determine whether that particular page is using a custom taxonomy post type and that particular page is using a particular custom taxonomy post category as well. In this case, i search a bit but couldn't find this answer easily which resulted me to write this in the case i need this in the future as well.

In order to find whether a particular page is a custom taxonomy category type, we test with the following sentence

 if(is_single()){
          } else if(is_tax('reviews', $term = 'Games')){
            $args = array( 'post_type' => 'reviews', 'showposts' => 72, 'tax_query' => array(
		array(
			'taxonomy' => 'review_category',
			'field' => 'slug',
			'terms' => 'games'
		)
            ) );
          }else if(is_tax('reviews', $term = 'Apps')){
            $args = array( 'post_type' => 'reviews', 'showposts' => 72, 'tax_query' => array(
		array(
			'taxonomy' => 'review_category',
			'field' => 'slug',
			'terms' => 'apps'
		)
            ) );
          }else
            $args = array( 'post_type' => 'reviews', 'showposts' => 72);

My custom taxonomy is 'reviews' and i wanted to check whether a particular page is type 'Apps' or 'Games', this way i am able to determine whether the particular page is using a custom taxonomy category which is different from using is_category which check post category.