Boris Chien

@monkeymonkey

Joined on Jan 4, 2022

  • dispatch:將任務送進隊列 dispatchNow:不進隊列,立即執行,意外時直接拋出Exception dispatchSync:不進隊列,立即執行,新增failed處理異常,預設直接拋出Exception ref Synchronous Dispatching dispatchNow 與dispatchSync
     Like  Bookmark
  • Abstract Class:特殊的類,不能被實例化,只能被繼承,可提供屬性、預設實作 Interface:不是類,沒有實作,只提供名稱 總結 多版本元件,可以建立抽象類別,更新基類,所有繼承類都會隨著變更自動更新。另一方面,介面一旦創建就無法更改。如果需要新版本的接口,您必須建立一個全新的接口。 功能對不同的物件都很有用,使用介面。抽象類用於密切相關的對象,而介面最適合為不相關的類別提供通用功能。 小而簡潔,使用介面。大型功能單元,抽象類。
     Like  Bookmark
  • 龜速筆電 最近在玩 docker,想將Express API build 成 image,部屬到雲端 超級簡單的Dockerfile FROM node:lts-alpine ENV NODE_ENV development WORKDIR /express-docker
     Like  Bookmark
  • useContext is a React Hook that lets you read and subscribe to context from your component. 深層子組件取用母組件更新後的值 官方範例 import { createContext, useContext } from 'react'; const ThemeContext = createContext(null); export default function MyApp() {
     Like  Bookmark
  • MongoDB 中,只有在獲取內容後才會真正建立集合! 建立資料庫 use <name> 建立集合 db.createCollection(<name>) 查看集合 show collections 插入 db.posts.insertOne({
     Like  Bookmark
  • 2024/03/12發佈,要求PHP v8.2,新功能包含 Laravel Reverb與目錄結構更新 Laravel Reverb 新的第一方websocket套件,提供更快響應、整合監視、易於拓展、可以跟pusher結合 目錄結構更新 移除 middleware,改成 app service provider 註冊 移除 kernal 從 Http 資料夾,移到 bootstrap 中 移除 config 資料夾 更新 Migration 時間戳
     Like  Bookmark
  • windows對docker的支援不友善,需要多個安裝步驟,開啟Hyper-V、安裝WSL等 開啟Hyper-V 進BIOS開啟Hyper-V,windows設定也要勾選 如果是家用版需要手動另外安裝,否則看不到勾選按鈕 撰寫並執行以下 pushd "%~dp0"
     Like  Bookmark
  • 限制登入人數為1,根據 Single Session Login in Laravel 大致有以下方法 1.檢查 session_id 是否改變 2.裝置或其他獨特 id,登入時刪除同使用者其他 session 3.內建 我用3,最簡單直觀
     Like  Bookmark
  • 有時候需要客製login,例如登入分流,找到 LoginController,加入以下模板 public function login(Request $request) { $request->validate([ 'email' => 'required', 'password' => 'required', ]); $credentials = $request->only('email', 'password');
     Like  Bookmark
  • 移動裝置較難使用開發者工具,可以插入除錯腳本,不建議在正式環境中使用 c-kick/mobileConsole
     Like  Bookmark
  • 權限控制模型 ACL、DAC、MAC、RBAC、ABAC ACL 存取控制列表 資源可以被哪些主體進行哪些操作 DAC 自主存取控制 規定資源可以被哪些主體進行哪些操作同時,主體可以將資源、操作的權限,授予其他主體 MAC 強制存取控制 a. 規定資源可以被哪些類別的主體進行哪些操作 b. 規定主體可以對哪些等級的資源進行哪些操作當一個操作,同時滿足a與b時,允許操作
     Like  Bookmark
  • $("iframe").on("load", function() { const newStyleElement = $("<style>.foo{display: none;}</style>"); $(this).contents().find("head").append(newStyleElement); });
     Like  Bookmark
  • 網路攝影機webcam屬相機的一種,一般具有視訊攝影/傳播和靜態圖像捕捉等基本功能,它是藉由鏡頭採集圖像後,由網路攝影機內的感光元件電路及控制元件對圖像進行處理並轉換成電腦所能識別的數位訊號,然後藉由並列埠、通用序列匯流排連接,輸入到電腦後由軟體再進行圖像還原。有些則支援乙太網路或WiFi,內建有處理器及網頁伺服器,接上網路後可連線檢視畫面 閉路電視CCTV,來自英語:Closed-Circuit Television的簡稱)是指在特定的區域進行視訊傳輸並只在固定迴路裝置裡播放的電視系統。例如錄影機、大樓內的監視器等。這類播放模式就被稱作閉路電視。 比較 網路攝影機 閉路電視 傳輸 網路傳輸 類比信號
     Like  Bookmark
  • 給定起點跟終點,是否能在時間內從起點到終點,移動方式是周圍8格,一秒一步 class Solution: def isReachableAtTime(self, sx: int, sy: int, fx: int, fy: int, t: int) -> bool: width = abs(sx - fx) height = abs(sy - fy) if width == 0 and height == 0 and t == 1: return False return t >= max(width, height)
     Like  Bookmark
  • You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists. A substring is a contiguous sequence of characters within a string. var largestOddNumber = function (num) { for (let i = num.length - 1; i >= 0; i--) { if (Number(num[i]) % 2 === 1) { return num.slice(0,i+1) } }
     Like  Bookmark
  • You are given a 0-indexed integer array nums whose length is a power of 2. Apply the following algorithm on nums: Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer array newNums of length n / 2. For every even index i where 0 <= i < n / 2, assign the value of newNums[i] as min(nums[2 * i], nums[2 * i + 1]). For every odd index i where 0 <= i < n / 2, assign the value of newNums[i] as max(nums[2 * i], nums[2 * i + 1]). Replace the array nums with newNums. Repeat the entire process starting from step 1. Return the last number that remains in nums after applying the algorithm.
     Like  Bookmark
  • Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things: Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums. Return k. Input: nums = [3,2,2,3], val = 3 Output: 2, nums = [2,2,_,_] 題幹給定輸入一個陣列與目標數字,希望能夠回傳不等於目標數字的元素總數,同時要求以In-place處理陣列。
     Like  Bookmark
  • You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where: 0 <= j <= nums[i] and i + j < n Return the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1]. var jump = function(nums) { let left=0; let right=0; let steps=0;
     Like  Bookmark
  • Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums. Consider the number of unique elements of nums to be k, to get accepted, you need to do the following things: Change the array nums such that the first k elements of nums contain the unique elements in the order they were present in nums initially. The remaining elements of nums are not important as well as the size of nums. Return k Input: nums = [0,0,1,1,1,2,2,3,3,4] Output: 5, nums = [0,1,2,3,4,_,_,_,_,_] var removeDuplicates = function(nums) { let slow=0; for(let fast=0;fast<nums.length;fast++){
     Like  Bookmark
  • Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Hashmap var majorityElement = function(nums) { let map={}; let maxChar=nums[0]; for(let i=0;i<nums.length;++i){ const char=nums[i]; if(!map[char] || map[char]===0){
     Like  Bookmark