Sunday, May 29, 2011

When android project return funny results or findviewbyid return null for no-sense

Most likely is because of the half-boiled eclipse auto-compile resource implementation, your XML files and the compiled resources are not sync. to solve it goto project->clean...

another tips: getDafaultSensor() should pass in Sensor.TYPE_SENSOR_xxxxx not SensorManager.SENSOR_xxxxx. the latter is for the deprecated registerListener(listener, sensor, delay)

Friday, May 6, 2011

How to setup ejabberd clustering

- change /etc/ejabberd/ejabberd.cfg hosts
- sudo ejabberdctl register NEW_ADMIN 192.168.2.xxx P@55w0rd
- change /etc/ejabberd/ejabberd.cfg admin user
- use web admin, make sure you could access the admin panel
- copy /var/lib/ejabberd/.erlang.cookie to all seondary node // might need to restart secondary nodes
- add all node name to /etc/hosts
- stop all secondary nodes
- copy .erlang.cookie to /root/ // use su bash to change to root user or a fresh restart to solve the problem?
- run sudo erl -sname ejabberd -mnesia dir '"/var/lib/ejabberd"' -mnesia extra_db_nodes "['ejabberd@HOSTNAME']" -s mnesia
// crash if ejabberd instance is running and
// /var/lib/ejabberd/ has something in it. BUT .erlang.cookie must maintain in the folder
- mnesia:change_table_copy_type(schema, node(), disc_copies). in the console
- after quitting from console make sure all the new files in /var/lib/ejabberd own by ejabberd.ejabberd
- if hav doubt remove /dev/null from /etc/init.d/ejabberd


Failed to merge schema: Incompatible schema cookies. Please, restart from old backup.'ejabberd@HOSTNAME'
- remove /var/lib/ejabberd/ content ** except .erlang.cookie

USEFUL PATH
================
/var/lib/ejabberd/ - database and .erlang.cookie. ejabberd home directory
/etc/ejabberd/ejabberd.cfg - ejabber configuration file
/usr/sbin/ejabberdctl - controller
/var/log/ejabberd/ - log folder
/usr/lib/ejabberd/ebin/ - plugin folder

USEFUL LINKS
=================
- http://www.process-one.net/docs/ejabberd/guide_en.html#ejabberdctl
- http://jabber.nes.ru/logs/ejabberd@conference.jabber.ru/2006/01/09.html // ejabberd must stop and db must clean before running erl -sname ejabberd
- http://tdewolf.blogspot.com/2009/07/clustering-ejabberd-nodes-using-mnesia.html // point 8, ejabberdctl.cfg modification is obsolete

Monday, May 2, 2011

Simple JSON parser

I have written a simple json parser in actionscript. i re-create a wheel because the one in as3corelib is too complicated for me. this is pretty straight forward, it does single pass parsing, convert JSON text into ActionScript Object. currently it supported string, object and array only. i think it is good enough for configuration purposes. so enjoy :)

/**
* Simple JSON parser. this parser does a single pass translation of JSON to
* Actionscript string, array and object. no int and float support yet and no error checking
* as well. but this parser does support nested object and array
* @param content JSON text
* @param stack parser
* @param parent Parent Object or Array depends on context
* @return Object Actionscript object that represent the JSON (content)
*/
private function parse(content:String, stack:Vector., parent:Object):Object {
var ret:Object;
var curr:uint = stack[CFG_POS];
var type:String = content.charAt(curr);
++curr;
stack[CFG_POS] = curr;
switch(type) {
case OPEN_BRACKET_OBJECT:
// push the new stack
stack.unshift(TYPE_OBJECT);
stack.unshift(PART_KEY);
stack.unshift(curr);
ret = new Object;
while(stack[CFG_TYPE] == TYPE_OBJECT){
ret = parse(content, stack, ret);
}
// pop the old stack
curr = stack.shift();
stack.shift();
stack.shift();
stack[CFG_POS] = curr;
break;
case CLOSE_BRACKET_OBJECT:
stack[CFG_TYPE] = NA; // stop the object's while loop
ret = parent;
break;
case OPEN_BRACKET_ARRAY:
// push the new stack
stack.unshift(TYPE_ARRAY);
stack.unshift(PART_VALUE);
stack.unshift(curr);
ret = new Array;
while(stack[CFG_TYPE] == TYPE_ARRAY){
ret.push(parse(content, stack, ret));
}
ret.pop(); // pop out the unwanted last null set by CLOSE_BRACKET_ARRAY
// pop the old stack
curr = stack.shift();
stack.shift();
stack.shift();
stack[CFG_POS] = curr;
break;
case CLOSE_BRACKET_ARRAY:
stack[CFG_TYPE] = NA; // stop the array's while loop
ret = null;
break;
case BRACKET_ITEM:
stack[CFG_POS] = content.indexOf(BRACKET_ITEM, curr) + 1;
if (stack[CFG_PART] == PART_KEY){
parent[content.substring(curr, stack[CFG_POS]-1)] = parse(content, stack, parent);
ret = parent;
}else{
ret = content.substring(curr, stack[CFG_POS]-1);
}
break;
case SEPARATOR_KEY_VALUE:
stack[CFG_PART] = PART_VALUE;
ret = parse(content, stack, parent);
break;
case SEPARATOR_STATEMENT:
if (stack[CFG_TYPE] == TYPE_OBJECT)
stack[CFG_PART] = PART_KEY;
else
stack[CFG_PART] = PART_VALUE;
ret = parse(content, stack, parent);
break;
}
return ret;
}