[blind tasting] Rose wine

November 14th, 2015 Phanix

2015/11/13, blind tasting.

Read the rest of this entry / 繼續閱讀 »

Julian date 儒略日

October 13th, 2015 Phanix

最近在看 google web search api(reference), 剛好看到這個東西…
Read the rest of this entry / 繼續閱讀 »

取得網頁中滑鼠油標下的元素 / Get the web element under mouse cursor

September 21st, 2015 Phanix

方法1: 透過 mouse events 去取得 mouse cursor position, 然後再呼叫 document.elementFromPoint

var x = event.clientX, y = event.clientY,
elementMouseIsOver = document.elementFromPoint(x, y);

方法2: 在比較新的瀏覽器可以用 jquery 的 querySelectorAll 取得

document.querySelectorAll( ":hover" );

Sandcastle Help File Builder — Visual Studio Class Library 說明文件產生器

September 10th, 2015 Phanix

清爽易閱讀且詳細的說明文件真的很重要
09

Read the rest of this entry / 繼續閱讀 »

Nicolas Joly Tasting

August 23rd, 2015 Phanix

未滿十八歲請勿飲酒,飲酒過量有礙身體健康

Read the rest of this entry / 繼續閱讀 »

Jmeter increase the user defined variable in loop 迴圈中遞增使用者自定變數

August 4th, 2015 Phanix

直接看圖說故事…
Read the rest of this entry / 繼續閱讀 »

Nebbiolo of different maturation processes

July 15th, 2015 Phanix

IMG_20150708_213321_HDR
2015/07/08, @wutong
未滿十八歲請勿飲酒,飲酒過量有礙身體健康
Read the rest of this entry / 繼續閱讀 »

NV Andre Clouet Grande Reserve Brut, Champagne, France

May 16th, 2015 Phanix

未滿18歲請勿飲酒,飲酒過量有礙身體健康
NV Andre Clouet Grande Reserve Brut, Champagne, France
Read the rest of this entry / 繼續閱讀 »

C# stack trace

February 13th, 2015 Phanix
using System.Diagnostics;

[STAThread]
public static void Main()
{
  StackTrace stackTrace = new StackTrace();           // get call stack
  StackFrame[] stackFrames = stackTrace.GetFrames();  // get method calls (frames)

  // write call stack method names
  foreach (StackFrame stackFrame in stackFrames)
  {
    Console.WriteLine(stackFrame.GetMethod().Name);   // write method name
  }
}

Ref: http://www.csharp-examples.net/reflection-callstack/

Using T4 template to read resource files (.resx) and generate multiple output files

February 12th, 2015 Phanix

T4 (Text Template Transformation Toolkit) 可以幫忙訂出 template 並用程式輔助來產生程式碼或文件(比方說不同語言的定義檔)。

使用 T4 之前可以先去下載 T4 Toolbox,安裝之後在 Visual studio 增加新項目時就可以看到有 “T4 Toolbox” 的分類,有 Generator、Script、Template 三種可選
T4Toolbox_01

首先定義template檔案,在這邊用System.Xml去讀取 resource file,同時 include SaveOutput.tt 做輸出用。

<#@ template language="C#" debug="True" #>
<#@ include file="SaveOutput.tt" #>
<#@ include file="T4Toolbox.tt" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Xml" #>
<#
// <copyright file="i18n_js.tt" company="Onelab">
//  Copyright © Onelab. All Rights Reserved.
// </copyright>

string[] files = System.IO.Directory.GetFiles(this.Host.ResolvePath("..\\App_GlobalResources"));
string outputFileLang = "";

foreach (string f in files) {
	if (f.Substring(f.Length-4) != "resx"){
		continue;
	}

	XmlDocument xd = new XmlDocument();
	xd.Load(f);


	if (f.LastIndexOf("Resource") + 8 == f.LastIndexOf(".")) {
		outputFileLang = "en-Us";
	}
	else
	{
		outputFileLang = f.Substring(f.LastIndexOf("Resource") + 9, f.LastIndexOf(".") - f.LastIndexOf("Resource") - 9);
	}


	foreach (XmlNode node in xd.SelectNodes("//data")) {
		try
		{
#>
			<#=node.Attributes[0].Value#> = <#=node.SelectNodes("value")[0].InnerXml#>;
<#
		}
		catch
		{
		}
	}

	SaveOutput("lang\\" + outputFileLang + ".js");
}
#>

另外定義 SaveOutput function於另一個檔案SaveOutput.tt中

<#@ import namespace="System.IO" #>
<#+
  void SaveOutput(string outputFileName)
  {
      string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
      string outputFilePath = Path.Combine(templateDirectory, outputFileName);
      File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString()); 

      this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
  }
#>

當resource file變動後,必須要執行”Run Custom Tool”才會更新輸出的檔案內容。
T4Toolbox_02

Other resources: Oleg Sych’s article