My name is Johnny,I have being working as a developer, programmer for about 13 years now, and I think I will stay as a programmer for as long as I can. All these years I have used so many technologies , programming languages,but majority is using C++ and .net, there are ups and downs along the way, this blog is just to write down all the issues that I had been worked on, things that I learned. if someone else can also benefit a little bit from it , that's already a big bonus.
Sunday, March 27, 2011
In GDI+ how to draw a text vertically.
Sunday, March 13, 2011
How to setup Form Authentication Service through WCF
These few days, I am trying to implement something based on my own interest. And I would like to host my business logic on my server. So Obviously WCF is a good choice. but I was thinking how can I make sure that my service can be only accessed by legitimate users instead of everyone, then I thought of Form Authentication, and it turns out Microsoft already provide a solution for this.
http://msdn.microsoft.com/en-us/library/bb386582.aspx
Given the fact that there are already pretty much articles about this topic on internet, I just want to write what I had been through.
- When you invoke the authentication service, if you get an error message say that the service is disabled. Make sure that the following few lines exist in your web.config file, and enabled has been set to true.
- Why IsLoggedIn function always return false, even right after login.
<system.web.extensions>
<scripting>
<webServices>
<authenticationService enabled="true"
requireSSL = "false"/>
</webServices>
</scripting>
</system.web.extensions>
Check your local config file, to make sure that allowCookies option had been turned on.
3. For all the service that protected by form authentication, when you call those services, make sure you had passed in the form cookie. otherwise , you will be kicked out.
Monday, March 7, 2011
An interesting interview question, How to store an grid of which each dimension has more than 1m elements
I was thinking this these few days, assume each node in the grid, we need to persist it's x axis and y axis,
public struct Node
{
int x;
int y;
}
each node need at least 8 bytes in memory, put the memory alignment aside , don't worry about it at this moment, for an 1million * 1million grid, if we store all the nodes in memory, how big it will be,
Total = 1million * 1million * 8 /1024/1024/1024 GB
= 7450.58GB
so, obviously , it is not possible to store the whole grid in memory, we have to break down the grid to small grids.Assume the size of the view port is 1024 * 768, I will say each small grid, the size is 1024 * 768, a view port.
Based on this , we can break down the big grid to a small one, I will call it page grid, but each cell in the grid, pointing to another grid, which is exactly the size of one view port, I call it a page, sorry, I borrow this idea from database .
x:0-1024 y:0-768 | x:1024-2048 y:0-768 | x:2048-3072 y:0-768 | x:3072 - 4096 y:0-768 | ...... |
x:0-1024 y:768-1536 | x:1024-2048 y:768-1536 | x:2048-3072 y:768-1536 | x:3072 - 4096 y:768-1536 | ...... |
.... | .... | .... | .... | ...... |
The width of this new grid is 1million / 1024 = 977
The height of this grid is 1million / 768 = 1303
The data of each cell on above grid will be store on hard disk, based on the left top position of the view port, we can easily identify data in which cell we need to access. the formula is quite simple
maximum we will need to load in four cells of data. think about it.
In this way, the is not too big anymore, so we don't need to bother whether to use linked list or binary tree, or whatever, for linked list, it is not design for fast search, it is for easy expandable. while binary tree, it good for search, but maintenance cost is very high. obviously we need to balance
while in this case , I will say , use an array or a hash map to persist the page grid, which is easy to search and maintain.