肖恩D++
Not Equal C && !=C && C && 不等于西-
补胎记
Posted on January 26th, 2012 No comments昨晚,挠人的轮胎报警灯又亮了。在经历了一次又一次狼来了之后,还是决定检查一下看看到底是因为胎压不稳还是轮胎真有问题。撅着腚趴在地上一个轮子一个轮子检查之后,狼真来了:一根直径大概半厘米的铁钉很不识相的嵌在轮胎的胎纹里。郁闷半天之后,决定第二天一早去补胎。
早就知道家附近就有一个叫“America Tires”的轮胎店,虽然从来没进过。店员都还很亲切,简直有点肉麻,让我“噗通,噗通”乱跳的小心脏又增加了几分紧张,要知道服务往往是和价钱挂钩的。
在一番检查之后,技工把车开进车间里修理。大约半个多小时后,接待我的店员递给我钥匙和一张收据,说道:“Sir, you are all set. have a nice day!”
开车赶向办公室的途中,在苦思冥想了半天总觉得“忘了什么事儿”后,终于意识到,原来这次补胎竟然不用给钱……
5 views -
未尽的事业
Posted on January 14th, 2012 No comments据说这十大地方会在不远的未来彻底消失——悉数一下,这十个地方去过的数字仍然是“0”。看来在人类还未曾找到有效改善自己方法的前提下,最好还是尽早踏上这十个濒危的地方。

15 views -
Custom Validation for MVC 3 Model Example 1: Positive Integer
Posted on January 7th, 2012 No commentsWhen you define a property of the model, you can always put some MS’s attributes to validate the data, like “Required”, “Range”. Also you can use custom validation via expression or creating new attribute class. For example, the “NumberOfStock” for “Product” must be an integer and positive.
Actually to accomplish this validation is quite easy, if use regular expression:public class Product { [Required(ErrorMessage = "Number of Stock is Required")] [RegularExpression("^\\+?\\d+$", ErrorMessage = "Must be a Positive Non-decimal Number")] public int NumberOfStock{ get; set; } /******** Other Properties **************/ }The way showed above will be good enough if you only have a few models or a small application. For a big project, you might want to create your own attribute instead of using expression. The advantage of dong this is easy to centralize (if you have many custom validations), and easy to debug.
First, we need to create custom attribute class:[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class PositiveIntegerAttribute : ValidationAttribute { public PositiveIntegerAttribute() : base("Must be a Positive Non-decimal Number") { } public override bool IsValid(object value) { if (value == null) { return true; } int num; if (int.TryParse(value.ToString(), out num)) { if (num >= 0) return true; } return false; } }Then, we will create validation adapter to enable client side validation
public class PositiveIntegerValidator : DataAnnotationsModelValidator { public PositiveIntegerValidator(ModelMetadata metadata, ControllerContext context, PositiveIntegerAttribute attribute) : base(metadata, context, attribute) { } public override IEnumerable GetClientValidationRules() { return new[] { new PositiveIntegerClientValidationRule(ErrorMessage) }; } } public class PositiveIntegerClientValidationRule : ModelClientValidationRule { private const string Regex = @"^\+?\d+$"; public PositiveIntegerClientValidationRule(string errorMessage) { ErrorMessage = errorMessage; ValidationType = "regex"; ValidationParameters["pattern"] = Regex; } }Last thing we need to do is register the adapter in “Application_Start” function of “Global.asax” file:
protected void Application_Start() { /**********Other code************/ DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(Library.PositiveIntegerAttribute), typeof(Library.PositiveIntegerValidator)); }Now, we can use the custom validation attribute “PositiveInteger” for the model “Prodcut”
public class Product { [Required(ErrorMessage = "Number of Stock is Required")] [PositiveInteger] public int NumberOfStock{ get; set; } /******** Other Properties **************/ }
68 views -
One line to remove all unneeded old kernel for Ubuntu
Posted on December 5th, 2011 No commentsAlong with the kernel keeps updating, many old kernels are kept in the system. For normal users, those old kernels are no longer needed, so the best way just remove them.
To remove all kernels, just run the single line with below:dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge*Original post from here
80 views -
火鸡和感恩节
Posted on November 23rd, 2011 No comments在美国,一提起感恩节,就马上会和火鸡联系起来。人们纷纷去超市购买火鸡,然后与全家一起分享,颇有点合家欢乐的感觉。不过,换位思考一下,如果站在火鸡的立场上,一定是对感恩节深恶痛绝、势不两立的……
明天,有是一年一度的火鸡的冤家。可没想到,中午竟然发现一队火鸡在领队的带领下,在公司的停车场游荡。不得不为他们的勇气致敬,难道他们是在提醒我们,“嘿,感恩节到了,准备好了吗?”
88 views
0 guests, 1 bots, 0 members
Max visitors today: 5 at 01:13 am PST
This month: 9 at 01-04-2012 05:46 pm PST
This year: 9 at 01-04-2012 05:46 pm PST
All time: 102 at 01-17-2011 05:47 am PST









Recent Comments