Archive
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.
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;
Compress with RAR and split into multiple files
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/.
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:
Free HTML5 templates

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.
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 :)
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.
C-64 programming on PC
I found an interesting tutorial: Commodore 64 Programming #1: A quick start guide to C-64 assembly programming on Windows.
This is part of a series.
Screenshot and video information with mplayer
Let our test file be “/tmp/test.wmv“.
Getting video info
mplayer '/tmp/test.wmv' -ao null -vo null -frames 1 -identify
It will produce a long output. You can refine the output:
(mplayer '/tmp/test.wmv' -ao null -vo null -frames 1 -identify | grep ID_) 2>/dev/null
Again, it will produce a long output that I omit. The video length is here (given is sec.):
ID_LENGTH=119.93
Another interesting line is the video summary:
(mplayer '/tmp/test.wmv' -ao null -vo null -frames 1 -identify | grep 'VIDEO:') 2>/dev/null
Sample output:
VIDEO: [WMV3] 320x240 24bpp 1000.000 fps 386.0 kbps (47.1 kbyte/s)
Taking a screenshot at a given time
mplayer '/tmp/test.wmv' -ss '20' -noautosub -frames 1 -ao null -vo png:outdir='/tmp'
Here we take a screenshot from the video at 20 sec. The output file will be /tmp/00000001.png (mplayer gives this name automatically).
Ref.: I found these tricks in this project.
You must be logged in to post a comment.