Monday, July 27, 2009

MPD, a wonderful player.

MPD(media player daemon), though very classic, but indeed is one of the most versatile solution for linux guys and music lovers. Here I am going to describe how to get MPD up and running and using it...

Step 1:
Install mpd. (Ubuntu specific: sudo aptitude install mpd, Fedora specific: #yum install mpd)

Step 2:
Now its time to set it up for our requirements, open /etc/mpd.conf in your favorite editor and change the following lines, it takes me quite a while to get everything working...
music_directory "/media/Entertainment/Music"
playlist_directory "/media/Entertainment/Music"
db_file "/home/shamail/.mpd/db"
log_file "/home/shamail/.mpd/log.log"
error_file "/home/shamail/.mpd/errors.log"
pid_file "/home/shamail/.mpd/pid"
state_file "/home/shamail/.mpd/state"
user "shamail"

Replace the settings accordingly, and make a directory in home directory
$ mkdir ~/.mpd

User is very important as this line specifies the user MPD will run as, leave all the options as such.

Step 3:
Now run the mpd as, if successful, following output (or similar) should appear.
# /etc/init.d/mpd start
shamail@busybox:~$ sudo /etc/init.d/mpd start
* Starting Music Player Daemon mpd No "audio_output" defined in config file
Attempt to detect audio output device
Attempting to detect a alsa audio device
Successfully detected a alsa audio device

We now have our music server running, but no method to play... For that we need a client for mpd to play. There are tons of clients for mpd (http://mpd.wikia.com/wiki/Clients), the native client is called as mpc(media player client). To begin we will use this, then move to some very equipped and advanced clients that resembles whole music player and have even more functionalities)
Imagine multiple clients, one in sys tray showing song change notification, one at gnome panel displaying the song being played, other access from web to do all the music surfing and even a vim client to change the music while coding! All accessing one unified media queue powered by MPD.


Step 4:
Next step of ours is to install a client. Install mpc in the same way mpd was installed.
Step 5:
Now we need to add some music to the playlist, but what to?
$ mpc listall #list all the music in music dir.
$ mpc add #add file to the playlist
$ mpc listall | mpc add #add all music
$ mpc play|pause #play/pause/resume play
$ mpc stop #stop playing
$ mpc status #show current status
$ mpc volume 80|+1|-5 #increase/decrease volume.

This is conventional way to access mpd, while doing work on shell these comes handy though, but this ain't give media player benefits, for this install gnome-musicplayer-client (a very beautiful media player, backed by mpd) or Sonata (a fast light way to do things quickly) or both.
Then you can install music-panel to give you notifications and panel display of the playing tracks. This has a nice UI indeed.

(This is what music-panel comes at notification and quick control)

(Gnome Music Player Client)

For programmers and geeks install client for vim to change and navigate in songs while working!!
For web freaks you can additionally install one of web based client from 10s of available web clients.

Enjoy with it... :)

Tuesday, July 14, 2009

CP with progress bar...

We have seen a lot of scripts available that uses combination of cp and du etc to display progress, bet they are basic shell scripts that may not necessarily have all the functionalities of cp, and can even go crazy at times...
   Lets use rsync for this which is a very powerful and tested application available in GNU's GPL.

shamail@computer16:~$ touch RTest/{a,b,c,new}
shamail@computer16:~$ dd if=/dev/zero of=RTest/file.dd bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.076776 s, 273 MB/s
shamail@computer16:~$ rsync -r --progress RTest ./Copy/
sending incremental file list
RTest/a
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=4/6)
RTest/b
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=3/6)
RTest/c
           0 100%    0.00kB/s    0:00:00 (xfer#3, to-check=2/6)
RTest/file.dd
    20971520 100%   43.79MB/s    0:00:00 (xfer#4, to-check=1/6)
RTest/new
           0 100%    0.00kB/s    0:00:00 (xfer#5, to-check=0/6)

sent 20974372 bytes  received 108 bytes  41948960.00 bytes/sec
total size is 20971520  speedup is 1.00

Cool, isnt that?
You can alias cp='rsync --progress', and the sytanx will remain exactly same as that of cp, except that DO NOT put leading / in the source filenames... Even multiple files can be given.

Enjoy...

Wednesday, July 8, 2009

Delete all tables in MySQL

Sometimes we may encounter a problem to delete all tables in a database, where drop database cannot work because you may not have necessary rights to recreate a database.

The following command may work very well for that..

mysql -u username -p passwd database -e "show tables" | grep -v Tables | sed s/^/drop\ table\ if\ exists\ /g | sed s/$/\;/g | xargs -0 mysql -u username -p passwd database -e

Enjoy...

Thursday, July 2, 2009

Stay Charged

Well this post is the description of what i am currently working upon, http://staycharged.in, presently under development @ http://staycharged.co.cc

To begin, introduction...
   Stay charged is a service that one can use to stay recharged on there cell phones. User can get recharged by either logging onto the web portal or by sending an SMS to our service number.

Who can use staycharged?
   You, if you are a prepaid cell phone user and have a credit/debit card, every 10-15 days you need a recharge, staycharged provides a convenient facility of getting recharged just by sending one sms, Equivalent amount will be deducted from your account.

Benifts?
Of course.. Many
  • Ease, most important. Comfort of getting recharged just by sending an SMS and in case of emergency.
  • No extra charge, get 100 rs card @ 100 rs only.
  • Safe, we do not take cvv number from you(required for transaction), your password is CVV_num+3_digits_of_your_choice, and we use this number only at the time of transaction, and does not save them ever in our database.
  • Manage everthing in very simply designed interface on the web, including purchase of the card.
  • Feature of recharging other mobiles as well and gift coupons.
  • Supports most of the vendors and cards.

Use it once and you will start loving it... :) So say "hi" to staycharged.

Thursday, March 26, 2009

Making Gmail shortcut

Email addict? Tired of logging in each time and opening gmail.com again and again?
Try this simple trick..

Right Click on the gnome panel -> Add to Panel
Select Custom application launcher..

In the Create Launcher window, type Name as Gmail
Command:
firefox 'https://www.google.com/accounts/ServiceLoginAuth?
continue=http://mail.google.com/gmail&service=mail&Email=LOGIN&Passwd=PASSWORD&null=Sign+in'
Replace LOGIN and PASSWORD with your username and password.

Use whatever comment and icon you want. Or use this standard icon.

Whenever you'll click on this launcher, your gmail account will open in your default web browser.

Enjoy..

Monday, December 22, 2008

Linux to Hack...

Hi,
  Here is a trick to obtain friends IP and related info using very basic Linux tools...

#1) Open Google Talk or Yahoo(pidgin etc works). (Don't know about other protocols, but should work)

#2) Run this command: netstat -n
It will show something like..
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State     
tcp        0      1 192.168.1.2:44761       212.162.2.67:80         LAST_ACK  
tcp       38      0 192.168.1.2:48178       67.228.78.116:443       CLOSE_WAIT
tcp        0      1 192.168.1.2:44769       212.162.2.67:80         LAST_ACK  
tcp        0      1 192.168.1.2:48694       195.122.131.22:80       LAST_ACK  
tcp        0      1 192.168.1.2:44766       212.162.2.67:80         LAST_ACK  
:
:

Try to identify the port, yahoo uses pager port 5050 and google 5222/5223..
Also redirect the optput to some temp file,

$ netstat -n 2>&1 > /tmp/out1

Now the connections with Foreign Address with port 5050/5222 are the outgoing connection to yahoo/google server respectively.

Q: So where is friends IP?

A: HACK: Both yahoo and google uses P2P connection for client2client communication..
So, a similar connection will appear when you chat with them.
P.S if you are sure that your friend is using some Y! messenger < v7.0 then initiate a file request or a web cam request(though you dont have a webcam ;-)), its still P2P.
Case of failure: Friend is using a web client, such as gmail, morange etc. So until your friend is using a native messenger(including pidgin) you can use this trick to identify.
A certain more manipulations can help you identify whether your friend is invisible or not, using wireshark like tool and reading the packets directly prior to your chat client.

Open a chat window and send a hi, connection will establish. And rerun netstat as

$ netstat 2>&1 > /tmp/out2

Now perform a diff, as
$ diff /tmp/{out1,out2}

It will show you something like,
< tcp        0      0 192.168.1.2:36564       66.163.181.188:5050     TIME_WAIT 
>
...

This is the new connection that has taken place.

Now to know more about the ip, perform whois and traceroute as
$ whois 
66.163.181.188
# tells you operator info, area info, and provider info.. along with telephone numbers and all
$ traceroute
66.163.181.188
# tell you the route to the friend, you may then whois those hops to know about the path and physical route of the packets being sent.


:)

Wednesday, July 30, 2008

Sun Microsystems, The Campus Ambassador Program..

Writing after a long time, but anyways, its never too late... following post is about my experience at Bangluru in the Campus Ambassador Induction program.

    I am one of the lucky 100 Campus Ambassador for Sun Microsystems to get selected from India for the FY09. This time Sun Organized its three day induction program in Bangluru(M.S Ramalla Institute of Technology), Initially is was not filled with so much charm to go there and attend the program, but still, reached there well before and met Ankit on way itself, seldom you find sweet people like him, so polite to everyone. Throughout the time, this guy made us feel like "home away home", as we reached Orchid Inn, the place where we stayed, we started finding people like us, who came from all around India, and interacted with them. Its well said, "Every child is special", and to that i noticed that everyone has got something special in himself/herself, and that is why he/she was there to represent his/her college, community and most important himself/herself amongst the chosen ones.
   
    <joke>
       I am still not able to figure out why i was there ;-)
    </joke>


    Well, next day it all started. The time i reached there i met with Ganesh(for CA program, Asia Pacific region) and i was so glad that he recognized me on the first look itself. Actually previous year we at Jamia, New Delhi organized this program for the previous CA batch, and he came there as the mentor and i had interaction with him that time, but it was an year passed. Then the program began and my interest started developing with the energetic talk from Abhishek. Oh man! No terms to define this person. If i am asked to define him in one word.. "Cool"!!  Soon they introduced us with Sun Technologies, and i was like knowing all that before so was having fun and good understanding of it. The event organization was again "Cool". Slowly time goes on and we were like knowing each other better.
    Among the sessions, the most interesting session that seems to me was the last presentation that we've to give, so exciting and funny :) The hands-on sessions, mostly by Angad were superb, it gave a boost off and set a platform for all of us. Lately at the last day, it was MySQL workshop, and i unfortunately had to leave in the midst, because i had to rush for the flight.
    To conclude, it was a whole new exposure to technologies, people, resources in a great fun filled way, one thing that i appreciated is the work culture at Sun Microsystems. Finally a heartiest thanks to all of the Sun guys with a BIG simle :-)