Category Archives: 1

Who went viral ? The best viral videos website delivering most viewed internet videos.

I had a lot of time one beautiful Saturday morning and I started watching VIRAL VIDEOS. If you dont know what’s a viral video its a video on the internet that becomes very very popular and spreads on the internet like a Virus (you see the analogy). Soon I realized that its not easy to search for viral videos on YouTube. How do I view only the videos which are highly popular, Most Viewed, Most discussed, Most Responded ? I wanted to answer questions like:

What are the top viral videos of this month ? It can be the top music video or a comedy video or an Entertainment Video.
What are the top viral videos of the day ?
What is the most viewed comedy video of the day ?
Which music video has the most views in the US this week ?
What video in the Autos category has the most number of comments for the past month?
What is the most popular video on the internet of all times ?
What are the top 10 US comedy videos in the US for today ?

The site brings you the most viewed video content on the internet . The data and searching is based on youtube and It can retrieve the most viral videos given a region, category and time. Here is a screenshot of the webpage and you can check it out at www.whowentviral.com

Screenshot

Whowentviral

You see what I am getting at ? I did the application using HTTP REQUEST , YouTube API and an algorithm. You can check it out at Who went viral ? . http://www.whowentviral.com not only lets you view your selected content but also lets you watch it youtube style. YouTube ftw !! ūüôā ….. I would love to hear your feedback, comments and suggestions on it and appreciate your time. Hope you like it !!

Leave a comment

Filed under 1

But Why ?

These are the questions that I really want the answers of but for some reason either I cant ask the concerned authorities or it is really difficult to find the answer of :

1/ Why is it odd ?????????? (Yeah not everybody is gonna understand this question, If u dont move on and never mind ūüėČ )

2/ Why is not everyone created equal ?

3/ Why is Muhammad Yusuf the captain of Pakistan cricket team ? Why is Yunis Khan even selected ??

4/ What good is Asif Zardari for. Why cant anybody else be the president ?

5/ Why vegetables dont taste as good ?

6/ Why all the things that I like are so caloric ?

7/ Why do people hate BING with a passion ?

8/ Why do I hate everything (LOL) ??

9/ Why didnt I get my Mail in Rebate for the stupid*  Video Card I bought 5 months back ?

10/ Why cant I spend money :O ?

11/ Why are you still reading this post ?

I will keep adding as I get more and more…. Feel free to do so if u know the answers of any or want to add ur own issues …. Tata

3 Comments

Filed under 1

Creating a dynamic Array Generator Web Service using AXIS

I just happened to create a webservice and a client using ASIX for a web service class. As I know that in the environment it is difficult to get things to work and minor issues can halt the process. I am posting a simple Service, Client and my configurations just in case they are helpful to any one. In my environment TOMCAT is the web container and I compile it with AXIS jar files in my classpath, deploy.wsdd is used for deployment:
I use the variable %AXISCLASSPATH% which is set in my environment variables to following:

%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery-0.2.jar;%AXIS_LIB%\commons-logging-1.0.4.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\wsdl4j-1.5.1.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;

AXIS_LIB is set to: %AXIS_HOME%\lib
AXIS_HOME is set to : C:\axis-1_4

Step 1 is to code the service: In the given scenario the service expects an integer passed to it in the GetDynamicArrayOfRandomNumbers method and it will return an array with the number of elements equal to the number passed in. It will populate the array with random numbers.

import java.util.Random;

/**
 * @author Muhammad Asad Siddiqi
 * 06/13/2009
 *  This class is used as the web service and the .class has to be copied under Tomcat/axis/webapps
 *  deploy.wsdd has to be used for deployment
 */

public class DynamicArrayGeneratorService
{   
    /*
     * This is the remote method that would be called by the client
     */
    public int [] GetDynamicArrayOfRandomNumbers (int nArraySize) throws Exception
    {
        int []arrRandomNumbers = new int[nArraySize];
       
        for (int nCount=0; nCount < nArraySize; nCount++)
        {
            Random randomGenerator = new Random();
            arrRandomNumbers[nCount] = randomGenerator.nextInt((nCount * 4) + 10);           
        }
       
        return arrRandomNumbers;       
    }
}

Step 2: Compiling the service can be done by running the following commands from where your code is:

javac -classpath %AXISCLASSPATH% DynamicArrayGeneratorService.java

Step 3 is coding the client, I am copying and pasting the code for the client below:

import java.lang.*;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.net.URL;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;

/**
 *
 * @author Asad Siddiqi
 * Assignment # 2 Web services
 * This class is the client for the service running on localhost
 */
 
public class DynamicArrayGeneratorClient
 {
 public static void main(String args[])
 {
     try
  {
   int nSizeToReturn = 0;
   
   if ( args == null || args.length != 1 )
   {
¬†¬†¬†¬†System.out.println(“The client utility has to pass in the exactly 1 parameter [size of the array]”);
    System.exit(1);
   }
   
   nSizeToReturn = Integer.parseInt(args[0]);   

   // Create an instance of the service
          Service serArrayGenerator = new Service();
   
   // Create an instance of the Call to call the method
   Call call = (Call) serArrayGenerator.createCall();
   
   // Set the Address for connection
¬†¬†¬†call.setTargetEndpointAddress(new java.net.URL(“http://localhost:8080/axis/services/DynamicArrayGeneratorService“));
   
   // Specify the method to call
¬†¬†¬†call.setOperationName(“GetDynamicArrayOfRandomNumbers”);
   
   // Call the remote method
   int [] arrReturned = (int[]) call.invoke(new Object [] {new Integer(nSizeToReturn)});

   // Print the output

¬†¬†¬†System.out.println(“PRINTING THE NUMBERS RETURNED BY SERVICE :”);
¬†¬†¬†System.out.println(“——————————————“);
   
   for (int i = 0; i < arrReturned.length; i++)
   {
    System.out.println(arrReturned[i]);
   }
     }
     catch( Exception e )
  {
   // Error occured during processing
¬†¬†¬†System.out.println(“Error Occured during processing …”);
   e.printStackTrace();
     }
 }
};

Step 4: Compiling the Client can be done by executing the following command from the same directory as your client code:

javac -classpath %AXISCLASSPATH% DynamicArrayGeneratorClient.java

Step 5 : In your command prompt navigate to the directory where your deploy.wsdd file is located. Once you are in the right directory execute the following command:

java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

Step 6: The client can be executed by again changing the directory to where the .class files were generated for the client and executing the following command:

java -cp .;%AXISCLASSPATH% edu.jhu.webservices.Siddiqui.Asad.DynamicArrayGeneratorClient 20

I am also posting the contents of deploy.wsdd file:

<deployment name=”hw2″ xmlns=”http://xml.apache.org/axis/wsdd/
¬†¬†¬† xmlns:java=”http://xml.apache.org/axis/wsdd/providers/java“>

¬† <service name=”DynamicArrayGeneratorService” provider=”java:RPC”>
¬†¬†¬† <parameter name=”className” value=”DynamicArrayGeneratorService”/>
¬†¬†¬† <parameter name=”allowedMethods” value=”GetDynamicArrayOfRandomNumbers”/>
¬†¬†¬† <parameter name=”wsdlServicePort” value=”GetDynamicArrayOfRandomNumbers”/>
  </service>

  </deployment>

If you find it useful or I was able to help you out or you have a question, feel free to comment and I will make sure to reply. Being a .Net developer this was a real pain and it sucks, I just posted to help anyone in the same boat as me.

Leave a comment

Filed under 1

DOM and SAX Parsing using JAVA

I am not a very proficient java developer but I can find my way after spending some time. This might help save some time who is just like me and not a real pro at JAVA ūüôā . I am posting a sample XML and the parser to parse it in DOM and SAX using Java.

Here is the xml:

<?xml version=”1.0″?>
<!DOCTYPE Syllabus SYSTEM “Syllabus.dtd”>
<Syllabus xmlns:xsi=”http://www.w3.org/2001/XMLSchema” xsi:schemaLocation=”http://www.w3schools.com note.xsd”>
¬† <Lecture SerialNo=”1″>
    <Week>1</Week>
    <Date>Jun 3</Date>
    <Material>Sample Material</Material>
    <Reading>Sample Reading </Reading>
    <AssignedHW>Sample Text</AssignedHW>
    <DueHW></DueHW>
  </Lecture>
¬† <Lecture SerialNo=”2″>
    <Week>2</Week>
    <Date>Jun 10</Date>
    <Material>Some Text</Material>
    <Reading>Some Boring Text </Reading>
    <AssignedHW>HW2</AssignedHW>
    <DueHW>HW1</DueHW>
  </Lecture>
¬† <Lecture SerialNo=”3″>
    <Week>3</Week>
    <Date>Jun 17</Date>
    <Material>Some Lame material</Material>
    <Reading>Lame reading</Reading>
    <AssignedHW>HW4</AssignedHW>
    <DueHW>HW3</DueHW>
  </Lecture>
</Syllabus>

Here is the code:

import java.io.File;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

public class Parser
{   
   
    public Parser()
    {
    }   
   
    public void doDOMParsing(String strFileName)
    {
        try
        {           
            java.io.File file = new File(strFileName);
            DocumentBuilder builder =   DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(file);

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList nodes = doc.getElementsByTagName(“Lecture”);
            for (int i = 0; i < nodes.getLength(); i++)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“PARSED LECTURE DATA”);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“————-“);
               
                Element element = (Element) nodes.item(i);
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList weekData = element.getElementsByTagName(“Week”);
                Element line = (Element) weekData.item(0);               
                String strWeekData = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Week : ” + strWeekData);

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList dateData = element.getElementsByTagName(“Date”);
                line = (Element)dateData.item(0);
                String strDateDate = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Date : ” + strDateDate);
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList materialData = element.getElementsByTagName(“Material”);
                line = (Element)materialData.item(0);
                String strMaterial = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Material : ” + strMaterial);
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList readingData = element.getElementsByTagName(“Reading”);
                line = (Element)readingData.item(0);
                String strReading = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Reading : ” + strReading);
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList assignedHWData = element.getElementsByTagName(“AssignedHW”);
                line = (Element)assignedHWData.item(0);
                String strAssignedHW = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Assigned HomeWork : ” + strAssignedHW);
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† NodeList dueHWData = element.getElementsByTagName(“DueHW”);
                line = (Element)dueHWData.item(0);
                String strDueHW = getCharacterDataFromElement(line);
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Due HomeWork : ” + strDueHW);¬†¬†¬†¬†¬†¬†¬†¬†
               
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“——————————–“);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }     
    }   
   
    /* This is the helper function to get Element Data in DOM Parsing */
    private String getCharacterDataFromElement(Element e)
    {
        try
        {
            Node child = e.getFirstChild();
            if(child instanceof CharacterData)
            {
                CharacterData cd = (CharacterData) child;
                return cd.getData();
            }
 }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
       
¬†return “”;
    }
   
    /* This is the innerclass that inherits from Default Handler for SAX Parsing */
    class SAXHandler extends DefaultHandler
    {
        boolean bWeek = false;
        boolean bDate   = false;
        boolean bMaterial = false;
        boolean bReading = false;
        boolean bAssignedHW = false;
        boolean bDueHW = false;
       
        public void startElement(String nsURI, String strippedName,String tagName, Attributes attributes)      throws SAXException
        {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“Week”))
                bWeek = true;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“Date”))
                bDate = true;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“Material”))
                bMaterial = true;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“Reading”))
                bReading = true;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“AssignedHW”))
                bAssignedHW = true;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (tagName.equalsIgnoreCase(“DueHW”))
                bDueHW = true;
        }
       
   
        public void characters(char[] ch, int start, int length)
        {
            if (bWeek)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Week : ” + new String(ch, start, length));
                bWeek = false;
            }
            else if (bDate)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Date :¬† ” + new String(ch, start,length));
                bDate = false;
            }
            else if (bMaterial)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Material :¬† ” + new String(ch, start,length));
                bMaterial = false;
            } 
            else if (bReading)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Reading :¬† ” + new String(ch, start,length));
                bReading = false;
            } 
            else if (bAssignedHW)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Assigned Homework :¬† ” + new String(ch, start,length));
                bAssignedHW = false;
            } 
            else if (bDueHW)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Due Homework¬† :¬† ” + new String(ch, start,length));
                bDueHW = false;
            } 
        }
    }
   
    /* This is the entry point where SAX Parsing starts */
    public void doSAXParsing(String strFileName )
    {
        try
        {
            SAXParserFactory saxFactory = SAXParserFactory.newInstance();
            SAXParser saxParser = saxFactory.newSAXParser();   
            SAXHandler handler = new SAXHandler();
            saxParser.parse(new File(strFileName),handler);
       
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
   
    /* This is the driver function from where the DOM AND SAX parsing has to be called
¬†¬†¬†¬†¬†¬† The file name has to be passed in like “Syllabus.xml”
     */
    public static void main(String []args)
    {
        try
        {  
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† String strFileName = “..\\resources\\Syllabus.xml”;
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† String strParsingMode=””;
           
            if (args.length != 1)
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“The valid values of the parameter passed in are DOM and SAX. Press any key to continue:”);
                int a = System.in.read();           
                System.exit(0);
            }       
           
            Parser driverParser = new Parser();
           
            strParsingMode =  args[0];                   
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† if (strParsingMode.equalsIgnoreCase(“dom”))
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“DOM PARSING”);
                driverParser.doDOMParsing(strFileName);
            }
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† else if (strParsingMode.equalsIgnoreCase(“sax”))
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“SAX PARSING”);
                driverParser.doSAXParsing(strFileName);
            }
            else
            {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“The parsing mode can be DOM or SAX”);
                System.exit(0);
            }           
       
        }
        catch(Exception ex)
        {
¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† System.out.println(“Error Occured while processing”);
            ex.printStackTrace();
        }
       
    }
}

To me how SAX parsing is implemented using Inner classes was really interesting . I hope it helps someone looking for some help and finds it ūüôā

2 Comments

Filed under 1

An ExpressionTree in C++

I implemented an expression tree in Object Oriented Style and that was one of the homework i had for a class at school.I hated it a lot, but finally when completed I liked it a lot, ahhhhhh felt really like i have achieved something. By the way this is a good example of polymorphism and inheritence and the concept of virtual functions and abstract base classes (if you know what I mean ? ) Many of us do all this stuff in school and keep it to school. We never design types like that at work or someone else doesnt because we dont have the time to spend in design (at least nowhere i worked people had the time to design) but oh well !!

The logic is as Follows:

An Expression Tree consists of Nodes.Nodes can be of different types (Operators , Constants , Variables). All nodes can print themselves and allow their derivative to be taken which also is a expression tree . The derivative has to be taken with respect to a¬†variable and the expression tree can be evaluated by plugging in a value of the variable from a look up table or symbol table …¬†

I am posting the code (of the header file and the driver program)  just in case it interests anyone. Your comments and feedback is welcome and you can get a working copy of code if you want. Leave your email address as a comment and i will send you the copy. This is not finished as i did not implement the destructors but you will get the idea.

#include  <iostream>
#include  <map>
#include  <string>
#include  <math.h>
using  namespace  std;

/******************************************************************************************
Muhammad Asad Siddiqi
Making an Expression Tree Representation, given an expression
This files contains the prototype for following classes
-GenericNode
-VariableNode
-BinaryOperatorNode
– AdditionNode
– SubtractionNode
– MultiplicationNode
– DivisonNode
-UnaryOperatorNode
– NegateNode
– SineNode
– CosNode*******************************************************************************************/

 

class 

 PoorManSymbolTable {
private:
std::map<std::string,
double> symbolTable;
public:
PoorManSymbolTable();
void       InitializeSymbolTable();
double  getSymbolTableEntry(std::string symbol);
};

//——————————————————————————————// This class represents a Generic Node
class GenericNode
{
public:
GenericNode();
virtual double EvaluateNode() = 0;
virtual void     PrintExpression() = 0;
virtual GenericNode *Clone()= 0;
virtual GenericNode* TakeDerivative(std::string variable) = 0;
};
//—————————————————————————————–// This is the node that represents a constant like 15
class ConstantNode : public GenericNode
{
private:
double value;
public:
ConstantNode(
doubleconstant);
double EvaluateNode();
voidPrintExpression();
ConstantNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};

//————————————————————————————
// This node represents a Variable like ‘X’

class VariableNode : public GenericNode
{
private:
std::string symbol;
PoorManSymbolTable symbolTable;
public:
VariableNode(std::string variable);
double  EvaluateNode();
void       PrintExpression();
VariableNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};
 

//—————————————————————————————–// This is the node that represents a binary Operator ( + , – , * )

class BinaryOperatorNode : public GenericNode
{
protected:
GenericNode *left;
GenericNode *right;
public:
BinaryOperatorNode(v
oid);
BinaryOperatorNode(GenericNode *leftOperand , GenericNode *rightOperand);
GenericNode* TakeDerivative(std::string variable);
};

//—————————————————————————————–// This is the node that represents a unary Operator ( + , – , * )

class UnaryOperatorNode : public GenericNode
{
protected:
GenericNode *childNode;
public:
UnaryOperatorNode(
void);
GenericNode* TakeDerivative(std::string variable);
};

//—————————————————————————————–// This is the class that represents a + operator¬†

class

AdditionNode : public BinaryOperatorNode
{
public:
AdditionNode(GenericNode *leftOperand , GenericNode *rightOperand);
// realize the pure virtual function
double EvaluateNode();
void PrintExpression();
AdditionNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};

//—————————————————————————————–
// This is the class that represents a – operator

class SubtractionNode : public BinaryOperatorNode
{
public:
SubtractionNode(GenericNode *leftOperand , GenericNode *rightOperand);
// realize the pure virtual function
double EvaluateNode();
void PrintExpression();
SubtractionNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};

//—————————————————————————————–// This is the class that represents a * operator
class MultiplicationNode : public BinaryOperatorNode
{
public:
MultiplicationNode(GenericNode *leftOperand , GenericNode *rightOperand);
// realize the pure virtual function
double EvaluateNode();
void     PrintExpression();
MultiplicationNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};
//—————————————————————————————–// This is the class that represents a / operator
class DivisonNode : public BinaryOperatorNode
{
public:
DivisonNode(GenericNode *leftOperand , GenericNode *rightOperand);
// realize the pure virtual function
double EvaluateNode();
void      PrintExpression();
DivisonNode *Clone();
GenericNode* TakeDerivative(std::string variable);
};

//—————————————————————————————–// This would be used to negate a node
// Return a negative when evaluate is called

 

class NegateNode: public UnaryOperatorNode
{
public:
NegateNode(GenericNode *argChildNode);
double EvaluateNode();
NegateNode *Clone();
void PrintExpression();
GenericNode* TakeDerivative(std::string argSymbol);
};

// ————————————————————————————–
// This would be used to create a Sine Operator in the Expression Tree
// It is a unary operation and derivative is a cos Node
class SineNode : public UnaryOperatorNode
{
public:
SineNode(GenericNode *argChildNode);
double EvaluateNode();
void     PrintExpression();
SineNode *Clone();
GenericNode* TakeDerivative(std::string argSymbol);
};

//—————————————————————————————–// This would be used to create a Cos Operator in the Expression Tree// It is a unary operation and uses negation in derivative

class CosNode : public UnaryOperatorNode
{
public:
CosNode(GenericNode *argChildNode);
double EvaluateNode();
void      PrintExpression();
CosNode *Clone();
GenericNode* TakeDerivative(std::string argSymbol);
};

// The driver program

int

_tmain(int argc, _TCHAR* argv[])
{
GenericNode *objGenericNode , *cloneTest , *derivativeResult;
ConstantNode *var1 =
new ConstantNode(45);
ConstantNode *var2 =
new ConstantNode (25);
VariableNode *var3 =
new VariableNode(“Xray”);
VariableNode *var4 =
new VariableNode(“Yellow”);
objGenericNode =
new MultiplicationNode(new AdditionNode(var3,var4),new CosNode(var2));
cloneTest = objGenericNode->Clone();
cloneTest->PrintExpression();
cout << endl <<
“Printing Derivative of Expression Tree … “ << endl;
derivativeResult = cloneTest->TakeDerivative(
“Xray”);
derivativeResult->PrintExpression();
return 0;
}

Notely: This is not about parsing an expression by putting it on 2 stacks using Infix or Postfix notation . This is an implementation of an expression tree where the structure of the tree is known ūüôā . I could not post the implementation but would be provided on request .

3 Comments

Filed under 1

Where is the C++,C# and UML …

And for those of you thinking where are all the while loops and pointers and my keen .Net Tutorials and object oriented designing thoughts some stuff is coming soon enough , just busy with some projects and I will put the design here for your consideration. For right now though , the focus is on the stock market (Laugh out loud)

…. Take care

1 Comment

Filed under 1

How to generate WCF Client Proxy Class using svcutil.exe

I wanted to use wcf because I read about it and like the power and clean implementation which is highly configurable without a lot of effort. I have used and made many clients for web services using Visual Studio .Net and all it requires is to know where the web service is hosted. When you add a service reference and pass in a url where it is hosted (WSDL) the IDE generates a proxy class and WOW !! there you go… Call the methods in ur client, no fuss at all clean , nice and smooth. I was under the impression that WCF is esentially the same and support many other types of bindings like http,tcp blah blah ….. So i started developing the Kool WCF server client application. Little did I know about generating the client proxy class using svcutil.exe . I knew that you can generate proxy classes using svcutil.exe but that is a painful painful process. A little up and down and it gives you exceptions that are very easy to understand [ Devilish smile ] . So to save you the time and effort that you will have to put it to generate proxy classes I will show you the exact app.config file and how to use the svcutil. You can simply copy and paste it and be happy [just rename the Contracts , end point info according to your own and you are good to go] …

I have changed the font to BOLD whatever i was missing and was required by svcutil to generate the proxy class that I used.
Here is my app.config in the Hosting Application (server) from where the service would be run:

<?xml version=1.0 encoding=utf-8 ?>

<configuration>

  <system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior name=mex>

          <serviceDebug includeExceptionDetailInFaults=true />

          <serviceMetadata />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <services>

      <service name=WCFServiceLibrary1.service1 behaviorConfiguration =mex>

        <endpoint address=net.tcp://localhost:6587/Service1/

                  binding=netTcpBinding

                  bindingConfiguration=TestBinding

                  name=RoleEndPoint

                  contract=WCFServiceLibrary1.IService1 >

          <identity>

            <dns value=localhost />

          </identity>

        </endpoint>

        <endpoint

             address=mex

             binding=mexTcpBinding

             name=MEX

             contract=IMetadataExchange />

        <host>

          <baseAddresses>

            <add baseAddress=net.tcp://localhost:6587/Service1/ />

          </baseAddresses>

        </host>

      </service>

    </services> 

    <bindings>

      <netTcpBinding>

        <binding name=TestBinding maxBufferPoolSize=524288 maxReceivedMessageSize=65536 portSharingEnabled=false>

          <readerQuotas maxDepth=32 maxStringContentLength=8192 maxArrayLength=16384 maxBytesPerRead=4096 maxNameTableCharCount=16384 />

          <security mode=None />

        </binding>

      </netTcpBinding>

    </bindings> 

  </system.serviceModel>

</configuration>

Observe that there is an endpoint defined for metadata exchange called mex. This is used by the svcutil to generate the proxy class. The behavior node also contains a behavior named as mex. Now you are all set to use the svcutil.exe. Simply open the Visual Studio Command prompt from your startup menu à Visual Studio à tools and Command Prompt and type in the following command:

(Remember to replace the name to the service with yours as defined in the server configuration file)
Hope it helps and save you time and effort and I wish you don’t have to go through the pain of getting svcutil to work. Happy Coding !!

C:\Program Files\Microsoft Visual Studio 8\VC>svcutil.exe  net.tcp://localhost:6587/Service1/mex

This will generate two files service1.cs (proxy class for the client) and output.config (the app.config for the client). Enjoy !!

 

 

 

 

 

 

4 Comments

Filed under 1