發表文章

目前顯示的是 7月, 2018的文章

[JWT] Bearer Token in Asp.Net Core

[JWT] Bearer Token in Asp.Net Core JWT (Json Web Token),主要是為了保護網路安全傳輸的資訊,透過 JWT 可以產生一把權杖,透過這把權杖,來驗證使用者的資訊,細節可以參考附錄4。 JWT Token (權杖) 權杖主要由三個部分所組成(Header, Payload,以及Signature)。 {{"alg":"HS256","typ":"JWT"}.{"nameid":"ROBERT.CHEN@RFF.COM","http://schemas.microsoft.com/ws/2008/06/identity/claims/role":"Admin","exp":1532966362,"iss":"Robert Chen","aud":"Robert For Fun"}} "token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJST0JFUlQuQ0hFTkBSRkYuQ09NIiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiQWRtaW4iLCJleHAiOjE1MzI5NjYzNjIsImlzcyI6IlJvYmVydCBDaGVuIiwiYXVkIjoiUm9iZXJ0IEZvciBGdW4ifQ.5wl6YqmVI9IHSDSgFw_i1bW5OpZuiKGJ9s38V0HiGog" Header 表頭 表頭主要定義演算法,與權杖的類別。 {"alg":"HS256","typ":"JWT"} 上面的內容是指 HMACSHA256 演算法,權證的類別為"JWT" Payload ...

[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 ...