Friday, May 20, 2011

How to select pages from a PDF file/ split a PDF file using pdftk



Say I want to save only the first 31 pages to the new pdf:

pdftk A=orig.pdf  cat A1-31 output new001.pdf

Monday, May 16, 2011

How to copy/delete word under cursor in Vim


Assuming that the cursor is at the first character of the word simply do this in command mode:


yw


y is for yank and w is for word.

Other ways of doing the same thing which are not as efficient:


vey


the v starts visual select mode. e tells vim to move to end of word. y yanks or copies the word. to delete replace y with x.

if the cursor is somewhere in the middle of the word, add a b before the command as in:

byw



or


bvey

Software engineering models on Wikipedia

Starting some research on software engineering and did a bit of digging around on wikipedia:

Saturday, May 14, 2011

RUBYLIB and installing ruby to a custom directory

I needed to install ruby on my uni's lab machine without admin privileges.

To install ruby, I downloaded the version of ruby i needed from http://ftp.ruby-lang.org/pub/ruby/1.8/. And then do the following:


./configure --prefix=/path/to/dir
make
make install


Obviously, you should have read/write privileges to the directory /path/to/dir. Most of the time, it will probably be your home directory.

After much searching and tweaking later on, I also found that you have to set the RUBYLIB environment variable.

Assuming you're using Linux and bash, you do the following:


export RUBYLIB=/path/to/dir


What if you have a different installation of ruby, say the standard one on the same machine? Good question. I don't know the answer. :) If you do, please leave it in the comments.

Wednesday, May 11, 2011

How to rotate pages in a PDF document

I recently scanned quite a number of documents only to discover that every other page was rotated 180 degrees. (Let's just say that I learned my lesson and will be doing a test run before committing time to a task like that. :)

So I searched for a way to be able to selectively rotate pages in a PDF document. As always, I like command line tools that are open source.

Enter pdftk - The PDF toolkit.

To solve my particular problem, the command is:



pdftk input.pdf cat 1 2S 3 4S output output.pdf


Here's a brief explanation:

cat - assembles the pages mentioned
1 2S 3 4S - these are the pages needed. I couldn't find an easy way to say rotate only the even pages but still print out the odd pages, so I had to enumerate the pages
output - specifies the output filename

Monday, May 9, 2011

Floating point on bc, command line calculator

bc is a great commandline calculator on Linux and *nix like OSes. But the default setting on the Linux machine here at Tufts gives:

7/16 = 0

Obviously, this is not what I was looking for. After a little googling, I found the following.

Quoting from the bc online manual:

"There are two attributes of numbers, the length and the scale. The length is the total number of significant decimal digits in a number and the scale is the total number of decimal digits after the decimal point. For example, .000001 has a length of 6 and scale of 6, while 1935.000 has a length of 7 and a scale of 3."

To set the scale (say 4 digits), just type:

scale = 4