Saturday, 30 April 2011
Controlling Rhythmbox/banshee from shell
I wrote few alias to do so ...
Rhythmbox
alias pauseplay='dbus-send --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.playPause boolean:true'
alias next='dbus-send --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.next'
alias prev='dbus-send --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.previous'
alias incvolume='dbus-send --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.setVolumeRelative double:.1'
alias decvolume='dbus-send --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.setVolumeRelative double:-.1'
Banshee
alias pauseplay='dbus-send --type=method_call --dest=org.bansheeproject.Banshee /org/bansheeproject/Banshee/PlayerEngine org.bansheeproject.Banshee.PlayerEngine.TogglePlaying'
alias next='dbus-send --type=method_call --dest=org.bansheeproject.Banshee /org/bansheeproject/Banshee/PlaybackController org.bansheeproject.Banshee.PlaybackController.Next boolean:false'
alias prev='dbus-send --type=method_call --dest=org.bansheeproject.Banshee /org/bansheeproject/Banshee/PlaybackController org.bansheeproject.Banshee.PlaybackController.Previous boolean:false'
Place these alias in your .bashrc or .bash_aliases file. Now you can control rhythmbox from shell like
pauseplay - play or pause rhythmbox Music player
next - next track
prev - previous track
incvolume - increase volume
decvolume - decrease volume
Change the alias for your convenience ...
Thursday, 28 April 2011
Odd or Even number
Tuesday, 26 April 2011
Puzzle 1 : Survivor Problem
Solution
For various N, survivor number obtained is given below,
1 -> 1 | 2 -> 1 | 4 -> 1 | 8 -> 1 |
3 -> 3 | 5 -> 3 | ||
6 -> 5 | |||
7 -> 7 |
It is apparent from above pattern that when N is power of 2, Survivor is 1. Otherwise we have to add 2 to every number away from power of 2.
Method 1(Using Recursion):
- Let Survivor number be 1
- Until N is power of 2
- Subtract N by 1
- Add 2 to Survivor number
Method 2:
- If N is power of 2, return 1
- Find next lower power of 2 wrt to N
- Find difference between N and result from step 2. Double and add 1
Thursday, 21 April 2011
Convert: The Image Conversion Tool
Many times command line tools are so cool and able than a GUI. I got to know about such a command line image conversion tool. It helped me complete my work so fast and efficient than many GUIs.
This tool does not come by default in ubuntu 10.10. You need to install imagemagick.
sudo apt-get install imagemagick
Giving you glimpse of what this amazing tool can do ... This is just a tip of the iceberg. You can do much much more using this ...
Convert an Image from one Format to another (You can give any image format you know)
$ convert a.jpg b.png
$ convert a.bmp c.jpg
To convert all files in folder
$ convert *.jpg -set filename:name '%t' '%[filename:name].png'
To convert all files in a folder and rename it as per your prefix
$ convert *.jpg mynameprefix.png'
To create a gif animation from the image files you have
$ convert *.jpg mygif.gif
To add a pause between transition in a gif image
$ convert *.jpg -delay 100 mygif.gif
To resize an image
$ convert myimg.jpg -resize 50% myimgsmall.jpg
$ convert myimg.jpg -resize 120x120 mythumbnail.jpg
- To resize the image to pixel of 120 x 120 (width x height) image
To add images to a pdf
$ convert *.jpg photos.pdf
Sometimes the image size will be too big but you can reduce it by reducing the quality(You may not be able to perceive it in computer screen)
$ convert img.jpg -quality 75 new_img.jpg
$ convert *.jpg -quality 75 mynameprefix.jpg
- To convert all the jpg files and rename it to required prefix followed by sequential number
$ convert *.jpg -quality 75 -set filename:name '%t' '%[filename:name].jpg'
- To lower the quality without changing their name.To Add string to your file at a given location (0,0 denotes top left)
$ convert myimg.jpg -draw 'text 100,200 “MY STRING”' mynewimg.jpg
$ convert myimg.jpg -pointsize 20 -draw 'scale 1.5,1.5 text 100,200 “MY STRING”' mynewimg.jpg
- This makes font size 20
$ convert *.JPG -set filename:name '%t' -pointsize 36 -draw 'text 500,200 "COOL STUFF"' '%[filename:name].JPG'
To make an image black and white
$ convert myimg.jpg -colorspace gray myblack.jpg
$ convert myimg.jpg -charcoal 5 myfun.jpg
- It converts an image to pencil sketch the number indicates the thickness of line
For Further hacks refer to