Saturday, January 28, 2012

iOS Training Cource by Stanford University

I wrote the following blog while I was in Wuhan, China, during my vacation. For some reason, I could not access to my blogger there. I had to write my blogs in my sina blog. Now I copy the blog back to my programming blog.


I had to write my English blog at Sina blog web site since the Blogger is not accessible, during my visit to my extended family in Beijing and Wuhan. Fortunately, I have a Sina blog account so that I can continue to write my blog. I'll copy this blog to my Blogger when I get back.

Before I left for China, I found that iOS training by Stanford University(SU) was released. This is fall session course, started being published in Nov 2012. SU started to provide iPhone training courses several years ago, and I watched all the past iPhone training courses. I enjoy watching those courses very much. Even the course is an entry program for developers about iPhone application and Objective-C, the content has been kept up with the update of iOS. Based on the techniques and knowledge I learned from the course, I started my iPhone application development. I have to say that SU's course helps me a lot.

I think that SU's training course was one of a few educational programs for iPhone development and Obective-C. I greatly appreciate the updated content of the course along with the iOS progress. This time, the SU's iOS course has so many new contents about iOS 5. This course is quite different from the previous ones. For example, there is no more memory management by keeping track of reference counts. The XCODE is based on the new version of XCODE 4. The storyboard is included in the course as well. I think this course is a must-watch program for every iPhone and iPad developer.

I like the instructor, Paul Hegarty, very much. He started to teach this course last year. In this training, during the date Steve Jobs passed away, he revealed that he was in part of Steve Jobs' NeXT computer team in the early years. Later on he moved to University to teach computer courses. He is very knowledgable in Mac and iOS development.

I have downloaded all available classes before my leave from iTunes U. Now (Jan 7, 2012) I finished about 7 classes.

It seems that all those courses are available in iTunes U in China. The iTunes U course is in two formats: one in SD and another in HD. There is big difference in size. HD, in hight definition, takes a lot of spaces and thence takes too long time to download. For me, it is just a course to learn new things, and most likely I would not watch it again. Therefore, I would recommend to download the SD serials instead. Search for "iPhone" in iTunes to find SD serials.



References


Read More...

Sunday, January 15, 2012

Two ASP.Net Tips

I will be on vacation to China and be back on Jan 15, 2012. Since the Blogger is not accessible from China, I have to schedule my blog so that I will keep my promise to write at least one blog per week. This blog is a scheduled post.

This is note on two tips I found in ASP.Net.

Bind Field with Object Method


It is very common to bind a field to an object's property value. However, I find out one case that I prefer to bind a field with the object's method. The advantage of binding to a method is that I can pass parameter values in. I found a solution from SO.

Here is my example:

<asp:RequiredFieldValidator 
ID="RequiredFieldValidator1" 
runat="server" 
ControlToValidate="txtValue1"
Visible='<%#((MyData) Container.DataItem).RawValueAvailable(1) %>'
ErrorMessage="Value cannot be empty">*
</asp:RequiredFieldValidator>

I need to add required validation control with a condition if there is value for the bound object.  The above example sets Visible with the method "RawValueAvailable(..) of the bound object of MyData.  It works great.

Set Login Timeout


By default ASP.Net authentication has a timeout of 30 minutes. This timeout looks like that it can be customized. I found an answer from SO. Here is an example:

<system.web>
  <authenticationmode="Forms">
    <formstimeout="50"/>
  </authentication>
  <sessionStatetimeout="60"  />
</system.web>

Setting the forms timeout to something less than the session timeout can give the user a window in which to log back in without losing any session data. However, I think that client side cached data will be gone if redirect is called. For example, if a user enters several data into a data grid view, the changed data may be lost if login timeout is passed. There may be a way to provide warning for saving data by using Javascripts.

References

Read More...

Tuesday, January 03, 2012

Interesting Discovery of float.Parse()

I found some thing really interesting about float.Parse() method. Normally, I thought this parse method should be able to convert any numeric string to a float value, as long as it does not cause overflow. However, I found that it does not really faithfully do the conversion. If the string value is too small or too big, you may lost some precision in value.

Here I tried to narrow down this issue to a test program:

private static void TestFloat() {
  for (int index = 1; index &lt; 10; index++)
  {
      string val = string.Format("{0}.123456", new string('8', index));
      float f = float.Parse(val);
      string sF = f.ToString();
      string sF1 = f.ToString("0.000000");
      Console.WriteLine(@"string value: {0}(len: {5}); float value: {1}(len: {6}-{7});
string to float.Tostring()    {0}=={1}? {3};
string to float.Tostring(xxx) {0}=={2}? {4}",
       val, f, sF1, val.Equals(sF), val.Equals(sF1), val.Length, sF.Length, sF1.Length);
  }
}

The result is very surprising:


string value: 8.123456(len: 8); float value: 8.123456(len: 8-8);
  string to float.Tostring()    8.123456==8.123456? True;
  string to float.Tostring(xxx) 8.123456==8.123456? True
string value: 88.123456(len: 9); float value: 88.12346(len: 8-9);
  string to float.Tostring()    88.123456==88.12346? False;
  string to float.Tostring(xxx) 88.123456==88.123460? False
string value: 888.123456(len: 10); float value: 888.1235(len: 8-10);
  string to float.Tostring()    888.123456==888.1235? False;
  string to float.Tostring(xxx) 888.123456==888.123500? False
string value: 8888.123456(len: 11); float value: 8888.123(len: 8-11);
  string to float.Tostring()    8888.123456==8888.123? False;
  string to float.Tostring(xxx) 8888.123456==8888.123000? False
string value: 88888.123456(len: 12); float value: 88888.13(len: 8-12);
  string to float.Tostring()    88888.123456==88888.13? False;
  string to float.Tostring(xxx) 88888.123456==88888.130000? False
string value: 888888.123456(len: 13); float value: 888888.1(len: 8-13);
  string to float.Tostring()    888888.123456==888888.1? False;
  string to float.Tostring(xxx) 888888.123456==888888.100000? False
string value: 8888888.123456(len: 14); float value: 8888888(len: 7-14);
  string to float.Tostring()    8888888.123456==8888888? False;
  string to float.Tostring(xxx) 8888888.123456==8888888.000000? False
string value: 88888888.123456(len: 15); float value: 8.888889E+07(len: 12-15);
  string to float.Tostring()    88888888.123456==8.888889E+07? False;
  string to float.Tostring(xxx) 88888888.123456==88888890.000000? False
string value: 888888888.123456(len: 16); float value: 8.888889E+08(len: 12-16);
  string to float.Tostring()    888888888.123456==8.888889E+08? False;
  string to float.Tostring(xxx) 888888888.123456==888888900.000000? False

To my discovery, the parsed result lost its precision, 9 out of 10!

I found this issue when I tried to take an input string from a text box, convert it to a float value and finally save to database.  My tester found that the results are not consistent when value is too big. At the beginning I did not believe it, but after I repeated the case, I found the bizarre result.  Finally I realized the issue is caused by Parse() method.

Any way to get around this issue? It seems there is no way to save the exactly value to database. Even I can save the value as a string to database, eventually, it may reach a point that database will present the value as xxxEzz format, which may lost precision when the value is retrieved back.

It looks like that we have to limit values to be entered, to a realistic range. Then handle the value from UI to database or vice visa.


This blog is published by schedule.

Read More...

Sunday, January 01, 2012

Tips for Better 2012

This is a scheduled post. I got the following tips from my friend in a PPS show. I like it very much. Instead of chaining the email to others, here I put it in my blog.

Tips for the better life for 2012


  • Take a 10-30 minutes walk every day and while you walk, smile.
  • Sit in silence for at least 10 minutes each day.
  • Sleep for 7 hours
  • Live with the 3E's Energy, Enthusiasm, and Empathy.
  • Play for more games.
  • Read more books than you did in 2011.
  • Drink plenty of water
  • Eat more foods that grow on trees and plants and eat less food that is manufactured in plants.
  • Eat breakfast like a king, lunch like a prince, and dinner like a beggar.
  • Make time to practice meditation, yoga, and prayer. They provides us with daily fuel for our busy lives.
  • Dream more while you are awake.
  • Smile and laugh more.
  • Try to make at least three people smile each day.
  • Don't waste your previous energy on gossip.
  • Don't have negative thoughts or things you cannot control. Instead invest your energy in the positive present moment.
  • Spend time with people over the age of 70 & under the age of 6.
  • Life is too short to waste time hating anyone. Don't hate others.
  • Don't take yourself so seriously. No one else does.
  • Forget issues of the past. Don't remind your partner with his/her mistakes of the past. That will ruin your present happiness.
  • Realize that life is a school and you are here to learn. Problems are simply part of the curriculum that appear and fade away like algebra class, but the lessons you learn will last a lifetime.
  • You don't have to win every argument. Agree to disagree.
  • Don't compare your life to others'. You have no idea what their journey is all about. Don't compare your partner with others.
  • Make peace with your past so it won't spoil the present.
  • Your job won't take care of you when you are sick. Your friends will. Stay in touch.
  • Forgive everyone for everything.
  • What other people think of you is none of your business.
  • However good or bad a situation is, it will change.
  • Get rid of anything that isn't useful, beautiful or joyful.
  • Envy is a waste of time. You already have all you need.
  • The best is yet to come.
  • No matter how you feel, get up, dress up and show up.
  • Don't over do. Keep your limits.
  • Your inner most is always happy. So be happy.
  • Do the right thing!
  • Call your family often.
  • Each day give something good to others.
Please, forward this to everyone you care about.

Read More...