Egit merge

Today I made my first git merge, using EGit(an Eclipse plugin), I had to read a lot of documentation about egit, fix some conflicts and finaly commit the fixes. In the end all worked ok,not great  I am not sure I like how the conflict resolving works.

Accessing the ItemRenderer in a Flex spark DataGrid

I did not found a way to do this with the spark DataGrid, only with the mx one, the developers encapsulated very well the renderers. Because Flex is open source I read the code and finaly found a way to access the renderers. I could not use bindings in my case and I did not had other idea at that moment and because the renderers are very optimized it is hard to make them refresh.

 

 

Java Yahoo messenger robot/bot

I made a application in Java to act as a simple yahoo messenger client and that can be used from scripts like bash or php. I am using openYMSG, the problem is the documentation, you have only the javadoc no examples, i think that Qt is the best documented software that i ever used. Alos C# is well documented on MSDN,Stack Overflow and . You search stuff for c or c++ and you get the answer for C#.

I am now searchibg for a way to find out who is invisible on yahoo

My first scala steps

2Disclaimer(this is not a tutorial or how to, i am a newb to scala and i recod my thoughts)

I was reading about scala for a time now and yesterday i started coding. I started with a simple application, making some simple function and try to get used with the syntax. So i started coding without looking in the book(Programing in scala) or on the web(to really learn it,i used to copy paste or read then type code in the scala interpretor but those methods don’t let you make mistakes that will help you remember )



package scalaprim

object Main {

  /**
   * @param args the command line arguments
   */
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
    println(divide(10,2))
    println(divide(10,3))
    println(isPrime(11))
    println(isPrime(4))
    //findPrimes(100)
    val primes=findPrimes3(100)
    //primes.foreach(println)
  //consecutivePrimes(primes);
  consecutivePrimes2(primes);
  }
def divide(number:Int,divizor:Int):Boolean=(number%divizor==0);
def isPrime(number:Int):Boolean={

  val range = 2.until(Math.sqrt(number).intValue +1)
  for (i <- range)
    {
    if(divide(number, i))
     return false;
  }
  return  true;
}
def findPrimes(number:Int):Unit={
    for(i <-2.until(number))
      {
        if(isPrime(i))
          println(i)
      }
  }
  def findPrimes2(number:Int):IndexedSeq[Int]={
    val range=2 until number+1
    val primes=range.filter(isPrime)
    return primes
  }
  def findPrimes3(number:Int):IndexedSeq[Int]={
    (2 until number+1)filter isPrime   
  }

  def consecutivePrimes(listOfPrimes:IndexedSeq[Int]):Unit={
    var i:Int=0;
    while(i{
        if(prev+2==curent)
          println(prev,",",curent)
         curent
        }})
  }
}


My conclusion on this project is that using scala i can write less code, especially it could be possible to skip using lots of for, i worked on a c++ program and i think i have more then 100 fors, and nested fors that could be easily replaced in scala with calls to filter or exist or something else. And reducing for is not only about code clarity but often you can make bugs in for loops, like mistaking the indices in nested loops or getting outside of the array bounds.

I will investigate Scala in my free time and hope i could put it to use in a large project.

P.S. blogilo is failing uploading my posts, hope eventualy this post will be uploaded(finding a fix and trying another apps)

C++ debugging tip(for gcc and STL)

I want to wrote this tip down for me,to find it when i forget the details and for others that are searcing for it.

So if you are using STL containers like a vector,some strange errors errors can appear if you use an out of range index to the container. If you use .at() method then you are safe ,but you used [] in a lot of places and you can use the flag -D_GLIBCXX_DEBUG to use a safe STL container that will check and will find this errors.

The problem with this errors is theat the program will crash usualy in other place not in the place were the bug is. In my case the program crashed in the ~vector destructor. Read on google about using this flags have some problems(the important one is that you must rebuild all the parts that interoperate with STL containers).

To add this flag in a Qt project you need to add this line in the .pro file

QMAKE_CXXFLAGS +=-D_GLIBCXX_DEBUG1

Extracting webpage content using Qt4

Sometimes we want to check a web page or even to extract it’s content but we do not need to get all the information in the page, the images, the format ,we want only the essential information, In this case I will present I needed a application that will check a forum for new posts and display only the important stuff to me(no adds or other stuff). This particular forum has no mechanism to notify a member if no posts appear in one topic. This program works without using an account.

This can be done very easy in Qt using the class QWebView. An object of this class that in my code is declared

QWebView *view;

can display a web page. The important feature that i use is not displaying the page but executing JavaScript code on the page,so instead of using RegExp or other techniques to extract the information i use a JavaScript query

//get the main frame

QWebFrame *frame=view->page()->mainFrame();

if(frame==NULL)

return "NULL";

//get the elements i need

QWebElementCollection elements=frame->findAllElements("*.tr_list_f");

My application formats this data and stores it and displays it,here is the code

QString RL_HtmlParser::onPageLoad(bool ok)

{

if(!ok)

throw 11;//throw a exception , create a nice exception class later

//get the main frame

QWebFrame *frame=view->page()->mainFrame();

if(frame==NULL)

return "NULL";

//get the elements i need

QWebElementCollection elements=frame->findAllElements("*.tr_list_f");

int length=elements.count();

if(0==length)

return "NO MATCH FOUND";

QString sb("<html><head></head><body><table border=’3′>");

for(int i=0;i<length;i++)

{

if(0==i%2) continue;

sb+="<tr><td> "+elements.at(i).toPlainText()+"</td></tr>";

}

sb+="</table></body></html>";

//old text contains the old data that was read

//so if we have an update we store this data

if(sb!=oldText)

{

oldText=sb;

settings->setValue("oldtext",oldText);

}

//we display the current data

this->view->setHtml(sb);

//and return it as a string

return sb;

}

This is how a web page look like

and this is the application’

It is possible to use proxy and authentication to login and get the page, i downloaded the page in a temporary file and then i loaded it up in the webview but is possible to load it directly from the web

Installing windows sucks

I had to install a windows on my laptop to do some windows related work. I chose to install XP ,Win 7 is to large to consider it . I must confess that i hate windows interface, i have a disability and i need to use large fonts and zoom tools. The problem in windows is that the zoom tool sucks in comparison with the zoom effect in compiz or kwin(in Linux) and is impossible to make all the windows app to use same fonts e.g. Skype or Yahoo Messenger , i can’t really use large fonts, YM uses some html stuff so the settings in appearance have no effect on it, the only option is to use a small resolution like 800×600 that makes all controls large and windows not fitting the screen.

About the installation, i chose to install on the second partition,all was OK until restarting when i received a message like "Invalid partition table", and i was thinking "the stupid windows destroyed my partition table", i booted from a live CD, confirmed that the partitions are OK , recovered my GRUB from the first partition(GRUB is the Linux boot loader) and i added the windows to the Linux boot loader entry. After restart i chose to use windows from GRUB menu and i continued to install it.

After installation comes the hard part , install everything else. First i disabled the system restore then i installed my drivers from the CD,. After installing the drivers using the CD wizard and restarting i noticed that no driver was installed, i clean up the CD and CD-ROM unit ,reinstalled the driver and finally all was OK. The stupid driver wizard skipped installing the drivers because it had problems reading the CD but failed to tell me about the problems.

After the drivers i installed FireFox and Opera , Skype and Yahoo messenger, and hunted for a nice theme(still searching) i get bored of the classic XP theme. I Searched for a zoom tool but failed and currently i am writing this blog from my KDE/;Linux install, where the fonts are large and smooth.

It remains to do:

install antivirus,antispyware/malware stuff, maybe a firewall, a winrar like program, VLC, pdf reader, Open Office, a better image viewer , a better text editor, find a nice theme but first patch the dlls because you ave to pay money to M$ to change your themes.

I will have to search for new drivers manually, (the ATI driver from CD has some bugs).

For programming i must think if i reinstall some Visual studio 2008 or 2010 express or some trial, maybe i install it when i need it.

How an install works in Linux:

1 you will have no problem with the boot loader

2 you will have driver for all your parts(not all the time, some hardware may be not supported yet) but in my case all works in Linux, card reader,wireless, everything.

3 you do not need to browse the web to install apps ,you use your package manager

4 no antivirus and other stuff to run in background

5 no annoying stuff installed and starting and showing up in tray, like wireless indicators when no wireless is present and i do not use my wireless card, or when you install Yahoo messenger toolbars and other stuff appear in your browser (are installed behind your back)

The desktop does not get filed with icons, in Linux you have a nice structured menu ,using categories .

and more, maybe i will rite later about using windows pains.

Anunt/Anouncement

Fac programe la cerere / comanda,realizez lucrari de licenta/disertatii atestate, in domeniul informaticii >Limbaje de programare: c,c++,c#,java,javascript lucrez si cu qt

I do software /progrms /applications on demand .Programming languages :c ,c++,c#,java javascript. I do homeworks /papers for exams etc.

Contact:

simion314 &@& y a h o o & .& c o m (REMOVE the dolar sing & , i placed it there to aviod my email beeing picked up by spamers) SCOATE semnul dolar & , e pus acolo ca spameri sa nu imi fure emailul

Or leave a comment

SAU lasa un comentariu

Link http://simion314.isgreat.org/

Creating a Image,Picture widget in Qt4 that keeps the aspect ration has zoom and rotate features

To display image in Qt4 you can use a QLabel and the setPixmap() method. But if you need something more complex that will keep the aspect ratio and can zoom and rotate you will have to create a custom widget. This is how i did it for a Image viewer application that i make it in Qt4 using c++.

#ifndef IMAGEWIDGET_H

#define IMAGEWIDGET_H

#include <QWidget>

class QSize;

class QImage;

class ImageWidget : public QWidget

{

Q_OBJECT

public:

explicit ImageWidget(QWidget *parent = 0);

void setImage(const QImage &image);

QImage *getImage();

float getZoomFactor();

//this is absolute depends only on the size of the image

void setZoomFactor(float zf);

//this is relative with the curent size/zoom

void zoom(float zoomWithThisFactor);

//if set to true the image will be zoomed to fit the widget

void setZoomToFit(bool ztf);

signals:

public slots:

protected:

//custom drawing rutine

void paintEvent(QPaintEvent *);

//custom sizeHint method

QSize sizeHint() const;

private:

QImage *image;

float zoomFactor;

float aspectRatio;

bool zoomToFit;

void computeZoomFactorToFitImage();

void adjustSize();

};

#endif // IMAGEWIDGET_H

I subclased QWidget and reimpemented 2 methods paintEvent() and sizeHint():

void ImageWidget::paintEvent(QPaintEvent *)

{

int x,y,w,h;

//compute the image displaty size by multipling with the zoom factor

w=image->width()*zoomFactor;

h=image->height()*zoomFactor;

//compute the x and y offset

x=(rect().width()-w)/2;

y=(rect().height()-h)/2;

//if from some strange bug we get a negative value,

//probly this must be changed to an assert or thow and error and fix the eventual problem

x=qMax(x,0);

y=qMax(y,0);

QRectF target(x,y,w,h);

QPainter p(this);

p.drawImage(target,*image);

}

QSize ImageWidget::sizeHint() const

{

if(image!=NULL)

{

QSize hint= image->size();

hint=zoomFactor*hint;

return hint;

}else

return this->minimumSize();

}

The zoomToFit method will compute the zoom factor to fit the widget and will zoom the image

void ImageWidget::setZoomToFit(bool ztf)

{

this->zoomToFit=ztf;

if(zoomToFit)

{

computeZoomFactorToFitImage();

}

else

{

zoomFactor=1.0;

}

adjustSize();

this->update();

}

void ImageWidget::computeZoomFactorToFitImage()

{

//compute the aspect ration of the widget

//cast t float to get a float result, if forget (float) you will get

//a int value

float ratio=rect().width()/(float)rect().height();

if(ratio>aspectRatio)

{//the widget width is larger relative of the image wirth

zoomFactor=rect().height()/(float)image->height();

}

else

{

zoomFactor=rect().width()/(float)image->width();

}

}

void ImageWidget::adjustSize()

{

resize(this->sizeHint());

}

You can find all the code on source forge in a Image viewer application, the application is licnsed under GPL v3 , if someone needs the code under other license email me and i can give the rights

UPDATE:

download

svn co https://kisviwer.svn.sourceforge.net/svnroot/kisviwer kisviwer

you must use a svn client or the svn command line application, if in linux install svn and paste that line in the terminal,and a drectory kisviwer will appear with the code,windws guys google it

a simple image viewer ,Qt4