http://oreilly.com/ruby/archive/rails.html
http://www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials
Sunday, August 30, 2009
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)) {
...
}
}
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
XSS (Cross Site Scripting) Cheat Sheet
http://ha.ckers.org/xss.html
http://amix.dk/blog/viewEntry/19432
http://amix.dk/blog/viewEntry/19432
Thursday, August 27, 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
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
</smtp>
</mailSettings>
</system.net>
Tuesday, August 25, 2009
Sunday, August 23, 2009
Friday, August 21, 2009
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 "";
}
Wednesday, August 19, 2009
Get url without filename
var path = window.location.href.substr(0, location.href.lastIndexOf("/") + 1)
Tuesday, August 18, 2009
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.
The possible cause:
1. The file is already there and cannot be overwritten even the permission is set.
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".
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
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
Thursday, August 6, 2009
Wednesday, August 5, 2009
Discussion on changing chode that written by other colleagues
http://stackoverflow.com/questions/1236940/respecting-fellow-developers
http://stackoverflow.com/questions/206286/how-do-you-tell-someone-theyre-writing-bad-code
Download the Builder.com Ten Commandments of Egoless Programming
http://articles.techrepublic.com.com/5100-10878_11-1045782.html
http://stackoverflow.com/questions/206286/how-do-you-tell-someone-theyre-writing-bad-code
Download the Builder.com Ten Commandments of Egoless Programming
http://articles.techrepublic.com.com/5100-10878_11-1045782.html
Tuesday, August 4, 2009
IIS Web Deployment Tool
http://learn.iis.net/page.aspx/346/web-deployment-tool/
Web Deployment Project
http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx
http://blogs.msdn.com/webdevtools/archive/2008/01/25/announcing-rtw-of-visual-studio-2008-web-deployment-projects-wdp.aspx
Web Deployment Project
http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx
http://blogs.msdn.com/webdevtools/archive/2008/01/25/announcing-rtw-of-visual-studio-2008-web-deployment-projects-wdp.aspx
Monday, August 3, 2009
Linq to SQL DataContext Lifetime Management
http://www.west-wind.com/weblog/posts/246222.aspx
http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx
http://stackoverflow.com/questions/337763/linq-to-sql-multiple-single-dbml-per-project
http://stackoverflow.com/questions/1949/are-multiple-datacontext-classes-ever-appropriate
http://stackoverflow.com/questions/1127283/linqtosql-mapping-out-the-datacontext-with-lots-of-tables
http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to-sql-datacontext.aspx
http://stackoverflow.com/questions/337763/linq-to-sql-multiple-single-dbml-per-project
http://stackoverflow.com/questions/1949/are-multiple-datacontext-classes-ever-appropriate
http://stackoverflow.com/questions/1127283/linqtosql-mapping-out-the-datacontext-with-lots-of-tables
Sunday, August 2, 2009
Saturday, August 1, 2009
Subscribe to:
Posts (Atom)