發表文章

[ORM] Using Dapper async in asp.net core 2.1

[ORM] Using Dapper async in asp.net core 2.1 Dapper 是一套輕量化 ORM 套件,有優秀的效能,支援物件對應,與快速查詢,...,等。 Dapper 優點 查詢快速 優秀的效能 支援物件映射 支援預存程序 SP 支援 Bulk 處理 支援強型別 支援動態綁定 支援參數化查詢 支援例舉 Packages Please install Dapper Nuget PM> Install-Package Dapper -Version 1.50.5 建立 Model public class Employee { public int Id {get;set;} public string Name {get;set;} public Datetime birthday {get;set;} } Repository Pattern IRepository public interface IRepository<T> { Task<List<T>> GetAll(); Task<T> GetById(int id); } XXXRepository public class EmployeeRepository : IRepository<Employee> { readonly IConfiguration _config; public EmployeeRepository(IConfiguration config) { this._config = config; } public IDbConnection Connection { get { return new SqlConnection(_config.GetConnectionString("MyConnec...

[ASP.Net Core] Day 1 - Note

ASP.Net Core - Day 1 Setup Environmen VS 2017 Community Dotnet COre 2.1 SQL Server Express SQL Server Management Studio 建立 ASP.NET Core 專案 File => Project => Empty ASP.NET Core 檔案結構 專案裡的檔案,主要以 Program.cs 與 Startup.cs 為主。 程式的進入點從 Program 開始,透過 WebHost ,將 Startup 註冊進去。 $ ls Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 7/23/2018 5:57 PM obj d----- 7/23/2018 5:56 PM Properties d----- 7/23/2018 5:56 PM wwwroot -a---- 7/23/2018 5:56 PM 630 Program.cs -a---- 7/23/2018 5:56 PM 1118 Startup.cs -a---- 7/23/2018 5:56 PM 310 testcore.csproj 主程式中,建立一個 WebHostBuilder ,告訴 WebHost 要從哪一支程式開始 UseStartup 。 public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder Cr...

[Git] Alias

[Git] alias 有時候指令太長,就會覺得想偷懶,所以來打造自己的 Git 快速鍵吧!順便就筆記一下。 .gitconfig 要做 alias,就需要去修改 .gitconfig 檔案。通常 .gitconfig 檔案會位於帳號的跟目錄下。 $ ls -al ~/ ... -rw-rw-r-- 1 robert robert 245 7月 13 04:55 .gitconfig ... 修改 .gitconfig 在檔案裡,添加 [alias] ,將一些想做 alias 的命令,依序填寫進去。 [alias] lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue) %Creset' --abbrev-commit lo = log --oneline --graph ci = commit co = checkout br = branch ba = branch -a st = status rt = remote rtv = remote -v 測試 alias 指令 測試 git log $ git lg commit xxxxx Author: oooo Date: Fri Jul 13 03:42:27 2018 +0800 ... commit xoxoxoxoxo Author: oooo Date: Thu Jul 12 20:35:02 2018 +0800 ... 測試 git log --oneline $git lo 8b7a80f ... 3451bc9 ... af0e2d6 ... abc6b88 ... 228cd43 ... 955dff6 ... ... Reference 打造專屬於你的 Git 工作流程 — Alias、Commands、Hooks

[Tools] GCOV & LCOV 初探

[Tools] gcov & lcov gcov 是一套代碼覆蓋率的工具,可以有效地查閱分析程式,找出程式中重載的部分,它也是 gcc 中的內建工具。 lcov 則是可以將 gcov 所分析完的結果,轉譯成 html 。 Required Packages $ apt update $ apt upgrade -y $ apt install gcov lcov gcov $ gcov -h Usage: gcov [OPTION]... SOURCE|OBJ... Print code coverage information. -h, --help Print this help, then exit -v, --version Print version number, then exit -a, --all-blocks Show information for every basic block -b, --branch-probabilities Include branch probabilities in output -c, --branch-counts Given counts of branches taken rather than percentages -n, --no-output Do not create an output file -l, --long-file-names Use long output file names for included source files -f, --function-summaries Output summaries for each function -o, --object-directory DIR|FILE Search for object files in...

[Audio] MP4 convert WAV with ffmpeg

[Audio] MP4 convert WAV 最近因為工作上的關係,需要特別對聲音做處理。由於我們系統預設錄製下來是 MP4,因此需要特別將 MP4 轉成 WAV。 在 Windows 上,轉檔要特別去找工具,不然就是要將檔案傳送到某些支援轉檔的網站上,請他們幫忙將檔案轉換成 WAV 檔。 但是在 Linux 上,只需安裝 ffmpeg,透過指令就可以簡易的將 MP4 轉換成 WAV。 FFMPEG $ ffmpeg -h ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3) configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg libavutil ...

[C#] 初探 XUnits

Unit Testing with xUnit 單元測試以前都沒寫過,上次去外面上課,稍微接觸一下。由於最近在網路上買了一本 .Net Core 來看,感覺 Unit Test 是一個好東西。 所以,我得做一點筆記,紀錄一下,不然哪天又忘了。 Unit Test 在軟體工程中,有一個 SRP Pattern ,大意是盡量讓一個類別維持單一原則,不要做太多事。這時候,我們就可以透過單元測試,來個別驗證這些類別與功能。 單元測試可以提高軟體的可靠度,減少將來軟體釋出時,帶來的一些臭蟲。 Business day Calculator Example 書上給了一些範例,就套用這範例,紀錄下去吧! 透過 VS 建立一個空方案(BusinessDays),接著新增一個 Lib 專案(BizDayCal),在新增一個 xUnit 專案(BizDayCalTests)。 BizDayCal namespace BizDayCal { using System; using System.Collections.Generic; public class Calculator { private List<IRule> rules = new List<IRule>(); public void AddRule(IRule rule) { this.rules.Add(rule); } public bool IsBusinessDay(DateTime date) { foreach (var rule in rules) if (!rule.CheckDate(date)) return false; return true; } } } namespace BizDayCal { using System; public Interface IRule { bool CheckDate...

[C#] API 設計規則

API 設計規則 先前看了一篇文章,在講述 API 的設計理念,方法與規則,分為三個階段。算是一篇不錯的文章,很實用的,於是就做了點筆記,把重要的內容記錄下來,提醒自己將來好遵守。 基礎 : 考慮用詞與語法一致 API 的命名拼寫要正確。 準確的用詞。(正反義詞不可混用。) 注意單複數。 不要誤用詞性。 (例如 : Success/Failure<名詞>,Succeed/Fail<動詞>,Successful/Failed<形容詞>) 處理縮寫。(Pascal 與 Camel 命名方式) 用對時態和語句。(盡量避免使用被動語句) 進階 : 多思考語義與可用性 單一職責原理。(SRP,一個類別或是方法,只專職做一件事就好) 避免副作用。(Expected 與 OCP,當類別擴充時,不會影響到原生的系統結構,要與預期的結果相符。) 合理的設計函數參數。(相關性越高的參數,越要將參數前置,或是將同類型的參數整合到所傳遞的物件中。) 合理的運用函數多載。(Overload。Hint : 當傳入的參數,無法進行有效區分時,建議不要選擇多載) 一致性的術語表 遵循一致性的 API 風格 Note : 一致性可以最大化程度的降低 訊息熵 一致性範例 -------------------------------------- pic | 圖片 | image, picture -------------------------------------- path | 路徑 | URL,url, uri -------------------------------------- on | 事件綁定| bind, addEventListener -------------------------------------- off | 解除綁定| unbind, removeEventListener ------------------------------------------- emit | 觸發事件| fire, trigger -------------------------------------- module| 模組 ...