Posts

Showing posts from 2011

7 inch tablets specs comparison

Image
 Specs Comparison Table (click to enlarge) I'm planning to get a 7" tablet recently and thus created this table for comparing their specs. Though Samsung generally rules by their specs, but it also comes with a premium prices. Nook Tablet seem to be a great choice FOR ME, since I plan to use it mainly for reading (books & web pages), I have an iPad 2 but its to bulky to be a portable reading device. Furthermore, USD 249 seem to be a resonable price.

Using bitwise operation OR & AND on integer for validation

Today I'm going to revisit bitwise OR (|) and AND (&) operation on integer specifically for role based security checking scenario. Scenario : There are few reason why bitwise operation on integer is needed in an application, but more frequently seen to be use for validation for e.g. user's role validation. This is a very useful scenario, the application stores only one integer on the database to represent all the role that is assigned to that user. And on the application, user role is usually represented as Enum (Enum is a kind of integer). Lets get into some coding. Following is small C# program I wrote on LINQPad. void Main() { // PART (A) Define user role int Public = 1; int Sales = 2; int Marketing = 4; int Engineering = 8; // PART (B) Assign some role to user. Assigned role is stored as an integer in the db of the user table. int currentUser1 = Sales | Public; int currentUser2 = Marketing | Public; int currentUser3 = Sales | Marketing | Public; // D

Copy all public properties from an object to another object

I often ran into situation where I need to copy all the value of an object into another object, this normally happen in ORM related project where you need the value to be copy from an entity to an entity retrived from db (ActiveRecord) kind of entity, so I created a simple extension method to facilitate this action. /// /// Copy the speficied public properties from source to target. /// /// Type of object. /// Target object to copy to./// Source object to copy from./// Target object with each public properties copied from source object. public static T CopyFrom (this T target, object source) { var sourceObjType = source.GetType(); //loop through each public properties in the type foreach (var targetProperty in target.GetType().GetProperties()) { var sourceProperty = sourceObjType.GetProperty(targetProperty.Name); if (sourceProperty != null) // match found { // check types and take care of Nullable type. var sourceType = Nullable.GetUnderlyingType(sourceProp