Sunday, April 24, 2016
public static double StdDev<T>(this IEnumerable<T> list, Func<T, double> values)
{
// ref: http://stackoverflow.com/questions/2253874/linq-equivalent-for-standard-deviation
// ref: http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/
var mean = 0.0;
var sum = 0.0;
var stdDev = 0.0;
var n = 0;
foreach (var value in list.Select(values))
{
n++;
var delta = value - mean;
mean += delta / n;
sum += delta * (value - mean);
}
if (1 < n)
stdDev = Math.Sqrt(sum / (n - 1));
return stdDev;
}
Or
public static double StdDev(this IEnumerable values)
{
// ref: http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/
double mean = 0.0;
double sum = 0.0;
double stdDev = 0.0;
int n = 0;
foreach (double val in values)
{
n++;
double delta = val - mean;
mean += delta / n;
sum += delta * (val - mean);
}
if (1 < n)
stdDev = Math.Sqrt(sum / (n - 1));
return stdDev;
}
ref: http://stackoverflow.com/questions/2253874/linq-equivalent-for-standard-deviation
Friday, April 22, 2016
go to this, please:
http://www.excitesubmit.com
Wednesday, April 20, 2016
Convert and Loop through JSON with PHP and JavaScript Arrays/Objects
0 comments Posted by Duc Nguyen at 12:15 AM$("#gender").on("change", function() {
$.ajax({
type: "POST",
data: {
"gender": $("#gender").val()
},
url: "response.php",
dataType: "json",
success: function(JSONObject) {
var peopleHTML = "";
// Loop through Object and create peopleHTML
for (var key in JSONObject) {
if (JSONObject.hasOwnProperty(key)) {
peopleHTML += "
"
;
peopleHTML += "" + JSONObject[key]["name"] + "
";
peopleHTML += "
see more:
https://jonsuh.com/blog/convert-loop-through-json-php-javascript-arrays-objects/
Tuesday, April 19, 2016
//準備資料
string collapse_key = "score_update";
int time_to_live = 108;
bool delay_while_idle = true;
string score = "4x8";
string time = "15:16.2342";
List<string> registration_ids = new List<string>() { "4","8","15","16","23","42"};
//開始拼接字串
StringBuilder sb = new StringBuilder();
sb.AppendLine("{");
sb.AppendLine("\"collapse_key\":\""+collapse_key+"\",");
sb.AppendLine("\"time_to_live\":"+time_to_live+",");
sb.AppendLine("\"delay_while_idle\":"+delay_while_idle.ToString().ToLower()+",");
sb.AppendLine("\"data\":{");
sb.AppendLine("\"score\":\""+score+"\",");
sb.AppendLine("\"time\":\""+time+"\"");
sb.AppendLine("},");
sb.AppendLine("\"registration_ids\":[");
foreach (string item in registration_ids)
{
sb.Append("\""+item+"\",");
}
sb = new StringBuilder(sb.ToString().TrimEnd(','));//移除最後一個「,」字元
sb.AppendLine("]");
sb.AppendLine("}");
//輸出結果
Response.Write(sb.ToString());
More here:
https://dotblogs.com.tw/shadow/archive/2012/08/16/74099.aspx
Sunday, April 17, 2016
Make AJAX JSON call to ASP.Net WCF Service using jQuery and Javascript
0 comments Posted by Duc Nguyen at 10:01 PMHere Mudassar Ahmed Khan has explained how to modify the ASP.Net WCF (Windows Communication Foundation) service to make it accept AJAX JSON calls and to make AJAX JSON calls to ASP.Net WCF Service using JavaScript and jQuery
see more:
http://www.aspsnippets.com/Articles/Make-AJAX-JSON-call-to-ASP.Net-WCF-Service-using-jQuery-and-Javascript.aspx
$("#search").live("click", function () {
";
Tuesday, April 12, 2016
500: Internal Server when call Webservice in jquery and Asp.net
0 comments Posted by Duc Nguyen at 2:55 AM
maxJsonLength="50000000"/>
Sunday, April 10, 2016
Asp.net C# + Dropzone js : Easy way to upload images [Drag & Drop feature]
0 comments Posted by Duc Nguyen at 8:08 PMGeneric Handler ashx file : Post send JSON data in Asp.net c#, jQuery
0 comments Posted by Duc Nguyen at 8:00 PM$("#bntSubmit").on('click', function (e) {
// Initialize the object, before adding data to it.
// { } is declarative shorthand for new Object()
var obj = {};
obj.first_name = $("#txtFirstName").val();
obj.last_name = $("#txtLastName").val();
obj.qualification = $("#txtQualication").val();
obj.age = $("#txtAge").val();
//In order to proper pass a json string, you have to use function JSON.stringfy
var jsonData = JSON.stringify(obj);
$.ajax({
url: 'myGenericHandler.ashx',
type: 'POST',
data: jsonData,
success: function (data) {
console.log(data);
alert("Success :" + data);
},
error: function (errorText) {
alert("Wwoops something went wrong !");
}
});
e.preventDefault();
});
# Add Generic Handler ( ashx file) in your Asp.net Application.
using System.Web.Script.Serialization;
using System.IO;
// we create a userinfo class to hold the JSON value
public class userInfo
{
public string first_name { get; set; }
public string last_name { get; set; }
public string qualification { get; set; }
public string age { get; set; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
try
{
string strJson = new StreamReader(context.Request.InputStream).ReadToEnd();
//deserialize the object
userInfo objUsr = Deserialize(strJson);
if (objUsr != null)
{
string fullName = objUsr.first_name + " " + objUsr.last_name;
string age = objUsr.age;
string qua = objUsr.qualification;
context.Response.Write(string.Format("Name :{0} , Age={1}, Qualification={2}", fullName, age, qua));
}
else
{
context.Response.Write("No Data");
}
}
catch (Exception ex)
{
context.Response.Write("Error :" + ex.Message);
}
}
if (objUsr != null)
{
string fullName = objUsr.first_name + " " + objUsr.last_name;
string age = objUsr.age;
string qua = objUsr.qualification;
context.Response.Write(string.Format("Name :{0} , Age={1}, Qualification={2}", fullName, age, qua));
}
else
{
context.Response.Write("No Data");
}
}
catch (Exception ex)
{
context.Response.Write("Error :" + ex.Message);
}
}
<%@ WebHandler Language="C#" Class="myGenericHandler" %>
using System;
using System.Web;
using System.Web.Script.Serialization;
using System.IO;
public class myGenericHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
try
{
string strJson = new StreamReader(context.Request.InputStream).ReadToEnd();
//deserialize the object
userInfo objUsr = Deserialize(strJson);
if (objUsr != null)
{
string fullName = objUsr.first_name + " " + objUsr.last_name;
string age = objUsr.age;
string qua = objUsr.qualification;
context.Response.Write(string.Format("Name :{0} , Age={1}, Qualification={2}", fullName, age, qua));
}
else
{
context.Response.Write("No Data");
}
}
catch (Exception ex)
{
context.Response.Write("Error :" + ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
// we create a userinfo class to hold the JSON value
public class userInfo
{
public string first_name { get; set; }
public string last_name { get; set; }
public string qualification { get; set; }
public string age { get; set; }
}
// Converts the specified JSON string to an object of type T
public T Deserialize(string context)
{
string jsonData = context;
//cast to specified objectType
var obj = (T)new JavaScriptSerializer().Deserialize(jsonData);
return obj;
}
}
if (objUsr != null)
{
string fullName = objUsr.first_name + " " + objUsr.last_name;
string age = objUsr.age;
string qua = objUsr.qualification;
context.Response.Write(string.Format("Name :{0} , Age={1}, Qualification={2}", fullName, age, qua));
}
else
{
context.Response.Write("No Data");
}
}
catch (Exception ex)
{
context.Response.Write("Error :" + ex.Message);
}
}
public bool IsReusable
{
get
{
return false;
}
}
// we create a userinfo class to hold the JSON value
public class userInfo
{
public string first_name { get; set; }
public string last_name { get; set; }
public string qualification { get; set; }
public string age { get; set; }
}
// Converts the specified JSON string to an object of type T
public T Deserialize
{
string jsonData = context;
//cast to specified objectType
var obj = (T)new JavaScriptSerializer().Deserialize
return obj;
}
}
Wednesday, April 6, 2016
Download and install Microsoft SQL Server 2008 R2 Express
0 comments Posted by Duc Nguyen at 6:56 PMIntroduction
Instructions
- Download Microsoft SQL Server 2008 R2 Express. There are 32-bit (x86, file name SQLEXPRWT_x86_ENU.exe) and 64-bit (x64, file name SQLEXPRWT_x64_ENU.exe) versions available for download. If you are unsure if your operating system is 64-bit, download the 32-bit version:
• Microsoft SQL Server 2008 R2 Express 32-bit (x86)
- or -
• Microsoft SQL Server 2008 R2 Express 64-bit (x64)
This download also includes basic management tools for the database server.
Important: You may have to install Microsoft .Net Framework 3.5 SP1, Windows Installer 4.5 and Windows PowerShell 1.0 before installing Microsoft SQL Server 2008 R2 (typically required for Windows XP and Windows Server 2003).- Open the downloaded file (SQLEXPRWT_x86_ENU.exe or SQLEXPRWT_x64_ENU.exe) to start the SQL Server Installation Center.
- Click on New installation or add features to an existing installation.
- Follow the installation wizard.
- When prompted for the Instance Configuration, select Default instance.
- Follow the installation wizard.
- When prompted for the Database Engine Configuration, it is recommended that you select Mixed Mode (SQL Server authentication and Windows authentication) and provide a strong password.
- Follow the installation wizard and wait until the installation is complete.
- Go to Start > All Programs > Microsoft SQL Server 2008 R2 > Configuration Tools > SQL Server Configuration Manager.
- Open the node SQL Server Network Configuration and select Protocols for MSSQLSERVER.
- Double-click on TCP/IP.
- Set Enabled to Yes.
- Click on OK.
- Close the SQL Server Configuration Manager.
- Restart the computer or the SQL Server service.
Labels: SQL Server 2005, SQL Server 2008 Express