node js on mac machine

Update Node and npm on mac OSX

How to completely remove Node and reinstall it

It might be a bit annoying to uninstall stuff. But sometimes you gotta do it.

To uninstall node completely from your machine:
brew uninstall --ignore-dependencies npm

This will handle the issue you may have with dependencies. If you have other modules like yarn or jhipster on your machine, they are dependent on node and uninstalling might not come easy.

To uninstall node in a more aggressive way:
rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

how to install node, npm (node package manager) on Mac OSX

It is rather simple. Just go to https://nodejs.org and download and follow the steps.

Screen Shot 2016-04-10 at 7.49.57 PM

install composer and make it globally accessible

Unless you have been living under rocks, you have heard about composer already. It is a dependency manager and more than that actually. If your PHP app is using a lot of dependencies, then it is time to consult composer.

Here I will put some notes on how to install it and make it available globally so that you can use it from any directory.

First thing first, go and grab the phar file from composer download page

It would be a single phar file and u can use that as it is:

composer.phar install

Of course you would need the composer.json file for the above to work where you would list the dependencies.

But, this would require you to call the phar from where you downloaded and that might not be handy

cd /to/composer/phar/file
sudo mv composer.phar /usr/local/bin/composer

Now, you can call composer from any directory and rock from there
get more @ get composer
That is how you install composer on linux/mac computer and make it globally accessible with in

Deploying Symfony app on micro instance of aws – Amazon EC2

The major issue you would face is memory. Yeah, the instance comes with small memory allocation and anything memory intensive task might not work there. Your composer install command might not do anything as well.

The major one would be Composer install just hangs and even aborts the process
When you are issuing

composer install

It will eat a bit of memory and doing it on the instance might not work as expected.

Here are the methods I used to overcome it.

1. Incremental install
On you composer.json file, you can try to list only one or two packages at a time and issue composer update vendor/package and if your individual packages are small enough you might get away with it. In my case this didn’t work

2. Ship your vendor from your local machine to the instance
yeah, just have all your composer install where you will be comforted by memory in Gigabytes and just zip and ship it to your instance.
On your local machine

tar -cf vendor.tar.gz /path/to/vendor/folder

Once you have the tar or zip of any of your favorite compressed file

scp -i /path/to/your/pem/file vendor.tar.gz ec2-user@ec2-domain-goes-here:/path/on/instance

This is assuming this will transfer your vendor file to instance.
Then log into your instance and just uncompress the file and put it on the root directory of your application.
This would be just the half of the work.
Then you will need to generate the bootstrap cache file

composer run-script post-update-cmd

yeah.. this will take care of creating the cache file of the bootstrap along with other stuffs that you put on your composer.json post-update-cmd part.
Sometimes you might want to give the write access to the app/cache and app/logs folders as well

ENjOY

pidora running out of space on SD card on raspberry

I was having a lot of problem using the debian version of raspberrypi. The problem was lots of dependencies when I was trying to install some packages.
So, I respectfully ditched raspbian and moved to the fedora flavor – pidora

I flashed the OS on it without any problem but I had a problem again when I try to load packages – this time, I am running out space.

Problem

Trying to install git gave me this error

Error downloading packages:
  1:perl-Error-0.17021-1.fc20.noarch: Insufficient space in download directory /var/cache/yum/arm/20/pidora/packages
    * free   0 
    * needed 31 k
  perl-Git-1.9.3-1.fc20.noarch: Insufficient space in download directory /var/cache/yum/arm/20/pidora-updates/packages
    * free   0 
    * needed 53 k
  perl-TermReadKey-2.30-20.fc20.armv6hl: Insufficient space in download directory /var/cache/yum/arm/20/pidora/packages
    * free   0 
    * needed 28 k
  git-1.9.3-1.fc20.armv6hl: Insufficient space in download directory /var/cache/yum/arm/20/pidora-updates/packages
    * free   0 
    * needed 4.2 M

Diagnosis

I was trying to communicate with the raspberrypi headless. And I noticed that the there are only two partitions being used allocated a little more than 2GB from all my 16GB secure disk.

df -h

Gave me the output of

Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.9G  1.8G     0 100% /
devtmpfs        218M     0  218M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  280K  218M   1% /run
tmpfs           218M     0  218M   0% /sys/fs/cgroup
tmpfs           218M  4.0K  218M   1% /tmp
/dev/mmcblk0p1   50M   23M   28M  45% /boot

As you can see the root is allocated only 2G and it is used of course.

Then I tried to see the partitions

fdisk -l

And that listed

Disk /dev/mmcblk0: 14.5 GiB, 15548284928 bytes, 30367744 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: **********

Device         Boot     Start       End  Blocks  Id System
/dev/mmcblk0p1 *         2048    104447   51200   c W95 FAT32 (LBA)
/dev/mmcblk0p2         104448   4233960 2064756+ 83 Linux

If you notice closely, the used partitions start with number 1. And on the top you will see there is another partition with the number 0. That is being unused.

Goal

To extend the partition size of the root using the unused space from /dev/mmcblk0

Process

This can be done in two different processes.
1. Take out the SD card put it in your other computer where you have partitioning software, like on ubuntu you can use gparted which is graphical and easy to use or on mac with disk utility
2. Use the old school fdisk and parted tools for partition
I am old school :)

fdisk /dev/mmcblk0

Hit p for printing the partition information:

Disk /dev/mmcblk0: 14.5 GiB, 15548284928 bytes, 30367744 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: **********

Device         Boot     Start       End  Blocks  Id System
/dev/mmcblk0p1 *         2048    104447   51200   c W95 FAT32 (LBA)
/dev/mmcblk0p2         104448   4233960 2064756+ 83 Linux

This will be the information we would be matching against later after the partition is done
Then use the parted tool

parted /dev/mmcblk0

This will provide

GNU Parted 3.1
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit chs                                                         
(parted) print                                                            
Model: SD SA16G (sd/mmc)
Disk /dev/mmcblk0: 1890,77,42
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1890,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start     End         Type     File system  Flags
 1      0,32,32   6,127,56    primary  fat16        boot, lba
 2      6,127,57  263,140,45  primary  ext4

Look the Disk /dev/mmcblk0: 1890,77,42 information. The ending point for the disk is at cylinder 1890 while partition two is at 263, the head is at 77 while that of partition 2 is at 140 and 42 vs 45 for the sector. Well, as you can see the limit is higher and we want to use the maximum that is using the Disk ending..

Now delete the partition

(parted) rm 2

Ignore the notice and press i

Now if you type ‘print’ you will see the listing without the partition 2

(parted) print                                                            
Model: SD SA16G (sd/mmc)
Disk /dev/mmcblk0: 1890,77,42
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1890,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start    End       Type     File system  Flags
 1      0,32,32  6,127,56  primary  fat16        boot, lba

Now the fun part Making the partition with larger size

(parted) mkpart primary 6,27,57 1890,77,42

This will allocate the space starting from the first partition to the end of the disk

hit print again

Model: SD SA16G (sd/mmc)
Disk /dev/mmcblk0: 1890,77,42
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 1890,255,63.  Each cylinder is 8225kB.
Partition Table: msdos
Disk Flags: 

Number  Start     End         Type     File system  Flags
 1      0,32,32   6,127,56    primary  fat16        boot, lba
 2      6,127,57  1890,77,42  primary  ext4

You can see the end information of partition 2 is we instructed it

Then reboot your raspberry

sudo reboot

Then ssh again

ssh root@[raspberrypi.ip.address.here]

Finally do the resizing for partition 2

resize2fs /dev/mmcblk0p2

Then check your bank

df -h

This has listed

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        15G  1.8G   12G  14% /
devtmpfs        218M     0  218M   0% /dev
tmpfs           218M     0  218M   0% /dev/shm
tmpfs           218M  280K  218M   1% /run
tmpfs           218M     0  218M   0% /sys/fs/cgroup
tmpfs           218M  4.0K  218M   1% /tmp
/dev/mmcblk0p1   50M   23M   28M  45% /boot

As you can see the available size of /dev/root has bumped to 12G!

ENjOY the pi!

installing macports

If you are a programmer/developer one thing you would face on date to date basis is handling packages.
Macports is a package manager for mac using that simplifying the installation of free/open softwares on you mac.
All how to install procedure is found on http://www.macports.org/install.php
After installing the macports don’t forget to update it

sudo port -v selfupdate

Installing Imagick for php using pecl

If you are dealing with CAPTCHA or some graphics stuff you have definitely come across with Imagick.. it is a nice library that you should check out..
to install.. it is much really easy with pecl
here is the step by step process to install it..

pecl download imagick
tar -zxvf imagick-VERSION.NUMBER.GOES.HERE.tgz
cd imagick-VERSION.NUMBER.GOES.HERE
phpize
./configure --with-imagick=/opt/local
make
make install

Then, on successful make, you will see the path where the “dot so” is saved..
go to you php.ini file and add

extension=imagick.so

then restart you apache and check if the imagic is available on phpinfo()..

DONe!