Wednesday, March 31, 2010

Backup Databases

Backing up database is tricky. Database evolution is incremental; you will need another database to log every user action, and another, and another... Database development is progressive. There is hardly a subversion control. But there are two practical approaches. First, physical backups which are backups of the physical files used in storing and recovering your database. Ultimately, every physical backup is a copy of files storing database information to some other location, whether on disk or some offline storage such as tape. Second, logical backups that contain logical data (for example, tables schema or stored procedures) exported from a database, for later re-importing into a database using the corresponding import utility.

If a structural backup of the database (without any data) is needed, get the logical backups. If a full database backup (both schema and data) is needed, get the physical backups.

In SQL server, there are utilities for backup and restore. Essentially, it creates mirror image of the database file system, and loads it back when required. Occasionally, you may want to create another standalone database that mirrors the existing one. In this case, you need to
1. Create a database and give a proper name;
2. Specify the new mdb and log file location;
3. Find and load the backup file.
and done.

Doing both backup is essential.

Wednesday, March 24, 2010

Old IIS problem

I spent two good hours to figure out a tricky problem.
Scenario: I have two masterpages pointing to one code_behind. By doing this, I can have different layouts for different login. Locally, it runs perfectly. After I publish to server and test it on the net, I got
"Server Error in '/' Application."

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30456: 'CreateResourceBasedLiteralControl' is not a member of 'ASP.masterpage_master'.


Basically, Old IIS (v2.0) doesn't like code reuse -- The solution is to create two vb files that are identical masterpage code-behind for both masterpages (sure, you can make a difference there). And the old IIS satisfied.

Two good articles about masterpages.
http://www.asp.net/(S(pdfrohu0ajmwt445fanvj2r3))/learn/moving-to-asp.net-2.0/module-04.aspx
http://odetocode.com/Articles/450.aspx
http://www.beansoftware.com/ASP.NET-Tutorials/Master-Pages.aspx

Tuesday, March 23, 2010

Bye google.cn

To fight with evil, one has to be more evil. Google abandoned millions of users in Mainland China to protect its "free will". If it does the same to US (where FBI is famous), I would believe that it is really saint.

From "How I met your mother":
She (Robin)'s got one last photo to identify. Robin's pretty cocky when she takes the picture from him. "That, Barney, is the America actor beloved by millions -- the "Hey Vern" guy from the popular series of Ernest films, and his name is... Jeff Foxworthy." Barney laughs. He can't believe she doesn't know it's Jim Varney. Robin points at him. "Uh, that's Jeff Foxworthy, dumbass. End of story. Now shut your stupid face!" Barney says, "Not only are you wrong, but you are belligerently sticking to your guns, and insulting me in the process. Robin Scherbatsky..." He clicks his heels together and salutes her. "You are an American."

Wednesday, March 17, 2010

又一节体育课

星期三中午,pain in the domain。今天绕着domain跑,隔海望着歌剧院做俯卧撑、仰卧起坐。四周张望才发现澳洲人真喜欢运动啊,到处都是training。路上跑步的人川流不息。草地上的人比办公室的都多。果然天气好的地方,人们都喜欢在户外晃。
由于大家都剃了头,我们这队人形象不太好,极有可能被误解为出来放风的,引起了小小围观。

Tuesday, March 16, 2010

Using zip

using ICSharpCode.SharpZipLib.Zip;

public class ZipFileParser
    {
        public static IEnumerable UnzipFile(Stream fileStream)
        {
            var files = new List();
            using (ZipInputStream ZipStream = new ZipInputStream(fileStream))
            {
                ZipEntry theEntry;
                while ((theEntry = ZipStream.GetNextEntry()) != null)
                {
                    if (theEntry.IsFile)
                    {
                        if (theEntry.Name != "")
                        {
                            MemoryStream stream = new MemoryStream();
                            int size = 2048;
                            byte[] data = new byte[2048];
                            while (true)
                            {
                                size = ZipStream.Read(data, 0, data.Length);
                                if (size > 0)
                                    stream.Write(data, 0, size);
                                else
                                    break;
                            }
                            stream.Seek(0, SeekOrigin.Begin);
                            files.Add(new FileStream(theEntry.Name, stream));
                        }
                    }
                }
                ZipStream.Close();
            }
            return files;
        }


        public static void ZipFiles(Stream output, IEnumerable fileStreams)
        {
            using (ZipOutputStream stream = new ZipOutputStream(output))
            {
                stream.SetLevel(6);
                foreach (var s in fileStreams)
                {
                    s.Stream.Seek(0, SeekOrigin.Begin);

                    ZipEntry entry = new ZipEntry(s.Name);
                    long bufferSize = s.Stream.Length;
                    entry.Size = bufferSize;
                    entry.DateTime = DateTime.Now;

                    var crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
                    byte[] data = new byte[bufferSize];
                    int size = s.Stream.Read(data, 0, data.Length);
                    crc.Reset();
                    crc.Update(data);
                    entry.Crc = crc.Value;
                    stream.PutNextEntry(entry);
                    stream.Write(data, 0, size);
                    s.Stream.Dispose();
                }
                stream.Finish();
            }
        }

Monday, March 15, 2010

Joel on Software

I forgot and stopped to follow his blog http://www.joelonsoftware.com/ for quite a while until I saw his Chinese-translated book on a “best seller” shelf in China! -- At least 1/6 of the developer population are potential his fan. 

I finished reading his book today. This has accompanied me for my daily train ride in the morning (while in the afternoon, I usually try a Sudoku). I have to say, it is a good book -- contains some exceptional tech insights and not boring at all. I recommended this book to Ro. He bought one copy (English version costs about 4 times more than a Chinese one). He is enjoying it too.

Friday, March 12, 2010

Gmap must be a Kayak fan


Sydney NSW
1.    Head north on George St towardsAngel Pl         0.4 km
2.    Take the 3rd left on to Grosvenor St         0.2 km
3.    Continue onto Western Dstr         0.5 km
........
56.    Slight right at Goyder Rd         0.3 km
57.    Slight left at Gilruth Ave         1.8 km
58.    At the roundabout, take the 3rd exit ontoKahlin Ave         0.4 km
59.    At the roundabout, take the 3rd exit ontoMyilly Tce         72 m
60.    Turn left to stay on Myilly Tce         0.3 km
61.    Kayak across the Pacific Ocean
Entering Japan         5,404 km
62.    Turn right towards ??384??         1.3 km
63.    Continue straight onto ??384??         4.3 km
........
121.    Turn right         0.4 km
122.    Kayak across the Pacific Ocean
Entering United States (Hawaii)         6,243 km
123.    Turn right at Kalakaua Ave         0.5 km
124.    Turn left at Kapahulu Ave         2.5 km
........
134.    Turn left at Kuilima Dr         0.8 km
135.    Turn right         0.2 km
136.    Kayak across the Pacific Ocean
Entering Washington         4,436 km
137.    Sharp right at N Northlake Way         1.8 km
138.    Continue onto NE Pacific St         1.3 km
139.    Slight right at Montlake Blvd NE         0.5 km
........
Entering New York         3.8 km
165.    Take the ramp to Downtown/Brooklyn         0.3 km
166.    Slight left at Laight St         94 m
167.    Continue onto Thompson St         28 m
168.    Continue onto Canal St         0.4 km
169.    Turn right at Broadway         0.7 km
     New York, NY

Friday, March 5, 2010

Prophet

Last time when I flew back to SH, I watched <Surrogates >. It’s a not so fancy Sci-Fi movie, but it has a very realistic sense of feeling.  The background and the characters are not much different from todays.

The prophet in the movie reminded me of the founder of the Free Software movement, Richard Stallman. They look quite assembled! It looks like the director is mocking the real world. In the movie, the prophet himself is actually a surrogate; in the real world, I am pretty sure that RS is not using any non-GNU software – in fact, he probably doesn’t use any software at all. Still remember last time I listened to his speech: he started for 5 minutes and the video recorder asked him to start over again because the camera was off. Then he started all over again, and repeated exactly for 5 minutes. Honestly, I lost some interest of his speech after that point.

Anyway, I am pretty much a MS addicted man now: Win 7, VS2010, MS SQL server, except IE. If there is a prophet telling me that the machine will take over the world, I will buy.  

Wednesday, March 3, 2010

PE class

时隔多年,今天又上了体育课:pain in the domain。公司每个星期三,一帮子人到domain,一个trainer像催命鬼一样,催着你跑啊、俯卧撑啊、再跑啊……直到你趴下。
年纪大了,玩不动了。不过也的确该多运动运动,锈了。