Extract pages from PDF in Linux
I am not usually have to extract pages from a pdf file, but when I do, I used Adobe(R) Acrobat 7.0 that resides on my old Windows XP machine (believe me, it's still work at this time). Today one friend asked me to extract a page from his pdf file, and I only have my MAC and Linux workstation with me. Fortunately, I figured out I can just use a single command to do this. Kudos to pdftk. For example:
-
pdftk A=inputfile.pdf cat A1-10 output outputfile.pdf
This command will extract page 1 to 10 from inputfile.pdf to outputfile.pdf
Very handy. Happy extracting!
How to install rtorrent and rutorrent
In order for rutorrent to work, rtorrent must be compiled with xmlrpc-c support. Here is the full instruction.
1. First, check to make sure the following libraries are installed on your system. At any step below, if you cannot run ./configure script correctly, you might have to install -dev or -devel packages of these libraries
- gcc
- ncurses
- libsigc++-2.0
- libssl
- xmlrpc-c
- subversion
2. Download and install xmlrpc-c if your distro does not support it
-
svn co http://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/advanced xmlrpc-c
-
cd xmlrpc-c
-
./configure
-
make
-
make install
3. Download and install libtorrent and rtorrent
-
wget http://libtorrent.rakshasa.no/downloads/libtorrent-0.13.3.tar.gz
-
wget http://libtorrent.rakshasa.no/downloads/rtorrent-0.9.3.tar.gz
-
tar xzfv libtorrent-0.13.3.tar.gz
-
tar xzfv rtorrent-0.9.3.tar.gz
-
cd libtorrent-0.13.3
-
./configure
-
make
-
make install
-
cd ../rtorrent-0.9.3/
-
./configure --with-xmlrpc-c=/usr/local/bin/xmlrpc-c-config
-
make
-
make install
4. Execute this line to copy rtorrent config to your home directory
-
cp /usr/share/doc/rtorrent/examples/rtorrent.rc .rtorrent.rc
5. Add the following line to the end of your .rtorrent.rc
-
scgi_port = 127.0.0.1:5001
6. Create download and session directories as pointed out in .rtorrent.rc. You might also change these directory as desired.
7. Download, extract rutorrent and plugins and placed them anywhere under your web root so that you can access it via HTTP
-
wget http://rutorrent.googlecode.com/files/rutorrent-3.5.tar.gz
-
wget http://rutorrent.googlecode.com/files/plugins-3.5.tar.gz
-
tar -xf rutorrent-3.5.tar.gz
-
cd rutorrent
-
tar -xf ../plugins-3.5.tar.gz
-
cd ..
-
mv rutorrent /var/www/
8. Delete /var/www/ruttorrent/.htaccess to disable htaccess authentication (you can always enable it in the future)
9. Fire up your web browser and open http://yourdomain.com/rutorrent. You will see the GUI very similar to uTorrent.
Happy torrenting. Download responsibly.
How to disable comment box from Facebook like widget
It have been a long time since the last time I used Facebook like widget on my blog. At that time, I feel that Facebook scripts take a lot of time to load, hence slowdown my site and affect its performance. Today, I changed my mind and add it back. With just 2 pieces of code (one load all.js at bottom and one load the like button), Facebook like button appears again on my site. Sweet and simple!
But wait. When I test by click on Like button, an ugly comment box appear:
As this is unexpected, I want to disable it. But Facebook Developer page does not give me any information about this. Fortunately, with just one simple CSS trick, I can hide that ugly comment box so the Facebook like become beautiful (like it should)
-
.fb_edge_widget_with_comment span.fb_edge_comment_widget iframe.fb_ltr {
-
display: none !important;
-
}
Happy hacking!
How to find all files of a particular size in a particular directory
Last weekend, I worked on a Linux malware cleaning project. After 30 minutes of finding, I found 2 suspected scripts that are not included in Drupal by default. I soon realized that there are many of them, and I have a very limit access to his website (just normal account SSH access). Fortunately, after doing some research, I found that I can easily find all files of a particular size in his home directory. Simple like that: Suppose we want to find all files that has size = 1234 bytes and in /home/codepie directory, just type the following command
-
find /home/codepie -type f -size 1234c -exec ls {} \;
You might wonder what does 'c' in command mean. As units you can use:
- b – for 512-byte blocks (this is the default if no suffix is used)
- c – for bytes
- w – for two-byte words
- k – for Kilobytes (units of 1024 bytes)
- M – for Megabytes (units of 1048576 bytes)
- G – for Gigabytes (units of 1073741824 bytes)
Additionally, you can also search for bigger (+) or smaller (-) files. Just add a plus (+) or minus (-) for bigger and smaller files, respectively.
-
find /home/codepie -type f -size +1234c -exec ls {} \;
Have fun finding!
How to generate SSH public key from private key
Normally you will generate and store a pair of SSH public and private key. But do you know you can generate public key from private key with ease? Here is the trick:
1. For OpenSSH key: Open terminal and type:
-
ssh-keygen -y
2. For PuTTY key: Open PuttyGen program and choose Load key. Public key will show up.
Have fun.
How to format bytes to kilobytes, megabytes, gigabytes in PHP
This is the best function I found on StackOverflow:
-
function formatBytes($bytes, $precision = 2) {
-
-
-
// Uncomment one of the following alternatives
-
// If 1 kilobytes = 1024 bytes
-
// $bytes /= pow(1024, $pow);
-
// If 1 kilobytes = 1000 bytes
-
// $bytes /= (1 << (10 * $pow));
-
-
}
How to know exactly which Linux distribution you are using
I myself usually have to connect to a lot of Linux server to troubleshot. As you know, different Linux distribution has different config file location. For example, Apache config file in CentOS server is /etc/httpd/httpd.conf but in Ubuntu/Debian is /etc/apache2/apache2.conf
It would be easier for us if we know exactly the distribution name from the beginning. Here are several solutions:
1. From the boot time message
-
dmesg | head -1
You might see something like this:
-
Linux version 2.6.31-14-generic (buildd@crested) (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) ) #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009
2. Using /proc/version
-
cat /proc/version
You might see something like this:
-
Linux version 2.6.31-14-generic (buildd@crested) (gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu8) ) #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009
3. Using /etc/issue
-
cat /etc/issue
You might see something like this:
-
Debian GNU/Linux 6.0 \n \l
4. Using /etc/*-release
-
cat /etc/*-release
You might see something like this:
-
Gentoo Base System release 1.12.9
Disclaimer: The results are different because I'm using different machine when testing. have fun :)
CSS: How to add width and height attributes to anchor tag
You might face this problem sometimes: You want to add width and height to an anchor instead of giving these attributes to its container. Surprisingly, width and height attribute are not works. For example, consider the following codes:
-
a.ansok {
-
width:86px;
-
height:41px;
-
line-height:41px;
-
background-image: url(../images/layout/button.png);
-
}
-
And here is what you will get (instead of beautiful buttons):

So, what is the reason and how to fix it?
Well, anchor tags are not block level HTML elements but rather inline elements. So what is the difference between the two? Here is the definition of the two items:
Inline Element definition:
- Inline elements typically may only contain text and other inline elements. When rendered visually, inline elements do not usually begin on a new line.
Block Element:
- Block-level elements typically contain inline elements and other block-level elements. When rendered visually, block-level elements usually begin on a new line.
So, all you have to do is just add display:block to CSS class of anchor. And here is the result:

Some useful links:
How to install Ant correctly on Ubuntu
When using Ant the first time, you might notice that it return errors
-
ant -version
-
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar

Is it because of wrong jdk version? You probably tried to locate tools.jar and found this:
-
locate tools.jar
-
/usr/lib/jvm/java-6-sun-1.6.0.06/lib/tools.jar
Is it the same tools.jar required by ant? How can you point to this file so ant will not return any error? Here is the solution:
1. Make sure you have the "multiverse" repository
2. Install all Sun Java 6 packages
-
sudo apt-get clean
-
sudo apt-get update
-
sudo apt-get install sun-java6*
This process might take a while, so you might need to grab a cup of coffee and wait.
3. Check that you are using the newly installed jdk
-
javac -version
The output should be something like this:
-
javac 1.6.0_06
4. Check that you are using the correct jre
-
java -version
The output should be something like...
-
java version "1.6.0_06"
-
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
-
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
If you find you are not using the correct Sun Java 6 jre you can fix it by:
-
sudo update-alternatives --config java
The above command will let you choose which jre to make default if you have multiple jre installed.
How to make Cufon works in IE9
IE, and probably Microsoft, has a lot of surprises for you. As you know, each IE version has its own behavior. And don't surprise if IE9 does not render Cufón at all
Meaning that every beautiful things you see in Firefox, Chrome, ... will not even show up in IE9. Nothing. You will only see a blank space.

Then, how to fix it?
First, you need to download the latest version of Cufón. It's 1.09i, which has support for IE9. Download here
Second, add the following lines to your code:
-
<!--[if gte IE 9]>
-
<script type="text/javascript">
-
Cufon.set('engine', 'canvas');
-
</script>
-
<![endif]-->
And it works. Combination of the two method will give you a great look of your website in IE9.

Have fun.
