# Leetcode 260 Single Number & bitwise operation

Leetcode 260 題 Single Number III 又是一道只能使用 bitwise operation 才能達到要求的題目，除了需要使用基本的 AND, XOR 之外，還引入了 lowbit function 的概念。

# Leetcode 260 — description

Given an integer array `nums`, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.

Follow up: Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity?

`let result = []for (let i = 0; i < nums.length; i++){  let index = Math.abs(nums[i]) - 1  if (nums[index] < 0) {    result.push(index …`

# How Array.prototype.sort() works in V8?

`let arr = [1, 3, 2]arr.sort((a, b) => {  console.log(`Now comparing a = \${a} & b = \${b}`);  return a - b;});`

`Now comparing a = 3 & b = 1Now comparing a = 2 & b = 3Now comparing a = 2 & b = 3Now comparing a = 2 & b = 1`

# 先講結論

Timsort 的概念是，將一大筆資料拆成小批次的資料，在小批次的資料當中使用 Binary Inserttion Sort，之後再將已經排序好的小批次資料，用 Merge Sort 把所有小批次資料整合在一起。

# 前情提要

Passport.js 是在開發 Node.js 應用程式時，常用到的驗證系統。想了解更多，可以參考以下文章

# 先講結論

## 2. 開啟 failureFlash 設定

`// flash type 自動設定為 error“I’m error message”      // flash type 自動設定為 error。注意這裡的 key 必須為 message{message: "I’m error message”}          // 手動設定flash type 為 hi。注意後面訊息的 key 必須為 message{type: 'hi', message: “I’m error message”}   `

`app.post('/signin', passport.authenticate(  'local',   { ... …`

# Get pure object from Sequelize instance

[quick note]

Handlebars 升級到 4.6 之後，會限制傳入的資料規格，不允許帶有 prototype properties 的物件。

From version 4.6.0 on, Handlebars forbids accessing prototype properties and methods of the context object by default. The reason are various security issues that arise from this possibility. The following options can be used to control this access.

## 在 query option 當中設定 raw: true

`let users = await User.findAll({ raw: true, nest: true })`

## 取出 dataValue

`let user = await User.findOne({ where: { id: req.user.id } })user = user.dataValue`

## 用 .get() 方法

`let user = await User.findOne({ where: { id: req.user.id } })user = user.get()`

# What is a “variable” and “declaring a variable”?

• 要處理什麼資料
• 怎麼處理資料

• 要處理什麼資料：財務報表
• 怎麼處理資料：從檔案庫當中拿出給老闆

• 要處理什麼資料：薪水
• 怎麼處理資料：印出來

`console.log(salary)            // 印出 salary`

`let salary = 20000             // 宣告 salary`

`let salary = 20000    console.log(salary)            // 看到輸出結果為 20000`

`console.log(20000)`

`let salary = 20000  let mySalary = 30000  let tdSalary = 40000`

Self-taught and trained in software development knowledge and skills, I am passionate about creating changes through technology.

Find more at `Github`, `LinkedIn`, `Teaching at ALPHA Camp`

# AWS Elastic Beanstalk

Elastic Beanstalk 是 AWS 提供的一項服務，能讓開發團隊快速部署及管理應用程式。Elastic Beanstalk 是在 EC2 (Elastic Compute Cloud) 之上所建立的一層 layer，因此透過 Elastic Beanstalk 部署，不僅僅只是幫我們開啟 server，過程中更可以透過設定，開啟 S3, Simple Notification Service, CloudWatch, auto-scaling, load balancing 等服務，可以說是個方便的一站式服務。

# Namecheap

Namecheap 是一家域名註冊與 hosting 的服務商。其實購買網域相當方便，就像是逛線上商店一樣，選好自己要的網域名，然後再次確認自己可以付得起，就可以結帳囉！

# 輸出什麼？

`const flash = require('connect-flash')`

`exports = module.exports = require('./flash');`

`var format = require('util').format;var isArray = require('util').isArray;`

`module.exports = function flash(options) {    options = options || {};    var safe = (options.unsafe === undefined) ? true : !options.unsafe; …`

`The default interactive shell is now zsh.To update your account to use zsh, please run `chsh -s /bin/zsh`.For more details, please visit https://support.apple.com/kb/HT208050.`

## 重新安裝 bash

`brew install bash`

`echo '/usr/local/bin/bash' | sudo tee -a /etc/shells`

`chsh -s…`

# An update of Express & body-parser

express.json([options])
[This middleware is available in Express v4.16.0 onwards.]
This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.

express.urlencoded([options])
[This middleware is available in Express v4.16.0 onwards.]
This is a built-in middleware function in Express. It parses incoming requests with urlencoded payloads and is based on body-parser.

`const express = require('express')const app = express()const bodyParser = require('body-parser')...app.use(bodyParser.json())app.use(bodyParser.urlencoded({ extended: true }))`

`const express = require('express')const app = express()...app.use(express.json())app.use(express.urlencoded({ extended: true }))`

Reference:

# Node.js & MongoDB with Docker (補充)

`FROM node:latestWORKDIR ‘/app’COPY ./package.json ./appRUN npm installCOPY . .EXPOSE 3000CMD [ “npm”, “start” ]`

`FROM node:latestWORKDIR ‘/app’COPY ./package*.json ./appRUN npm installCOPY . .EXPOSE 3000CMD [ “npm”, “start” ]`