Tuesday, October 4, 2011
Air: getting current user name
well , for this you can use following technique:
1)File path to user directory [in windows user director name = user name]
2) parse the path to get user name [last string has user name ie: c:\..\..\username]
Implementation:
1)File path to user directory [in windows user director name = user name]
2) parse the path to get user name [last string has user name ie: c:\..\..\username]
Implementation:
var userFolder:String = File.userDirectory.nativePath;
var userName:String = userFolder.substr(userFolder.lastIndexOf(File.separator) + 1);
Extjs: Chaning tip text: acessing thumb value while dragging
- initComponent: function () {
- this.tipText = function(thumb){
- return Ext.String.format(thumb.value+" is the current thumb value");
- };
- this.callParent();
- }
Saturday, October 1, 2011
Extjs error: "me.events is undefined" when you fire event to an object
>> make sure that you ahve done addEvents("yourEvent") for your object
Extjs error: while setting tree/rendering tree nodes error: record undefined
while setting tree/rendering tree nodes error: record undefined
>>Make sure objects you used as tree nodes do not have duplicate id,
"me.events is undefined" when you file event to an object
>> make sure that you ahve done addEvents("yourEvent") for your object
>>Make sure objects you used as tree nodes do not have duplicate id,
"me.events is undefined" when you file event to an object
>> make sure that you ahve done addEvents("yourEvent") for your object
Monday, September 19, 2011
Flex AdvancedDatagrid, changing renderers
You can change columerenderer and the grouping colume renderer as following:
<components:CustomDataGrid variableRowHeight="true" folderClosedIcon="{null}" folderOpenIcon="{null}" groupItemRenderer="MyGroupingItemRenderer" groupRowHeight="100">
<components:dataProvider>
<mx:GroupingCollection id="gc" source="{someArray/arrayCollection}" >
<mx:grouping>
<mx:Grouping>
<mx:GroupingField id="groupingField" name="groupField" compareFunction="{MyCompareFunction()}" descending="true"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</components:dataProvider>
<components:columns >
<mx:AdvancedDataGridColumn itemRenderer="MyColumeRnnderer" />
</components:columns>
</components:CustomDataGrid>
//Defining MyGroupingItemRenderer
public class MyGroupingItemRenderer extends AdvancedDataGridGroupItemRenderer {
.....
....
}
Thursday, September 15, 2011
PHP and SQLITE [executing sqlite query using PDO]
public function execute($query) {
$dbname='../../db.sqlite';
$base= new PDO('sqlite:'.$dbname.'');
$preparedStatement = $base->prepare($query);
$i=0;
while($tmp = $preparedStatement->fetch(PDO::FETCH_ASSOC)) {
$array[$i] = $tmp;
$i++;
}
return $array;
}
$dbname='../../db.sqlite';
$base= new PDO('sqlite:'.$dbname.'');
$preparedStatement = $base->prepare($query);
$i=0;
while($tmp = $preparedStatement->fetch(PDO::FETCH_ASSOC)) {
$array[$i] = $tmp;
$i++;
}
return $array;
}
Latest Deadline first
- among tasks without successors select the task with the latest deadline
- remove this task from the precedence graph and put it into a stack
- repeat until all tasks are in the stack
- the stack represents the order in which tasks should be scheduled
Wednesday, September 14, 2011
Adobe Air: Problem while reading „ and “
Solution: use UTF-32 encoding
var fs:FileStream = new FileStream();
fs.open(,FileMode.READ);
var string:String = fs.readMultiByte(fs.bytesAvailable, "UTF-32");
Sunday, September 11, 2011
Air: change / specify runtime location of air application [way to run air application in machine with out runtime installation]
Only way is to use adl.exe while running your applicaiton. With normal installer you cannot do so. So idea is to 1)use a bat file to manually specify your applicaiton.xml location and adobe run time location.
2) If you do'nt like console then wire a program for you own that does what bat file does but with out console visible. I have written such program in c++. If you need it just leave a comment .
2) If you do'nt like console then wire a program for you own that does what bat file does but with out console visible. I have written such program in c++. If you need it just leave a comment .
reading a file in C [reading line]
#include <stdio.h>
int main ()
{
FILE * pFile;
char lines[2][200];
int i=0;
int j=0;
int c;
int n = 0;
//clear file
for(int i=0;i<2;i++) {
for(int j=0;j<200;j++) {
lines[i][j] = '\0';
}
}
pFile=fopen ("name.txt","r");
if (pFile==NULL) perror ("Error opening file");
else
{
do {
c = fgetc (pFile);
if (c == '$') n++;
if(c== '\n') {
i++;
j=0;
continue;
printf("new line begins\n");
}
lines[i][j] = c;
printf ("%c",lines[i][j]);
j++;
} while (c != EOF);
fclose (pFile);
printf("line1 %s \n",lines[0]);
printf("line2 %s \n",lines[1]);
}
return 0;
}
Saturday, September 10, 2011
Extjs tree filter [filtering tree items in extjs 4 ]
Download source code from here: treeDemp.html, treeDemo1.js [Note: you will need extjs 4]
Click the image to see demo
The main idea is for each keyup in the text box i do following:
Detail code given below:
Click the image to see demo
The main idea is for each keyup in the text box i do following:
- tree.getRootNode().cascadeBy(function() { // descends into child nodes
- if(!(this.data.qtip.indexOf(txt.getValue())>-1)) {//Now do the actual filtering
- console.log("remove");
- removeArray[i] = this;//cannot call this.remove() here as cascadeBy() tends to traverse all the nodes and if node is removed it gives error
- i++;
- }
- });
- for(var j=0;j<i;j++) {
- removeArray[j].remove();//do actual removing, but unforunately once //removed,,there is not a easy way to add back to same location so , here i //simply regenrate whole tree again at line 53 : setnode(tree)
- }
- Ext.application({
- name: 'treeFilterDemo',
- appFolder: 'app',
- requires: [ 'Ext.form.Panel','Ext.container.Viewport',
- 'Ext.tab.Panel','Ext.tree.Panel','Ext.data.TreeStore','Ext.layout.container.Border'
- ],
- setnode:function(tree){
- var node = {text:'', qtip:'',expanded:true, leaf:false, children:[]};
- var node1_1 = {text:'apple_1', qtip:'apple_1',expanded:true, leaf:true, children:[]};
- var node1_2 = {text:'apple_2', qtip:'apple_2',expanded:true, leaf:true, children:[]};
- var node1 = {text:'apple', qtip:'apple,apple_1,apple_2',expanded:true, leaf:false, children:[node1_1,node1_2]};
- var node2_1 = {text:'apricoat_1', qtip:'apricoat_1',expanded:true, leaf:true, children:[]};
- var node2_2 = {text:'apricoat_2', qtip:'apricoat_2',expanded:true, leaf:true, children:[]};
- var node2 = {text:'apricoat', qtip:'apricoat,apricoat_1,apricoat_2',expanded:true, leaf:false, children:[node2_1,node2_2]};
- node.children = [node1,node2];
- tree.setRootNode(node);
- },
- launch: function() {
- var setNodeFn = this.setnode;
- var tree = Ext.create('Ext.tree.Panel', {
- myRootNodes:[],
- region:'center',
- hideHeaders: true,
- rootVisible: false,
- expandedNodes:[],
- viewConfig: {
- plugins: {
- ptype: 'treeviewdragdrop',
- appendOnly: true
- }
- },
- height: 350,
- width: 400,
- });
- var textField = {xtype:'textfield',
- prompt:'serach',
- name: 'name',
- region:'north',
- value:'Type filter text',
- enableKeyEvents:true,
- listeners:{
- focus:{fn:function (view, record, item, index, even) {
- this.setValue("");
- }},
- keyup:{
- fn:function(view, record, item, index, even){
- var txt= this;
- setNodeFn(tree);
- var removeArray = [];
- var i=0;
- tree.getRootNode().cascadeBy(function() { // descends into child nodes
- if(!(this.data.qtip.indexOf(txt.getValue())>-1)) {//Now do the actual filtering
- console.log("remove");
- removeArray[i] = this;//cannot call this.remove() here as cascadeBy() tens to traverse all the nodes and if node is removed it gives error
- i++;
- }
- });
- for(var j=0;j<i;j++) {
- removeArray[j].remove();//do actual removing, but unforunately once removed,,there is not a easy way to add back to same location so , here i simply regenrate whole tree again at line 53 : setnode(tree)
- }
- }
- }
- }
- };
- this.setnode(tree);
- Ext.create('Ext.container.Viewport', {
- items: [
- textField,tree
- ]
- });
- }
- });
Friday, September 9, 2011
Solution for the problem with: drag drop not accepted in HBox in Flex
private function dragEnterHandler(event:DragEvent):void {
if (event.dragSource.hasFormat("some format"))
{
DragManager.acceptDragDrop(event.currentTarget as UIComponent);
}
}
private function dragDropHandler(event:DragEvent):void {
Alert.show("dropped");
Alert.show("dropped");
}
.........<mx:HBox id="v1" width="100%" height="100%" label="dd" dragDrop="dragDropHandler(event);" dragEnter="dragEnterHandler(event);">
........
Here drop is not accepted by Hbox
solution: Just set the background of the container like: backgroundColor="#ffffff"
<mx:HBox id="v1" width="100%" backgroundColor="#ffffff" height="100%" label="dd" dragDrop="dragDropHandler(event);" dragEnter="dragEnterHandler(event);">
Handeling text overflow in Flex Alert
//your code//
var a:Alert = Alert.show("..long..text....");
handelOverFlow(a,500);
private function handelOverFlow(alert:Alert,maxHeight:int):void {
var array:Array = alert.getChildren();
var uiCom:UIComponent = array[0];
var txtField:UITextField = uiCom.getChildAt(0) as UITextField;
var box:Box = new Box();
var array:Array = alert.getChildren();
var uiCom:UIComponent = array[0];
var txtField:UITextField = uiCom.getChildAt(0) as UITextField;
var box:Box = new Box();
//if AlertForm (uiCom) has more height then desired height
if(uiCom.height>maxHeight) {
uiCom.height = maxHeight;
txtField.parent.removeChild(txtField);;
box.width = uiCom.width;
box.height = maxHeight - 50;
box.addChild(txtField);
uiCom.addChildAt(box,0);
}
if(uiCom.height>maxHeight) {
uiCom.height = maxHeight;
txtField.parent.removeChild(txtField);;
box.width = uiCom.width;
box.height = maxHeight - 50;
box.addChild(txtField);
uiCom.addChildAt(box,0);
}
}
problem while generating web application in web ratio
I had problem in generating web application from web ratio. I would like to share the solution i found,, because other may also face same problem
After viewing the description , Problem seems to be to fact that, i had my tomcat directory in my “Program File” and web ration was in some other directory and my Operating system [windows 7] denied the write to that folder.
[my webratio did'nt had tomcat installation in it, because i denies installation of tomcat as i already had one]
Solution:
In the project outline view, select the project
In the project property view, you will find the “output path”
Change this path to some other location
[Once deployed , you can just copy the deployed folder to tomcat "webapp" folder manually and restart the tomcat]
After viewing the description , Problem seems to be to fact that, i had my tomcat directory in my “Program File” and web ration was in some other directory and my Operating system [windows 7] denied the write to that folder.
[my webratio did'nt had tomcat installation in it, because i denies installation of tomcat as i already had one]
Solution:
In the project outline view, select the project
In the project property view, you will find the “output path”
Change this path to some other location
[Once deployed , you can just copy the deployed folder to tomcat "webapp" folder manually and restart the tomcat]
work arround for: “ArgumentError: Error #2082: Connect failed because the object is already connected” in Flex, Air
This error can occur for three reasons:
1) The string value passed to the connection Name parameter was null.
Pass a non-null value.
Pass a non-null value.
2) The value passed to the connection Name parameter contained a colon
(:). Colons are used as special characters to separate the superdomain
from the connectionName string in the send() method, not the
connect()method.
(:). Colons are used as special characters to separate the superdomain
from the connectionName string in the send() method, not the
connect()method.
3) The LocalConnection instance is already connected.
Following solution is for 3)
idea: For every exception thrown for reconnect create a nw connection.
idea: For every exception thrown for reconnect create a nw connection.
/*while initializing the connection call connect() method,, and use variable "connectionName" while invoking methods as: localConnection.send(_connectionName,"methodName");*/
private var _connectionName:String = “swf2AIR”;
private function connect():void {
try {
fromAIR.connect(_connectionName);
}
catch(e:*) {
_connectionName = _connectionName+”1″;;
connect();
private function connect():void {
try {
fromAIR.connect(_connectionName);
}
catch(e:*) {
_connectionName = _connectionName+”1″;;
connect();
}
}
Red5 hello world [Java - flex communication] implementation
Requirement for gives example are: red5 server [i used : red5-0.9.1], Eclipse [example contains eclipse projects]
Note: before running example, unzip it and view read me
Download example here
EXTJS Error : strange error in border.js
make sure you imported 'Ext.layout.container.Border'
EXTJS Error : me.dockedItems is undefined:
one main reason is that, in your init function you did not called "callParent()".
"callParent()" should be called usually at the end of your init function
"callParent()" should be called usually at the end of your init function
adobe air :: File handling
- The static properties included in File class :
File.applicationDirectory Directory where the application is installed and it is read only
File.desktopDirectory Desktop directory of the User
File.documentsDirectory Documents directory of the user
File.userDirectory User Directory
- saving file:
- var bytearray:ByteArray = new ByteArray();
- var fileToCopy:File = new File("url of file");
- var newFile:File = new File("url of file to be created");
- var fileStream:FileStream = new FileStream();
- fileStream.open(file,FileMode.READ);
- fileStream.readBytes(bytearray);//getting bytes
- var newFileStream :FileStream = new FileStream()
- newFileStream.openAsync( newFile, FileMode.WRITE );
- newFileStream.writeBytes(bytearray);//filling bytes
- newFileStream.close();
- Updating file
public function update(value:String,url:String,startIndex:int = 0):void
{
var file:File = new File(url);
var fs:FileStream = new FileStream();
fs.open(file,FileMode.UPDATE);
fs.position = startIndex;
fs.writeUTFBytes(value);
fs.close();
}
{
var file:File = new File(url);
var fs:FileStream = new FileStream();
fs.open(file,FileMode.UPDATE);
fs.position = startIndex;
fs.writeUTFBytes(value);
fs.close();
}
- Getting current directory in air:
- NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvokeEvent);
- public function onInvokeEvent(invocation:InvokeEvent):void {
- var currentDir:File = invocation.currentDirectory;
- }
- File systems's tutorial:
- Draggout out gesture [Dragging file from air to filesystem]
- Uploading file in air
Thursday, September 8, 2011
Amf (open amf) hello world [Flex - java communication] implementation
This example demonstrate the flex – java communication using open amf
Requirement:
1) openamf [i used openamf-1.0RC12]
2) eclipse [i used 3.4 (example contains eclipse project)]
3) tomcat server [i used 6.0]
Download example project amf helloworld.zip
Unzip the project, and view read me. There are 2 projects inside, one client and one server project.To run just import them in you eclipse and run it.
Requirement:
1) openamf [i used openamf-1.0RC12]
2) eclipse [i used 3.4 (example contains eclipse project)]
3) tomcat server [i used 6.0]
Download example project amf helloworld.zip
Unzip the project, and view read me. There are 2 projects inside, one client and one server project.To run just import them in you eclipse and run it.
Minimal cut set and Fault tree analysis
Fault tree: Fault tree diagrams represent the logical relationship between sub-system and component failures and how they combine to cause system failures. The TOP event of a fault tree represents a system event of interest and is connected by logical gates to component failures known as basic events.
Figure is a fault tree: a tree where A,B,C,D,E,F are sets of fault events that can cause software to fail.
Here, minimal events for software to fail is {A,C},{B,C}.... These {A,C},{B,C} are the minimal cut set [a minimal set of events to cause failure, whose further sub set do not cause failure]
Conclusion: We should always strive to make minimal cut set as big as possible. In above figure the desirable minimal cut set would be {A,B,C,D,E,F}
Why? :
Say was have minimal cut sets : {A,C},{B,C},{A,C},{A,E},{A,F}
So, Probability to fail = P{A,C}+P{B,C}+P{A,C}+P{A,F}
=P(A)*P(B)+P(B)*P(C)+P(A)*P(C)+P(A)*P(F)
When mininal cut set is{A,B,C,D,E,F}
Probability to fail = P{A,B,C,D,E,F}
= P(A)*P(B)*P(C)*P(D)*P(E)*P(F)
Therefor, P(A)*P(B)*P(C)*P(D)*P(E)*P(F) < P(A)*P(B)+P(B)*P(C)+P(A)*P(C)+P(A)*P(F)
Figure is a fault tree: a tree where A,B,C,D,E,F are sets of fault events that can cause software to fail.
Here, minimal events for software to fail is {A,C},{B,C}.... These {A,C},{B,C} are the minimal cut set [a minimal set of events to cause failure, whose further sub set do not cause failure]
Conclusion: We should always strive to make minimal cut set as big as possible. In above figure the desirable minimal cut set would be {A,B,C,D,E,F}
Why? :
Say was have minimal cut sets : {A,C},{B,C},{A,C},{A,E},{A,F}
So, Probability to fail = P{A,C}+P{B,C}+P{A,C}+P{A,F}
=P(A)*P(B)+P(B)*P(C)+P(A)*P(C)+P(A)*P(F)
When mininal cut set is{A,B,C,D,E,F}
Probability to fail = P{A,B,C,D,E,F}
= P(A)*P(B)*P(C)*P(D)*P(E)*P(F)
Therefor, P(A)*P(B)*P(C)*P(D)*P(E)*P(F) < P(A)*P(B)+P(B)*P(C)+P(A)*P(C)+P(A)*P(F)
DWR hello world example implementation : sending – reciving objects
- Put dwr.jar in your Project's lib.
- Put the Commons Logging Jar in your Projects's lib. ( Dwr uses Apache Commons Logging )
- Add the configuration settings in your web.xml for the DWR Servlet.
- Add the debugging parameters for the DWR Servlet during the development phase.
- Add the dwr.xml under WEB-INF and configure it to expose your Java Classes.
- Add the converters in dwr.xml to ensure the conversion of Java POJOs to JavaScript Objects & vice versa.
- Include the reference to all the JavaScript libraries required in your JSPs.
Download example here
It’s an eclipse project, you can just download and import the project and run
Strategy Pattern Implementation – java
[image source: http://wikipedia.org]
Get implementation here : strategy_pattern.zip [It's an eclipse java project]
stateful example in extjs [saving tree selection in extjs]
First read this: http://dev.sencha.com/deploy/ext-4.0.2a/docs/#/api/Ext.state.Stateful-cfg-stateful
Following example demonstrate simple way to save a selected item in tree:
Following example demonstrate simple way to save a selected item in tree:
this.tree = Ext.create(‘Ext.tree.Panel’, {
viewConfig: {
plugins: {
ptype: ‘treeviewdragdrop’,
appendOnly: true
}
},
height: 350,
width: 400,
stateEvents: ['saveSelectedItem'],
stateId:’myTreeId’,
stateful:true,
rootVisible: false,
mySelectedItem:”,//my own added Variable
getState : function () {
/*this is place where we state what things are to be saved*/
console.log(‘saving’+this.mySelectedItem);
/*we return thing to be save in format key:value*/
return {
mySelectedItem: this.mySelectedItem
}
},
applyState : function (state) {
/*this is place where we recover the saved state*/
console.log(state);
console.log(“Previosuly selected “+state.mySelectedItem);
},
listeners:{
itemclick:{fn:function (view, record, item, index, even) {
console.log(“saving item:”+record.data.text);
this.mySelectedItem = record.data.text;
this.fireEvent(‘saveSelectedItem’);
}}
}});
Subscribe to:
Posts (Atom)