About three years back, Siddharth Upmanyu found a way of getting invisible in Pidgin, which is demonstrated in my earlier blog post about Invisible Mode for Google Talk. The method is raw and simple, but looks geeky. Couple of days back, Nilesh Govindrajan looked upon the idea and came up with a way to get this done, right inside Kopete instant messenger. He has demonstrated the method at this blog post on iTech7. This method looks great to me, although i haven’t tried it myself.
If you people find any bugs or suggestions, do respond here. Also, i would like to see more people coming up with new ways of tweaking other popular messengers like Google Talk, Pidgin, Telepathy to provide a reliable and better invisible mechanism in Google Talk (XMPP) protocol.
Tag: C++
My journey to Python
It starts even before one can think. So, i was in my first semester of my Bachelor’s in Engineering and it was December of 2004. I was back at my home place, Jaipur for vacations. There i met my school friend Himanshu Bhojwani, who made some real cool robotics and other electronics gadgets and he showed me them. I was quite curious and asked him how did he do all that stuf. Technology and gadgets had always interested me. So, he told me about Parallel Port programming and about Visual Basic 6.0. He said that he did all this by connecting his electronics stuff to parallel port of his computer and use Visual Basic to get his stuff done. That evening while returning back home, i purchased Parallel Port Programming. My initial plan was to use C++ to do the programming part, but looking at the ease VB6.0 could make same programs in much less time, i decided to learn VB6.0. I also got a neighbor of mine, who was a Software Engineer at that time, to guide me out with VB. Well, as time went on, i forgot the Parallel port programming, and was making small applications in VB6.0. This language opened a complete new world for me. From C++ to VB 6.0.
It dates back to the Jan of 2006. I was a fourth semester student student at Bharati Vidyapeeth University, Pune and those were the days of college tech-fest, Bharatiyam. I was in the college technical team, softwares division, supervised by Hemant Sahni, who was technical head at that time. He is real good when it comes to application software development. I was initially working with the networking team, but when he found out that i had good VB skills, he asked me to help him, as he was using VB and SQL Server 2000 for this application he was designing. We were making a software to manage event scheduling, registrations, accounts and other details for the techfest. At the same time, another technical head of our University, Siddharth Upmanyu was working on a online c/c++ compiler. (Yea, the same which was hosted earlier on this blog). Somehow i was quite interested in this “online compiler” business. So, i went to him, and asked ‘Sir, how have you made this cool stuff?’. And he gave me a detailed information about the underlying architecture and flow, most of which bounced off my brains. So i went ahead with another question, ‘Which language you used to code all this stuff?’. ‘Perl’, came the reply. I had no clue there was a programming language “Perl”. What kind of a name is this, i was thinking. And then i said, “Perl?”. Judging my expressions, he said “its a language similar to python in some aspects”. And i was even more confused. How can anyone name a language as “Python”. Obviously i had no clue what Python was. But I decided not to make another fool of myself, so i said “Oh Python! Its a cool language” and hurried back home. LoL
After i came back, i did a quick Google for Perl and Python, and decided to learn one of the language. Perl looked a little complex to me, so i went on for Python, and haven’t looked back since then. I used Python for almost everything i had to do programatically!! I had always been in love with Python.
After graduation, I joined Harbinger-Systems, Pune and was working on ColdFusion MX7 and SQl Server 2000. I used Python for some small programs and bot, which helped me in my day to day job. After that i am currently working with Oxylabs Networks, where I am working in a language i love, Python 🙂
This is in short, my love story with Python, a tale of inspiration, aspiration and willingness.
A better feed reader
Most of the feed readers – web based, desktop based are more or less similar in their approach. You subscribe to a feed, and they will display all new (or non read) items. It is good. Now this is what a feed reader should do. Some feed readers (like Google reader) go beyond this and allow you to share your favorite feeds with your friends.What more does anyone needs?
Well, there are many more ways in which a feed reader can be enhanced. I wil be talking about the one that i find most useful.
Everything is not important
I am a feed junkie. I go to any website, and if i find anything interesting, i immediately subscribe to its feed. Months later, i realise that not all posts from that website is what i actually am interested in. Let’s take a scenario.Most people are subscribed to Slashdot or LifeHacker or Reddit. I am particularly interested in Programming and Technology. And specifically in Python, C++, WebApps. But what i am getting in my feeds is everything from FORTRAN to JAVA and from Microprocessors to launch of new space craft. This is useless information for me, and what i will be doing probably is – select all, mark as read. If i dont get a chance to read my feeds for a day or two, i will easilt have 1000+ posts and when bulk mark as read, i am probably going to miss out things that might be important for me.
Overcoming the situation
In my opinion, there is only one way to overcome the situation. Get the specific posts from the feeds, in which the reader is interested. So, if i am interested in Python and C++, i will be able to see and read only those feeds that have relevent information about Python and C++.
Again, there are two approaches to make this possible.
Approach 1) Let the reader speak for himself.
When a user is subscribing a new feed say “Programming”, suggest him – This is a very broad category. Would you like something in particular, say C++ or Python? If he says yes, go ahead and keep this thing in memory.
Aproach 2) Find out yourself.
In this approach, the user is initially presented with all the posts corresponding to a feed. A track record is kept for the feeds that the user has actually read and for those feeds for which he has just “marked as read”. Based on these data over a span of time, the system will be generating a set of keywords, which describe a range of interests for one particular user.
One or both of the above approaches can be used. What matters is that the set of keywords for the range of user’s interests in posts should be accurate. This is never guaranteed to be comprehensive, but should be somewhat near to it.
Now things are quite simple. We have the feed, we have the list of posts, and we have the user’s interest. For every post in the feed, scan it. See if it contains things that might interest user. Show him only those posts, that he is interested in. If the system is uncertain about a post, that can be under the “posts you might be interested in” section of the feed reader.
If implemented in this manner, i believe that feed readers can be more popular and good than the present ones.
If any engineer who is working on some feed reader is reading this post, and might consider it for their next release, i would be happy if they could contact me and say “Thanks” 🙂
Make this world a better place.
OnlineCompiler.org
OnlineCompiler.org is a completed online development environment for C/C++ in Linuc/Unix Style and built over the opensource WebDevStudio project.
The Castle Guard Problem
Problem Statement
We have a rectangular castle. The first floor is protected by some number of guards. We want to have at least one guard in each row and in each column. You are given a String[] castle. The j-th character of the i-th element of castle is either ‘.’ (free cell) or uppercase ‘X’ (guard). Return the smallest number of additional guards we have to place in the castle to achieve our goal.
Constraints
– castle will contain between 1 and 50 elements, inclusive.
– Each element of castle will contain between 1 and 50 characters, inclusive.
– All elements of castle will contain the same number of characters.
– Each character of each element of castle will be either ‘.’ or uppercase ‘X’.
Examples
0)
{ “….”,
“….”,
“….”,
“….” }
Returns: 4
Here we can place 4 guards on one of the diagonals and that will satisfy us.
1)
{ “XX…”,
“.XX..”,
“…XX” }
Returns: 0
No additional guards needed.
2)
{ “….XXXX”,
“……..”,
“XX.X.XX.”,
“……..”,
“……..” }
Returns: 3
3)
{ “……..X..”,
“…X…….”,
“………..”,
“..X…X….”,
“………..”,
“………..”,
“……..X..”,
“………..”,
“………..”,
“……..X..”,
“…..X…..” }
Returns: 6
This code has not yet been tested,
and hence it cannot be guaranteed that this code is a proper solution to the above problem.
Watch the space after some span of time and this will be done.
#include "iostream.h"
#include "conio.h"
char Map[50][50];
int maxE=0, maxC=0;
int scan(int X, int Y, char* dir){
int i=0;
if(dir == "horiz"){
for(i=0;i< maxC;i++){
if(Map[i][Y]=='X')
return 0;
}
return 1;
}
if(dir == "vert"){
for(i=0;i< maxE;i++){
if(Map[X][i]=='X')
return 0;
}
return 1;
}
}
int findShortage(int seedC, int seedE){
static int less=0;
int horiz, vert;
if(seedE > maxE){
return less;
}
horiz = scan(seedC,seedE,"horiz");
vert = scan(seedC,seedE,"vert");
if(horiz && !vert){
findShortage(seedC+1, seedE);
}
if(vert && !horiz){
findShortage(seedC,seedE+1);
}
if(horiz && vert ){
less++;
findShortage(seedC+1, seedC+1);
}
}
void main(void){
clrscr();
int i,j;
cout<>maxE;
cout<>maxC;
for(i=0;i< maxE;i++)
for(j=0;j< maxC;j++){
cout<<"Map["<< i <<"]["<< j <<"]";
cin>>Map[i][j];
}
cout<< findShortage(0,0);
getch();
}
Game development
This Programming Challenge requires you to read in a text file, process the contents of the file and output the results.
The file consists of 50 lines of text. Each line consists of 3 sections: First is 3 characters made up of spaces and digits that you can ignore, then 80 characters which are either a space or a + then another 2 characters. The first 3 and last 2 characters are just 1 or 2 digits line numbers padded with spaces. The important part is the 80 characters.
The file would look something like this…
File starts here:
1 1
27 ++++++++ ++++ +++++++ ++++++++++++ +++ 27
28 ++++++++ ++++ +++++++ ++++++++++++ + ++++ ++++++ 28
This is a map of a game world where each location is either land or sea.Land points are +, sea are spaces. What you have to do is process the 80 x 50 map, determine how many continents there are and output how many continents there are plus a list of those continents, together with the size of each continent. The definition of a continent is one or more connected locations where each location is a +. Connected means that in a 3 x 3 grid around a +, if any of the 8 surrounding locations contains a + then the two are connected.
the map file can be downloaded from this location.
I present the code for this problem as below.
/* C++ */
/*
author : pranav prakash
country : india
email : pranavprakash@programmer.net
*/
#include
char map[50][85];
int getMap(char*);
int scanContinent(int, int , int);
int findNext();
int getMap(char* mapfile){
fstream fl;
char v;
fl.open(mapfile, ios::in);
if(fl.bad() || fl.eof()){
return -1;
}
for(int i=0; i<50; i++){
for(int j=0; j<85; j++){
fl.read((char*)&v, sizeof(v));
map[i][j] = v;
}
}
return 1;
}
int findNext(){
int Xpos=0, Ypos=0, unit=0, i, j;
static int continent=1;
for(i=0; i<50; i++)
for(j=3; j<83; j++)
if(map[i][j] == '+'){
Xpos = i;
Ypos = j;
cout<<"\n\n--- Continent Number: "<< continent<<" ---";
//cout<<"\nXpos: "<< Xpos<<" Ypos: "<< Ypos<<"\n";
unit = scanContinent(Xpos, Ypos, continent++);
cout<<"\nNo. of units: "<< unit;
}
return 0; // No more continents left in the map;
}
int scanContinent(int seedX, int seedY, int continent){
static int count=0;
if(map[seedX][seedY] == '+'){
count++;
map[seedX][seedY] = continent;
scanContinent(seedX,seedY+1,continent);
scanContinent(seedX,seedY-1,continent);
scanContinent(seedX+1,seedY+1,continent);
scanContinent(seedX+1,seedY,continent);
scanContinent(seedX+1,seedY-1,continent);
scanContinent(seedX-1,seedY+1,continent);
scanContinent(seedX-1,seedY,continent);
scanContinent(seedX-1,seedY-1,continent);
}
return count;
}
void main(void){
if(getMap("map.txt")){
findNext();
}
}
The original problem statement can be viewed at this location.
This solution was actually selected as a correct solution and was in the top 20 codes. The actual content can be seen at this location.