Pages

Tuesday, September 29, 2009

Social network vs Community site

Yesterday, when I have to research a technical solution for a new prospect, I asked some questions to Mr. Hong - an excellent Technical manager in our company - about approaches to build current system for a big community. He tells me many good points and consult me a lot. However, I found another lack thing in my knowledge: what are differences between Online Community site and Social network? For a long time, I use the terms "online community" and "social network" interchangeably.

After trying searching and digging into these concepts, I found some points help me to understand them more clearly.
A social network is a social structure made of individuals (or organizations) called "nodes," which are tied (connected) by one or more specific types of interdependency, such as friendship, kinship, financial exchange, dislike, sexual relationships, or relationships of beliefs, knowledge or prestige.
Social network analysis views social relationships in terms of network theory about nodes and ties. Nodes are the individual actors within the networks, and ties are the relationships between the actors. The resulting graph-based structures are often very complex. There can be many kinds of ties between the nodes. Research in a number of academic fields has shown that social networks operate on many levels, from families up to the level of nations, and play a critical role in determining the way problems are solved, organizations are run, and the degree to which individuals succeed in achieving their goals.

(From http://en.wikipedia.org/wiki/Social_network)

A virtual community, e-community or online community is a group of people that primarily interact via communication media such as newsletters, telephone, email, internet social network service or instant messages rather than face to face, for social, professional, educational or other purposes.

(http://en.wikipedia.org/wiki/Online_community)

These definitions may make us more confuse. However, in my opinion, these are some things that we should consider:
1. Target of a social network is "building the social structure". Target of an online community site is: "building communication tools of a community". Anyways, in many cases the boundary is not always clear.
2. All activities of a user in a social network must be attached with "social nodes". That means "a user joined to a social network must find and expand his/her relationships". Without doing this, he/she can not see any activities are happening. This is the strongest point of social network ("encouraging and forcing making relationships"). In online community site, this is not required. You can join a community site (like Community Server forum) and can see all happening activities without making friends with anyone. (I found this point in this article).

I am waiting for your comments and sharings about these concepts!

Wednesday, September 23, 2009

Meditation Garden iPhone app and SiO2


I love this app. It inspires me to develop app with SiO2 game engine!

MeditationGarden from SIO2 Interactive on Vimeo.

Saturday, September 12, 2009

NHibernate auto create database bug when using attribute for mapping

I am on vacation. However, I've just received a feedback email from a developer in Brazil on TinyERP (an open source project that I posted several months ago). He found that TinyERP framework can not create database automatically although he set the "create" value for hibernate.hbm2ddl.auto NHibernate properties in spring.xml config.
Actually, I haven't released any version of TinyERP in Codeplex. In the past, I created a sample database (not generate DB automatically from schema). Anyway, I need to check this issue.
After several minutes checking, I found the issue:

In TinyERP, I use NHibernate attribute on Business Entity for mapping. To use this, we have to override a LocalSessionFactoryObject to add assembly contains Business Entity classes into HbmSerializer. HbmSerializer only helps us to create Hibernate mapping config in stream. A very stupid thing is: the code to check and generate DB schema does not exist in parent classes of LocalSessionFactoryObject => Nothing happens when you set hibernate.hbm2ddl.auto="create".

The old code
public class LocalSessionFactoryObjectImp : LocalSessionFactoryObject
    {
        protected override void PostProcessConfiguration(NHibernate.Cfg.Configuration config)
        {
            base.PostProcessConfiguration(config);
            HbmSerializer.Default.Validate = true;
            IList modules = ApplicationConfiguration.GetInstance().Modules;
            foreach (Module module in modules)
            {
                Assembly assemblyInAppDomain = FindAssembly(module.Assembly);
                if (assemblyInAppDomain != null)
                {
                    config.AddInputStream(HbmSerializer.Default.Serialize(assemblyInAppDomain));
                }
            }
           
        }

The above code is a common code template to override LocalSessionFactoryObject - that we mostly see in many forums. The problem is: default SessionFactoryObject in NHibernate keeps the code to export DB schema. However, LocalSessionFactoryObject and its parent class do not implement any line of code for this. So, we have to add this feature manually if we want to override it.

This is the new code to fix this issue:
public class LocalSessionFactoryObjectImp : LocalSessionFactoryObject
    {
        protected override void PostProcessConfiguration(NHibernate.Cfg.Configuration config)
        {
            base.PostProcessConfiguration(config);
            HbmSerializer.Default.Validate = true;
            IList modules = ApplicationConfiguration.GetInstance().Modules;
            foreach (Module module in modules)
            {
                Assembly assemblyInAppDomain = FindAssembly(module.Assembly);
                if (assemblyInAppDomain != null)
                {
                    config.AddInputStream(HbmSerializer.Default.Serialize(assemblyInAppDomain));
                }
            }
            SchemaExport schemaExport = new SchemaExport(config);
            string autoCreateDBMode = config.GetProperty("hibernate.hbm2ddl.auto");
            if (!string.IsNullOrEmpty(autoCreateDBMode) && autoCreateDBMode == "create")
            {
                schemaExport.Create(true, true);
            }
        }
}

Hope it's useful in case you have same problem with using NHiberate attribute for mapping and auto creating DB schema.

Friday, September 11, 2009

I am inventor of Facebook

Now, I become a famous man - Inventor of Facebook. Don't you believe?
See below video:

Saturday, July 18, 2009

iPhone OS - drawing image and stupid thing from Apple

Just because of a piece of code, a team in Singapore gave up an iPhone project. Actually, they do not know how to play tricks with Apple. ... and I also faced to a similar situation when I play as a technical consultant to fix this stupid bug.

The need of client is: drawing some effects on an image and save it as a photo in Photo library. So, if anyone has experience with graphic programming may think this is a very simple task. However, that's not true.

Many forums and online articles just shows us a real problem on iPhone graphics programming: the root position (0,0) of the image to draw is on the bottom left and the root position of the graphic context is on the top-left corner. So, we must do some transformation to keep the image in the correct position.

And the simple code to fix this issue is as below:
int width = image.size.width;
int height = image.size.height;
CGSize size = CGSizeMake(width, height);
//create the rect zone that we draw from the image
CGRect imageRect = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
//Save current status of graphics context
CGContextSaveGState(context);
//Do stupid stuff to draw the image correctly
CGContextTranslateCTM(context, 0, height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, imageRect, image.CGImage);
//After drawing the image, roll back all transformation by restoring the 
//old context
CGContextRestoreGState(context);
DO OTHER EFFECTS HERE
//get the image from the graphic context
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
//commit all drawing effects
UIGraphicsEndImageContext();
Above piece of code is thing that you see in all online technical articles related to iPhone graphic programming. Anyway, that's not enough. If you deploy that piece of code into iPhone OS 3.0 on real device, it does not run correctly: saved images are always scaled in horizontal and inverse. However, there is a very strange thing: this code is run perfectly on simulator for iPhone OS 3.0.

After 1 day to detect the problem, I found that: when an image is shown on iPhone, it has a direction. Direction is included: UP, DOWN, LEFT, RIGHT. So, we must to fix the code to satisfy when they're in those cases. The above code is run correctly in case image direction is UP.

Here is the fixed version:
int width = image.size.width;
int height = image.size.height;
CGSize size = CGSizeMake(width, height);
//create the rect zone that we draw from the image
CGRect imageRect;

if(image.imageOrientation==UIImageOrientationUp 
|| image.imageOrientation==UIImageOrientationDown) 
{
    imageRect = CGRectMake(0, 0, width, height); 
}
else 
{
    imageRect = CGRectMake(0, 0, height, width); 
}

UIGraphicsBeginImageContext(size);
CGContextRef context = UIGraphicsGetCurrentContext();
//Save current status of graphics context
CGContextSaveGState(context);

//Do stupid stuff to draw the image correctly
CGContextTranslateCTM(context, 0, height);
CGContextScaleCTM(context, 1.0, -1.0);

if(image.imageOrientation==UIImageOrientationLeft) 
{
    CGContextRotateCTM(context, M_PI / 2);
    CGContextTranslateCTM(context, 0, -width);
}
else if(image.imageOrientation==UIImageOrientationRight) 
{
    CGContextRotateCTM(context, - M_PI / 2);
    CGContextTranslateCTM(context, -height, 0);
} 
else if(image.imageOrientation==UIImageOrientationUp) 
{

//DO NOTHING

}
else if(image.imageOrientation==UIImageOrientationDown) 
{
    CGContextTranslateCTM(context, width, height);
    CGContextRotateCTM(context, M_PI);
}

CGContextDrawImage(context, imageRect, image.CGImage);
//After drawing the image, roll back all transformation by restoring the 
//old context
CGContextRestoreGState(context);
DO OTHER EFFECTS HERE
//get the image from the graphic context
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
//commit all drawing effects
UIGraphicsEndImageContext();
After fixing this bug, I can say only one thing: why Apple always do something stupid and make developer do the stupid thing?