From : http://en.wikipedia.org/wiki/URI_scheme
---------------------------------------------
RFC3986: http://tools.ietf.org/html/rfc3986
 

Foxbrush 發表在 痞客邦 留言(0) 人氣()

1. Download the new FF
 
2. Go to /usr/lib/firefox
 

Foxbrush 發表在 痞客邦 留言(0) 人氣()

From: http://blog.4psa.com/url-urn-uri-iri-why-so-many/
-------------------------------------------------
Computer guys tend to lack imagination, especially when they work with acronyms. This may lead to a lot of funny stuff. Let’s look at the following acronyms, for instance: URI, URN, URL, and IRI.
In interviews I like to ask this question and only once a guy was able to give an almost 100% correct answer. Somehow, I was not particularly surprised about it, as even widely adopted specifications contain subtle mistakes.

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/11/dependency-injection-6.html
------------------------------------------------------
續上集,接著要談 Ambient Context 與 Service Locator 模式。
Ambient Context 模式
前述三種注入相依物件的方式,有些場合可能不適用,例如:應用程式特定執行環境的範圍內需要共享特定物件。碰到這種場合,便可以考慮採用 **Ambient Context **(環境脈絡)模式來解決。
Ambient Context又叫做 Context Object(環境物件),是一種常見的設計模式,主要用於跨階層、跨模組共享物件、界定程式執行區塊的範圍、以及提供橫切面的功能(cross- cutting concerns)。這些到處都需要的物件或服務,不太可能一一注入到每個需要它們的地方:一來過於繁瑣,二來有些子模組或程式區塊是碰觸不到、或不在控 制範圍內的。因此,Ambient Context 沒有明顯「注入物件」的味道;它不是侵入性的,而是在某個地方已經準備好、被動地等著別人來取用。此特性在某些場合正好可以彌補前述注入方式的不足,故在 此一併討論。
已知應用例
.NET 類別庫中提供交易管理功能的 System.Transactions.TransactionScope 就是 Ambient Context 的一個例子。以下程式片段示範了基礎用法。
using (TransactionScope trxScope = new TransactionScope())
{
    // 執行多項資料異動作業。
    order.Add(newOrder);
customer.LastOrderDate = DateTime.Now;
    trxScope.Complete();  // 確認交易。
}
此外,ASP.NET 應用程式經常會用 Http.Web.HttpContext.Current 來取得目前的 HttpContext 物件。這也是一個常見的例子。
範例程式(一)
如前面提過的,Ambient Context 模式可用於程式特定執行範圍內共享物件狀態,此「特定範圍」可以是整個應用程式、特定執行緒、或其他自訂的執行範圍。如果是整個應用程式範圍內皆可存取的 共享物件,實作起來相當容易,通常用一個公開的靜態類別和靜態屬性就能達成。例如以下程式片段:
public static AppShared
{
    private static ILogger _logger = new MyLogger();
    public static ILogger Logger
    {
        get { return _logger; }
        set { _logger = value; }
    }
}
每當應用程式需要寫入日誌訊息時,在任何地方皆可使用如下方式達成:
AppShared.Logger.Info("請謹慎使用靜態變數和全域變數。");
範例程式(二)
這裡再提供一個範例,示範如何實作一個依個別執行緒(per thread)共享物件資訊的 Ambient Context 類別。此類別會使用 .NET Framework 4.0 之後提供的 ThreadLocal<T> 來保存個別執行緒的狀態資訊。
令此 Ambient Context 類別名稱為 PerThreadContext,而且它要提供一個靜態的 Current 屬性,供外界取得當前的 context 物件。如此一來,用戶端程式可以透過以下方式取得當前執行緒 context 中的共享物件:
var obj = PerThreadContext.Current.SomeMember;
PerThreadContext 類別的程式碼如下:
public class PerThreadContext
{
    // 用一個靜態的 ThreadLocal<T> 來管理各執行緒的 context 物件。
    private static ThreadLocal<PerThreadContext> _threadedContext;
    static PerThreadContext()
    {
        _threadedContext = new ThreadLocal<PerThreadContext>();
    }
    // 共享的狀態
    public DateTime OnceUponATime { get; set; }
    // 把建構函式宣告為私有,不讓外界任意 context 物件。
    private PerThreadContext()
    {
        OnceUponATime = DateTime.Now;
    }
    public static PerThreadContext Current
    {
        get
        {
            // 如果目前的執行緒中沒有 context 物件...
            if (_threadedContext.IsValueCreated == false)
            {
                // 就建立一個,並保存至 thread-local storage。
                _threadedContext.Value = new PerThreadContext();
            }
            return _threadedContext.Value;
        }
    }
}
這裡使用了延遲初始化(lazy initialization)的技巧:當用戶端程式透過靜態屬性 Current 取得當下的 context 物件時,先檢查目前的執行緒中有沒有 context 物件,有則直接傳回物件參考,若沒有,便建立一個,並保存至目前執行緒專屬的儲存區(thread-local storage)。其中的公開物件屬性 OnceUponATime 代表要與其他物件共享的狀態。
我們可以用一個簡單的 Console 程式來觀察其運作機制:
static void Main(string[] args)
{
    ShowTime();
    System.Threading.Thread.Sleep(2000);
    var t1 = new Thread(ShowTime);
    var t2 = new Thread(ShowTime);
    t1.Start();
    System.Threading.Thread.Sleep(2000);
    t2.Start();
    System.Threading.Thread.Sleep(2000);
    ShowTime();
    /* 執行結果:
       Thread 1: 2014/5/4 下午 01:37:09
       Thread 3: 2014/5/4 下午 01:37:11
       Thread 4: 2014/5/4 下午 01:37:13
       Thread 1: 2014/5/4 下午 01:37:09
     */  
}
static void ShowTime()
{
    Console.WriteLine("Thread {0}: {1} ",
        Thread.CurrentThread.ManagedThreadId,
        PerThreadContext.Current.OnceUponATime);
}
執行結果顯示,同樣是印出 PerThreadContext.Current.OnceUponATime 屬性值,不同的執行緒會有不同的結果。
Service Locator 模式
Service Locator(服務定位器)是一種設計模式,它同時具有前面提過的 Ambient Context 和 Factory 模式的性質,而且經常與 DI 搭配使用(儘管頗具爭議),故在此一併介紹。
顧名思義,Service Locator 的功能是用來尋找應用程式所需的服務,並返回該服務的執行個體。說得更具體些,當用戶端需要特定介面(或抽象類別)的物件時,既不使用 new 來建立物件,也不使用注入物件的機制,而是向 Service Locator 要一個物件。其基本運作機制如下:
用戶端向 Service Locator 提出請求,要求一個符合 IServiceA 的物件。
Service Locator 透過本身的型別搜尋/對應機制來尋找符合(相容於) IServiceA 介面的具象類別,然後建立該類別的物件實體,並回傳給用戶端。
下圖為 Service Locator 模式的結構圖。

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/11/dependency-injection-5.html
----------------------------------------------------------
續上集,介紹完幾個相關設計模式之後,接著要來看 DI 的模式,亦即注入物件的方式。
注入方式
DI 的核心概念是寬鬆耦合,是「針對介面寫程式」,故一旦開始在程式中運用 DI 技術,你可能會開始對「new 一個物件」的寫法更敏感。你可能會開始考慮,這個地方如果用 new 來建立特定實作類別的物件,將來需要修改程式時會不會很麻煩?如果只依賴介面或抽象類別會不會比較好?一旦開始出現這種現象,您已經朝向寬鬆耦合之路邁進 了。
本節將介紹 DI 的三種注入方式,包括:

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/10/dependency-injection-4.html
-------------------------------------------------------
續上集未完的相關設計模式...
Composite 模式
延續先前的電器比喻。現在,如果希望 UPS 不只接電腦,還要接電風扇、除濕機,可是 UPS 卻只有兩個電源輸出孔,怎麼辦?
我們可以買一條電源延長線,接在 UPS 上面。如此一來,電風扇、除濕機、和電腦便都可以同時插上延長線的插座了。這裡的電源延長線,即類似Composite Pattern(組合模式),因為電源延長線本身又可以再連接其他不同廠牌的延長線(這又是因為插座皆採用相同介面),如此不斷連接下去。
呃….延長線的比喻有個小問題:它在外觀上看起來也像是層層串接,容易和 Decorator 模式混淆。事實上,這兩種設計模式在結構上的確有相似之處。下圖所示為 Composite 模式的結構圖。

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/10/dependency-injection-3.html
---------------------------------------------------------------------
續上集,本文開始進入第二章。
讀完第 1 章以後,您應該已經了解 DI 的用途與目的,接著要來進一步了解的是 DI 的實作技術,也就是注入相依物件的方式。本章所介紹的相依性注入方式,又稱為「窮人的 DI」(poor man’s DI),因為這些用法都與特定 DI 工具無關,亦即不使用任何現成的 DI 框架(例如 Unity、Autofac)。畢竟,DI 只是一組設計原則與模式,不依賴任何工具也能實現。

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/10/dependency-injection-2.html
--------------------------------------------------
續上集,接著要說明如何運用 DI 來讓剛才的範例程式具備執行時期切換實作類別的能力。
入門範例—DI 版本
為了讓 AuthenticationService 類別能夠在執行時期才決定要使用 EmailService 還是 ShortMessageService 來發送驗證碼,我們必須對這些類別動點小手術,把它們之間原本緊密耦合的關係鬆開——或者說「解耦合」。有一個很有效的工具可以用來解耦合:介面 (interface)。
說得更明白些,原本 AuthenticationService 是相依於特定實作類別來發送驗證碼(如 EmailService),現在我們要讓它相依於某個介面,而此介面會定義發送驗證碼的工作必須包含那些操作。由於介面只是一份規格,並未包含任何實 作,故任何類別只要實作了這份規格,便能夠與 AuthenticationService 銜接,完成發送驗證碼的工作。有了中間這層介面,開發人員便能夠「針對介面、而非針對實作來撰寫程式。」(program to an interface, not an implementation)3,使應用程式中的各部元件保持「有點黏、又不會太黏」的適當距離,從而達成寬鬆耦合的目標。
提煉介面(Extract Interface)
開始動手修改吧!首先要對 EmailService 和 ShortMessageService 進行抽象化(abstraction),亦即將它們的共通特性抽離出來,放在一個介面中,使這些共通特性成為一份規格,然後再分別由具象類別來實作這份規 格。以下程式碼是重構之後的結果,包含一個介面,兩個實作類別。我在個別的 Send 方法中使用 Console.WriteLine 方法來輸出不同的訊息字串,方便觀察實驗結果(此範例是個 Console 類型的應用程式專案)。

Foxbrush 發表在 痞客邦 留言(0) 人氣()


From: http://huan-lin.blogspot.com/2011/10/dependency-injection-1.html
-----------------------------------------------------------
本文摘自電子書《.NET 相依性注入》的第一章,您可至書籍首頁下載試閱章節。
書籍首頁網址:https://leanpub.com/dinet

Foxbrush 發表在 痞客邦 留言(0) 人氣()

From: http://stackoverflow.com/questions/21109361/why-is-reacts-concept-of-virtual-dom-said-to-be-more-performant-than-dirty-mode
--------------------------------------------

I'm the primary author of a virtual-dom module, so I might be able to answer your questions. There are in fact 2 problems that need to be solved here

  • When do I re-render? Answer: When I observe that the data is dirty.

  • How do I re-render efficiently? Answer: Using a virtual DOM to generate a real DOM patch


  • In React, each of your components have a state. This state is like an observable you might find in knockout or other MVVM style libraries. Essentially, React knows when to re-render the scene because it is able to observe when this data changes. Dirty checking is slower than observables because you must poll the data at a regular interval and check all of the values in the data structure recursively. By comparison, setting a value on the state will signal to a listener that some state has changed, so React can simply listen for change events on the state and queue up re-rendering.
    The virtual DOM is used for efficient re-rendering of the DOM. This isn't really related to dirty checking your data. You could re-render using a virtual DOM with or without dirty checking. You're right in that there is some overhead in computing the diff between two virtual trees, but the virtual DOM diff is about understanding what needs updating in the DOM and not whether or not your data has changed. In fact, the diff algorithm is a dirty checker itself but it is used to see if the DOM is dirty instead.
    We aim to re-render the virtual tree only when the state changes. So using an observable to check if the state has changed is an efficient way to prevent unnecessary re-renders, which would cause lots of unnecessary tree diffs. If nothing has changed, we do nothing.
    A virtual DOM is nice because it lets us write our code as if we were re-rendering the entire scene. Behind the scenes we want to compute a patch operation that updates the DOM to look how we expect. So while the virtual DOM diff/patch algorithm is probably not the optimal solution, it gives us a very nice way to express our applications. We just declare exactly what we want and React/virtual-dom will work out how to make your scene look like this. We don't have to do manual DOM manipulation or get confused about previous DOM state. We don't have to re-render the entire scene either, which could be much less efficient than patching it.

    Foxbrush 發表在 痞客邦 留言(0) 人氣()

    Heroku runs Node.js if there is one package.json file in your PHP project...
    WTF !?
    How to get PHP back :
     

    Foxbrush 發表在 痞客邦 留言(0) 人氣()

    From: http://liaosankai.pixnet.net/blog/post/27533126-php-%E5%8F%96%E5%BE%97%E6%AA%94%E6%A1%88%E7%9A%84%E5%89%AF%E6%AA%94%E5%90%8D%28php-get-file-extension%29
     
    --------------------------------------------------------------------------
     

    Foxbrush 發表在 痞客邦 留言(0) 人氣()

    Blog Stats
    ⚠️

    成人內容提醒

    本部落格內容僅限年滿十八歲者瀏覽。
    若您未滿十八歲,請立即離開。

    已滿十八歲者,亦請勿將內容提供給未成年人士。