Wednesday, July 18, 2012

Convert HTML to PDF using WKHTMLTOPDF


I was looking for solution to generate the PDF from dynamic HTML in last week. I was looking for easy way to generate the PDF without being affected with syntax and design.

While goggling I found the tool: WKHTMLTOPDF  

This tool is converting HTML (CSS support) to PDF the same way you save a PDF from browser.

Here are the steps to install and integrate the tool.

First, install the webkit library on your server.

$ wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.8.3-static.tar.bz2
$ tar -jxvf wkhtmltopdf-0.8.3-static.tar.bz2
$ sudo aptitude install ia32-libs

Make symbolic link to tool in /usr/local/bin

$ sudo ln -s /full_path/WKHTMLTOPDF /usr/local/bin/WKHTMLTOPDF

Now we are ready to useJ.

Now try the following command to convert the google page into PDF:

$ wkhtmltopdf http://www.google.com example1.pdf

There are many options where you can generate the different size/types of PDF like A4, A2 etc

Here are few examples:

$ wkhtmltopdf http://www.google.com examplea1.pdf -s A4

$ wkhtmltopdf http://www.google.com examplea2.pdf -s A2

Wednesday, July 11, 2012

Increase size of the file system in AWS


Assuming that you are using a linux AMI, in your case you have an easy method for increasing the size of the file system:

1) Stop the instance
2) Detach the root volume
3) Snapshot the volume
4) Create a new volume from the snapshot using the new size
5) Attach the new volume to the instance on the same place where the original one was
6) Start the instance, stop all services except ssh and set the root filesystem read only
7) Enlarge the filesystem (using resize2fs command) and/or the partition if needed
8) Reboot

As an alternative you can also launch a new instance and map the instance storage or you can create a new ami combining the two previous steps.

Install GD Library and ImageMagick on Linux server


Most scripting language is mostly used to manipulate and create image files in various different image formats including GIF, PNG, JPEG, etc. with the help of GD. Also scripting language can output image streams directly to a browser.

ImageMagick is an open source software suite for displaying, converting, and editing raster image files.

Following are the steps to install GD library:

Step 1: $ yum install php-gd
Step 2: $ yum install glib
Step 3: $ yum install glib2
Step 4: $ yum install libpng
Step 5: $ yum install libjpeg
Step 6: $ yum install libtiff
Step 7: $ yum install ghostscript
Step 8: $ yum install freetype


Following are the steps to install ImageMagick:

Note: Download ImageMagick.tar.gz from www.imagemagick.org or a mirrors and verify its message digest.

Step 1: $ tar xvfz ImageMagick.tar.gz
Step 2:
$ cd ImageMagick-[VERSION]
Step 3:
$./configure
Step 4:
$ make
Step 5:
$ sudo make install
Step 6:
$ sudo ldconfig /usr/local/lib

Great :) Now ImageMagick is installed on your server. 


You can verify the installation by following Commands:

$ /usr/local/bin/convert logo: logo.gif
$ make check

Tuesday, August 2, 2011

LEARNING TO LIVE WITHOUT RECOGNITION IS A SKILL - Horse & Pig Story


There was a farmer who collected horses; he only needed one more breed to complete his collection. One day, he found out that his neighbor had the particular horse breed he needed. So, he constantly bothered his neighbor until he sold it to him. A month later, the horse became ill and he called the veterinarian, who said: Well, your horse has a virus. He must take this medicine for three days. I'll come back on the 3rd day and if he's not better, we're going to have to put him down. Nearby, the pig listened closely to their conversation. The next day, they gave him the medicine and left. The pig approached the horse and said: Be strong, my friend. Get up or else they're going to put you to sleep! 
On the second day, they gave him the medicine and left.
 
The pig came back and said: Come on buddy, get up or else you're going to die! Come on, I'll help you get up. Let's go! One, two, three...

On the third day, they came to give him the medicine and the vet said: Unfortunately, we're going to have to put him down tomorrow. Otherwise, the
 virus might spread and infect the other horses. After they left, the pig approached the horse and said: Listen pal, it's now or never! Get up, come on! Have courage! Come on! Get up! Get up! That's it, slowly! Great! Come on, one, two, three... Good, good. Now faster, come on.... Fantastic! Run, run more! Yes! Yay! Yes! You did it, 
you're a champion!!!
 
All of a sudden, the owner came back, saw the horse running in the field and began shouting: It's a miracle! My horse is cured. This deserves a
 party. Let's kill the pig! 

Point for reflection: This often happens in the workplace. Nobody truly knows which employee actually deserves the merit of success, or who's actually contributing the necessary support to make things happen.

LEARNING TO LIVE WITHOUT RECOGNITION IS A SKILL 

If anyone ever tells you that your work is unprofessional, remember: amateurs built the Ark and professionals built the Titanic. 

Wednesday, July 27, 2011

Install phpmyadmin to operate MySQL from web

In my last post, we saw how to setup a LAMP on AWS. Let's have a look into how to install phpmyadmin on your linux server.

To install phpmyadmin to operate MySql from web browser, web server is needed.

Steps to install phpmyadmin:
1. yum -y install phpMyAdmin php-mysql php-mcrypt
2. vi /etc/httpd/conf.d/phpMyAdmin.conf
3. Add IP address you allow on line #14
Allow from 127.0.0.1
4. Close Editor
5. Reload the httpd process
/etc/rc.d/init.d/httpd reload

Once you are successfully run the above 6 steps, phpmyadmin is installed on your server.

Now we will see how we can access phpmyadmin.

Access to 'http://(your hostname or IP address)/(alias name you set)/' with web browser.
Alias name is by default 'phpmyadmin'.

When you enter above url on browser, it will ask you the login credentials for MySql user.
You can enter MySql user login credentials, can able to see phpmyadmin dashboard.

Wednesday, July 6, 2011

Getting started with Amazon EC2 and PHP – MySql

Do you know nothing about AWS or linux, but want to run PHP/MySql server set up on AWS? Are you new comer on AWS?
I was like you, relying on webhosting services to manage/configured on servers, so it was tough to work on AWS EC2 but later I feel it’s simpler.
In this tutorial I will show you how to setup PHP and MySql and how to make it web-accessible.

AWS:
Amazon has different products, but we are more interested in Amazon Elastic Compute Cloud (EC2).
Click on link and Sign up for Amazon EC2.
Once you have setup for EC2, go to AWS Console and click on Instance in left hand side panel.
You can see more details on Amazon documentation.
Now you create a Key Pair - this will be the credentials you will use to SSH.
Next is the Security Group - which will be used to specify the firewall used for your instance.
For now use the default Group and add port numbers as you want to open.
Now Elastic IP address — In the AWS Management Console, click on “Elastic IPs”, then “Allocate New Address” under “Addresses”. Once the address is created, click on it, then “Associate Address”. Select the instance and associate it.

You should now be able to SSH into your instance using your .pem file.
Now question is how do I access my instance? Couple of Software.
PuTTY.exe — Secure Shell client
PuTTYgen.exe — SSH public/private key generator
Putty available at your finger tip, For that you need http://www.putty.nl/download.html

Configuring the Linux Server:
We have got server up and running, now lets setup some packages.
I’ll show you how to set up PHP and MySQL on the server.

PHP:
sudo yum install php-mysql php php-xml php-mcrypt php-mbstring php-cli mysql httpd
Press ‘y’ for each of the prompts that show up. Note that you’re logged in as ec2-user, so you need to sudo all of these command (No need on fedora).
You should now be able to create and run a PHP sample file.

MySql:
Install MySql server.
sudo yum install mysql-server
Now start the mysql server
sudo /etc/init.d/mysqld start
Next, set the root password.
mysqladmin -u root password '[PASSWORD]'
Now we set up two users for MySQL: the administrator, which you’ll use to create and modify tables; and the app user, which the app will use to query the DB (with more limited privileges).
Log into MySQL as root (mysql -u root -p) for mysql prompt.
If you want to grant privileges for other server (MySql is not setup on same server)then type following command
GRANT ALL PRIVILEGES ON *.* TO root@'SCRIPTSERVERIPADDRESS' IDENTIFIED BY 'MYSQLUSERNAME' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Now you have PHP and MySql running on server, but cannot accessible though browser.

Make it web accessible:
Now we need to configure the web server.
To set up web server, we need to modify config file which is httpd.conf, located at /etc/httpd/conf/httpd.conf.
You can open this file using editor, I used vi.
Now go to bottom of the file, where there is a small section on the VirtualHost.
Add the following code in it.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot [your document root]
ServerName [your server name]
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

Note: If you are planning to run multiple sites on same server, you can add multiple virtual host section with document root and server name changes according to site.

Now restart the httpd process or server using following command.
sudo /etc/init.d/httpd restart


Using two Instances


It will be better to separate the web/script server and the DB server. For this, you will need to set up two Instances with two Elastic IPs, one of which has the web server httpd running, and the other of which has the mysql server mysqld running.
To make accessible on the web, instead of using “localhost” as the MySQL host, use the IP address of the MySQL instance. On the DB instance, set up your grant permissions (Given the query in MySql section) to allow db from anywhere.

Now you are done with setting up Amazon server and your server is loaded with PHP and MySql.
In upcoming blogs, I will introduce you with FTP server setup and phpmyadmin setup.

Monday, July 4, 2011

Time Management

Everyone wants to make the most of their time. You recognize that time is a unique and precious resource that you need in order to do your work, accomplish your goals, spend time with your loved ones, and enjoy everything that life has to offer.
Perhaps you have a heavy workload and want to find ways to become more effective so you can get more done in less time.
Maybe you feel overwhelmed or “stressed out” and want to find ways to do less and enjoy more. Or maybe you simply want to feel more focused and in control of your time, instead of feeling like you rush madly from one activity to the next until you fall into bed exhausted every night.
A Thought, “Do you love life? Then do not squander time, for that's the stuff that life is made of.”

What Exactly Is Time Management?

Time management is a set of principles, practices, skills, tools, and systems working together to help you get more value out of your time with the aim of improving the quality of your life.
The important point is that time management is not necessarily about getting lots of stuff done, because much more important than that is making sure that you are working on the right things, the things that truly need to be done.
Smart time managers know that there is much more to do than anyone could possibly accomplish. So instead of trying to do it all, smart time managers are very picky about how they spend their time.
They choose to focus and spend their time doing a few vital projects that will really make a difference, rather than spending all their time doing many trivial things that don't really matter all that much.
If you become a good time manager, you’ll not only get a lot more done in less time, but you’ll feel more relaxed, focused and in control of your life.
You’ll be able to use your time in a much more balanced and effective way and you’ll be able to make time for the people and activities that you love. When you get to the end of a busy day, you’ll feel a strong sense of accomplishment from everything that you actually got done.
Improving your time management skills can even help you get better results by doing less work, because you're focusing on the things that really matter rather than all the low-priority busywork that just keeps you busy.
If you don’t learn how to manage your time well, you’ll be far less productive than you could be and you’ll get a lot less done. You’ll also feel much more stressed and overwhelmed, and you’ll struggle to find time to spend with the people you care about and to do the things you enjoy.

Learning Time Management Skills

In the end, time management comes down to choices. Good choices lead to better results, while poor choices lead to wasted time and energy.
The good news is that time management skills can be learned and mastered by anyone. All it takes is practice and dedication.
Like any other skill, you can teach time management the easy way or you can learn it the hard way.
The hard way usually involves years of trial and error and lots of false starts trying to figure out what works and what doesn't.
If you'd like to save yourself some time, money and effort, I recommend you try the easy way: learn from someone who has already done it.

15 Time Management Tips

Here are 15 practical time management tips to help you get started...

1. Write things down
A common time management mistake is to try to use your memory to keep track of too many details leading to information overload. Using a to-do list to write things down is a great way to take control of your projects and tasks and keep you organized.

2. Prioritize your list
Prioritizing your to-do list helps you focus and spend more of your time on the things that really matter to you. Rate your tasks into categories using the ABCD prioritization system described in the time management course.

3. Plan your week
Spend some time at the beginning of each week to plan your schedule. Taking the extra time to do this will help increase your productivity and balance your important long-term projects with your more urgent tasks. All you need is fifteen to thirty minutes each week for your planning session.

4. Carry a notebook
You never know when you are going to have a great idea or brilliant insight. Carry a small notebook with you wherever you go so you can capture your thoughts. If you wait too long to write them down you could forget. Another option is to use a digital recorder.

5. Learn to say no
Many people become overloaded with too much work because they overcommitted; they say yes when they really should be saying no. Learn to say no to low priority requests and you will free up time to spend on things that are more important.

6. Think before acting
How many times have you said yes to something you later regretted? Before committing to a new task, stop to think about it before you give your answer. This will prevent you from taking on too much work.

7. Continuously improve yourself
Make time in your schedule to learn new things and develop your natural talents and abilities. For example, you could take a class, attend a training program, or read a book. Continuously improving your knowledge and skills increases your marketability, can help boost your career, and is the most reliable path to financial independence.

8. Think about what you are giving up to do your regular activities
It is a good idea to evaluate regularly how you are spending your time. In some cases, the best thing you can do is to stop doing an activity that is no longer serving you so you can spend the time doing something more valuable. Consider what you are giving up in order to maintain your current activities.

9. Use a time management system
Using a time management system can help you keep track of everything that you need to do, organize and prioritize your work, and develop sound plans to complete it.

10. Identify bad habits
Make a list of bad habits that are stealing your time, sabotaging your goals, and blocking your success. After you do, work on them one at a time and systematically eliminate them from your life. Remember that the easiest way to eliminate a bad habit, it to replace it with a better habit. In these days it’s a social networking addiction.

11. Don’t do other people’s work
Are you in the habit of doing other people’s work because of a ‘hero’ mentality? Doing this takes up time that you may not have. Instead, focus on your own projects and goals, learn to delegate effectively, and teach others how to do their own work.

12. Keep a goal journal
Schedule time to set and evaluate your goals. Start a journal and write down your progress for each goal. Go through your goal journal each week to make sure you are on the right track. Keeping a journal on your computer has never been easier!

13. Don’t be a perfectionist
Some tasks don’t require your best effort. Sending a short email to a colleague, for example, shouldn’t take any more than a few minutes. Learn to distinguish between tasks that deserve to be done excellently and tasks that just need to be done.

14. Beware of “filler” tasks
When you have a to-do list filled with important tasks, be careful not to get distracted by “filler” tasks. Things such as organizing your bookcase or filing papers can wait until you tackle the items that have the highest priority.

15. Avoid “efficiency traps”
Being efficient doesn’t necessarily mean that you are being productive. Avoid taking on tasks that you can do with efficiency that don’t need to be done at all. Just because you are busy and getting things done doesn’t mean you are actually accomplishing anything significant.

I have learned this stuff from my managers and from my past experience. Do share your thoughts here to make time more precious.