Monday, 3 September 2012

What life means to me


Life to me is....
a random variable where the element of uncertainty is  0.99

using Irrlicht 1.6 with Devcpp

here is the link to my solution which i posted
on the irrlicht forum itself

http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?p=213843#213843

Extremus Coder LCD Lib v1.0-- my lcd library which uses random pins and can be adapted to any compiler or any platform easily

/*******************************************************************
  EXTREMUS CODER LCD LIBRARY V 1.0
  USE RANDOM PINS
  CAN BE EASILY ADAPTED TO ANY COMPILER AND ANY MCU OR EVEN THE PARALLEL PORT FOR THAT MATTER
  THIS IS THE PART CONCERNING THE CONNECTIONS
 

  CONNECTIONS ARE E ,Rs, D4, D5, D6, D7
  DEFINE THEM AS SHOWN IE CHANGE THEM IN THE HEADER FILE "lcd.h" AS SHOWN BELOW


 '(
  For Eg:
  If E pin is connected to PORTC.0, then
  #define EPort PORTC
  #define E 0
  #define Edir DDRC
  ')

'(
 VERY IMPORTANT
 NOTE THE RW PIN IS NOT USED SO DONT DEFINE RW PIN CONNECTIONS
UNLESS ITS ALREADY CONNECTED AND U CAN'T UNDO THE CONNECTION
 
 LOOK FOR THE FOLLOWING FOUR LINES IN THE HEADER AND COMMENT THEM (//) IF THE RW PIN IS NOT CONNECTED
 WHICH SHOULD BE THE CASE IF U ARE MAKING UR OWN CONNECTIONS

 #define RwPort PORTB
#define Rw 1
#define Rwdir DDRB
#define RwExists 1

 ')

 THEN DEFINE THE NO OF ROWS AND COLUMNS OF UR LCD
 

  for eg if ur display is 20*4
  then
  #define displayRow 20
  #define displayColumns 4

BY DEFAULT THEY ARE 16 and 2
  AFTER THAT in ur program include the following files
  without which the program wont work
  FOR EG:
  //TEST PROGRAM FOR WINAVR (main.c)
--------------------------------------------------------------
  #include //winavr io for codevision it is #include and so on
  #include "lcd.h"
  #include "lcd.c"
  #include "printf.c"

  int main(void)
  {
 
  init_lcd(); //initialise the lcd
  lcdTest(); //prints EXTREMUS CODER LCD LIBRARY V1.0
  _delay_ms(3000);
  lcdClear();
 
  char* s="LCD_LIB";
  lcdGotoXY(0,0); //First line first character pos
  lcdPrintf("STRING:%s",s);
  lcdGotoXY(0,1); //SECOND line first character pos
  lcdPrintf("NO:%d, FLOAT:%f",1,1.23);
 


  }
--------------------------------------------------------------

 THE IMPORTANT FUNCTIONS ARE
void init_lcd(); //DONT START UR PROGRAM WITHOUT IT!!!!
void lcdPrintf(char *fmt, ...); //DITTO PRINTF FUNCTIONALITY U SHUD BE USING THIS THE MOST
void lcdGotoXY(int x, int y); // X STARTS FROM 0, Y STARTS FROM 0
void lcdClear(void);
void lcdToHome(void);
void lcdPrintSpaces(int no); //PRETTY NIFTY AI :)

//DONT THINK U WILL BE NEEDING THESE BUT ANYWAY
void lcdPutString(char* s);
void lcdPutInt(int a);
void lcdPutChar(char c);

//LOW LEVEL ROUTINES
void toggleE(void);
void writeByte(int val);
void writeToLcd(int val);



//CODEVISION DOESNT SEEM TO SUPPORT va_arg function for floating point
// so no floating point support for lcdprintf for codevision ie, in winavr it is working fine though




  DONT LOOK BEYOND THE CONNECTIONS PART IF U FEEL A BIT CONFUSED

ANY PROBLEM: MAIL DON'T PESTER AT knapshots@gmail.com

*******************************************************************/
Heres the link:

OPENCV 2.1 QT CREATOR INTEGRATION

Assuming u downloaded this setup 
and installed it successfully 
"OpenCV-2.1.0-win32-vs2008.exe" 

Let us assume for now that the installation directory is "C:\OpenCV2.1" 

To make ur current qt project or a new project "opencv" compatible :| 
here are the modifications or rather additions which are to be made to ur 
.pro file 

# INCLUDING HEADER PATHS AND LIBRARIES AND THEIR PATHS###

INCLUDEPATH
 +="C:\OpenCV2.1\include/opencv"


LIBS += -L"C:\OpenCV2.1/lib"


LIBS += -lcv210 -lcxcore210 -lhighgui210 -lcvaux210 -lcxts210 -lml210 -lopencv_ffmpeg210


# END OF HEADER INCLUDES AND LIB INCLUDES ### 


so, a sample complete .pro file would look like this.... 

#-------------------------------------------------
#
# Project created by QtCreator 2010-09-21T15:20:29
#
#-------------------------------------------------
QT       += core


QT       -= gui


INCLUDEPATH   +="C:\OpenCV2.1\include/opencv"




LIBS += -L"C:\OpenCV2.1/lib"
LIBS += -lcv210 -lcxcore210 -lhighgui210 -lcvaux210 -lcxts210 -lml210 -lopencv_ffmpeg210


TARGET = opencvTest


CONFIG   += console


CONFIG   -= app_bundle


TEMPLATE = app


SOURCES += main.cpp




heres a sample program as well to help u with it







##dont forget to include QDir,QDebug as well to ur existing app

## along with its existing defaults i.e. QCoreApplication if its  a console app

## etc....etc....

#include "cv.h"

#include "cxcore.h"

#include "highgui.h"

#include "stdio.h"



int main(int argc, char *argv[])

{     QCoreApplication a(argc, argv);

   IplImage* test=cvLoadImage("test.jpg",1);

    cvNamedWindow("test",CV_WINDOW_AUTOSIZE);      cvShowImage("test",test);

    float i=32.45;

   char* temp="amar";

   qDebug() <<   QDir::currentPath() << i <<temp;

    return a.exec();

}





a sample project will be added soon 

Thursday, 10 May 2012

entity framework one to many  editing quirks


while editing ur one to many thingy


dont forget this.. in this case the many thingy is theColumn... devs will get it...otherwise umm  the  collection isnt updated....there is no need for this in  case of  a similar operation when it comes to create though...whatever....


  if (ModelState.IsValid)
            {
             
                context.Entry(pseudosharepointview).State = EntityState.Modified;

                 ///important!!!!!!!!!achtung!!!!!!!!!!!!!!
                foreach (SharepointColumn theColumn in pseudosharepointview.SharepointColumns)
                {

                        context.Entry(theColumn).State = EntityState.Modified;
                       // context.SaveChanges(); noob operation :D
                 
                }

                context.SaveChanges();
                return RedirectToAction("Index");
            }

Saturday, 28 April 2012

my pointer friendly binary search tree ...has not been tested yet...i was too scared...:|


template <class T> class BinarySearchNode
{
   
   
public:   
   
   
    T* theNode;
 
    BinarySearchNode* theLesserNodePointer;

    
    BinarySearchNode* theGreaterNodePointer;
   

    BinarySearchNode(T* theContents)
    {
        if(theContents==NULL)
        {
            return;
        }
        theNode= new T();
        *theNode=theContents;
        //theLesserNodePointer= new BinarySearchNode();
        theLesserNodePointer->theNode=NULL;
        //theGreaterNodePointer= new BinarySearchNode();
        theGreaterNodePointer->theNode=NULL;
       
    }
};


template <class T> class BinarySearchTree
{
   
   
   
public:     
     
      BinarySearchNode<T>* theRootNode;
     

      BinarySearchTree(T* theRootNodeContents)
      {
         
           if(theRootNodeContents!=NULL)
               theRootNode= new BinarySearchNode<T>(theRootNodeContents);
         
         
         
      }
     
     
      BinarySearchNode<T>* findNode(T* theContents)
      {
     
          // gc is for sissies who are too scared to handle memory related stuff and all...
          //pointers rule...!!!!!!!
          // going the recursive way will give us
          //all stack related headaches and what not...blah blah blah
          //the logic is the same though...phoooey
         
          if(theContents==NULL || theRootNode==NULL)
          {
              return NULL; //:|
          }
         
           BinarySearchNode<T>* temp=theRootNode;
           T value=*theContents;
         
          if(*(temp->theNode)==theContents)
          {
             
              return temp; //we have a match sergeant
          }
         
          else if(*(temp->theNode)>value)
            {
               
                //to the left keep goin
                 
                  temp=temp->theLesserNodePointer;
               
                  while(temp!=NULL && *(temp->theNode)>value)
                  {
                     
                        temp=temp->theLesserNodePointer==NULL?NULL:temp->theLesserNodePointer;
                 
                  }
                 
                  //u reach the node where eventually temp shud be null
                   //or temp shud be the answer since it shud equal it right...
                   ///mmmmmmmmmmmmm now u get it
                    return temp;
                   
                   
            }
           
            else if(*(temp->theNode)<value)
            {
               
                //to the left keep goin
               
                  temp=temp->theGreaterNodePointer;
               
                  while(temp!=NULL && *(temp->theNode)<value)
                  {
                      
                        temp=temp->theGreaterNodePointer==NULL?NULL:temp->theGreaterNodePointer;
                 
                  }
                 
                  // what are u looking at....theres an explanation somewhere above
                  return temp;
                 
            }
         
       
         
          
      }
     
       
       void  insertNode(T* theContents)
      {
          //T shud implement comparison operators :|
         
          if(theContents==NULL)
          {
             
              return;
          }
         
         
         
           BinarySearchNode<T>* temp=theRootNode;
         
         
          if(temp==NULL)
          {
              //create a new root done
             
               this=BinarySearchTree(theContents);
             
          }

            BinarySearchNode<T>* previous=theRootNode;
           
            T value=*theContents;
           
            if(*(temp->theNode)>value)
            {
               
                //to the left keep goin
                   previous=temp;
                  temp=temp->theLesserNodePointer;
               
                  while(temp!=NULL && *(temp->theNode)>=value)
                  {
                        previous=temp;
                        temp=temp->theLesserNodePointer==NULL?NULL:temp->theLesserNodePointer;
                 
                  }
                 
                  //u reach the node where eventually temp shud be null
                   //and since the same is done for every node prior to this
                    //this shud be the only approachable case neglecting
                     //murky stuff which can happen unknown to u and me
                   
                   
                     temp= new BinarySearchNode<T>(theContents);
                   
                     temp->theGreaterNodePointer= new BinarySearchNode<T>(previous->theNode);
                     temp->theGreaterNodePointer->theLesserNodePointer=temp; //obs duhhhhhh
                  
            }
           
           
            else if(*(temp->theNode)<value)
            {
               
                //to the left keep goin
                   previous=temp;
                  temp=temp->theGreaterNodePointer;
               
                  while(temp!=NULL && *(temp->theNode)<value)
                  {
                        previous=temp;
                        temp=temp->theGreaterNodePointer==NULL?NULL:temp->theGreaterNodePointer;
                 
                  }
                 
                  //u reach the node where eventually temp shud be null
                   //and since the same is done for every node prior to this
                    //this shud be the only approachable case neglecting
                     //murky stuff which can happen unknown to u and me
                   
                   
                     temp= new BinarySearchNode<T>(theContents);
                   
                     temp->theLesserNodePointer= new BinarySearchNode<T>(previous->theNode);
                     temp->theLesserNodePointer->theGreaterNodePointer=temp; //obs duhhhhhh
                  
            }
         
           
           
         
      }
};



Thursday, 19 April 2012

the right way to construct a sql search query from a list of parameters

.....the right way to construct a sql  search query from a list of parameters...
//this is obviously a c# example but the pattern shud hold gud in general for any freakin language out there


public string constructASearchQuery(searchOperator[] theSearchOperators)
        {


            StringBuilder searchQuery = new StringBuilder(@"select somecolumn from" + "theTable");

            
            if (theSearchOperators != null)
            {

                bool firstCriterion = true;
                int index = 0;
                foreach (searchOperator theSearchCriterion in theSearchOperators)
                {

                    if (theSearchCriterion != null && !(string.IsNullOrEmpty(theSearchCriterion.Id)) && !(string.IsNullOrEmpty(theSearchCriterion.Value)) && !(string.IsNullOrEmpty(theSearchCriterion.OperatorExpression)))
                    {
                        if (firstCriterion)
                        {

                            searchQuery.Append(" where " + theSearchCriterion.Id + theSearchCriterion.OperatorExpression + "'" + theSearchCriterion.Value + "'");
                            firstCriterion = false;
                        }
                        else
                        {
                            searchQuery.Append(" and " + theSearchCriterion.Id + theSearchCriterion.OperatorExpression + "'" + theSearchCriterion.Value + "'");

                        }

                        index++;
                    }
                }




                //if (index > 0) //query constructed

            }
                  return searchQuery.ToString();

        }