Feeds:
Posts
Comments

Archive for the ‘My_Works’ Category

Atlast i came up with a real rhythmbox plugin for setting the status message in pidgin as the current song title playing in Rhythmbox music player .I wrote it a few month before and was using it. Thought of sharing it before but didnt get time. Actually i forgot about my blog when i started microblogging. From now onwards i will be updating this blog regularly.( this is what i wanted to do always 😀 )

Download the plugin from here : http://ragsagar.freehostia.com/rb-nowplaying.tar.gz
To install it.
1) Extract the tarball.
2) Copy it to ~/.gnome2/rhythmbox/plugins/ (if no such directories exists, create them)
3) Open rhythmbox. Edit -> Plugins
4) Check ‘Now Playing Pidgin’

That’s it. If you are facing any problems do comment.

Advertisements

Read Full Post »

Just thought of sharing the code i written to learn linked list implementation the day before my data structures model practical exam.

/*
 *      linkedlist.c
 *      
 *      Copyright 2009 Rag Sagar.V <ragsagar@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */


#include <stdio.h>
#include <stdlib.h>

typedef struct list
{
	int data;
	struct list *next;
}LIST;
LIST *ptr,*temp,*start=NULL;
void insert_after(int ,int );
void remove_item(int );
void display(void);
int count=0;
int main()
{
	int item,opt,dat;
	system("clear");
	ptr=NULL;
	/* printf("%d",sizeof(LIST)); */
	do
	{
		printf("\n########## MENU ##########\n");
		printf("1.Insert\n2.Remove\n3.Display\n4.Exit\n");
		printf("Enter your option : ");
		scanf("%d",&opt);
	 	switch(opt)
	 	{
	 		case 1:
	 		printf("Enter the data to insert ");
	 		scanf("%d",&item);
	 		if(count==0)
	 		{
	 			ptr = (LIST *)malloc(sizeof(LIST));
	 			ptr->next = NULL;
	 			ptr->data = item;
	 			start = ptr;
			}
			else
			{
				printf("Enter the item after which you have to insert new element : ");
				scanf("%d",&dat);
				insert_after(dat,item);
			}
			count++;
				break;
	 		case 2: 
	 		if(count==0)
	 		{
	 			printf("\nList is empty\n"); break; 
			}
	 		printf("Enter the item to remove : ");
	 		scanf("%d",&item);
	 		remove_item(item);
	 		count--;
	 		break;
	 		case 3: 
	 		if(count==0)
	 		{
	 			printf("\nList is empty\n");
	 			break;
	 		}
	 		else
	 		{
	 			printf("List elements are \n"); display(); 
			}
			break;
	 		case 4: break;
		}
	}while(opt!=4);
	return 0;
}
void insert_after(int data, int item)
{	
	LIST *tmp;
	temp=(LIST *)malloc(sizeof(LIST));
	temp->data=item;
	ptr=start;
	
	while(ptr!=NULL)
	{
		if(ptr->data==data)
		{
			tmp=ptr->next;
			ptr->next=temp;
			temp->next=tmp;
			break;
		}
	ptr=ptr->next;	
	}
		
}	

void remove_item(int item)
{
	ptr=start;
	if(ptr->data == item)
	{
		start = ptr->next;
		free(ptr);
	}
	while(ptr->next!=NULL)
	{
		if((ptr->next)->data==item)
		{
			temp=ptr->next;
			ptr->next=(ptr->next)->next;
			free(temp);
			break;
		}
		ptr=ptr->next;
	}
}
			
void display()
{
	ptr = start;
	while(ptr!=NULL)
	{
		printf("%d -> ",ptr->data);
		ptr=ptr->next;
	}
}			

Read Full Post »

Here is a script to provide weather information of a city with the help of google api.
#!/usr/bin/python
#Rag Sagar 
#Free to copy, modify and redistribute

import sys 
from urllib2 import urlopen, URLError
from xml.sax import make_parser
from xml.sax.handler import ContentHandler


class WeatherFinder(ContentHandler):
	"""the handler class"""
	def __init__(self):
		self.weather_list = []
		self.go_on = False
		
	def startElement(self, tag, attrs):
		"handles the opening tags"
		if tag == 'current_conditions':
			self.go_on = True
		if self.go_on : # so that only values inside current_conditions tag is appended
			if tag == 'condition' :
				self.weather_list.append('Condition: '+attrs.get('data',""))
			elif tag == 'humidity' :
				self.weather_list.append(attrs.get('data',""))			
			elif tag == 'temp_c' :
				self.weather_list.append('Temperature:'+attrs.get('data',"")+'C')
			elif tag == 'wind_condition' :
				self.weather_list.append(attrs.get('data',""))
		return
		
	def endElement(self, tag):
		"handles closing tags"
		if tag == 'current_conditions':
			self.go_on = False

if len(sys.argv) is not 2 :
	print "Syntax : ",sys.argv[0],"  \n"
	sys.exit(1)
else :
	city = sys.argv[1]
	url = 'http://www.google.com/ig/api?weather='+city
	parser = make_parser()
	obj = WeatherFinder()
	parser.setContentHandler(obj)
	try :
		parser.parse(urlopen(url))
	except URLError:
		print "\n\33[33m Unable to fetch data..\33[0m\n"
		sys.exit(1)
	if obj.weather_list == [] :
		print "\n\33[33m Invalid city name, Try another.. \33[0m\n "	
	else :
		print "\33[33mWeather Conditions of",city,"\33[36m"
		for i in obj.weather_list:
			print i	
		print "\33[0m"
		

Checkout its screenshot

Weather utility

Weather utility

Thanks to rohit

Read Full Post »

Here is small simple script in python to encode and decode string using base64.

~Happy Hacking

Click Here To Download the Script

Read Full Post »

Here is a simple search utility i wrote in python.it makes use of the modules os,os.path and re for the surfing through the filesystem and to match the files.The name of the file to find is given as an argument,ie

python search <filename_u_want_to_find>

It uses sys.argv to acces the arguments given.give ‘–help’ as an argument to display help.

python search –help

You can download the script from here

Read Full Post »

I was working with pygtk for fewdays.It is pretty interesting.Suddenly thoughts about making a calculator came into my mind.So i started working on it.GUI designing was pretty easy when compared to the calculation part. Finished the GUI part pretty fastly,but the calculation part really made my head at sixes and sevens :-o.Anyway soon i got a solution.In pygtk when a widget (eg button) is pressed it calls a particular function.For that we connects the signal emitted from the button with that function.So the calculation part should be in the function that is called when the operators(+,-,/,*) are pressed.The function that executed when the numbers are pressed just sends that number to the Text Entry widget (ie our calculator’s screen).Hope you got an idea abt the program! Any way it is well commented as far as i can.So there wont be much problems to understand the code.As the code is somewhat big iam not pasting it here..You can download it from here

Run it using this command :

python calculator.py

Here is its screenshot :-

pygtk_calculator

pygtk_calculator

Dont forget to drop your comments , thanks 🙂

Read Full Post »

Few days ago i wrote a script to update the status message in pidgin with the title of the song playing in audacious music player.It is written in python.it makes use of the dbus for the inter application communication.when you invoke that script it just appends the title of the song currently playing in audacious as the status message in pidgin .i used the shell command $watch to invoke it in every 30 seconds so that the status message gets updated with the songtitle within 30 seconds after the song change.You can reduce the number of seconds so that the status message gets updated frequently reducing the time delay between the song change and updation of status message.What the script does is, it retrieves the song title from the audacious music player using dbus.Then this songtitle is assigned as the status message in pidgin by communicating through dbus.This script needs dbus and py-dbus.So make sure that you have both packages installed in your system.

Here is the script :

def set_message(message):
# Get current status type (Available/Away/etc.)
current = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())
# Create new transient status and activate it
status = purple.PurpleSavedstatusNew(“”, current)
msg=”Now Playing: ”
emsg=msg+message
purple.PurpleSavedstatusSetMessage(status, emsg)
purple.PurpleSavedstatusActivate(status)

import dbus
session_bus=dbus.SessionBus()
proxy = session_bus.get_object(“im.pidgin.purple.PurpleService”, “/im/pidgin/purple/PurpleObject”)
purple = dbus.Interface(proxy, “im.pidgin.purple.PurpleInterface”)
proxy1 = session_bus.get_object(‘org.mpris.audacious’,’/TrackList’)
purple1 = dbus.Interface(proxy1,’org.freedesktop.MediaPlayer’)
ct = purple1.GetCurrentTrack()
proxy2 = session_bus.get_object(‘org.mpris.audacious’,’/org/atheme/audacious’)
purple2 = dbus.Interface(proxy2,’org.atheme.audacious’)
currentsong = purple2.SongTitle(ct)
print currentsong
set_message(currentsong)

Running this script will update the status message just once , so u have to shell command $watch as i said earlier.if you dont want to do this things manually, dont worry! i got package for this, grab it from here http://ragsagar.freehostia.com/pidgin-audacious_plugin.tar.gz , untar it and run the installer..

$wget http://ragsagar.freehostia.com/pidgin-audacious_plugin.tar.gz

$tar -xvf pidgin-audacious_plugin.tar.gz

$cd pidgin-audacious\ plugin/

$sudo chmod a+x installer

$./installer

Now run the script using this command :

$pidgin-plugin

PS: Make sure that you have both audacious and pidgin already running

Read Full Post »

%d bloggers like this: