EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

有人問docker

1、用docker-machine建立開發環境 (VM),vm內的docker 環境是完整的,自己灌很浪費時間
http://sueboy.blogspot.com/search/label/docker-machine
然後 記得vm裡面跑 portainer.io 管理docker用,web介面
會省下你一大堆時間!
以上這個步驟是快速建立可以跑docker環境,然後又可以用圖形管理看log、砍image等等

2、docker 一般操作網路上都有,一定要看,就算有圖形化介面,有些時候你還是需要指令
記得一件事,要學docker-compose,然後基本上專案用docker,更正確來說,是要會用、會寫docker-compose
docker-compose 會比 單純用docker,好用很多
http://sueboy.blogspot.com/2018/12/ethereum-poa-docker-compose-docker.html

3、注意iptables,用docker後,常常會碰到iptables的問題,網路有問題,不能連,連不上,解答:把docker服務重開,就會重新設定iptables…這一堆人死在這上面
如果docker服務重開後,網路還是不行,我建議是用docker-machine重建一台vm比較快,再用docker-compose重新執行,比較快,省時間


4、通常用了docker的後端,十之八九就會想上K8s (kubernets)
到這階段就是超級大坑了!!!
非常大的坑! 會死人的坑! 到這階段千萬要避開,一定要避開!

坑指自架

node-gyp rebuild failed windows 10

npm install --global windows-build-tools

https://www.npmjs.com/package/windows-build-tools
https://stackoverflow.com/questions/32457761/how-to-solve-node-gyp-rebuild-issue-on-windows-10

truffle truffle-hdwallet-provider Error: Error: the tx doesn't have the correct nonce. account has nonce of: 3 tx has nonce of: 2


What this Error?


Example:

transaction A get nonce 1
transaction B get nonce 2
transaction C get nonce 3

But blockchain package B、C first, then package A. If happen this step, get error.


With truffle?


Because

Normal

const wallet = new HDWalletProvider(mnemonic, url, id);
const AContract = new TruffleContract(Json_contract);
AContract.setProvider(wallet);

wallet.addresses[]
AContract. use contract api



Sometime you call contract "set/write" api two times.

Example:

Create contract first. Write data into contract second. This two step are in one function. This mean is you call two time "new HDWalletProvide". Usually you think “New“ two time is ok, get "new" instance. But

https://github.com/trufflesuite/truffle-hdwallet-provider/blob/master/index.js


function HDWalletProvider(
  mnemonic,
  provider,
  address_index=0,
  num_addresses=1,
  shareNonce=true,
  wallet_hdpath="m/44'/60'/0'/0/"
) {


shareNonce default is true. new HDWalletProvide use same Nonce.

Answer is shareNonce => false, when you set/update data into to contract use api.





[???]nestjs Cross modules dependency injection

import module
providers service

So if you want use some controllers(this controllers is in some module), this time need to import module. ????

===========
https://github.com/zelazna/NestAPI/tree/master/src

Impotant:

constructor don't use new(). Use this.usersService.

src/auth/auth.service.ts

import { Component } from '@nestjs/common';
import { UsersService } from '../users';

@Component()   ?? Injectable
export class AuthService {
  constructor(
    private readonly usersService: UsersService,
  ) { }

  async validateUser(signedUser): Promise {
    const { email, password } = signedUser;
    const user = await this.usersService.findOneByEmail(email);
    return await EncryptorService.validate(password, user.password);
  }


Impotant:

exports need UsersService

src/users/users.module.ts

import { UsersService } from './users.service';

@Module({
    controllers: [UsersController],
    components: [UsersService],
    imports: [TypeOrmModule.forFeature([User])],
    exports: [UsersService],
})

[轉]Nestjs framework 30天初探:Day30 總結Nest.js

https://ithelp.ithome.com.tw/articles/10195523

Controller,透過Nest.js把metadata映射到我們自定義的route,Nest.js本身也有提供很多裝飾器,而且是對應Express框架,讓我們可以更好上手,更容易了解Controller層,可以寫出很Express風格的Controller。

Component,Nest.js裏頭很多東西都是Component,如:Service,Repository,Factory,Helper...,再透過依賴注入的方式,將Component注入到其他地方使用。

Module,Module是Nest.js專案的根基,Nest.js可以寫出Module tree風格的專案,Component可以注入到Module,如此,該Module底下的Controller和Component就屬同作用域,然後就可以依賴注入使用該Component。

Middleware,用Express框架的朋友應該不陌生,這概念雷同,在程式處理請求前,我們可以做些事情,這就是Middleware的功用,但要記得要調用next(),不然程式會卡在那XD,導入Middleware的方式上跟Express略有不同,多注意一下就好。

Exception Filter,錯誤處理層其實還蠻常使用,統一格式回給Client端或進行錯誤Log處理,這都蠻重要。我們可以繼承HttpException,做一個客製化的HttpException回應給Client,也可以繼承ExceptionFilter,做更多的錯誤處理(如Log)。

Pipe,Pipe可以將input data轉換成我們想要的output data,它也可以扛下參數資料驗證工作,在參數資料不正確時拋HttpException出來,這個錯誤會被ExceptionsHandler或自定義的Exception Filter所捕捉。

Guard,Guard就是擔任路由警衛,決定程式在收到HTTP請求後,是否要執行 route handler。

注意:客戶發動請求的流程為 Request->Middleware->Guard->Pipe->route handler。


Interceptor,我們可以透過Interceptor做些事情,像在請求前,完整記錄post過來的data,或在給予Client回應前,攔截一下,做些處理再返回,另外Interceptor 拋出的錯誤仍然可以被Exception Filter捕捉處理。

[轉]2018 年了,你还是只会 npm install 吗?

https://juejin.im/post/5ab3f77df265da2392364341


本地模块引用 這段不錯

nest.js 是 nodejs 服务运行时,要等待数据库服务启动完毕,也就是有一个启动等待的需求

https://juejin.im/entry/59a6325d6fb9a024932228e0


version: "2"
services:
  app:
    build: ./
    restart: always
    ports:
      - "5000:8000"
    links:
      - db
      - redis
    depends_on:
      - db
      - redis
    environment:
      WAIT_HOSTS: db:3306 redis:6379

CMD ./scripts/docker/wait-for.sh && npm run deploy


#!/bin/bash

set -e

timeout=${WAIT_HOSTS_TIMEOUT:-30}
waitAfterHosts=${WAIT_AFTER_HOSTS:-0}
waitBeforeHosts=${WAIT_BEFORE_HOSTS:-0}

echo "Waiting for ${waitBeforeHosts} seconds."
sleep $waitBeforeHosts

# our target format is a comma separated list where each item is "host:ip"
if [ -n "$WAIT_HOSTS" ]; then
  uris=$(echo $WAIT_HOSTS | sed -e 's/,/ /g' -e 's/\s+/\n/g' | uniq)
fi

# wait for each target
if [ -z "$uris" ];
  then echo "No wait targets found." >&2;

  else

  for uri in $uris
  do
    host=$(echo $uri | cut -d: -f1)
    port=$(echo $uri | cut -d: -f2)
    [ -n "${host}" ]
    [ -n "${port}" ]
    echo "Waiting for ${uri}."
    seconds=0
    while [ "$seconds" -lt "$timeout" ] && ! nc -z -w1 $host $port
    do
      echo -n .
      seconds=$((seconds+1))
      sleep 1
    done

    if [ "$seconds" -lt "$timeout" ]; then
      echo "${uri} is up!"
    else
      echo "  ERROR: unable to connect to ${uri}" >&2
      exit 1
    fi
  done
echo "All hosts are up"
fi

echo "Waiting for ${waitAfterHosts} seconds."
sleep $waitAfterHosts

exit 0

nestjs vs code推荐插件

https://github.com/jiayisheji/blog/issues/18

vs code推荐插件:(其他插件自己随意)
Debugger for Chrome -- 调试
ejs -- ejs文件高亮
Beautify -- 代码格式化
DotENV -- .env文件高亮
Jest -- nest默认测试框架支持
TSLint -- ts语法检查
TypeScript Hero -- ts提示
vscode-icons -- icons

nest.js TypeORM Database

https://medium.com/@shaibenshimol/nestjs-and-mysql-in-10-minutes-711e02ec1dab

ormconfig.json



{
  "type": "mysql",
  "host": "localhost",
  "port": 3306,
  "username": "root",
  "password": "root",
  "database": "my_nestjs_project",
  "entities": ["src/**/**.entity{.ts,.js}"],
  "synchronize": true,
  "extra": { connectionLimit: 10, ... }
}

Very Important !!


app.module


import { Module } from '@nestjs/common';
import { UsersModule } from './users/users.module';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot(),
    UsersModule
  ],
})
export class AppModule {}


=====nest command can use or not=====

nest g module users
nest g service users
nest g controller users
nest g class users/user.entity

Use TypeORM Active Record
https://github.com/typeorm/typeorm/blob/master/docs/active-record-data-mapper.md

user.entity.ts



import {BaseEntity, Entity, PrimaryGeneratedColumn, Column} from "typeorm";

@Entity()
export class User extends BaseEntity {
       
    @PrimaryGeneratedColumn()
    id: number;
    
    @Column()
    firstName: string;
    
    @Column()
    lastName: string;
    
    @Column()
    isActive: boolean;

    static findByName(firstName: string, lastName: string) {
        return this.createQueryBuilder("user")
            .where("user.firstName = :firstName", { firstName })
            .andWhere("user.lastName = :lastName", { lastName })
            .getMany();
    }
}


How to use


import { User } from './user.entity';

const timber = await User.findByName("Timber", "Saw");

===== Use Other way ====

Users module



app.module.ts


import { Module } from '@nestjs/common';
import { UsersModule } from './users/users.module';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot(),
    UsersModule
  ],
})
export class AppModule {}


users.module.ts


import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import { User } from './user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([User])],
  providers: [UsersService],
  controllers: [UsersController],
})

export class UsersModule { }


users.controller.ts


import { Controller, Post, Body, Get, Put, Delete,Param} from '@nestjs/common';
import { UsersService } from './users.service';
import { User } from './user.entity';

@Controller('users')
export class UsersController {

    constructor(private service: UsersService) { }

    @Get(':id')
    get(@Param() params) {
        return this.service.getUser(params.id);
        //return timber = await User.findByName("Timber", "Saw");
    }

    @Post()
    create(@Body() user: User) {
        return this.service.createUser(user);
    }

    @Put()
    update(@Body() user: User) {
        return this.service.updateUser(user);
    }

    @Delete(':id')
    deleteUser(@Param() params) {
        return this.service.deleteUser(params.id);
    }
}


users.service.ts This file maybe don't need because use Active Record.


import { Injectable, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { User } from './user-entity';

@Injectable()
export class UsersService {

    constructor(@InjectRepository(User) private usersRepository: Repository) { }

    async getUsers(user: User): Promise {
        return await this.usersRepository.find();
    }

    async getUser(_id: number): Promise {
        return await this.usersRepository.find({
            select: ["fullName", "birthday", "isActive"],
            where: [{ "id": _id }]
        });
    }

    async updateUser(user: User) {
        this.usersRepository.save(user)
    }

    async deleteUser(user: User) {
        this.usersRepository.delete(user);
    }
}


https://blog.entrostat.com/setting-up-a-database-module-in-nest-js/

k8s kubernetes Lesson 7 ingress-nginx kubernetes

https://sueboy.blogspot.com/2019/01/ingress-nginx-kubernetes-ingress-with.html

Real site is


https://kubernetes.github.io/ingress-nginx/deploy/


kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml


Verify installation

https://kubernetes.github.io/ingress-nginx/deploy/#verify-installation


kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx --watch


Detect installed version

https://kubernetes.github.io/ingress-nginx/deploy/#detect-installed-version


shell script

POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version


=========

Other nginx-ingress

https://kubernetes.github.io/ingress-nginx/deploy/#using-helm

[轉]How To Create a Kubernetes Cluster Using Kubeadm on Debian 9

https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-debian-9

geth add peers static-nodes.json

https://medium.com/taipei-ethereum-meetup/%E4%BB%A5%E5%A4%AA%E5%9D%8A%E7%A7%81%E7%B6%B2%E5%BB%BA%E7%AB%8B-%E4%B8%80-43f8677fc9f8

如果要組成一個私人網路,同樣按照上面的流程建立其他節點。如果沒有下--nodiscover參數的話,最後節點應該會找到彼此。如果有下的話就必須用手動的方式加入其他節點,加入的方式有三種:

一是在geth指令加入--bootnodes參數;

二是進到console裡使用 admin.addPeer();

三是存成static-nodes.json檔,讓geth自動連線。

不管是使用哪一種,我們都要先知道要連到


static-nodes.json 裡面使用domain,可能會有問題,要自行更換ip


Example:

geth --data ~/data

cp static-nodes.json ~/data/geth/static-nodes.json


static-nodes.json  like this

[
   "enode://53999cc519079c5190798b1114bd16a05a8d5190796cc51907988a4e80ebda7b6c519079e56b0b161da3475c4dc62f6b51907967a6e327e46aa56329c519079f@192.168.0.10:30303"
]

[轉]The Ultimate Guide to Secure, Harden and Improve Performance of Nginx Web Server

https://www.tecmint.com/nginx-web-server-security-hardening-and-performance-tips/?fbclid=IwAR3WRK-N-buun8QIMDUbzes72-w6p8SKCxnzr0sGU_PFAyudPRbHiumtFu0

linux aws s3 exploer crossftp

supertest jest

Jest Expect Methods https://jestjs.io/docs/en/expect

it = test


        it('count > 30', async () => {
            await reqTarget.get("/members").expect(200)
            .then((res) => {
                //Can use foreach, more easy
                for(key in res.body){
                    //console.log(res.body[key].cou );
                    if (res.body[key].cou  > 100) throw new Error("count: "+res.body[key].cou +" > 30");  //for vars value check message
                    expect(res.body[key].cou ).toBeLessThan(30);
                }
            });
        });

geth 新版 豪秒產生無法匯入

geth新版的geth.log 會產生豪秒

舊 INFO [04-22|16:29:56]
新 INFO [03-28|13:43:35.004]

差別在.004

看log會發現只有logstash的warning,經同事正確解釋是:

>>因為logstash轉換出來的日期格式2019-03-28 13:43:35.004,Elasticsearch不認得,所以對logstash來說是Warning,但對Elasticsearch是Error,造成Log寫不進去~


所以在logstash.conf上必須在解析date上,補上 "YYYY-MM-dd HH:mm:ss,SSS", "YYYY-MM-dd HH:mm:ss.SSS"


  date {
    match => [ "gethdate" , "YYYY-MM-dd HH:mm:ss", "YYYY-MM-dd HH:mm:ss,SSS", "YYYY-MM-dd HH:mm:ss.SSS"]
    target => "gethdate"
    timezone => "Asia/Taipei"
  }

這樣就可以正常匯入geth.log了

Pinta windows linux mac

幸好Paint.NET是開放原始碼的軟體,於是有位任職於Novell公司,叫做Jonathan Pobst的開發者,利用了Paint.NET的原始碼,改用Gtk#函式庫開發了一款美工軟體,取名叫「Pinta」。

https://pinta-project.com/pintaproject/pinta/

nodejs version npm problem install & run

You can do:

1. reget git clone
2. npm install
3. remove node_module
4. npm install agin
5. npm audit fix
6. npm start or run


Sometime can Run.