Sunday, August 30, 2009

Rolling with Ruby on Rails

http://oreilly.com/ruby/archive/rails.html

http://www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials

Identifying and non-identifying relationships

http://stackoverflow.com/questions/762937/whats-the-difference-between-identifying-and-non-identifying-relationships

http://www.datanamic.com/support/relationshiptypes.html

Writing jQuery Plugin

http://www.easyjquery.com/jquery-plugins/how-to-write-jquery-plugin


http://blog.jeremymartin.name/2008/02/building-your-first-jquery-plugin-that.html


http://mattberseth.com/blog/2008/06/glowbuttons_writing_my_first_j.html

Sort JSON by its key(properites)

Today, I need to sort the JSON by its key(properties) and I write the following extended function to array element.

Array.prototype.extendSort = function(field,desc){
function sortField(a,b){
if (a[field] == b[field]){
return 0;
}
var result = a[field] > b[field]?1:-1;
if (desc == true) result=result*-1;
return result;
}
this.sort(sortField);

}
var testjson = [{"id":3, "name":"Charlie"},{"id":5, "name":"Danny"},{"id":4, "name":"Billy"}]
testjson.extendSort("id", false);

PS:
If you want to loop through the array using for...in statement, you may find that the extendSort also recognizes as one of the object.

You should use the following code to deal with that:
for (name in testjson) {
if (testjsonj.hasOwnProperty(name)) {
...
}
}

Friday, August 28, 2009

Wednesday, August 26, 2009

Send email to a folder instead of SMTP server when testing

While testing, you can have emails sent to a folder on your computer instead of an SMTP server. Put this in your web.config:

<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
</smtp>
</mailSettings>
</system.net>



http://stackoverflow.com/questions/54929/hidden-features-of-asp-net

Thursday, August 20, 2009

Get QueryString by javascript

function QueryString(name) {
var AllVars = window.location.search.substring(1);
var Vars = AllVars.split("&");
for (i = 0; i < Vars.length; i++) {
var Var = Vars[i].split("=");
if (Var[0] == name) return Var[1];
}
return "";
}

Thursday, August 13, 2009

Javascript date validation

Very simple:

function isValidDate(year, month, day) {
var date = new Date(month + "/" + day + "/" + year);
return date.getDate() == day && date.getMonth() == month - 1 && date.getFullYear() == year;
}

Wednesday, August 12, 2009

Write Permission Deployment Problem

Just ask the server admin to deploy the file and grant the write access to a folder. But the program still shows the access denied error.

The possible cause:
1. The file is already there and cannot be overwritten even the permission is set.

JSON and ASP.NET

http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/22/json_in_aspnetajax_part1.aspx

http://dineshmandal.wordpress.com/2009/07/25/jquery-json-asp-net-web-service/

window.onbeforeunload

https://developer.mozilla.org/en/DOM/window.onbeforeunload

IIncorrect MIME Type for CSS Files

今日deploy 左一堆file 上server,點知啲page 係IE 上面show 係正常,FF, Chrome, Safari 等其他browser 就讀唔到個 css file。

Firebug 出左呢一句:
The resource from this URL is not text: ................/xxx.css

搵左一輪都未知乜野事,跟住諗下會唔會同Server 有關,係Fiddler 發現佢用Sun one web server,然後就用sun one web server load css 係Google search,跟住發現好有可能同CSS MIME Type 有關:

http://forums.sun.com/thread.jspa?threadID=5011423

其中一個reply:
The problem is very likely with the CSS MIME type.

Take a look at the archives for this newgroup for solutions and workarounds.

Fiddler check 到個 Content-type: application/x-pointplus。

然後用css mime type x-pointplus 再搵,第一個search result 就係Firefox official doc:
https://developer.mozilla.org/en/Incorrect_MIME_Type_for_CSS_Files

https://developer.mozilla.org/en/Properly_Configuring_Server_MIME_Types

P.S.:原來係 Web Developer Plugin 寫住:
Error: The stylesheet http://stage.acuvue.com.hk/include/css/acuvue.css was not loaded because its MIME type, "application/x-pointplus", is not "text/css".

Tuesday, August 11, 2009

Best Practices for Using ADO.NET

Good Article of ADO.NET

http://msdn.microsoft.com/en-us/library/ms971481.aspx

SqlDataReader.Close Method

You must explicitly call the Close method when you are through using the SqlDataReader to use the associated SqlConnection for any other purpose.

The Close method fills in the values for output parameters, return values and RecordsAffected, increasing the time that it takes to close a SqlDataReader that was used to process a large or complex query. When the return values and the number of records affected by a query are not significant, the time that it takes to close the SqlDataReader can be reduced by calling the Cancel method of the associated SqlCommand object before calling the Close method.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.close.aspx