by Aref Wed, May 21 2014 10:19

Recently I came across an interesting specification by Mozilla called asm.js (
One of the things about asm.js is that it is a stricter version of JavaScript and is completely backward compatible with JavaScript. However the benefit is that this JavaScript (asm) is a lot more optimized, making use of low level JavaScript features such as typed arrays. A good summary is provided here:
So, the question is, how do you produce asm.js? You should not be doing this by writing JavaScript code from scratch. As sadistic as it is, it will also render the project very difficult to maintain.
One of the tools that can produce asm.js is Emscripten ( which is essentially a Low Level Virtual Machine byte code (LLVM bytecode) to JavaScript transpiler. Emscripten will take LLVM bytecode as its input and will produce asm.js compliant JavaScript as the output.
So, how do you produce LLVM if you are a C# developer?
Well, one option that I wish to explore is an academic project ( that will produce LLVM bytecode from C# code as its input. Then, it is a matter of piping the LLVM bc to Emscripten to produce good quality JavaScript.
If anyone has already attempted this, please comment your experience below, otherwise I will come back and update once I am able to try out this option for myself.



Rough-cutting and milling lumber to size

by Aref Tue, May 20 2014 16:57

Here are some of the tips that I have learned on how to go from lumber to flat, true stock.

Please note that these are for my own reference. Please consult all appropriate safety and tool instructions before you work with your hands and sharp/life and limb threatening tools.

Part 1 – Layout

1.       Mark/Circle off any problem areas such as knots, sap and other defects on the board, looking on both faces of the board.

2.       Looking at the plan, start to mark off each piece on the board, avoiding all problem areas. Try fitting smaller parts around the problem areas if possible and make extra parts from around remaining problem areas.

Part 2 - Dimensioning

1.       Make sure that we rough cut to size first. Batch the job, e.g. rough-cut all rails at the same time, rough-cut all stiles at the same time, rough-cut all drawers at the same time, rough-cut all legs at the same time and so on. Leave larger parts like tops and parts with large surface area for when you will be using them as otherwise, they will react to the moisture and cup or bow and twist as they wait to be used.

2.       Rough-cutting

a.       First take off the ends ¼ inch at a time and test the waste strip for fragility and hairline cracks. All of this can be done with a chop saw, miter saw, circular saw or something similar that makes it easier to work with large pieces of lumber.

b.      Then rough-cut (usually against the grain) the parts, an inch greater, than the called for length.

c.       Next up, head on over to the table saw and rip the pieces to rough width, 0.5 inch greater than the called for width. Look at the grain pattern and mark (number) the parts that will need to be next to each other in the middle, on the width side of the board.

3.       Flattening and jointing

a.       Next up, we will flatten one face of each piece, preferably on a jointer. If that is not possible then there are ways to do this using a table saw provided the parts are not too wide. Creep up on the dimension 1/16 th. of an inch at a time. Also look at the grain direction and move the piece “downhill” on the grain. Any perceived cups, bows and twists should be facing the blade. Generally a nice flat face will provide the feel of suction as it is being lifted off another flat surface.

b.      Next we will use a planer to achieve the correct thickness of the pieces. Try to again “creep up” on the final thickness by taking equal small amounts from each face.

c.       Next, use the jointer to square the thickness part of the piece against its face, running the piece with the grain “down-hill – wider part and not the peak of the grain moving towards the blades”.

4.       Rip to final width

a.       Now, we will take our pieces to the table saw, and using a good quality rip blade, rip the pieces to final width.

5.       Cross-cut one end to square

a.       Now, using a good cross-cut blade or a combination blade, score off one end and using an engineers’ square, check for squareness against the jointed edge.

b.      Next, cross-cut all pieces with the squared end against a stop block to final length. Make sure that you use a stop block on the cross-cut sled so that all lengths cut are consistent. Marking is always more accurate than measuring.



Data Entity Models – Customizing, Mappings and Reference Relationships

by Aref Tue, April 22 2014 12:05

Here is a cheat-sheet of the most commonly used data annotation attributes with Entity Framework

Data Attributes

Data Type: Use this to specify a more specific datatype than what is intrinsically assumed by EF. In this case a Date instead of Date Time.
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime EnrollmentDate { get; set; }

Column Attribute: The Column attribute specifies the column name that EF will assign (create) when the physical database model is generated. So your entity class (model) property may be called FirstName but with the Column attribute, that specifies [Column(“FNAME”)] will ensure that the corresponding database field name is FNAME.
public string FirstName { get; set; }

DatabaseGenerated Attribute: Use this to specify how primary key values will be generated by the database or provided by the user (by using None as in the example below).

Display Attribute: The Display attribute specifies the caption that will be used for the text boxes instead of the Property Names
[Display(Name = "Full Name")]
public string FullName {get; set;}

DisplayFormat Attribute and the NullDisplayText: Use this to specify a default text in case of nulls.
[DisplayFormat(NullDisplayText = “No Courses”)]

Read-Only Calculated Properties

Here is an example:
[Display(Name = "Full Name")]
public string FullName
                 return LastName + ", " + FirstName;


String Length: Specify a maximum length for a string data type. Note: You can also use the MaxLength attribute but this will not provide you with client side validation.
[StringLength(50, ErrorMessage = "First name cannot be longer than 50 characters.")]
public string FirstName { get; set; }

Regular Expression: Specify a regular expression to provide restrictions to an input.

Here are some online tools to help you build and test regular expressions:


Required Attribute: Makes the associated property a required field. Not needed for value types such as DateTime, int, double and float


Reference Relationships

Primary Key – the Key Attribute: Use the Key attribute to specify a Primary Key when naming convention (<entity>Id) was not used for instance. This tells EF to consider the following property as a primary key.

public int SID { get; set; }

Foreign Key – the ForeignKey Attribute: Use the ForeignKey attribute on the dependent class, for instance on the many side of a relationship to specify a Foreign Key relationship. For instance lets say the Primary Key for a Student is SID and a Student can have many courses. You will specify the ForeignKey attribute to SID in the Course entity (dependent) to specify the Foreign Key.

… in the Course class …
public int SID { get; set; }

NOTE: You must also include a navigation property to match the ForeignKey name (Student in the example above)!

public virtual Student Student { get; set; }

This tells Entity Framework that the SID property in the Course class is a Foreign Key to the Student class.



Navigation Properties are lazy loaded (therefore uses Virtual) and provides navigation to other entities if needed. For example if a student has enrolled in many courses, the Student entity can have a navigation property to the Course(s) as shown below. Note that this does not imply a Database Referential Relationship (Foreign Key, Primary Key). Also as in this case if the navigation is required to many of the referenced entity, it’s type must have implemented the ICollection<T> interface such as IList<T> but not IEnumerable<T>

… within the Student class…
public virtual ICollection<Course> Courses { get; set; }

NOTE: If you plan on eagarly loading the navigated properties and expose them as JSON formatted output, you may encounted the following error condition:

The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.

Self referencing loop detected for property 'parent-entity' with type 'Models.Core.Referenced-Entity'.

One way to get around this is to include the following in your Global.asax, Application_Start:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Re‌ferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;

References: Also see the following resources for more information

Creating a more complex data model

Implementing Inheritance with the EF6


Tags: ,

ORM | SQLServer