Uncategorized

Setup EC2 for Production using Ubuntu

29 Apr , 2014  

Here is full guide how to setup EC2 for production using Ubuntu. I use server for hosting many frameworks stacks start from PHP, Ptyhon and Nodejs.

1. Install default development packages

1
sudo apt-get install git-core curl build-essential openssl libssl-dev pkg-config python-dev libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full unzip unace unp bzip2 gzip patch bind9 apache2 haproxy subversion git -y nmap libmysqlclient-dev libmysqlclient-dev libmysqlclient18

2. Install LAMPP

1
sudo apt-get install nginx php5-fpm php5-mysql mysql-server php5-mysql phpmyadmin apache2-threaded-dev php5-dev php-pear php5 libapache2-mod-wsgi

3. Setup Python and Django Environment

1
2
3
4
sudo apt-get install python-pip python-setuptools libjpeg-dev libjpeg8-dev libpng3  libfreetype6-dev imagemagick
sudo pip install virtualenv
sudo pip install virtualenvwrapper
mkvirtualenv --no-site-packages --distribute production

Edit ~/.bashrc

1
2
3
4
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME # Tell pip to create its virtualenvs in $WORKON_HOME.
export PIP_RESPECT_VIRTUALENV=true # Tell pip to automatically use the currently active virtualenv.

Install PIP

1
sudo pip install PIL  --allow-unverified PIL --allow-all-external

For virtualhost, for new Apache, make sure virtualhost have .conf extensions.

Server

Set EBS as root partition on EC2

29 Apr , 2014  

We can replace main partition in EC2 using EBS for larger space. Make sure to use HVM instead of Paravirtual.
First thing, we need to create a new EBS and attach it into running instance. Now, we should login into our SSH server.

1. Copy old instance into new instance
Find what your root partition and new ebs partition by “sudo fdisk -l”. At this example, mine is “/dev/xvda1” for current main partition and new ebs at “/dev/xvde”. So, i need to clone from current main partition into new ebs.

1
dd bs=65536 if=/dev/xvda1 of=/dev/xvde

2. Check new partition

1
2
3
sudo fsck /dev/xvde
sudo e2fsck -f /dev/xvde
sudo resize2fs /dev/xvde

3. Installing
We need to stop the instance, detach all ebs partition. Then re-attach new ebs partition into instance with mount point into “/dev/sda1”. Re-associate your elastic IP (if any) and start instance.

Android

Remove element object from List / ArrayList in Java

20 Apr , 2014  

Removing object / element in List / ArrayList in Java a bit tricky. For instance, if we have ArrayList(); then we can remove the element using :

1
listItem.remove(new Integer(index));

But this way not working for listItem contains objects. To remove, we should pass object itself.

1
listItem.remove(Object);

Android

Spinner white text color white background android solution

15 Apr , 2014  

Here is how to solve spinner showing white text color on white background. Make sure to use “this” or “getActivity()” in arrayAdapter.

Here is correct example :

1
2
3
4
 ArrayAdapter<String> adapterCity = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item, listCity);
            adapterCity.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mSpinCity.setAdapter(adapterCity);

Android

Solve action bar null pointer exception ActionBarImplICS notitle

15 Apr , 2014  

When we using actionbar appcompat, we should enable window title applications. But, it’s ugly to have window title in our apps. Here is the solution :

Update your Android SupportLibrary and use

1
2
3
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);

Android

Android SDK requires Android Developer Toolkit version 22.6.1 or above

3 Apr , 2014  

Here is solution to solve Eclipse have problem after updating Android SDK :
Android SDK requires Android Developer Toolkit version 22.6.1 or above

Capture

1. Go to Help -> Install New Software

2. Add https://dl-ssl.google.com/eclipse/plugin/4.2

3. Tick on Developer Tools

4. Install and Restart your ADT