Monday, January 28, 2008

"Must be Server" error from PushRegistry with sms

Whew ! Took 2 days to figure this out.

Recently attempted to create a MIDlet which wakes up on SMS using the PushRegistry feature in Java ME.

Kept getting "Must be Server" error at the
mc.receive()
line in following code snippet :


if (url.startsWith("sms://")) {
MessageConnection mc = (MessageConnection) Connector.open(url);
Message msg = mc.receive();
String data = "";

if (msg != null) {
if (msg instanceof TextMessage) {
form.append("TextMessage\n");
data = ((TextMessage)msg).getPayloadText();
}
}
}


Turns out the JAD file of said MIDlet has the following incorrectly typed PushRegistry entry :


MIDlet-Push-1: sms://8033, org.whatever.Poink, *


There should be a ":" after the 2 "slashes" like so :


MIDlet-Push-1: sms://:8033, org.whatever.Poink, *


After the above fix, the "Must be Server" disappeared :)

Friday, January 25, 2008

Probability notations made simple

OK, this ain't Java. Nonetheless this article by Eliezer Yudkowsky really helped in me understanding probability notations (those "|" and "&") as used in Bayesian theory by presenting actual problems instead of the usual Math gobbledygook. Here's a quote :


... p(Q|P) is the proportion of things that have property Q and property P
within all things that have P; i.e.,
the proportion of women with breast cancer and a positive mammography within
the group of all women with positive mammographies.

If there are

641 women with breast cancer and positive mammographies,
7915 women with positive mammographies, and
89,031 women,

then p(Q&P) is the probability of getting one of those 641 women
if you're picking at random from the entire group of 89,031,

while p(Q|P) is the probability of getting one of those 641 women
if you're picking at random from the smaller group of 7915.


Here's another quote :


In a sense, p(Q|P)really means p(Q&P|P), but specifying the extra P all the
time would be redundant. You already know it has property P, so the property
you're investigating is Q - even though you're looking at the size of group
Q&P within group P, not the size of group Q within group P (which would be
nonsense).

This is what it means to take the property on the right-hand side as given;
it means you know you're working only within the group of things that have
property P. When you constrict your focus of attention to see only this
smaller group, many other probabilities change. If you're taking P as given,
then p(Q&P) equals just p(Q) - at least, relative to the group P.
The old p(Q), the frequency of

"things that have property Q within the entire sample",

is revised to the new frequency of

"things that have property Q within the subsample of things that have property P".

If P is given, if P is our entire world, then looking for Q&P
is the same as looking for just Q.

Sunday, October 7, 2007

Executing SQL scripts on MYSQL

OK, this one IS in the manual :)

But nonetheless, why not take a shortcut & just google it :)

Anyhoo, let's assume you have a database called MYDB at machine localhost which you can access under user name web with password password. The file you want to execute is called sql_script.sql which contains SQL commands delimited by ; as shown below.

DROP TABLE IF EXISTS general_detail;
DROP TABLE IF EXISTS general;

Here's how you can execute this script on MySQL 5.0 :

mysql MYDB -h localhost -u web -ppassword < sql_script.sql

BTW, if you want to execute an SQL command quickly via the command line, type :

mysql MYDB -h localhost -u web -ppassword -e "alter table general AUTO_INCREMENT = 1"