發表文章

目前顯示的是 12月, 2020的文章

GIT基本觀念與常用指令

cd 'folder path'  切換至資料夾路徑 git init GIT儲存庫初始化,準備管理資料夾內檔案 git add <file name> <==這個步驟很重要,初學者常忘記。 將<file name>建立索引,這時候還沒有COMMIT哦。 git status   查看GIT目前狀態 git commit -m 'commit 說明內容' --author = 'Editor name <email address>' 正式將檔案簽入儲存庫 git commit --amend -m '修改說明'  --author = 'Editor name <email address>' 執行COMMIT後,要修改說明 注意 :檔案再次修改後,要送入儲存庫時,上述 Step 1 & Step 3 都要作一次。    

Python程式佈署,使用 pip freeze > requirements.txt , 套件參考清單

  Tip : When you're ready to deploy the application to other computers, you can create a  requirements.txt  file with the command  pip freeze > requirements.txt  ( pip3  on macOS/Linux). The requirements file describes the packages you've installed in your virtual environment. With only this file, you or other developers can restore those packages using  pip install -r requirements.txt  (or, again,  pip3  on macOS/Linux). By using a requirements file, you need not commit the virtual environment itself to source control.

Python虛擬環境建置 , 啟動 , 安裝套件 , 關閉虛擬環境

1. 新增Python虛擬環境,名稱:.venv 2. 啟動虛擬環境(.venv\scripts\activate)   py -3 - m venv .venv . venv \ scripts \ activate 3. 虛擬環境啟動後,會長成這樣      (.venv) D:\ Projects\Python>        再安裝套件於虛擬環境內。      python -m pip install matplotlib 4. 注意:虛擬環境安裝後,會出現一個新的 interpreter編輯環境 5. 虛擬環境使用後,再關閉      (.venv) D:\ Projects\Python> deactivate D:\ Projects\Python>     

GIT常用指令

  # 複製一份到本地端 $ git clone https://github.com/kdchang/flask101.git # 移動到資料夾 $ cd flask101 # 初始化專案 $ git init # 查看狀態 $ git status # 檢查差異 $ git diff # 將變更檔案放入暫存區 $ git add index.py # 使用 commit -m 提交變更 $ git -a -m 'init commit' # 查看歷史 $ git log # 放棄已經 commit 的檔案重回暫存區 $ git reset HEAD index.py # 放棄檔案變更 $ git checkout index.py

C# object Serialize & Deserialize by JSON Format

 static void Main(string[] args)         {              string oriString = "output";   //字串轉位元組陣列 byte[] oriArray = System.Text.Encoding.UTF8.GetBytes(oriString);  //檔案轉位元組陣列 byte[] bytePDF = System.IO.File.ReadAllBytes(@"C:\Users\p10154383\Downloads\output.pdf"); //將C#物件以JSON格式序列化為字串             PDFfile f = new PDFfile             {                 FileName = "output",                 CreatedDate = DateTime.Now,                 FileSize = 560,                 FileContent = bytePD...

View加入jQuery DateTimePicker的注意事項

專案新增 jQuery.UI.Combined 套件 主版View新增下列索引 <script src="~/Scripts/jquery-1.12.4.min.js"></script> <script src="~/Scripts/jquery-ui-1.12.1.min.js"></script> <link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" /> 功能View在控制項加上jQuery辨識用class , ex: datepicker @Html.TextBoxFor(m => Model.Birthday, new { @class = "form-control datepicker " }) 最後,於功能View畫面內,加入下列程式碼( 須注意擺放JS位置,不然可能會抓不到物件 ): <script>     $(function () {         $(" .datepicker ").datepicker({              dateFormat:"yy/mm/dd"         });     }); </script>

View的Razor語法

  @{...} ,裡面都是C#語言。 在@{...}內要直接輸出文字,在文字前要加上 @:   錯誤:@{ int i = 0; @:文字} 正確: @if (true)             {                 @: 附註             } Razor語法內可以加入HTML標籤,例:@{ <p>我是註解</p> },正確寫法 詳見參考連接。 使用 Razor 語法 ASP.NET Web 程式設計的簡介(C#)

CH3-Controller控制器的應用【重點】

控制器撰寫時,應注意:類別必須是public , 類別名稱必須是Controller結尾 , XML標記大小寫視為相同 , Action方法必須是public才能被呼叫 Controller主要負責:找出要執行的Action方法、取得Action方法虛引數的值、指定呈現網頁的ActionResult(View檢視)  、...

MVC檔案上傳 兩大重點

 MVC檔案上傳:HttpPostedFileBase & <input type="file">兩大重點

ActionResult型別,Controller可回傳至用戶端的物件類別

  ActionResult的種類(基底類別是:ActionResult) ViewResult , return View() , 檢視直接轉顯示為網頁 PartialViewResult , return PartialView() , 顯示部份檢視 RedirectResult , return Redirect() , 以URL方式重新導向其他網頁<可以 跨網站 >或其他控制制方法 RedirectToRouteResult , return RedirectToAction() / return RedirectToRoute() , 重新導向至其他動作方法( 同網站 ) ContentResult , return Content() , 使用者自定的內容型別 JasonResult , return Jason() , 傳回JSON物件 JavaScriptResult , return JavaScript() , 傳回用戶端執行的JS程式碼 FileResult , return File() , 傳回指定的二進位輸出 EmptyResult , return null , 傳回空的(null)結果

模型繫結(Model Binding)

  簡單模型繫結 讀取用戶端表單欄位的 name 值,和伺服器方法參數作對應。 註: id 值是給前端JavaScript使用的,而 name 值就是給後端.NET Code使用。 複雜模型繫結 利用 DefaultModelBinder 類別物件將用戶端表單欄位自動繫結到.NET物件型別屬性,真是神。

ViewData , ViewBag , TempData 在 View & Controller間傳遞資料用的物件

ViewData Controller : ViewData["Key"] = Value ; View : @ViewData["Key"] 速度快,但須手動轉型 ViewBag Controller : ViewBag.屬性 = 屬性值; View : @ViewBag.屬性 速度較慢,但使用便利,動態型別,省去手動轉型的麻煩。 TempData Controller : TempData["Key"] = Value ; View : @TempData["Key"] TempData和ViewData用法相同,差異在於: TempData會放在Session中,生命週期在一個請求(Request)內,請求結束就會被刪除。 在Controller內可以跨不同的Action方法,但只允許導向1次,到第2次導向頁面後資料會被刪除。

View控制項中 id & name 的用途

id 是給前端JavaScript使用的。 name 則是給後端MVC處理用的。 <input type="text" id = "Company" name = "Company"> 注意哦,不同使用處,但都會用到。

Web Api (PUT or POST or Get or Delete)

  PutTodoItem  類似於  PostTodoItem ,但是會使用 HTTP PUT。   回應為  204 (沒有內容)  。   根據 HTTP 規格,PUT 要求需要用戶端傳送整個更新的實體,而不只是變更。   若要支援部分更新,請使用  HTTP PATCH 。

GroupBy 排序(預設依來源集合的出現順序)

 var GroupByCity = Contact.SampleData().GroupBy(c => c.City). OrderBy( o => o.Key ,  StringComparer.CurrentCulture); //Key另作指定排序 , 預設依來源集合的出現順序(不自動排序)             foreach (var group in GroupByCity)             {                 WriteLine($"Group Key : {group.Key}");                 foreach (var item in group)                 {                     WriteLine($" -  {item}");                 }             }

自然排序法運算子(F1,F2,F10,F11,F20...)

 //自然排序法運算子     public class AlphaNumberSort : IComparer<string>     {         public int Compare(string x , string y)         {             StringComparer sc = StringComparer.CurrentCultureIgnoreCase;             if (string.IsNullOrEmpty(x) || string.IsNullOrEmpty(y))             {                 return x.CompareTo(y);             }             string numberX = FindTrailingNumber(x);             string numberY = FindTrailingNumber(y);             if (numberX != string.Empty && numberY != string.Empty)             {                 //先比字母部份               ...

SOP-VS2008加入HTML5_CSS3支援-作法

 詳細作法: https://stackoverflow.com/questions/17568778/visual-studio-2008-css-upgrading http://e-troy.blogspot.com/2014/01/visual-studio-html5.html https://kevintsengtw.blogspot.com/2013/04/visual-studio-2008-html5-css3.html https://marketplace.visualstudio.com/items?itemName=Mojtabakaviani.CSS3IntellisenseSchema C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Packages\1028\schemas\CSS > 加入CSS30 C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Packages\schemas\html > 加入html_5

自訂StringComparer(自訂排序比較函數),實作 IComparer

 比較函數是回傳一個整數結果而運作。 若兩個型別物件相同,則回傳0 若第1個型別物件比第2個型別物件小,則回傳-1 若第1個型別物件比第2個型別物件大,則回傳正值(>0)

回傳序列元素 (Select Many)

使用兩個From , 達到 SelectMany的效果。  //寫法2:SelectMany             WriteLine("=寫法2=");             IEnumerable<string> words2 = sentence.SelectMany (segment => segment.Split(' '));             foreach (string w in words2)             {                 WriteLine(w);             } //寫法3:用查詢表達式,達到寫法2-SelectMany的效果,我比較喜歡寫法3             WriteLine("=寫法3=");             IEnumerable<string> words3 =                 from segment in sentence                 from w in segment.Split(' ')                 select w;             foreach (string w in words3)            ...