titbits from the world less travelled

Archive for August, 2009

Awesome website with tools to test spyware

Incase you are into testing anti spyware products, then this is the website to visit.

www.spycar.org.

They got a range of tools to test your spyware product. All the best.

posted by admin in Uncategorized and have No Comments

Memory leak detection when using heapalloc and heapfree

If your developing a product which is called a thousand many times and runs in the background as a process, even a byte of memory might be very important to you. Consider a application which is scheduled to run every few seconds for checking a update. This might leak a byte every time its called, so detecting such leaks will be very necessary.

You can make use of heapfree and heapsize to fix this leaks once you allocate memory.
Use heapalloc to allocate memory:
retValue = (RASENTRYNAME *) HeapAlloc(GetProcessHeap(), 0, sizeAlloc);
typeI32 mySize = HeapSize(GetProcessHeap(),0, <>);
std::wstring str = CStringUtils::I32ToStr(mySize);
std::string myStr = CStringUtils::WStringToString(str);
Write the memory size to a file.
FILE * pFile;
pFile = fopen (c:\myfile.txt,a);
const char *p;
p=myStr.c_str();
if (pFile!=NULL)
{
fputs (p,pFile);
fclose (pFile);
}
From the above code you will know how much memory has been used.
You can free the memory at the end using heapfree and then again call this code. you should see zero memory usage.
HeapFree(GetProcessHeap(), 0, pointer to memory you initialize);
pointer to memory you initialized= NULL;
posted by admin in Uncategorized and have No Comments

JFrame: Using panel and frame minimize and maximize

What should you do when you have a foundation as FrameView not the Frame. There comes a situation when you would need to hide or minimize this panel. the normal way of calling setVisible(true) might not work. You would need to use or call JFrame inside a method or action:

JFrame mainFrame = PostItApp.getApplication().getMainFrame();
mainFrame.setVisible(false);
This would surely be of use to people using netbeans to develop desktop applications since most applications use frameview over there.
posted by admin in Uncategorized and have No Comments

WebOS – Palm Pre tutorials – Adding a textfield and sample project

Wow…finally got to run my very own tutorial on eclipse. Actually developing on a webos SDK is an easy task. If not for the understanding of the architecture, everything else is child’s play I suppose.

If you have a understanding of HTML, CSS and Javascript you must be able to get through. Ok, right to the basics. In a Palm Pre SDK(webos) we have a stage, this stage is the one which is the foundation.  On this stage, you can run your scenes. In most cases index.html would be your default stage. So please dont try to run or add anything on the stage.

For example, I tried adding a text field to be displayed on this for nearly two hours, but then finally figured out that it was not possible. Basically, you code your application as a storyline. You go from one scene to the other.

To make it easy first install java, then virtual box from sun and then palm emulator. In eclipse first, add a mojo project.  Then you can check out the folder structure as below:

Take a look at the contents of the new HelloWorld folder:

  • app folder — contains the assistants, models, and views that make up the application. Later in the tutorial, you add files to this directory.
  • appinfo.json — the Application Information file.
  • icon.png — the image that the application presents in the Launcher on the emulator or device.
  • images folder — any other images the application uses.
  • index.html — the main stage on which the application’s scenes appear.
  • sources.json — a list of the source files for each scene.
  • stylesheets folder — contains the cascading style sheet file for the application.

I wont give you a run through of the structure since you can find it on the palm website. Now since index.html is basically a stage, and you have to add the scenes on top of this. Remember ( as far as I can see) you cant add anything to the stage.

So we go ahead and create a scene in eclipse.

[
{"source": "app\/assistants\/stage-assistant.js"},
{
"source": "app\/assistants\/myscene-assistant.js",
"scenes": "myscene"
}
]

The source.json will be as shown above. So we have the first scene. Next we goto the .html page of the scene where we need to add the display stuff. I just add a textfield as below-

//—————————-
MY ID: <div id=”myId” x-mojo-element=”TextField”></div>

//—————————–

Next we add the code to myscene-assistant.js to display this scene on the stage:

mysceneAssistant.prototype.setup = function() {
/* this function is for setup tasks that have to happen when the scene is first created */

/* use Mojo.View.render to render view templates and add them to the scene, if needed. */

/* setup widgets here */

/* add event handlers to listen to events from widgets */
var attributes = {
textFieldName: ‘username’,
hintText: ‘Enter Your Username’,
modelProperty: ‘value’
};

this.model = {
};

this.controller.setupWidget(‘myId’, attributes, this.model);
}

//—————————————-

Ok..finally go to the stage assistant and add this line to push the scene on the stage…

StageAssistant.prototype.setup = function() {
this.controller.pushScene(‘enter-reminder’);
}

WOWOWOWO—now you have your very own textfield displaying on the stage. Congrats..

posted by admin in Uncategorized, palm pre, webos and have No Comments