Tuesday, March 18, 2008
GWT(google Web Toolkit)
The tool kit allows programmers write plain Java which be compiled into JavaScript for rich web front-end application. There is a Java to JavaScript compiler will compile the Java code to JavaScript while the library that comes with the tool kit will hide the any browser quicks for you. The resulting JavaScript code will only be load once on the client and only the data will be dynamically requested by the JavaScript code. I think it is wonderful programming model.
The issue I am running into is that since Javascript has so called Same Origin Policy . It prevents any scripts that try to request data from any servers other than the server that the scripts are loaded.
It is not much a problem for the GWT, the front-end development server happens to be the same back-end server if you are using built-in RPC calls. For me, I was going to use Microsoft IIS as my development back-end server. Since I am going to use Eclipse with GWT plugin as my front-end development environment, the JavaScript will be loaded from my front-end development server and will not be able to request any data from back-end server on a different port (it will violate the Same Origin Policy).
To work around the problem, I use a tool called Fiddler which allows you to modify the request on the fly. What you need to do it just download and install the software from the web site. Upon launching the Fiddler UI, press CTRL-R to open customized script editor (it can also be open via menu Rules | Customize Rules... ). Locate a function call OnBeforeRequest and insert the following lines:
if (oSession.HostnameIs("MYAPP")) {
if (oSession.PathAndQuery.StartsWith("/search")){
oSession.host = "www.google.ca";
}
else {
oSession.host = "127.0.0.1:8888";
}
}
It is quite self-explanatory. It basically says that if the host name is MYAPP, then rewrite the host name based on the requesting URL. In the example, if the URL is starting with "/search", it will send the request to "www.google.ca" otherwise it will send requests to localhost port 8888. It needs to customized to suit your needs.
After you set it up, you can now requesting paging via Internet Explorer (unfortunately it works only on IE). Try the following:
This will overcome the Same Origin Policy restriction for you since your JavaScript and back-end server will all appear as it originated from the same server.
It has the following drawbacks.
1. It does not work on Firefox.
2. The breakpoint has no effect if you invoking the page via the proxy. (I do not know why?)
Friday, February 22, 2008
Microsoft Web UI
- ASP.NET/AJAX
- SliverLight
- Volta
- ASP.NET/MVC (a programming model that not related to always related AJAX)
- Visual Web GUI
- ...
Tuesday, February 05, 2008
Is object assignment statement thread safe?
" The CLR guarantees that for types which are no bigger than the size of a native integer, if the memory is properly aligned (as it is by default - if you specify an explicit layout, that could change the alignment), reads and writes are atomic. In other words, if one thread is changing a properly aligned
int variable's value from 0 to 5 and another thread is reading the variable's value, it will only ever see 0 or 5 - never 1 or 4, for instance. For a long, however, on a 32-bit machine, if one thread is changing the value from 0 to 0x0123456789abcdef, there's no guarantee that another thread won't see the value as 0x0123456700000000 or 0x0000000089abcdef. You'd have to be unlucky - but writing thread-safe code is all about taking luck out of the equation."From link
It does not mention object reference assignment. However the size of object reference is always equal to the native integer which means on 32-bit machine the reference size should be 32 bits and on 64-bit machine the reference size should always be 64 bits, therefore it is thread safe.
Monday, February 04, 2008
Best practice for database version
The way I am doing it is quite strange forward and involves 2 steps.
- Create base-line database.
- Create and maintain a single change script file which will be checked into source control.
Point A has no semantic difference.
For point B, it is not necessary because when you apply the script which has a version number in the source control (I am using SubVersion which will generate a unique repository-wide incremental number each time you make change(s) to the source repository and our build number is tied to this number), and therefore you know what is the database schema version after the script applies. If customer reports a problem with build 213, I know exactly what the database schema should be and all the source code that associated with this build.
Sunday, February 03, 2008
Session for ASP.NET
Thursday, January 24, 2008
Generic Wrapper for Session variable in ASP.NET
Usage:
GlobalAppParameter gp = GetSession<GlobalAppParameter>("gp", delegate {
return GlobalAppParameter.NewGlobalAppParameter();
});
protected delegate T CallBack<T>();
protected T GetSession<T>(string sessionName, CallBack<T> callBack ){ T ret;
if (Session[sessionName] == null)
{
ret = callBack();
Session[sessionName] = ret;
}
else
ret = (T) Session[sessionName];
return ret;
}
Tuesday, January 22, 2008
Order By Sub-query
SELECT BranchID,
( SELECT TOP 1 InstitutionName FROM Institution WHERE Institution.InstitutionID=FIServiceLocation.InstitutionID) InstitutionName
FROM FIServiceLocation
Order By (SELECT TOP 1 InstitutionName FROM Institution WHERE Institution.InstitutionID=FIServiceLocation.InstitutionID)
The feature actually is very useful for me in a project I am working on, since I wanted to be able to sort a computed field.