"""建立hi_dict的dictionary"""
hi_dict = {'name': '王小明', 'age': 25, 'mail': 'sample@gmail.com'}
"""取得某key的值"""
print hi_dict.get('name')
"""或"""
print hi_dict['name']
"""加入一組 key 與 value"""
add_dict = {'blog','http://myblog.com'}
hi_dict.update(add_dict)
"""或"""
hi_dict.update({'blog','http://myblog.com'})
"""移除一組 key 與 value"""
hi_dict.pop('blog') """若key 'blog' 不存在時會回傳, KeyError: 'bolg' 訊息"""
"""複製dict"""
hi_dict2=hi_dict.copy()
Python Dictionary, 字典的應用
dictionary, 字典是指有一組以上的 key 與 value 所組成不多說, 直接展示吧...
PG專用最佳字型, Monaco font
不解釋, 看下面註解XD
var hello = function () {
//再也不會搞不清楚是數字或英字大小寫 1,i,l,0,o,O
var my_array = ["1", "i", "l", "0", "o", "O"];
}
tags:
ASP.NET,
C#,
CSS3,
Django,
HTML,
javascript,
Mac,
Python,
SublimeText,
Windows 相關
wkhtmltopdf.exe 網頁Html轉PDF檔
網頁Html轉PDF檔(一行程式碼解決)
網頁轉PDF檔做法很多(Convert HTML to PDF in .NET)
這邊紀錄一下老外最多人加分的那篇做法,使用wkhtmtopdf(採GPL授權)可以省很多程式碼
1.首先到官網 http://code.google.com/p/wkhtmltopdf/downloads/list
2.找installer.exe下載,這邊Demo我是下載wkhtmltopdf-0.9.9-installer.exe下載完後執行安裝它
3.選擇安裝路徑, 進行安裝 (如果要解除安裝的話,就到剛剛安裝的資料夾下找uninstall.exe執行即可)
4.安裝完畢後找到wkhtmltopdf.exe
5.回到命令提示字元(開始→執行→cmd)輸入
6.以google網頁轉PDF為例, 按下Enter轉換完成.
7.既然知道底層使用方式,那就可以調用 useing System.Diagnostics.Process
8.使用System.Diagnostics.Process.Start 方法 (String, String)
第一個參數傳執行檔路徑,第二個傳參數(URL和PDF檔的存放路徑)
System.Diagnostics.Process.Start(@"你的安裝路徑\wkhtmltopdf.exe", @"http://www.google.com.tw 你要產生檔案的路徑\youFileName.pdf");
9.此小工具不會像WinForm的WebBrowser控制項一樣會共用IE瀏覽器的Cookie , 而且要抓的網頁來源不一定要URL,也可以像這樣直接抓本機上的Html檔轉PDF.
System.Diagnostics.Process.Start(@ "你的安裝路徑\wkhtmltopdf.exe" , @ "D:\youHtml.html D:\youFileName.pdf" );
目前已知
1.本機的Html檔案轉成PDF後,圖片顯示不出來
2.網頁中裝載flash檔案 *.swf 顯示不出來
引自: http://www.dotblogs.com.tw/shadow/archive/2011/09/28/38072.aspx
這邊紀錄一下老外最多人加分的那篇做法,使用wkhtmtopdf(採GPL授權)可以省很多程式碼
1.首先到官網 http://code.google.com/p/wkhtmltopdf/downloads/list
2.找installer.exe下載,這邊Demo我是下載wkhtmltopdf-0.9.9-installer.exe下載完後執行安裝它
4.安裝完畢後找到wkhtmltopdf.exe
5.回到命令提示字元(開始→執行→cmd)輸入
6.以google網頁轉PDF為例, 按下Enter轉換完成.
7.既然知道底層使用方式,那就可以調用 useing System.Diagnostics.Process
8.使用System.Diagnostics.Process.Start 方法 (String, String)
第一個參數傳執行檔路徑,第二個傳參數(URL和PDF檔的存放路徑)
System.Diagnostics.Process.Start(@"你的安裝路徑\wkhtmltopdf.exe", @"http://www.google.com.tw 你要產生檔案的路徑\youFileName.pdf");
9.此小工具不會像WinForm的WebBrowser控制項一樣會共用IE瀏覽器的Cookie , 而且要抓的網頁來源不一定要URL,也可以像這樣直接抓本機上的Html檔轉PDF.
System.Diagnostics.Process.Start(@ "你的安裝路徑\wkhtmltopdf.exe" , @ "D:\youHtml.html D:\youFileName.pdf" );
目前已知
1.本機的Html檔案轉成PDF後,圖片顯示不出來
2.網頁中裝載flash檔案 *.swf 顯示不出來
引自: http://www.dotblogs.com.tw/shadow/archive/2011/09/28/38072.aspx
tags:
ASP.NET,
C#,
ConvertToPDF
停止與移除, 工作管理員中的進程程序
今天公司客戶的java系統遇到了一個問題,就是java有一個job在執行系統上的某些資料,但執行的過程一直發生了java job卡在工作管理員無法結束,但也找不出有什麼異常的狀況,討論結果後決定寫一隻可以關掉java.exe的程序,java的程序雖然可以跨平台,但如要處理windows核心的事情,可能需要費一些功夫,所以決定以 .net 的程序來處理,所以這個項目就落在我身上了,雖然都已經弄好了,當然,順便紀錄一下,以後就可以方便找資料。
1.首先需要能有對工作管理員存取能力的命名空間
using System.Diagnostics;
2.使用Process類別可以獲取工作管理員的進程內容
DateTime now = DateTime.Now;
Process[] oProcesses = Process.GetProcessesByName(urProcessName);
foreach ( Process p in oProcesses )
{
TimeSpan ts = now.Subtract(p.StartTime);
//執行總時間大等於1000秒時就關閉這個進程
if ( ts.TotalSeconds >= 1000 ) p.Kill();
}
3.調用Kill方法,將工作管理員的進程程序結束,當然,還有很多Process的方法
可使用,看視情況而定嘍。
4. 完成了,收工...
1.首先需要能有對工作管理員存取能力的命名空間
using System.Diagnostics;
2.使用Process類別可以獲取工作管理員的進程內容
DateTime now = DateTime.Now;
Process[] oProcesses = Process.GetProcessesByName(urProcessName);
foreach ( Process p in oProcesses )
{
TimeSpan ts = now.Subtract(p.StartTime);
//執行總時間大等於1000秒時就關閉這個進程
if ( ts.TotalSeconds >= 1000 ) p.Kill();
}
3.調用Kill方法,將工作管理員的進程程序結束,當然,還有很多Process的方法
可使用,看視情況而定嘍。
4. 完成了,收工...
tags:
隨便寫寫,
C#,
Windows 相關
ASP.NET 利用 Global.asax 的 Application_Error 來記錄 Exception 訊息
利用 windows 的事件記錄器替我們做好記錄
錄網頁Exception訊息的方法有多種..在此介紹三種儲存方式...
1.記錄在事件檢視器裡
2.記錄在文字檔裡
3.用Email寄出訊息
1. 於應用程式中建立 global.asax , 在 application_error 事件中加入下列
void Application_Error(object sender, EventArgs e)
{
string Message = "";
Exception ex = Server.GetLastError();
Message = "發生錯誤的網頁:{0}錯誤訊息:{1}堆疊內容:{2}";
Message = String.Format(Message, Request.Path + Environment.NewLine, ex.GetBaseException().Message + Environment.NewLine, Environment.NewLine + ex.StackTrace);
//寫入事件撿視器,方法一
System.Diagnostics.EventLog.WriteEntry("WebAppError", Message, System.Diagnostics.EventLogEntryType.Error);
//寫入文字檔,方法二
System.IO.File.AppendAllText(Server.MapPath(string.Format("Log\\{0}.txt", DateTime.Now.Ticks.ToString())), Message);
//寄出Email,方法三
//此方法請參考System.Net.Mail.MailMessage
//清除Error
Server.ClearError();
Response.Write("系統錯誤,請聯絡系統管理員!!");
}
2. 於一個新網頁中加入, 產生一個Null Exception 錯誤
protected void Page_Load(object sender, EventArgs e)
{
throw (new ArgumentNullException());
}
3. 事件檢視器內容

4. 文字內容
5. 完成了 , 收工~~*-*
參考來源 :
http://www.dotblogs.com.tw/puma/archive/2008/08/31/5260.aspx
http://www.blueshop.com.tw/board/show.asp? subcde=BRD20080822113331G86&fumcde=FUM20041006161839LRJ
http://support.microsoft.com/kb/306355/zh-tw
錄網頁Exception訊息的方法有多種..在此介紹三種儲存方式...
1.記錄在事件檢視器裡
2.記錄在文字檔裡
3.用Email寄出訊息
1. 於應用程式中建立 global.asax , 在 application_error 事件中加入下列
void Application_Error(object sender, EventArgs e)
{
string Message = "";
Exception ex = Server.GetLastError();
Message = "發生錯誤的網頁:{0}錯誤訊息:{1}堆疊內容:{2}";
Message = String.Format(Message, Request.Path + Environment.NewLine, ex.GetBaseException().Message + Environment.NewLine, Environment.NewLine + ex.StackTrace);
//寫入事件撿視器,方法一
System.Diagnostics.EventLog.WriteEntry("WebAppError", Message, System.Diagnostics.EventLogEntryType.Error);
//寫入文字檔,方法二
System.IO.File.AppendAllText(Server.MapPath(string.Format("Log\\{0}.txt", DateTime.Now.Ticks.ToString())), Message);
//寄出Email,方法三
//此方法請參考System.Net.Mail.MailMessage
//清除Error
Server.ClearError();
Response.Write("系統錯誤,請聯絡系統管理員!!");
}
2. 於一個新網頁中加入, 產生一個Null Exception 錯誤
protected void Page_Load(object sender, EventArgs e)
{
throw (new ArgumentNullException());
}
3. 事件檢視器內容
4. 文字內容
5. 完成了 , 收工~~*-*
參考來源 :
http://www.dotblogs.com.tw/puma/archive/2008/08/31/5260.aspx
http://www.blueshop.com.tw/board/show.asp? subcde=BRD20080822113331G86&fumcde=FUM20041006161839LRJ
http://support.microsoft.com/kb/306355/zh-tw
tags:
ASP.NET,
C#,
Windows 相關
ic#code ( SharpDevelop )
輕巧好攜帶的編程工具 - SharpDevelop , 小而精巧的程式編程工具 (可比美VS.NET IDE環境) 是編程工程師出門在外的另一種方便的新選擇呢...哈哈
下載位置 http://www.icsharpcode.net/OpenSource/SD/Download/
SharpDevelop 台灣相關教學網站
台灣程式設計論壇 http://www.aboutwhat.org/forum/index.php?mforum=flyup
下載位置 http://www.icsharpcode.net/OpenSource/SD/Download/
SharpDevelop 台灣相關教學網站
台灣程式設計論壇 http://www.aboutwhat.org/forum/index.php?mforum=flyup
C# - 利用 Gmail SMTP 幫你寄信
只要有 Gmail 個人帳號與密碼,透過 Gmail SMTP SSL 的認證,Gmail 就可以幫助你寄信囉!
該程式利用 MailAddress 建立收發信人的郵件位址,MailMessage 建立郵件相關內容,SmtpClient 與 NetworkCredential 建立 Smtp 連線認證與寄信功能。
該程式利用 MailAddress 建立收發信人的郵件位址,MailMessage 建立郵件相關內容,SmtpClient 與 NetworkCredential 建立 Smtp 連線認證與寄信功能。
Console INPUT/OUTPUT
Console input and output
Explains how user input and output is integrated in the C# program
CONSOLE INPUT
To read some text from the command line you use the Console.Read or Console.ReadLine method implemented in the .net framework. The difference between them is that the Console.Read method reads the next character from the command line, whereas Console.ReadLine reads the next line of characters instead of just a simple character. The Console.Read method returns an integer and should be cast to a char during the input. There is also a special function called Console.ReadKey( Boolean display) which obtains the key that is pressed on the keyboard and if the display parameter is false it depicts it.
CONSOLE OUTPUT
The functions used for this purpose is the Console.Write and Console.WriteLine(). They both write the specified value to the console window but the second also adds a new line character. The following snippet of code demonstrates the usage of input methods:
static void Main()
{
char c;
string myString;
myString = Console.ReadLine();
Console.WriteLine(myString);
c = (char)Console.Read();
Console.Write(c);
Console.WriteLine(" comes before z");
Console.ReadKey();
}
Another option for writing on the console is with the use of markers in curly braces. Each marker links to a parameter which is inserted after the text. The first marker should always be 0. Copy the following code and see what it does:
Console.WriteLine("My name is {0}, {1} {0}.", "Sharp","C");
Another option is the use of formatting, you can specify the width and the justification of the text with the appropriate sign in the width number,positive values for right justification and negative values for left:
Console.WriteLine("My name is {0,6}, {1} {0}.","Sharp", "C");
Console.WriteLine("My name is {0,-6}, {1} {0}.","Sharp", "C");
Finally, you can enter a format string which can also take an optional precision value. Some of the most common format string are the following ones:
· C = Local currency format
· D = Decimal format. Leading zeros might be added if precision value is given.
· E = Exponential-Scientific format. The default number of decimal places is 6, but it can be altered with the precsion value.
· F = Fixed point format. The number of decimal places is given by the precision parameter.
· N = Number format using “,” for thousands sepertaors and “.” for decimals.
· X = Hexadecimal fomat.
The format string is placed axactly after the marker ( with the optional width specifier), seperated by a colon. To format an exponential with 5 decimal places use the following code:
int myInt = 123323;
Console.WriteLine("The result of our calculations were {0,7:E5}", myInt);
訂閱:
文章 (Atom)




