- Detailed SQL queries
- Request timer
- Common HTTP headers
- Cache statistics
- HTTP variables
- Settings variables
- Profile module
- Templates rendered
- Logging message output
星期四, 6月 17, 2010
[Python] Python Profilers in Default
[Django] Middle Concept and Introduction
星期二, 6月 15, 2010
[Django] Django Deployment with Fabric
[Django] Very Good Introduction to Django
[Django] Django Con High Performance Django
[Django] Debugging Django Slide
重新開始.....
星期日, 9月 21, 2008
[WPF] .net 3.5 SP1 feature - Splash Screen Support
WPF的Startup一直為人所垢病
在3.5 SP1的版本中 有做了一個很特別的Feature 可以十分容易在WPF Project隨便放一張圖變成Splash Screen
有效降低Users對Long Cold Startup Time的痛苦.... 至少... 他們知道程式還在run...
細節可以看這一篇
WPF Performance : What’s new in WPF 3.5 SP1: Splash Screen to improve perceived startup perf
[WPF] Cross Threading Binding Support of ObservableCollection
這幾天又重新在思考ObservableCollection的設計與用法
雖然Notifiy的機制已經十分方便 但是還是有效率上的考量
尤其是大量的CollectionChanged 會讓UI不是十分順....
所以在思考怎麼改善.... 其實最簡單的想法 就是開一個Thread來做
但其實是沒辦法的 因為Binding到的UI Object通常都有Thread Affinity (簡言之 就是只認自己的Thread可以用)
找到一篇解決了這個問題...........
WPF Data Binding ObservableCollection (cross thread binding support) « C# Live
星期五, 6月 13, 2008
[C#] Using Extension Methods in .net framework 2.0
在.net framework 2.0 or 3.0 沒辦法Compile Extension Method怎麼辦?
很簡單 在幾行code就可以了
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
方法是從下面的blog來的
The Moth: Using Extension methods in Fx 2.0 projects
星期日, 6月 01, 2008
[WPF] Initialized v.s. Loaded
常常在寫WPF的時候 搞不懂何時要用Loaded,何時要用Initialized
這一篇有十分詳盡的解說.........
In Summary
Initialized
--> Initialized比Loaded早很多,他的時機點是所有的Property都setup好了
--> 會被raised是因為呼叫了ISupportInitialize.EndInit.... FrameworkElemtn有實現這個interface(在load XAML的時候,是BAML Loader call的)
--> 如果是自己寫code去生成,而且沒呼叫EndInit,為什麼還是有呢? 因為在串Visual Tree的時候,任何Uninitialized的children串到Parent的時候,都會先被Initialized (根據 IsInitialized的property),那如果root怎麼呢? 唔...root最後會被串到PresentationSource
--> Initialized的順序是bottom-up,即children會先被叫起來,反之Loaded是從Top-down, 即從上到下....
Loaded
--> 被raised的時候,意味已經準備可以render了,所以ActualWidth, Layout Measurement, data-bound property都已經ready了
--> 順序是Top-Bottom
另外文章中提到....Proprety引發Event的關係,意即
IsInitialized --> Initialized Event
IsLoaded --> Loaded Event
舉個例子 如果XAML是如此寫的話
Page裡有一個Button的話
- Button.IsInitialized goes true
- Button.Initialized event is raised
- Page.IsInitialized goes true
- Page.Initialized event is raised
- Page IsLoaded goes to true
- Button IsLoaded goes to true
- Page.Loaded is raised
- Button.Loaded is raised
原始文章在
Mike Hillberg's Blog on Wpf (.Net and Silverlight) : The Loaded event and the Initialized event
星期三, 5月 28, 2008
[C#] Convert a string to enum
現在開始吧.......
from Mark Wagner's .NET C# Cogitation
Convert a string to an enumprivate enum Aircraft
{
Beech,
Cessna,
Piper
}You can easily convert the string to an enum value like this:
Aircraft air = (Aircraft) Enum.Parse(typeof(Aircraft), "Cessna", true);
Ideally you should wrap a try-catch around the Enum.Parse statement.
rated (enum) value
星期三, 3月 19, 2008
[Concept] Difference between Composition and Aggregation
最近在trace很大量的source code 所以開始認真想要畫一些圖記錄
以免會忘記....... 所以得學一些UML的基本概念...
一直來搞混的Aggregation跟Composition 今天終於查了google搞清楚了....
最清楚的說明 可以看這裡
結論就是....Aggregation跟Composition 都是一種Association, 一種owner ship的概念
只是Composition是更強烈的Ownership 主要是生命週期是一起的..... 而Aggregation就不是
for example
public class classA --> Composition
{
classB B = new ClassB()
~classA()
{
delete B;
}
}
public class classA -->Aggregation
{
classB *m_pB;
void SetB(classB *pB)
{
m_pB = pB; // lifecycle is not the same with parent!!
}
}
星期二, 2月 19, 2008
[Programming Concept] Coroutine
最近在研究C#與Script的結合,想到之前買的書「遊戲之旅 我的程式設計感悟」裡有一章在在講腳本(Script) 大概就是如何寫C++與Lua之間的整合.... 那時候才了解一個新的名詞叫Coroutine
本來以為這是我想要的東西,但是survey的結果似乎不是 不過也蠻好玩的,主要翻成「協同式多工」。
概念很簡單,就是如何讓兩個要run很久的function能交錯地run...好像是兩個thread在一起run,但事實是是兩個func之間作了些手腳,他們互讓的結果。
有興趣,可以參考以下的link..都有sample code可以試
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
星期一, 2月 18, 2008
[.net] How to ConfigureVisual Studio to Debug .net framework source code
找到這個網頁 十分詳盡介紹怎麼設定要debug .net framework source 的方法
不過還沒有時間試... 就先記吧
許多.net dll已經有 full source/symbols,可以直接一步步trace...
以後會比較少用reflector.net 一點 :-D
Shawn Burke's Blog : Configuring Visual Studio to Debug .NET Framework Source Code
Powered by ScribeFire.
星期二, 1月 22, 2008
[WPF]How can I get a ListBoxItem from a data bound ListBox?
我卻渾然未知 一直在navigate visual tree來解決
Data會藉由Data Template展開始Visual Tree
這兩邊的Binding要如何互相串連呢? 這是很重要的問題
從Visual Tree串連到Data 我已經找到方法 就是直接看任何一個UIElement裡的DataContext
就會指到Data
但是如果從Data 想要得到展開Visual Tree的item怎麼辦呢?
原來就是下面這一行
GreekGod greekGod = (GreekGod)(listBox.Items[0]);
ListBoxItem lbi1 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromIndex(0));
from http://www.beacosta.com/blog/?p=7[WPF] ItemsPanel, ItemsTemplate, DataTemplate, ControlTemplate? How to find ItemsPanel from code?
與許多功能重複的關係 造成搞不清楚狀況
今天我跟同事們又解釋了一次 覺得其實我之前也花了許多時間搞懂 不如就寫下來
順便剛又找到一個問題的workaround解法 也寫下來記錄一下 .....
WPF主要是希望用XAML與Code 的方式 把User Interface與Logics分開
所以可以想到我們要寫一個Control的話......
所有的behavior, property是寫在Code裡
而ControlTemplate (also can be defined in Style) 就是幫你把整個Custom Control的程式展開成Visual Tree,就是一大堆小元件,主要是Control 的Presentation....
ItemsTemplate 對於ItemsControl而言 就是將他的Items如何展開成Visual Tree....所以可想而知...ItemsTemplate是一種DataTemplates
DataTemplate 就是描述如何將Data (.net class)展開成Visual Tree (所以也就是我們assign source可以輕鬆地給.net data class,data template會為我們展開)
ItemsPanel就是對於一個ItemsControl而言 就是要去描述要如何layout所有的items,例如可以用StackPanel or WrapPanel.....
哈哈 這樣有比較清楚了嗎?..... 還有一個叫ContentTemplate
ItemsTemplate 之於ItemsControl 就等同於 ContentTemplate 之於 ContentControl
也就是描述如何將Content展開....
ok~~ 接下來是另一個問題 是我個人的經驗.....
何時要用Data Template,何時要用Custom Control,何時要用User Control
彈性而言 DataTemplate >> CustomControl >> UserControl
但是大家也知道 寫UI就是最容易東改西改 而且Control常混雜的很嚴重 也有可能很複雜
有時候很特別的一個UI 並不會需要有reuse的功能 我們可以直接用UserControl解決
但是如果是十分Common的Control 我們可以用CustomControl解決
DataTemplate則是如果能用現有的Control Composite成一個的話 就不需要花時間寫Control
大概是這樣 :D
最後一個問題 當ItemsPanel展開之後 我們沒辦法用Template.FindName找個ItemsPanel裡的Panel怎麼嗎?
我從google找到一個討論串 得enumerate Visual Tree解決 請享用
from http://www.msdner.net/dev-archive/210/153-119-2109609.shtm
private T FindItemsPanel
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(visual); i++)
{
Visual child = VisualTreeHelper.GetChild(visual, i) as Visual;
if (child != null)
{
if (child is T && VisualTreeHelper.GetParent(child) is ItemsPresenter)
{
object temp = child;
return (T)temp;
}
T panel = FindItemsPanel
(child); if (panel != null)
{
object temp = panel;
return (T)temp; // return the panel up the call stack
}
}
}
return default(T);
}
星期五, 1月 18, 2008
UI與Logics可[WPF]以完全分離嗎? TemplatePart可以解決不能分離的部分
但是發現這太難了~~ 如果想要加一下比較特別的功能 或是 Usability
UI跟Logics其實是有隱含的共識與假設的........ 這部分TemplatePart就可以用來解決這方面的問題
可以參考以下這二個link
http://www.cnblogs.com/zhouyinhui/archive/2007/12/01/979715.html
http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!634.entry
怎麼寫呢? 例如 ( from 以上Link的Copy & Paste)
星期二, 1月 01, 2008
WPF Asynchronous DataBinding
一直以來 我想要寫一個Async DataBinding... 因為大量使用Data Binding 可能會影響整個UI的Performance
結果我找到這篇.... 唔... 是我誤會WPF... 其實是有Asynchronous Mode的...
Beatriz Costa » How can I control whether my Binding is synchronous or asynchronous?
另外還有一篇也很有意思 有關cross threading的操作.... 蠻值得參考的
Beatriz Costa » How can I propagate changes across threads?
[WPF] .netfx 3.5 IDataErrorInfo
.net 2.0的Databinding似乎有這個用法 但是.net 3.0沒有 所以特別在.net 3.5加入進來....
WPF 3.5 的IDataErrorInfo的用法 -- >
WPF IDataErrorInfo and Databinding
Better WPF binding in .NET 3.5 « WPF Wonderland
Windows Presentation Foundation SDK : Data Validation in 3.5
Powered by ScribeFire.