minigweek 40 Junior Poster in Training

Hi Folks,

The page on which my userscript will run has a namespace, the namespace defines a constructor function. I would like to create an object using the same constructor and use methods of the object in my userscript. So far I have been unsuccessful. Here's what I am trying to do.

The Page has the following native javascript block :

var namespace={ constructor : function(){
   this.sum = function(value1,value2){
   alert(value1+value2);
    }
  }
}

being used like:

var pageObject=new namespace.constructor();
pageObject.sum(1,2);

In My Userscript its my intention to create an object just like pageObject and call sum from that with my own parameters.

I have tried doing the following :

var greaseNameSpace = unsafeWindow.namespace;
var greaseObject = new greaseNameSpace.constructor();
greaseObject.sum(1,2);

No Luck, appears though greaseNameSpace exist, and even greaseNameSpace.constructor is a valid function , using new greaseNameSpace.constructor() yields undefined.

also tried following :

var greaseObject =new unsafeWindow.namespace.constructor();

again greaseObject remains undefined.

I found one thread here GreaseMonkey: How can I create an object of a class which defined in the remote page?

But it uses eval , and I wonder if thats the right way ?

Any and all help would be much appreciated :) thanks!!

minigweek 40 Junior Poster in Training

Yes javascript can accomplish this quite well.

minigweek 40 Junior Poster in Training

Thanks for answering that sknake,

Now I need to know if there's a down side to using Resource Hacker and adding them as unmanaged win32 resources ? 1 downside I can think off is that using the same resource hacker, people could get my resource files from inside the exe. hmm I need to read up more and more on assemblies and resource management. Its still unclear ...drat.

thanks much.

minigweek 40 Junior Poster in Training

Thanks Sknake,
That works

So there is no way of directly accessing the resources ? Like it can be done for embedded win32 resources. I use Resource Hacker to insert resources inside the exe and then use the "res://" protocol to access the resources from the html page. Is there a downside to doing this ?

I am wondering because, suppose my program runs from a read only environment, then extracting to a temp folder will fail.

minigweek 40 Junior Poster in Training

Its an interesting feature, hopefully it grows, but it looks to be dead as of now :( .

minigweek 40 Junior Poster in Training

Hi there folks,

I have Visual C# Project- Windows Application , It has a Webbrowser Control , and I intend to load a local HTML file with images into it.

I want to embed the embed the html file and image files as resources. So I did. While using the DocumentText property of the Webbrowser Control I am able to load the HTML resource in the webbrowser control , the Image obviously isn't showing up , as the HTML file had image source as the local file path.

What I am looking for is, how do I get the embedded image to show up in the webbrowser control , when it loads the HTML file?

I googled some , and quite a lot of folks are saying to use the "res://ApplicationName.exe/SomeImage.png" in the src attribute. But obviously this is incorrect and doesn't work.

Can you help ?
thanks
miniGweek

minigweek 40 Junior Poster in Training

1. There are many ways to "redirect" a page. The HttpWebRequest will follow redirection if the server issues a HTTP-301 Permanent Redirect or a HTTP-302 Temporary Redirect but it will not redirect when javascript inside of the page contains the logic for the redirect, as is the case here. The server assumes you have javascript enabled because you obviously had to run javascript to get the hash value to login, right? ;) Remember the HttpWebRequest is dumb. It follows HTTP codes and thats about it.

Right! :D .... I will be using the dumbness of httpwebrequest and get back to you later on how I am faring . Again! Much thanks for breaking it down.

minigweek 40 Junior Poster in Training

Hi Sknake , thanks for your time. Yes I am able to login to the forum , as using wireshark ( as you showed me!! ) I am able to find out the hidden fields they are posting to their forms. I can now see which inputs I need to get from the user ( me , the userid and pass ) .

I understand the CookieContainer is important to store the session cookie. Thanks for showing me its use.

I have some more queries and doubts which I have been trying to find out about.

1. I am logging into the forum my user id and password. Its writing the HTML code in a rich text box and later loading it into a webbrowser control shows me the "Thank you for logging in Thor" and "Click here if your browser does not automatically redirect you." . Because of the redirection script snippet in the html, the webbrowser is redirected to the next page. But as the Webbrowser doesn't show me logged in and I see the login user id and password field.

I understand this is happening because the Cookie is stored in the CookieContainer object of HttpWebRequest object. So i would need to find a way to use the same cookie in the webbrowser if I plan to use the form posting via httpwebrequest and webbrowser control simultaneously. I have been trying but to no success.

Ok why I am trying ? The …

minigweek 40 Junior Poster in Training

Agree with you 100% there Ron. Good Post, I liked.

minigweek 40 Junior Poster in Training

Close. But still it will give wrong output. I will drop a hint.

for(int i=0;i<=5;i++)
{
//something goes in here...
}
cout>>i;

guess what is the output of i ?

And similarly whats the value of ctr1 when it comes out of the 1st loop.

Is that the value you want ctr2 to be initialized to ? ;)

minigweek 40 Junior Poster in Training
for (ctr2=0;ctr2>=0;ctr2--)

Now what have you done here ? You are saying to the loop ...

Initialize ctrl2 to 0, decrement it by 1 every time, run the loop till its greater than or equal to 0 ........ ??? It will run the loop exactly 1ce!!

As everytime the the 2nd time loop is about to run it fails the condition ctrl2 >=0.

You need to think and code how to display an array in reverse.

Hint: wrong intitialization in this 2nd for loop.

minigweek 40 Junior Poster in Training
for (ctr2=0;num>=0;ctr2--)
    {
        cout<<bin[ctr2];
    }

fault in your for loop. its telling :
initialize ctrl2 to 0, decrement it every time by 1, run the loop till num>=0 .
So always num >=0 , as its unchanging in the loop. hence it runs for infinite.

minigweek 40 Junior Poster in Training

Update : Just installed wireshark, and was going thru its helppages to learn the filters. Its amazing tool ! oh wow!

Now I can see whts the url encoded text the login form submitted! So much intersting info!! :))

http://www.adamek.biz/md5-generator.php

allowed me to confirm that its a just plain md5 function, nothing fancy :) which is good.

I will keep exploring your code and learn stuffs. thnks again!! :) will keep you posted!

minigweek 40 Junior Poster in Training

Thanks Scott for the code. I am reading it now, will be trying to understand what happened here, and then come back and ask if I have any doubts! :)

minigweek 40 Junior Poster in Training
minigweek 40 Junior Poster in Training

Thats wonderful!! See how pleasurable it is to find out a solution on your own!! :D

Ok , now for another self discovery. Check the difference between long int and long double.

minigweek 40 Junior Poster in Training

Yes I see they are hashing the password using md5 hashing. I have opened their vbulletin_md5.js file and am attempting to call their md5hash function in an html file and check if their md5hashed result is same that as of one of the md5 hashed generated value from the C# programs I found online. If its the same I will try posting the hidden input field which stores their md5 hash value, instead of the password field. I think the password is sent to the md5hash function,which returns the md5 hash and then this md5 hash is being posted as a password to the login form. Looks like it will take some time to understand the md5hash function as it has 4 arguments and I am yet to make head or tails of it.

Sigh. thanks for dropping by. I will keep updated on my progress. Learning lots stuffs.

minigweek 40 Junior Poster in Training

Hello anyhelp folks ?

minigweek 40 Junior Poster in Training

Good thing you proposed a challenging project. You will learn much more this way and your knowledge base will increase considerably. Don't be bothered about "biting off more than you can chew" ... u will choke, and then you will swallow , with pain, and you will be the wiser for it.

There is a vast ocean of resource available online to teach you all about C++ graphics and multimedia. just google well and all shall be disclosed. For starters practice functions well and get to know arrays well. and then you should be 50% there. My Best wishes!

A Wonderful book on C++ is Bruce Eckel's Thinking in C++ , its free for download and will teach u all u need.

minigweek 40 Junior Poster in Training

What you have done is :
num *= num;
num--;

which will do the following :
1. if suppose you entered 3.
num *= num will giv num = 3*3 = 9
then num-- i.e, 2
then it will proceed like:
9*2

Wrong. It will never be 9 * 2 , it will be 8 * 8 , as num -- takes it to 8 and then in the next while loop its num = 8 * 8 again.

its always num * num in the code , hence a squaring will take place. 9 * 2 doesn't come into the picture.

Thanks for teaching me why i got always an infinity as an output.... Let me see... all i have to do is just subtract one from the number you inputed.... and not the solution.... but what id i swap the num-- to --num what will that do??

My pleasure. Ok , yes you will have to substract 1 from the number you input. But not before the multiplication. Note how it works :-
if Num = 5 , you are looking for a product of
5 x 4 x 3 x 2 x 1 right ? So first the product then the decrement.

changing num-- to -- num will not help.

Lets try to see how this works :-

5! = 5 x 4 x 3 x 2 x 1

Which is 1 …

minigweek 40 Junior Poster in Training

Ok lets do a dry run to see where you went wrong in the program.

Say num = 5

while num >= 1 ( 5 >=1 , hence true )
num = num * num , num becmes 25.
num = num -1 , num becomes 24

again while num > = 1 ( 24 > =1 , hence true )
num = num * num , num becmes 24 squared = 576
num = num - 1 , num = 575 now

and so now , so basically your variable num keeps increasing and the condition while num >= 1 is always true , and thus ur program takes num to infinity or maximum 16bit integer value.

I guess u are looking for something like 5! = 120 right ?

thats 5 x 4 x 3 x 2 x 1 . Hint : thats 5 multiplication , with each number 1 less. try some more, then we are here.

minigweek 40 Junior Poster in Training

Hi sknake ( i almost typed snake!! )

thanks for dropping by. I have various ideas floating around which I want to do. Like there's a news /technology and gadget section in the forum, I would like to have first 10 topic snippets in my application , and reading it can reply in 1/2 sentences using my app without loggin into the forum via browser.

Then there's this forum where latest upcoming novels description are posted, I would like to get snippets of novel description from there. and so on!! :)

I also need to understand how this works for another more serious reason too.
@ Work we use a tool for keeping track of various JVMs in servers , its web based tool which fetches data from the JVMs. I plan to develop a desktop client which can query that webserver and get few important data into my tool where I can do more analysis and set up alerts as per my requirement. And so many more stuffs. Basically I am trying to self improvise and come up with new ideas. Any help ? :)

minigweek 40 Junior Poster in Training

Hi,

I am working on building a C# Winforms application which will allow me to login to a forum or site and perform certain tasks. I am stuck at the very 1st step. I cannot login to the forum. Here is what I have tried so far,
the Login button has the following code :-

try
            {
                Uri uri = new Uri("http://www.thinkdigit.com/forum/login.php");
                string data = "vb_login_username=userid&vb_login_password=password";
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
                request.Method = WebRequestMethods.Http.Post;
                request.ContentLength = data.Length;
                request.ContentType = "application/x-www-form-urlencoded";
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(data);
                writer.Close();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string tmp = reader.ReadToEnd();
                response.Close();
                richTextBox1.AppendText(tmp);               
            }
            catch (Exception ex)
            {
                textBox3.Text = ex.ToString();
            }

Thats what I scrounged up after google busting and visiting so many forum posts. Unfortunately this does not seem to log me in the forum. I am checking the HTML generated content in t my richtextbox control and there's the login fields there still. Which means it didn't login.

I checked the login page.

and these are the contents there

<form name="loginfrm" id="loginfrm" action="login.php?do=login" method="post" onsubmit="md5hash_2(vb_login_password, vb_login_md5password, vb_login_md5password_utf, 0);">

<input type="text" class="bginput" style="font-size: 11px" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" onblur="myUnTip();" onmouseout="myUnTip();" onfocus="if (this.value == 'User Name') this.value = '';myTip();"   />

<input type="password" class="bginput" style="font-size: 11px" name="vb_login_password" id="navbar_password" size="10" tabindex="102" />

<input type="submit" class="button" value="Log in" tabindex="104" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" />
minigweek 40 Junior Poster in Training

Hi there,

I am also new to this kind of programming. Meaning trying to built a C# winforms application which will allow me to login to a site and fetch relevant data or post some queries/datas.

I Came to this section to post my question but found your answer. I did some investigation via google and have a solution as to how to login to the site you mentioned. I created an account there and now am able to login using the winforms application.

here is what you need

webBrowser1.Document.GetElementsByTagName("a")[11].InvokeMember("click");

it would work just fine!!
Basically the 12th tag is where the form submitt takes place, and InvokeMember method raised the onclick even for the button!! :) Happy days!! I will post my own question as a separate thread. Thanks to you I learnt a new stuff!!

minigweek 40 Junior Poster in Training

Hi all!!

I am planning on developing a Image Hosting service for fun!!

I have prelimenary knowledge of ASP.NET and am sure to learn loads of new stuffs in this process!!

Could you guide me on to how to go about doing this ?

Thanks and Regards!!

minigweek 40 Junior Poster in Training

^^ correct he is , just try to convert the above algorithm into a c++ code and see. Post your code if it fails, and we will further look into it!

minigweek 40 Junior Poster in Training

Hello,

first a tip.

TO check whether a number 'n' is prime or not, it is just enuff to check whether n is divisible by any integer from 2 to n/2 . no need to loop till n-1.
As you will observe, for say a number 24, obviously no number greater than 12 can divide it. And that is true for all integers.

next, your code snippe ::

for (int n = 3; n <= 100; n++)
		{
			for (int i = 2; n < i; ++i)
 	                {
                                newn = n % i;
				while(newn > 0)
				{ 
					cout << n << " ";	
				}
			}
		}

if changed to

int flag=1;
for (int n = 3; n <= 100; n++)
		{
			for (int i = 2;i<= n/2; ++i)
 	                {
                                newn = n % i;
                                if(newn==0)
                                {
                                   flag=0;
                                   break;
                                 }
				
		    }
                               if (flag==1)
                             {
                              cout<<" "<<n;
                              }
                              flag=1;
		}

The changes i made are ::
1. loop i from 2 till n/2
2. variable int flag.
-> set this to 1 at first , if none of the division gives a remainder 0, then it remains 1, meaning the number checked ( i ) is prime. else set it to 0 and break from inner loop.

it shud work.
regards

minigweek 40 Junior Poster in Training

Hello there,

I am currently trying to solve Towers of Hanoi for N pegs using C++.

I am implementing the towers in the form of a link list.

Suppose there be three towers , TowerA,TowerB,TowerC

Then for
TowerA: 3 2 1
TowerB: -
TowerC:-

shall become

TowerA:
TowerB: 3 2 1
TowerC:


I have taken a class called 'pole' , is

class pole
{
public:
int data;
pole *next;

pole()
{
data=999;
next=NULL;
}

/*And Some Methods*/
};

The Methods are as follows :
1. void add(int temp_data) ->
Adds a node to the list of nodes of Calling object with data=temp_data;

2. pole* pop() ->
Returns a pointer to the node popped. Meaning, last node of the calling object's list of nodes is removed and pointer to that node is returned.

3. void move1(pole *PoleB) ->
Removes the last node from Calling Object's list of nodes and adds the node to *PoleB 's list of nodes. This is to move 1 peg from Pole A to Pole B

4. void move2(pole *PoleB,pole *PoleC) ->
Moves top two nodes of Calling Object's list of nodes to *PoleB.

5. Display method to show the nodes.
-----------

Non member methods.
--------------------------
1. void move(pole *PoleA,pole *PoleB,pole *PoleC) ->

A recursive method. Moves all nodes from *PoleA to *PoleB.

if *PoleA has two …

minigweek 40 Junior Poster in Training

Waah! Two Bytes can't be added ! That's ODD!!! lol...

Does it mean that any mathematical operation between two bytes is impossible ? Why is it So :O :(

minigweek 40 Junior Poster in Training

I am absolutely new to C# , reading the Book , Beginning Visual C# 2005 ,byKarli Watsonet al. , Wrox Press . Using Visual Studio 2005 .

Okay , I was practicing some of the concepts from Functions chapter and i faced a wierd error.

This the code which is running OK now.

namespace Ch06Ex01
{
    class Program
    {
        static void Write()
        {
            Console.WriteLine("This is my first C# Function Code");
        }
        static sbyte AddTwo()
        {
            Console.WriteLine("Adding two numbers and returning the value");
            sbyte testNum = 2 + 5;
            return testNum;
        }
  
          static double AddTwoNum(double Num1,double Num2)
       {
            return Num1+Num2;
        }   
        static void Main(string[] args)
        {
            Write();
            Console.WriteLine("{0}",AddTwo());
            Console.WriteLine("Enter two numbers two be added by a test function :");
            double Num1,Num2;
            Num1 = Convert.ToDouble(Console.ReadLine());
            Num2 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("The Addtion of abive 2 numbers r = {0}", AddTwoNum(Num1,Num2)); 
            Console.ReadKey();
        }
    }
}

which is fine and dandy . But the problem crops in when in the function static double AddTwoNum(double Num1,double Num2) i use byte inplace of double .

static byte AddTwoNum(byte Num1,byte Num2)
        {
            return Num1+Num2;
        }   

// ..Same Code...
// ..Same Code...
            Byte Num1,Num2;
            Num1 = Convert.ToByte(Console.ReadLine());
            Num2 = Convert.ToByte(Console.ReadLine());
            Console.WriteLine("The Addtion of abive 2 numbers r = {0}", AddTwoNum(Num1,Num2));
//..Same Code..

The error is shown @ return Num1+Num2; , a blue curly wavy underlined , when cursor is brought, a message pops up

Cannot Implicitly convert type 'int' to 'byte'. An Explicit Conversion exists (Are you missing a cast ?)

WHY ? :( …

minigweek 40 Junior Poster in Training

Thanks Narue,
Thats a nice explanation I understood quite nicely.
But I will have to do some reading on my own, to get complete understanding of this.
Interesting explanation...

Bench, that was a helpful link , thank you too..

I will let you know here , if I get myself in a fix regarding this again..

minigweek 40 Junior Poster in Training

Ok, I am going through two articles at present ..
http://www.codeproject.com/cpp/PointerArticle.asp
http://www.geocities.com/varunhostel/TechnicalArticles/PointerArticle/PointerArticle_Part2.html

Lets C, if I can find anything, but in the mean time, any help will be really appreciated !
Thank you.

minigweek 40 Junior Poster in Training

char *(*c[10])(int **p);

Ok, what does the above mean ? I compiled it fine. But I can't figure what it means :(

Also, how to make sense of any such questions ? I know pointers, and have a concept of it. But this one really baffled me ! Can anyone tell me how to REALLY make sense of other questions of this kind ?

Thank you!
regards
MiniGWeek ( Back ! )

Rashakil Fol commented: Whats up! +8
minigweek 40 Junior Poster in Training

Yes.
Do you like leading a community ?

minigweek 40 Junior Poster in Training

I have watched hellsing, must say it was short,
I also heard that a season 2 may be coming up.
Anyways, I njoyed watching Bloodlust - Vampire Hunter D.
Another thing, discussion related to hentai allowed here ? :D

minigweek 40 Junior Poster in Training

lol
My dilemma is solved. here is why the above was not working for an input greater than 32768 .. because rand() is a pseudorandom number generator between the seed [ set by srand() or the default if u do nt use srand() ] and RAND_MAX . RAND_MAX is an integer constant defined in cstdib.
Its value is 32767. As a result all the nodes randomly generated , lied between 32678. it seems i need to define my own function usinf rand() such that for an input greater than 32768 , it caters to that.
Thank u all for dropping by :)

minigweek 40 Junior Poster in Training

Yes, that is indeed the case. For cin , white space is a terminator, and the rest of the name stays in the input stream. the next cin statement reads from the remaining input buffer.
cin.get , will help u read the name inclusive of white spaces.
for
char name[20];
use
cin.get(name,19);

now it should work lets us know here.

minigweek 40 Junior Poster in Training

I am using Code::Blocks editor, and the minigw compiler that comes along with it. ALso Just tested it with Visual CPP Express Edition 2005 , same problem.

minigweek 40 Junior Poster in Training

Hi Everyone, Good day to you all.
I am solving a problem : to Generate a Random Network. I hv divided the problem into two parts. First generate a Graph, then from the graph from a network.
Here the code generates a random graph.
User Gives n ->no. of nodes , and the prog. generates the graph with n nodes.
Constraints:
1. No Self Loop
2. Each node must have atleast 3 edges
3. Each node can have at max 7 edges.
-------------------------------------------------
Here is what the problem is. I have used int in all, as a result the program runs fine for an input ( n ) < 32768 . But I would like the program to run for input of an even larger number. For that i used the Replace all function of my IDE ( code::blocks) and replaced all int with long . Except the MAIN of course.
No Luck. Still the program goes into infinte loop for n>32768.
I Know why that happens, int resets to n when input is 32768+n .
So changing it to Long should have solved the problem. I thought so. :( :( :( :(
---------------------------------------------------
Now what the program does :
Struct adj -> The Adjacency List. Adj shall store the node number, and the number of edges node n has, and the address of next nodes.
struct nodes ->Stores the node number and the …

minigweek 40 Junior Poster in Training

Yes :)
Have you played Command and Conquer Tiberium Wars ?

minigweek 40 Junior Poster in Training

No.
U like playing Strategy Games ? ( AOE etc)

minigweek 40 Junior Poster in Training

My all time favourite wouldd be the LOTR Series.
The scene where Aragorn gets down on his knees and tells Frodo, "You My Friend, Shall Bow to no Men" was wonderfull....

I love Axn/Adventure/Sci-Fi/Romantic movies....
:PU missed the Romantic part in the Poll :P ....lol
Recently I watched really a different kind of movie.
Russian with Eng Dub
Nightwatch , Daywatch ( Nightwatch2) ... really a different kind of movie with a totally different take on the Good V/S Evil war .
Though given the choice I will not sit through these movies a second time, but there was something in these two flicks, which always pulled me towards their ending. These have a certain attraction to them.

But I hate Horror Flicks. Do not enjoi them even a little. :(
My frnds find it funny. What can i Say ? :(

minigweek 40 Junior Poster in Training

[:D]
Do you believe that if one has the will, the person can achieve any thing ?

minigweek 40 Junior Poster in Training

I just started watching D Gray Man.. onto episode 7 now...
Its a cool one, liking it.. anybody here njoid it ?

minigweek 40 Junior Poster in Training

No.
Is My Name cool ? :P

minigweek 40 Junior Poster in Training

No.
Do you think you will touch 4000 posts before June ?

minigweek 40 Junior Poster in Training

No.
Were you ever kissed by a stranger ?

minigweek 40 Junior Poster in Training

Yes.
Do you wish u had siblings ?

minigweek 40 Junior Poster in Training

Yes.
Do you have siblings ?

minigweek 40 Junior Poster in Training

I have no idea about web design. lol.
What kind of / Which Programming language can aid me sieve data of a webpage ?
I mean, suppose there is a WebPage X , if I want to select certain lines of it containing certain terms... how do I go about that ?
I have knowledge of C/C++.
Did I make my self clear enuff ?
Thanks for your help.
Regards
MiniGWeek.