發表文章

目前顯示的是 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)            ...

Select & SelectMany 的差異為何?

資料來源: https://social.msdn.microsoft.com/Forums/vstudio/en-US/ebf4adac-8873-44f1-9def-a10912e4d2ef/what-is-the-difference-between-select-and-selectmany?forum=adodotnetentityframework   Select operator is used to select value from a collection and SelectMany operator is used to select values from a collection of collection i.e. nested collection. select 通常用於取得集合中的值,可能是單一值或另一個集合 selectmany 則用於取得集合中集合的值,不是想像中查詢多個欄位的用法,因為回傳多個欄位用的是 tuple value or anonymous type這兩種方式。 回到主題,selectmany的好處在於可以直接取得巢狀集合(集合中有另一集合)中的值,讓迴圈少跑1次。 //寫法2 :總算看懂了, 因為 select 裡再包 1個select , 回傳後會變IEnumerable<IEnumerable<string>> //如果是 selectmany 裡再包 1個select , 回傳時變成 IEnumerable<string> , 讓你少寫1次迴圈 var customerOrders_Tuple = customers.SelectMany( //SelectMany 簡化為單一序列 , 跑1次迴圈就能抓出值 .  (cust, custIndex) => cust.Orders.Select(o => "Customer #" + (custIndex + 1) + " has an order with OrderID " + o.OrderID)); foreach (var order in customerOrders_Tuple) { Console.WriteLine(order); } Wri...

Select with index of item(分別取得"列表值" & "列表索引")

 //Select with index of item(分別取得"列表值" & "列表索引")         static void Select_With_Index_of_item()         {             int[] numbers = { 6, 4, 3, 9, 8, 5, 7, 2, 0 }; //var numsInPlace = numbers.Select((num, index) =>  (Num: num, InPlace: (num == index)));  //元組tuple寫法,只有C#7可以用 var numsInPlace = numbers.Select((num, index) => new { Num = num, InPlace = (num == index) } );  //匿名anonymous寫法,C#6可以用             foreach (var item in numsInPlace)             {                 WriteLine($"{item.Num} : {item.InPlace}");             }         }

載入JavaScript code的最佳時機

 To summarize: async and defer both instruct the browser to download the script(s) in a separate thread, while the rest of the page (the DOM, etc.) is downloading, so the page loading is not blocked by the scripts. If your scripts should be run immediately and they don't have any dependencies, then use async. If your scripts need to wait for parsing and depend on other scripts and/or the DOM being in place, load them using defer and put their corresponding <script> elements in the order you want the browser to execute them.

LINQ學習重點(SELECT 1)

 //Select a subset of properties         static void Ex7()         {             List<Product> products = GetProductList();             var productInfos = from p in products                                select new { p.ProductName , Price = p.UnitPrice};             foreach (var item in productInfos)             {                 Console.WriteLine($"{item.ProductName} is and costs {item.Price} per unit.");             }         }         static void Ex7_Tuple() //元組寫法         {             List<Product> products = GetProductList();             //v...

[SOLVED] .NetFrameWork 4.5.2 不支援 C#7.0 語法,所以裝了 System.ValueTuple 套用也沒有用

因為公司開發環境是 4.5.2,不是4.7.2,為了避免亂裝一些東西,造成 寫好的程式掛掉。 就決定不升級至 4.7.2,也先不用元組型別(System.ValueTuple)練習 LINQ。 OK。

在匿名 anonymous type 和元組 tuple type 類型之間選擇

圖片
  在匿名和元組類型之間選擇 2020/07/01   選擇適當的類型牽涉到考慮其可用性、效能和取捨,相較于其他類型。   自 c # 3.0 起已提供匿名型別,但  System.Tuple<T1,T2>  .NET Framework 4.0 引進了泛型型別。   自從起,新選項在語言層級支援上引進,像是  System.ValueTuple<T1,T2>  名稱所暗示的,提供具有匿名型別彈性的實值型別。   在本文中,您將瞭解何時適合選擇另一種類型。 結論 當開發人員在元組和匿名型別之間進行選擇時,需要考慮幾個因素。   一般來說,如果您不是使用  運算式樹狀 架構,而且您熟悉元組語法,則請選擇  ValueTuple  其提供實值型別,而且可以彈性地命名屬性。   如果您是使用運算式樹狀架構,而且想要命名屬性,請選擇 [匿名型別]。   否則,使用  Tuple 。 資料來源:https://docs.microsoft.com/zh-tw/dotnet/standard/base-types/choosing-between-anonymous-and-tuple

LINQ學習重點(WHERE)

  Restriction operators : The  where  keyword The  where  keyword or  Where  method provide this capability. These operators restrict, or filter, the input sequence to produce an output sequence. Your first query : the structure of a LINQ query. Filter elements on a property : filter elements based on a single property Filter elements using multiple properties : test multiple properties to filter elements in a sequence. Filter and drilldown into the output elements : filter input elements, then drill into a sequence on each output element. Filter input elements based on index : use an element's position to filter it. //Filter elements based on position(這種寫法,第1次看)         static void Ex4()         {             string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };             var shortDigits = digits.Where((...

插補字串,指定日期格式

 static void Ex3()         {             var customers = GetCustomerList();             var tpeCustomers = from cus in customers                                where cus.Region == "TPE"                                select cus;             WriteLine("==Query Result==");             foreach (var item in tpeCustomers)             {                 WriteLine($" Customer<{item.CustomerID}> : {item.CompanyName}");                 foreach (var order in item.Orders)                 {                 ...

北商資管系-夜二技讀書計劃

北商讀書計劃(行動數位服務模組): 洽詢電話: 平日上、下午(02)2322-6050、6053、6048~49 平日晚間(02)2322-6235 通識科目: 10 學分 專業必修: 72(畢業最低學分數) - 10 - 36 = 26學分(一門課都不能少) =(一上)=     1. 程式設計(3)     2. 管理資訊系統(3) <= 企業e化模組     3. 資訊倫理與法律(2) =(一下)=     4. 應用統計學(3)    # 詢問是否可折抵學分     5. 物件導向系統分析與設計(3)     6. 資訊網路(3) =(二上)=     7. 電子商務與網路行銷(3) <= 企業e化模組     8. 資料庫管理(3) <=行動數位服務模組 =(二下)=     9. 行動商務應用(3) <= 行動數位服務模組 專業選修:13 * 3 = 39 (至少應修 36 學分) =(一上)=     1. 資料結構(3)     2. 網站應用程式設計(3) <= 行動數位服務模組     3. 資料探勘與大數據分析(3) <= 企業e化模組 =(一下)=     1. 行動應用開發(3) <= 行動數位服務模組     2. 國際認證管理(3) =(二上)=     1. 國際認證管理進階(3)     2. 行動應用程式設計(3)     3. 演算法(3)     4. 伺服器架設與規劃(3)     5. 資訊安全(3) =(二下)=     1. 商業智慧與資料科學(3)     2. 資料庫管理系統實作(3)     3. 密碼學(3)

SOP-C#資料結構-筆記

========= C#資料結構(參考書目:資料結構使用Visual C#。ISBN:978-986-500-413-2)   CH4-鏈結串列     類別,物件及成員(屬性,方法)       1.public 公開 所有類別皆可存取       2.private 私有 只適用該類別的成員函數       3.protected 保護 產生繼承關係的衍生類別可取用       4.internal 內部 只適用於目前專案(組件)       5.protected internal 只適用於目前(組件)或衍生自包含類別的型別          建構子       1. 語法:ClassName() ex. Student()       2. 建構子存取修飾詞必須使用 public       3. 一個類別可以有多個建構子(又稱多載),它不能有回傳值,也毋須用void       4. 類別若不含任何具參數建構子時,程式自動呼叫<預設建構函式>     解構子       1. 語法:~ClassName() ex. ~Student()       2. 解構子不能使用存取修飾詞       3. 一個類別只能有1個解構子,它不含任何參數,不能有回傳值,無法被繼承或多載       4. 解構子無法直接呼叫,只有物件被清除時才會執行     環狀串列       1.它和單向鏈結串列相似,不同點在於必須將 (最後1個節點) 指向 (第1個節點)       2.優:           回收時間固定,無關長度     ...

C# 6.0語法調整(匯入靜態類別及字串插補)

匯入靜態類別 原: using System; Console.WriteLine(); 新: using System; using static System.Console; //改變在這裡 WriteLine(); //直接指定方法,少寫一次類別名稱 字串插補 原:WriteLine("Hello {0} ",name) ;  新:WriteLine($"Hello {name}") ; //不用再排順序,直接將變數塞進去

VSCode 建立DEBUG設定

 按下F5,會提示你設定 "launch.json" 內容。 設定後,再次按下F5,VSCode就會執行,很方便的。 {      // Use IntelliSense to learn about possible attributes.      // Hover to view descriptions of existing attributes.      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387      "version" :  "0.2.0" ,      "configurations" : [         {              "name" :  "Launch Edge(file)" ,              "request" :  "launch" ,              "type" :  "pwa-msedge" ,              "file" :  "${workspaceFo...

LINQ哪種查詢語法比較好?

 原則上,兩種都要會。 擴充方法格式(.符號語法) 查詢表達式(推用法,尤其是群組與聯結),比較好懂 擴充方法+查詢表達式(作者傾向先用查詢表達式,再併用擴充方法) 因為作者有SQL背景,所以才會有上述建議(先用查詢表達式,除非不支援,才會加用擴充方法)。 還有另一個考量點,程式碼除了寫給自己看以外,還要讓外人看的懂。 int []  numsCombine  =  new   int []{ 0 , 5 , 1 , 9 , 2 , 6 , 3 , 10 , 1 , 1 , 1 , 3 , 4 };              var   result4  = ( from   n   in   numsCombine                            where   n  <  5                            orderby   n                            select   n ). Distinct (); //這裡就是兩種併用

超開心,完成第1個List實作。

最近剛到一家新的產險公司上班,企圖將以往落後許多的程式開發能力拉一點回來。

第一篇blog

 第一篇blog