船山王夫之 周易內傳卷三下 – 損卦(二)

《彖》曰:損,損下益上,其道上行。

地天泰的九三 和 上六爻互換,而成損卦。

泰卦裡,

九三爻是下卦的最上爻,上六爻是上卦的最上爻。互換的這兩爻都是最上爻,是為 “上行”。此“上行”,乃以下卦之有餘固上卦之有餘。

下卦不傷己之根本,上卦得固因而得以順暢。所以上下卦皆吉且皆能繼續發揮功用。

這符合“道”的本意,也是 道 的其中一種意志。所以說,這個損下益上啊,就是 道 的“上行”,這個 損 ,是有益的,不是傷害來的。(符合 道)

“其道上行” 另一解

而道在進”:道 的本質正如乾卦所說,是 元 亨 利 貞,自強不息的。

要怎麼做到自強不息呢?首先,要確保自身根基穩固,行有餘力,才能不斷進步,自強不息。

如果根基已損傷,要做的就是穩固根基,而這“進步”就要延遲一點了,更不要說行有餘力了。

所以也說“其道上行”,就是以有餘之力力求進步,這就是損下益上的作用。

船山王夫之 周易內傳卷三下 – 損卦(一)

最近朋友問到這本書內『損卦』的一些解釋,所以我很難得的拿了這本書來讀一讀。

本以為這本書有很多文言文,我可能讀不懂,可是想不到當我耐心的去讀,竟然能讀懂大部分內容,我自己也有點意外(竊喜)。

既然難得的讀懂了一篇這麼長的文言文,所以在這裡我把自己的一些感悟寫下來,留個紀錄。

這是個人淺見,不代表我理解的就是正確的。

損,兌下艮上

損。有孚元吉,無咎可貞,利有攸往。曷之用?二簋可用享。


第一段

損、益這兩卦是從『地天泰』和『天地否』這兩個卦變過來的。 損卦,是泰卦的 九三 去上位,而上六向下退來三位。 益卦是否卦的 九四 退來初位,而初六向上進到四位。

內卦為本,外卦為用。

泰的內卦是陽,外卦是陰。 所以泰卦變損卦,就是以內卦的實來補外卦的虛。 否的內卦是陰,外卦是陽,所以否卦變益卦,就是以外卦的實來增益內卦的虛。

同樣是以陽補陰,為什麼泰卦變損卦就叫損,而不叫益呢,同樣,為什麼否卦變益卦,卻不叫損呢?

我們先看回這個概念:內卦為本,外卦為用。損卦是以內補外,損了本體,所以是損,而益卦是以外補內,這是增益了本體,所以是益。 所以說損益的理解,是從內卦或本體的角度來出發。

內卦可以看成是事物的本質,外卦是事物的延伸展現,所以內外卦是有聯繫的。損、益則是說明這種聯繫的消長變化而已。損不一定是兇的,而益,也不一定是吉的。

為什麼『雷風恆』卦不當成和損卦一樣的性質來看呢?恆卦是雷上風下,是初六和九四爻易位(從泰卦看),難道不是損下益上嗎?

同理,為什麼鹹卦(澤上山下)不當成和益卦一樣的性質來看待呢?鹹卦是否卦的六三爻和上九爻易位,難道不是損上益下嗎?

損,是損有餘。可是恆卦的損,不是損有餘,而是損了泰卦的初九爻,這是損了自己根本,不知變通,所以恆卦多兇。

益,應當益在實處。可是鹹卦的益,只是把否卦的上九,益在了否卦下卦的六三位。

六三位是否卦下卦(坤卦)的最上之爻,乃有餘之位,屬錦上添花,所以這不是益。


第二段

泰卦損九三而益上六,內卦的初、二陽依然充實得中,上爻位得陽增益,卻已足用。因此內卦不傷根本,而外卦也得恰當的增益,不會太過。這就是“有孚”:也就是依據自身實力來增益外卦,不傷自己而外卦也得助,因此這個“有孚”會帶來“元吉”。

仰事:人民依賴政府。俯育:政府帶領人民。

仰事俯育之有餘:雙方皆以有餘奉獻對方。

貢賦將焉:我只能猜這句的意思,應該是說稅收才能有能力給予/收取。

應該是政府收取有餘之稅,人們以有餘而交稅,所以賦稅才能長久不絕。暗含生生不息,是道的一種體現。

內卦有損,會有咎嗎?卦辭裡重申這是“無咎”,因為這是內卦之損,不是虧傷。

泰卦九三離棄初九及九二同類,去了上爻位,這是不貞嗎?卦辭強調了這是“可貞”的,因為這是九三爻位的陽往上,協助外卦之用,而且是九三應當做的。

因此這損卦乃“有孚元吉,無咎可貞”,是順應人心自然而無不妥。

Quick way to check .NET Framework version in Powershell

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^[^0-9S]'} |
Select PSChildName, Version, Release, @{
name="Product"
expression={
switch -regex ($_.Release) {
    "378389" { [Version]"4.5" }
    "378675|378758" { [Version]"4.5.1" }
    "379893" { [Version]"4.5.2" }
    "393295|393297" { [Version]"4.6" }
    "394254|394271" { [Version]"4.6.1" }
    "394802|394806" { [Version]"4.6.2" }
    {$_ -gt 394806} { [Version]"Undocumented 4.6.2 or higher, please update script" }
    }
  }
}

Very useful tip to check .Net Framework version:

Run above commands in Windows Powershell to get .Net version currently installed in your windows.

Powershell check .Net Framework version

Powershell check .Net Framework version

References:

WCF Session, Instance and Threading Brief Explanations

After reading so many WCF articles, with some practical experiences, finally found these well explain articles for WCF.

 

The Architecture of WCF

WCF Sessions

WCF Instances and Threading

😉

Debug Dataset error

I got this error:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

With the debug tricks from PaulStock, that helps!

References: http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null

 

2013 in review

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 3,700 times in 2013. If it were a NYC subway train, it would take about 3 trips to carry that many people.

Click here to see the complete report.

 

——

Happy New Year 2014, of course!!

 

😉

Filter by Comma Separated Values in IN Clause ?

The Customer table has ‘PrimaryCode’ and ‘OtherCode’ columns store Code from Codes table:Image

However some of the codes store in Customer table do not exist in Codes table.

I need to let Codes table left join Customer table, this is the first version SQL:

select * from Codes a
left outer join Customer b
on a.CodeID in (b.PrimaryCode)

That did not give me the correct outcome as query above miss out the values in OtherCodes column, so I try this:

select * from Codes a
 left outer join Customer b
 on a.CodeID in (CAST(b.PrimaryCode as varchar) + ',' + b.OtherCodes)

I try to concat the PrimaryCode + OtherCodes to have a clause like this: IN(‘1,2,3,4,5’), but that does not seems right, and I get the error message:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value ‘23,24,26,27’ to data type int.

Ok, now I know that is not right doing that, there are few solutions provided in internet (search from Google of course!). The final solution would be using LIKE keyword, then I have this which work perfect:

select * from Codes a
left outer join Customer b
on ',' + Cast(b.PrimaryCode as varchar) + ',' + b.OtherCodes + ',' LIKE '%,' + Cast(a.CodeID as varchar) + ',%'

The result I want:

Image

 

Hints to search in Google: Comma separated values in IN Clause

Keywords: LIKE

Reference: http://stackoverflow.com/questions/4613273/sql-use-comma-separated-values-with-in-clause

IIS Handler for Custom Url

Recently need to setup environment for bug fix.

The client side code calling url like http://somewhere/upload/, while at the server side the url need to receives the POST request from client to perform certain actions.

We have the ready client code to send the POST request with the contents, the missing part is the receiving side, the url in server. Current code will always give us error whenever calls made to the url because the url does not exists at all. My mission today will be faking a url to receives request and output the content as a new file, so we can test the bug fix later on.

Client code: (Refer to Posting multipart/form-data Using .NET WebRequest)

private string ExecutePostRequest(
Uri url,
Dictionary<string, string> postData,
string fileMimeType
)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.AbsoluteUri);
request.Method = "POST";
request.KeepAlive = false;
string boundary = "ILikeSeperator";
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.Credentials = CredentialCache.DefaultCredentials;

// Connect to server and start sending data (use POST)
Stream requestStream = request.GetRequestStream();
postData.WriteMultipartFormData(requestStream, boundary);

byte[] endBytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "--");
requestStream.Write(endBytes, 0, endBytes.Length);
requestStream.Close();

// Get back response from server
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
};
}

Nothing much to say about the client code 😀

Server Code: (My works here)

The url I going to creates is http://localhost/uploadTest. We need to add a ashx handler in IIS to handle the calls into this url. The handler will create a new text file base on contents sent by client.

There are total 6 steps needed and the sequence numbers will be highlight in Bold + red colour = Number

~~~ 0 ~~~ 0 ~~~

1- First follow the must read step-by-step guides on creating handler for specific url – ASP.NET ASHX Handler

Project created follow above guide, removed unnecessary .aspx and files.

Aspx Handler Project

2- Another important step, use correct Web.config:-


<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<customErrors mode="Off"/>
<urlMappings enabled="true">
<add url="~/Default.aspx" mappedUrl="~/FileUploadHandler.ashx"/>
</urlMappings>
<compilation debug="true"/>
</system.web>
<system.webServer>
<modules>
<remove name="WebDAVModule"/>
</modules>
<handlers accessPolicy="Read, Write, Execute, Script">
<remove name="StaticFile"/>
<remove name="SimpleHandlerFactory-ISAPI-2.0"/>
<remove name="WebDAV"/>
<remove name="SimpleHandlerFactory-Integrated-4.0"/>
<remove name="SimpleHandlerFactory-Integrated"/>
<add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode"/>
<add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
<add name="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read"/>
</handlers>
<security>
<authorization>
<remove users="*" roles="" verbs=""/>
<add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG"/>
</authorization>
</security>
</system.webServer>
</configuration>

3- The core of the handler code inside FileUploadHandler.ashx:


public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");

// Read input
string requestContent = new StreamReader(context.Request.InputStream).ReadToEnd();
if (string.IsNullOrWhiteSpace(requestContent))
{
context.Response.Write("");
return;
}

string[] requestArray = requestContent.Split(new[] { "--ILikeSeperator" }, StringSplitOptions.RemoveEmptyEntries);

if (requestArray.Count() > 0)
{
string fileContent = GetContent(requestArray[0]);

if (!string.IsNullOrWhiteSpace(fileContent))
{
// Send back response to client
context.Response.Write(fileContent);

// Create upload file
CreateUploadedFile(fileContent);
}
}
}

4 – IIS Setup: Add new application, use default authentication

Ashx IIS Setup

5 – Deploy the Ashx handler to upload directory (Created from AspxHandler project).

Remember use Web.config given above.

Ashx_Handler_Folder_Setup

6 – Set folder permission in uploadTest directory. Allow write permission for IIS_IUSRS (This is built-in IIS user) so handler able to create new folder and files.

Ashx_Handler_IIS_IUSRS_Write_Permission

You will get errors in client and server if no write permission is allow in mapped directory of the url:

Client error:

System.Net.WebException was unhandled
  Message=The remote server returned an error: (500) Internal Server Error.

Error in client code

Server Error:

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path ‘C:\inetpub\wwwroot\uploadTest\MyUploadContents\’ is denied.

Error in Server code

Now DONE!

Enjoy your customize handler just for the url you want!

Next post will talks about the debugging in ashx handler, a simple and short article 😉

Sample source code:

————-

Keywords:

Customize url handler, file upload handler, file upload ashx, iis handler, HttpWebRequest

References:

WPF Performance – General

Deal with Performance in WPF applications

This article tells the basic thread structure of WPF (which I thinks is important for me right now as I need to know that for the WPF performance tuning), some tricks and basic concepts of WPF design.

Good article (I said that because probably I can understand them now after some time :P, also if the article can explain in more simpler way when compare to Microsoft documents)

Try to follow WPF design concept to have a best performance (MVVM, Display UI on the fly,…)

Next post will be some technical findings when I works on WPF performance.

英伦夜话

今夜遇见一个来自马来西亚的餐厅老板,聊他的孩子,工作,马来西亚和英国的教育,他70年代时的打拼,马来西亚的黑暗面,以前的共产党,他的趣事,他还在马来西亚的朋友的生活,还有很多。。。

谢谢他的两杯红酒。