Archive

Archive for May, 2011

Reduce the size of a PDF file

Problem
You produce a PDF but it’s too big. How to reduce its size?

Solution

Make a much smaller PDF. Note that images will be quite ugly.

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

The PDF will be a bit smaller. Images remain in good quality.

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

For more possible values of PDFSETTINGS, see this page.

Ref.: here.

Categories: bash Tags: , , , ,

Some notes on MySQL

Log in to MySQL as administrator:

mysql -u root -p

Show databases:

mysql> show databases;

Show tables in the database mysql:

mysql> use mysql;
mysql> show tables;

Administration program for the mysqld daemon: mysqladmin.

Accessing phpmyadmin: http://localhost/phpmyadmin.

Another GUI administration program: mysql-admin (note the ‘-‘).

Create a database called “finance”:

$ mysqladmin -u root -p create finance

Create a user who can work on the previously created finance database:

mysql> GRANT select, insert, update, delete, create, drop, index, alter,
create temporary tables, lock tables
ON finance.*
TO 'myuser'@'localhost'
IDENTIFIED BY 'mypass';

Now we have a user called “myuser” with the password “mypass” who can work on the “finance” database from localhost only.

Log in with the newly created user:

$ mysql -u myuser -p
mysql> use finance;
mysql> show tables;
Categories: mysql Tags: ,

Compress with RAR and split into multiple files

May 27, 2011 2 comments

Problem

You have a large file that you want to send to a friend. One possible way is to upload it to your Dropbox folder and when he got it you remove it. If the file is too big, split it into multiple smaller files. If your friend uses Windows, you should compress the file with ZIP or RAR. Here I show you how to do it with RAR.

Solution

rar a -m5 -v10m myarchive movie.avi

It will compress movie.avi and split it into 10 MB chunks (-v10m), using the best compression ratio (-m5). In the case of an AVI file it won’t help much, so here you could use -m0 too, which means no compression at all. The default is -m3 by the way. Output: myarchive.part1.rar, myarchive.part2.rar, etc.

If you prefer the traditional names (myarchive.rar, myarchive.r00, myarchive.r01, …), add the -vn switch too.

Extraction:

rar x myarchive.part1.rar

Credits
This entry is based on this post: http://linux.byexamples.com/archives/226/compress-to-multiple-volume-rar/.

Categories: bash Tags: , , ,

Hadoop

MapReduce and Hadoop have been on my list for some time. I hope I will have some time soon to look at them in detail. Until then, here are some nice tutorials:

Categories: Uncategorized Tags: , ,

Free HTML5 templates

Free HTML5 Templates are just what they sound like: free web templates using valid HTML5 code. Some of the templates may also include CSS3 code as well, but those will be clearly tagged, and because CSS3 is still evolving and is highly dependent upon browser vendor implementations, the CSS may not always validate.

The goal, of course, is to help you use the newest, most modern template code available. As the HTML 5 standard evolves, we’ll evolve with it.

We license our free templates under the Creative Commons Attribution (by) 3.0, which put simply, means you can distribute, remix, tweak, and build upon our work, even commercially, as long as you credit us for the original creation.” (source)

The template portfolio is here.

Categories: web Tags: , ,

Something happened to my laptop keyboard. Or not?

Yesterday evening something strange happened to my laptop keyboard. Some keys on the right side stopped working correctly thus it became unusable.

I switched to console with CTRL+ALT+F1 but the problem remained. I rebooted the machine, it didn’t help. I booted to Windows but it was working fine there. Hmm, so the hardware is OK. But why is it not working under Ubuntu? This morning I switched it on hoping that a night rest might have solved the problem :), but no luck. I have a USB keyboard, so I could use the system with that, but what’s wrong with the original keyboard?

Then I found the problem… Num Lock was pressed by accident :))) Holy crap. I use Midnight Commander a lot and Num Lock is right next to Insert, so I must have pressed it by accident. Strangely, Num Lock remains on after switching off and on the computer.

The important thing is that my keyboard is fine and it works correctly again :)

Categories: ubuntu Tags: ,

randomize-lines

There is a useful command in the randomize-lines package namely “rl“. It reads lines from the standard input and shuffles them. It can also be used to pick a random line from a text file.

Let’s see some examples from the man:

Play a random sound after 4 minutes (perfect for toast):

sleep 240 ; play `find /sounds -name ´*.au´ -print | rl --count=1`

Play the 15 most recent .mp3 files in random order.

ls -c *.mp3 | head -n 15 | rl | xargs --delimiter=´\n´ play

Roll a dice:

seq 6 | rl --count 2

Roll a dice 1000 times and see which number comes up more often:

seq 6 | rl --reselect --count 1000 | sort | uniq -c | sort -n

Shuffle the words of a sentence:

echo -n "The rain in Spain stays mainly in the plain." \
| rl --delimiter=´ ´;echo

Find all movies and play them in random order.

find . -name ´*.avi´ -print0 | rl -0 | xargs -n 1 -0 mplayer

Because -0 is used filenames with spaces (even newlines and other unusual characters) in them work.

Categories: bash Tags: , ,
Follow

Get every new post delivered to your Inbox.

Join 73 other followers