\( \newcommand{\N}{\mathbb{N}} \newcommand{\R}{\mathbb{R}} \newcommand{\C}{\mathbb{C}} \newcommand{\Q}{\mathbb{Q}} \newcommand{\Z}{\mathbb{Z}} \newcommand{\P}{\mathcal P} \newcommand{\B}{\mathcal B} \newcommand{\F}{\mathbb{F}} \newcommand{\E}{\mathcal E} \newcommand{\brac}[1]{\left(#1\right)} \newcommand{\abs}[1]{\left|#1\right|} \newcommand{\matrixx}[1]{\begin{bmatrix}#1\end {bmatrix}} \newcommand{\vmatrixx}[1]{\begin{vmatrix} #1\end{vmatrix}} \newcommand{\lims}{\mathop{\overline{\lim}}} \newcommand{\limi}{\mathop{\underline{\lim}}} \newcommand{\limn}{\lim_{n\to\infty}} \newcommand{\limsn}{\lims_{n\to\infty}} \newcommand{\limin}{\limi_{n\to\infty}} \newcommand{\nul}{\mathop{\mathrm{Nul}}} \newcommand{\col}{\mathop{\mathrm{Col}}} \newcommand{\rank}{\mathop{\mathrm{Rank}}} \newcommand{\dis}{\displaystyle} \newcommand{\spann}{\mathop{\mathrm{span}}} \newcommand{\range}{\mathop{\mathrm{range}}} \newcommand{\inner}[1]{\langle #1 \rangle} \newcommand{\innerr}[1]{\left\langle #1 \right \rangle} \newcommand{\ol}[1]{\overline{#1}} \newcommand{\toto}{\rightrightarrows} \newcommand{\upto}{\nearrow} \newcommand{\downto}{\searrow} \newcommand{\qed}{\quad \blacksquare} \newcommand{\tr}{\mathop{\mathrm{tr}}} \newcommand{\bm}{\boldsymbol} \newcommand{\cupp}{\bigcup} \newcommand{\capp}{\bigcap} \newcommand{\sqcupp}{\bigsqcup} \newcommand{\re}{\mathop{\mathrm{Re}}} \newcommand{\im}{\mathop{\mathrm{Im}}} \newcommand{\comma}{\text{,}} \newcommand{\foot}{\text{。}} \)

Monday, August 26, 2019

從零開始建立 React 需要用到的 Config

結合上一篇 youtube 的 webpack + bable 教學,這篇


在假設我們理解 webpack 跟 bable 是甚麼的前提下直接教授怎様做 configuration 令我們可以開始運行 react。加上一些自己的小修改 (例如文章沒有提到,處理 async function 還要引入其他 package,解法有好幾個,其中一個是引入 polyfill 來完事),終於算是可以把 express.js 做到的東西都搬到 asp .net 做了。

這是我送到 server 的資料


在 WebApiConfig.cs 做一些手腳,camel case 變成 pascal case,然後用 debugger 看看


最後回傳到前端的結果:


算是差不多了解怎様建立運行 react 的環境。知識總算開始結合起來了 ...。雖然還沒搞懂用 asp.net 的好處。

Sunday, August 25, 2019

React and WebPack

We would not use
npm create-react-app
to initiate a react project any more because it is built by a bunch of CLI that we don't understand. Instead we can build a react object on our own by using webpack and babel (that transpiles ES6 Javascript into ES5, a version that is friendly to most browser).

The steps are essentially taken form a youtube tutorial:


but unforturnately a few amendment is required to make things work, so I go through what I have done below.

Before going any further, our directory will look like:

Tutorial on Using Session to do Authetication

Record:
https://www.youtube.com/watch?v=EyrKUSwi4uI

Screenshots of several codes that I want to record:



In connection string, the intial catalog is the same as the name of database.

Saturday, August 24, 2019

Interface, Delegate and Predicate

  • Inside a class, when we write
    public class PhotoFilter
    {
        public deletegate void PhotoFilterHandler(Photo phpto);
    }
    

Wednesday, August 21, 2019

Web Api Config | Json Pascel Case 與 Camel Case 的轉換

如果新建一個 api project,所有設定檔都會自動妥當地設定好,但想在現有 mvc project 加上一個 api controller 則有可能像我那様,奇怪地少了很多必要的 config。在這裏紀錄一下缺少檔案時必須要加回來的設定檔:

在 App_Start 必須要有 WebApiConfig.cs:

Standard CRUD in .NET

Just a record:

ASP.NET 中的 Form

可能有些 old-school,現在我們都 post json format 到 server,但 project 裏有遇見過 form data 處理速度比 json 快的事例 (我還懵懂的在奇怪為甚麼 project 裏的 post request 在 network 的 xhr section 裏甚麼也看不到,多按幾次才發現按 "all" 就找到了,原來變成了 form data 在傳輸 ...),本着熟習 .net 的心態來學一下 form。

首先我們為一個 form 的頁面 (一個 view) 定義以下 ViewModel:

Visual Studio 新 Tab 從右邊插入

Visual Studio 從左邊插入這種設定不太符合自己處理 tabs 的習慣,我們可以到 tools > options 修改:

Tuesday, August 20, 2019

GULP

https://www.youtube.com/watch?v=vyI-Ko6fvKU 

第一次接觸 gulp,項目都在用 webpack 壓縮才看得到結果,最後還是得研究 webpack,發現 --watch 這個 flag,再仔細查一下 gulp 如何啟用 watch 選項,最終{watch: true} 保全家 (不用只作小修改,整個 project 都得再壓縮一次)。 終於可以安心寫 jsx 了...

Saturday, August 17, 2019

For Code-First Approach in Entity Framework 6.0:

        1 Setup. Entity Framework is more or less an analogue of Knex.js that accesses the database with "sequel like" methods. In knex we have yarn knex migrate:make, yarn knex migrate:latest, etc, and they all have a counterpart in .net framework. If our application is chosen to be "NO AUTHETICATION", we need to add a class file written as:

Tuesday, August 13, 2019

Blog 復活

由以前研究數學,到突然想當美術,再到去大陸當美術之前,這個 blog 累積了不少內容。現在在香港當 developer,想嘗試把所學的東西整合放在這裏,也為了方便自己工作做個紀錄。例如怎様 init 一個 react project 都已經忘了 ...,如果以前有在這邊做紀錄的話就可以直接 copy and paste 了。也由於有在上 data science course 的關係,基於自己的數學背景沒有辦法不執着背後定理的證明(接受不了把定理當成理所當然),所以也會順便把有深入研究到的相關證明寫到這裏。

看到以前那些不堪入目的畫作 ...,練畫真的有血有淚啊。

為了熟習 C# 的 syntax 所以做了一些簡單的 Leetcode 題目,
以下測試 syntaxhighlighter,我的 code 是解答這題:
https://leetcode.com/problems/longest-substring-without-repeating-characters/
using System;
using System.Collections.Generic;

namespace Leetcode
{
    public class Solution
    {
        public int LengthOfLongestSubstring(string s)
        {
            if (s.Length < 2)
            {
                return s.Length;
            }
            else
            {
                var resultingLengths = new List<int>();
                for (int i = 0; i < s.Length - 1; i++)
                {
                    int count = 1;
                    string substring = Convert.ToString(s[i]);
                    for (int j = i + 1; j < s.Length; j++)
                    {
                        if (substring.IndexOf(s[j]) != -1)
                        {
                            break;
                        }
                        else
                        {
                            substring += s[j];
                            count++;
                        }
                    }
                    resultingLengths.Add(count);
                }
                return resultingLengths.Max();
            }
        }
    }
}