Monday, October 31, 2011

[C#] DayDiff 取得天數差異

C# 裡面沒有 DateDiff 這種很方便取得時間差異的函式,雖然可以引用 Microsoft.VisualBasic來 使用裡面的 DateAndTime.DateDiff Method,不過不是每個人都想這樣做,所以只好自己來寫一個合用的,保哥有一篇文章寫了用 TimeSpan 判斷日期差異的方式,但是這也不合我用,所以就自己亂寫了一個。
protected int DayDiff(DateTime dfrom,DateTime dto)
        {
            int day;
            day=DateTime.IsLeapYear(dfrom.Year)?366:365;

            if (dto.Year == dfrom.Year)
                return dto.DayOfYear - dfrom.DayOfYear;
            else if (dto.Year > dfrom.Year)
                return dto.DayOfYear - dfrom.DayOfYear + day;
            else
                return dto.DayOfYear - dfrom.DayOfYear - day;
        }

會這樣寫主要是要讓某些狀況下的結果是正確的,例如今天23:00跟明天01:00,應顯示差一天,這時 TimeSpan 求出來的結果就會是零天,還有順便加上閏年的判斷。因為需求關係,我這寫法沒有去判斷跨多年的情況,如果有需要的話再自行加上吧。

Friday, October 28, 2011

PayEasy 寵物日



PayEasy在這周五舉辦了寵物日,這次的主角是貓,剛好有帶相機,就跑去拍了幾張照片。上頭這隻貓的臉很酷。

Wednesday, October 26, 2011

Tuesday, October 18, 2011

I AM NIKON



最近在電視上,看到了Nikon的這個形象廣告,相當有意境,於是上網找了一下,原來有相當多版本,甚至各國都有各自拍攝不同主題的版本,不過台灣撥出的廣告在Youtube上居然只有360P版本,NikonTaiwan實在是該打屁股,怎麼不丟HD畫質的呢 ? 所以我就放了上面那段比較完整的Brand Film,個人覺得相當精采。


Wednesday, October 12, 2011

選舉到了才愛國旗

IMG_4581

原本想在十月十號貼這篇文章,不過人一懶就拖到現在了。

馬政府上台後,台灣各個場合已經很難看到國旗的出現了,甚至拿國旗會被警察打、被關,國旗會被警察搶去丟掉、折掉,反而是中共五星旗可以大辣辣地在街上出現,我還看過在車上插著大大的五星旗,從警察前面開過博愛特區,也不會有事。

近來選舉到了,馬政府為了選舉,為了選票,又開始騙大家他們是愛國,愛國旗的,真是可笑至極。

Friday, October 7, 2011

Port of FTPS (implicit SSL)

因為年紀大了記性不好,所以特別把FTPS(FTP over implicit TLS/SSL)所要開的Port列一下,避免下次忘記的時候又要找一次。

Port用途
21cmd port
50000~5002050000~50020:傳輸資料PORT:此PORT若沒開,可以登入,但下list cmd命令時(如LS)則會無法看到目錄與資料
990990:交換SSL KEY 加密用

Thursday, October 6, 2011

[TroubleShooting] The remote host closed the connection. The error code is 0x80072746.

System.Web.HttpException
The remote host closed the connection. The error code is 0x80072746.

System.Web.HttpException (0x80072746): The remote host closed the connection. The error code is 0x80072746.at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte[] status, Byte[] header, Int32 keepConnected, Int32 totalBodySize, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32 doneWithSession, Int32 finalStatus, Boolean& async)
at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)
at System.Web.HttpResponse.Flush(Boolean finalFlush)
at LunchKingSite.Web.Service.coupon.ProcessRequest(HttpContext context) in c:#############################.cs:line 73
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


公司網站上常常有這個錯誤,不過放了很久卻都沒有人去解,今天找了一下解法,大致上有兩種。

先說說原因,這問題的主要原因通常是在輸出資料時,使用者已經關閉連線(關掉瀏覽器),但是程式卻不知道,於是跑到 Response.Flush(); 的時候,就會產生這個錯誤。

解法一是加上Response.Buffer = false;
解法二是在 Flush 前先用 Response.IsClientConnected 去判斷是否還有連線,有的話再繼續。

這錯誤有點難模擬,所以我沒有兩個都試然後去看結果,所以只用了第一個,解法二看起來還是會有很小的機會發生同樣的錯誤就是。

Wednesday, October 5, 2011

[C#] 取得WebRequest錯誤後的資訊

日前在用 WebRequest 與廠商串接功能,他們的錯誤訊息蠻特別的,是直接回 HTTP Error 400 Bad request ,然後把 error code 寫到 body 裡,在 C# 裡使用 WebRequest 一遇到 Status Code 400 就會跳錯誤了,所以沒辦法用原本的方式接資料,原本還在想要不要用 wget 先 debug ,後來找了一下才知道可以用 WebException 去讀出回傳的資料,這就方便了許多,方法如下。
            try
            {
                //your WebRequest , WebResponse
            }
            catch (WebException e)
            {
                Stream dataStream = e.Response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream, encode);                
                Console.WriteLine(reader.ReadToEnd());
            }

這樣就可以拉到錯誤時的資訊了。

Tuesday, October 4, 2011

[JS] Close fancybox within iframe

雖然 fancybox 的 API 文件中有說到在iframe中可使用 parent.$.fancybox.close(); 去關掉 fancybox ,但是我實際上測試卻是不會動,後來在網路上找半天,各種做法都搞不定,最後只好用很笨的方法,直接把 fancybox 顯示出來的圖層關掉:
        parent.jQuery('#fancybox-overlay').css('display', 'none');
        parent.jQuery('#fancybox-wrap').css('display', 'none');

後來想了一想,用了比較好的做法,程式上比較美觀,雖然我看不出來在表現上有啥差別。
    //parent
    function CloseFancy()
    {
        $.fancybox.close();
    }
    //iframe
    function fancyclose() {
        parent.CloseFancy();
    }

如果有用 fancybox ,可以參考一下,不過 fancybox 跟 BlockUI 會有衝突,我還找不到方法解,要注意一下就是。

[JS] 讀取條約後才可繼續 / EULA Scroll to End

有朋友問我個問題,就是一些使用者合約要看完才能繼續的功能怎麼做,想想我也沒試過,於是就來搞一下。做好的樣子就長的像下面一樣,手邊沒啥EULA所以上網找了D3的test agreement來用。

DIABLO III

PRE-RELEASE TESTING AGREEMENT

YOU SHOULD CAREFULLY READ THE FOLLOWING PRE-RELEASE TEST AGREEMENT (THE “AGREEMENT”) BEFORE INSTALLING THIS SOFTWARE PROGRAM. IF YOU DO NOT AGREE WITH ALL OF THE TERMS OF THIS AGREEMENT, YOU MAY NOT INSTALL THIS SOFTWARE PROGRAM.

This pre-release version of the “DIABLOR III” software program and any accompanying materials or documentation (collectively, the “Game”), is the copyrighted work of Blizzard Entertainment, Inc. (“Blizzard”), or its suppliers. All use of the Game is governed by the terms of this Agreement. This DiabloR III Pre-Release Test (the “Test”) provides a limited opportunity during which certain designated people (“Testers”) are given the opportunity to test the pre-release version of the “Game.” If you are designated by Blizzard as a Tester, then in consideration of your meeting the eligibility requirements set forth below, and agreeing and adhering to the terms and conditions of this Agreement, you will be given the opportunity to test the Game.

1. Eligibility. You are only eligible to participate in the Test if:

(i) You are designated by Blizzard as a Tester;

(ii) You have registered a Battle.netR account which is in good standing (the “Account”), and you are in full compliance with the Battle.net Terms of Use at all times during the Test;

(iii) You are an adult in your country of residence;

(iv) You allow Blizzard to obtain hardware and software information from the computer system that you will use to take part in the Test (the “System”) prior to registration for the Test in order for Blizzard to determine if you are eligible to participate in the Test; and

(v) The System meets the specifications which Blizzard determines are required for the Test.

You understand that Blizzard may change the required system specifications at any time during the Test, and if at any time during the Test your System does not meet the requirements, Blizzard, in its sole discretion, may determine that you are ineligible to continue to participate in the Test.

2. Grant of License. Blizzard grants you a license to install and use one (1) copy of the Game for your use on one (1) computer which you own or control at your place of residence for the purpose of testing the Game. This license is limited, non-exclusive, and can be revoked by Blizzard at any time, for any reason.

3. Distribution of the Game. The “Blizzard Downloader” utility utilizes the ‘upload’ capability of your computer to distribute the Game to other participants of the Test. By accepting the terms of this agreement, you agree that Blizzard may distribute the Game using the upload capacity of the System to ‘upload’ all or part of the Game to other participants of the Test.

4. Confidentiality. The existence of the Test and all elements thereof (including without limitation this Agreement) is confidential, and you agree to maintain secrecy associated with the Test. For purposes of example and not limitation, you agree that you will not disclose the following:

(i) Information about the Test, such as your role as a Tester, the length of the Test, the number of Testers, how you became a Tester, etc.

(ii) Information related to the Game, such as the Game’s look and feel, playable races, classes, combat, magic, communication, grouping, questing, monetary systems, the Game’s non-player character interaction, quests, items, armor, weapons, stability of the Game, etc.

During the Test, Blizzard can announce to Testers that certain information about the Game may be disclosed to the public. After such an announcement, you may disclose information that Blizzard has approved for public disclosure.

5. Ownership. Blizzard owns the Game, including all intellectual property rights in and to the Game and all copies thereof. The Game is protected by the copyright laws of the United States, international treaties and conventions, and other laws. The Game may contain materials licensed by third parties, and the licensors of those materials may enforce their rights in the event of any violation of this Agreement.

6. Tester Responsibilities

(i) You may not copy, photocopy, reproduce, translate, reverse engineer, derive source code from, modify, disassemble, decompile, or create derivative works based on the Game,

(ii) You may not remove any proprietary notices or labels from the Game.

(iii) Without limiting Blizzard’s rights hereunder, you agree that you shall not:

a) sell, rent, lease, lend, license the Game to others, grant a security interest in, or transfer reproductions of the Game and/or the Account to other parties, or let any third person use the Game and/or the Account;

b) exploit the Game or any of its parts for any commercial purpose;

c) host, provide or develop matchmaking services for the Game, or intercept, emulate or redirect the communication protocols used by Blizzard in any way, including without limitation, through protocol emulation, tunneling, packet sniffing, modifying or adding components to the Game, use of a utility program or any other techniques now known or hereafter developed, for any purpose, including without limitation unauthorized network play over the Internet, network play utilizing commercial or non-commercial gaming networks, or as part of content aggregation networks; or

d) facilitate, create or maintain any connection to the Game which has not been authorized by Blizzard, including without limitation any connection to any unauthorized server that emulates, or attempts to emulate, the Game.

7. Consent to Monitor. THE GAME MAY MONITOR YOUR COMPUTER’S RANDOM ACCESS MEMORY (RAM) FOR UNAUTHORIZED THIRD PARTY PROGRAMS RUNNING CONCURRENTLY WITH THE GAME. AN “UNAUTHORIZED THIRD PARTY PROGRAM” IS A THIRD PARTY SOFTWARE, SUCH AS AN “ADDON,” “MOD,” “HACK,” “TRAINER,” OR “CHEAT,” THAT: (i) ENABLES OR FACILITATES CHEATING OF ANY TYPE; (ii) ALLOWS USERS TO MODIFY OR HACK THE GAME INTERFACE, ENVIRONMENT, AND/OR EXPERIENCE; OR (iii) INTERCEPTS, “MINES,” OR OTHERWISE COLLECTS INFORMATION FROM OR THROUGH THE GAME. IF THE GAME DETECTS AN UNAUTHORIZED THIRD PARTY PROGRAM, THE GAME MAY (a) COMMUNICATE INFORMATION BACK TO BLIZZARD THAT COULD INCLUDE YOUR ACCOUNT NAME, IP ADDRESSS, DETAILS ABOUT THE UNAUTHORIZED THIRD PARTY PROGRAM DETECTED, AND THE TIME AND DATE THE UNAUTHORIZED THIRD PARTY PROGRAM WAS DETECTED; AND/OR (b) TERMINATE YOUR ACCESS TO THE TEST.

8. Termination. Blizzard may terminate this Agreement at any time, for any reason, or for no reason. Upon termination of the Agreement, you must destroy the Game and all documents and materials you received from Blizzard in connection with the Test, and remove any elements of the Game from any hard drives on which the Game has been installed.

9. Feedback. During and after the Test, Blizzard may provide you with an opportunity to provide Blizzard with comments, suggestions and impressions of the Game by using the in-program mechanisms provided to supply feedback and bug reports, internal websites and forums, and such other methods. The Game may also include a tool that will allow the System to forward system and driver information to Blizzard in the event of a crash. This tool will collect data on the System during the crash, and allow you to forward a report to Blizzard via electronic mail.

10. Acknowledgments. You that:

(i) the Game is a work in progress and may contain bugs which may cause loss of data and/or damage to the System;

(ii) you have, or will, back-up your hard drive prior to installation of the Game;

(iii) you have the resources necessary to easily reinstall your operating system and restore any and all data that may be lost;

(iv) Blizzard is not liable in any way for the loss of data or damage to the System, interruptions of service, software or hardware failures, or loss of data or disruption of service.

(v) Blizzard may monitor and record any and all communications, electronic or otherwise, pertaining to the Game including, without limitation, packets, chat, email, message board postings, etc.;

(vi) Blizzard may delete or modify the information stored by the Game for any reason at any time during the duration of the Test; and

(vii) Blizzard may transfer software program files to the System, including a program that will collect and send Blizzard CPU, RAM, operating system, video card, and sound card information from the System.

11. DISCLAIMER OF WARRANTIES. THE GAME AND ANY ACCOMPANYING DOCUMENTATION IS PROVIDED TO YOU “AS IS” WITHOUT WARRANTY OF ANY KIND. BLIZZARD DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

12. LIMITATION OF LIABILITY. BLIZZARD IS NOT LIABLE TO YOU FOR ANY DAMAGES OF ANY KIND INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT, COMPENSATORY, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT AND YOUR PARTICIPATION IN THE TEST.

13. Equitable Remedies. You agree that Blizzard would be damaged if you breach the terms of sections 2,3,5,7, and 10-14 of this Agreement, and if you are in breach of one or more of these sections of the Agreement, Blizzard shall be entitled, without bond, other security, or proof of damages, to appropriate equitable remedies with respect to breaches of this Agreement, in addition to any other legal remedies available to Blizzard.

14. Miscellaneous. If the terms of this Agreement and the Battle.net Terms of Use are in conflict, the terms of this Agreement shall govern and supersede any conflicting terms found in the Battle.net Terms of Use Agreement. Blizzard reserves the right to update, modify or change this Agreement or the Terms of Use at any time, for any reason, without notice to you. This Agreement shall be deemed to have been made and executed in the State of California, and any dispute arising hereunder shall be resolved in accordance with the law of California, before a state or federal court located in the State of California, County of Los Angeles. In the event that any provision of this Agreement shall be held by a court or other tribunal of competent jurisdiction to be unenforceable, such provision will be enforced to the maximum extent permissible and the remaining portions of this Agreement shall remain in full force and effect. This Agreement constitutes and contains the entire agreement between the parties with respect to the subject matter hereof and supersedes any prior oral or written agreements.

c 2011 Blizzard Entertainment, Inc. All rights reserved. Diablo and Blizzard Entertainment are registered trademarks of Blizzard Entertainment, Inc., in the U.S. and/or other countries.






還蠻簡單的,主要就是去比較兩個Div的高度與offset來判斷是否拉到底了,程式如下: