EExcel 丞燕快速查詢2

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

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.

ElastAlert elasticsearch elk


docker-compose


version: '3.3'

services:
  elasticsearch:
    build:
      context: elasticsearch/
    volumes:
      #- ./elasticsearch/esdata:/usr/share/elasticsearch/data:rw
      - alldata:/usr/share/elasticsearch/data:rw
      #- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    networks:
      - fastdev

  logstash:
    build:
      context: logstash/
    volumes:
      - ./logstash/config/logstash.yml:/etc/logstash/logstash.yml:ro
      - ./logstash/pipeline:/etc/logstash/conf.d:ro
    ports:
      - "5000:5000"
      - "5044:5044"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      - fastdev
    depends_on:
      - elasticsearch

  kibana:
    build:
      context: kibana/
    volumes:
      - ./kibana/config/:/usr/share/kibana/config:ro
    ports:
      - "5601:5601"
    networks:
      - fastdev
    depends_on:
      - elasticsearch

  fakelog:
    build:
      context: fakelog/
    volumes:
      - ./fakelog/logs:/ethereum-etl/output/:rw
    networks:
      - fastdev

  elastalert:
    build:
      context: elastalert/
    volumes:
      - ./elastalert/config/config.json:/opt/elastalert-server/config/config.json:ro
      - ./elastalert/config/elastalert.yaml:/opt/elastalert/config.yaml:ro
      - ./elastalert/rules:/opt/elastalert/rules:rw
      - ./elastalert/rule_templates:/opt/elastalert/rule_templates:ro
    ports:
      - "3030:3030"
    #  - "3333:3333"
    environment:
      - net=elasticsearch
    networks:
      - fastdev

volumes:  
  alldata: 

networks:
  fastdev:
    driver: bridge

Only elasticsearch/Dockerfile some error happen because debian mirror. Other YAML see before blogs


FROM java:8-jre

# grab gosu for easy step-down from root
ENV GOSU_VERSION 1.7
RUN set -x \
 && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)" \
 && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc" \
 && export GNUPGHOME="$(mktemp -d)" \
 && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 \
 && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu \
 && rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc \
 && chmod +x /usr/local/bin/gosu \
 && gosu nobody true

# https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-repositories.html
# https://packages.elasticsearch.org/GPG-KEY-elasticsearch
#RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 46095ACC8548582C1A2699A9D27D666CD88E42B4

#ENV ELASTICSEARCH_MAJOR 1.7
#ENV ELASTICSEARCH_VERSION 1.7.5
#ENV ELASTICSEARCH_REPO_BASE http://packages.elasticsearch.org/elasticsearch/1.7/debian

#RUN echo "deb $ELASTICSEARCH_REPO_BASE stable main" > /etc/apt/sources.list.d/elasticsearch.list

#RUN set -x \
# && apt-get clean && apt-get update \
# && apt-get install -y --no-install-recommends elasticsearch=$ELASTICSEARCH_VERSION \
# && rm -rf /var/lib/apt/lists/*

RUN wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN echo "deb http://packages.elastic.co/elasticsearch/1.7/debian stable main" | tee -a /etc/apt/sources.list.d/elasticsearch-1.7.list
RUN echo "deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie.list
RUN echo "deb [check-valid-until=no] http://cdn-fastly.deb.debian.org/debian jessie main" > /etc/apt/sources.list.d/jessie.list
RUN echo "deb [check-valid-until=no] http://archive.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list
RUN sed -i '/deb http:\/\/deb.debian.org\/debian jessie-updates main/d' /etc/apt/sources.list
RUN apt-get -o Acquire::Check-Valid-Until=false update && apt-get install elasticsearch

ENV PATH /usr/share/elasticsearch/bin:$PATH

WORKDIR /usr/share/elasticsearch

RUN set -ex \
 && for path in \
  ./data \
  ./logs \
  ./config \
  ./config/scripts \
 ; do \
  mkdir -p "$path"; \
  chown -R elasticsearch:elasticsearch "$path"; \
 done

COPY config ./config

#VOLUME /usr/share/elasticsearch/data

COPY docker-entrypoint.sh /
RUN chmod +x /docker-entrypoint.sh

EXPOSE 9200 9300
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]


ElastAlert/Dockerfile


FROM bitsensor/elastalert:latest

ElastAlert/config/config.json


{
  "appName": "elastalert-server",
  "port": 3030,
  "wsport": 3333,
  "elastalertPath": "/opt/elastalert",
  "verbose": false,
  "es_debug": false,
  "debug": false,
  "rulesPath": {
    "relative": true,
    "path": "/rules"
  },
  "templatesPath": {
    "relative": true,
    "path": "/rule_templates"
  },
  "es_host": "elasticsearch",
  "es_port": 9200,
  "writeback_index": "elastalert_status"
}

ElastAlert/config/elastalert.yaml


es_host: elasticsearch
es_port: 9200
rules_folder: rules

# How often ElastAlert will query elasticsearch                
# The unit can be anything from weeks to seconds
run_every:
  seconds: 5
  #minutes: 1
# ElastAlert will buffer results from the most recent                                                      
# period of time, in case some log sources are not in real time
buffer_time:
  minutes: 15
# If an alert fails for some reason, ElastAlert will retry                                                 
# sending the alert until this time period has elapsed 
alert_time_limit:
  minutes: 2
  #days: 2
  
writeback_index: elastalert_status

#smtp_host: ""

ElastAlert/config/rules/test_metric.yaml


name: Example rule

# How often ElastAlert will query elasticsearch                
# The unit can be anything from weeks to seconds
run_every:
  seconds: 5
  #minutes: 1
# ElastAlert will buffer results from the most recent                                                      
# period of time, in case some log sources are not in real time
buffer_time:
  minutes: 15
# If an alert fails for some reason, ElastAlert will retry                                                 
# sending the alert until this time period has elapsed 
alert_time_limit:
  minutes: 2
  #days: 2
    
type: metric_aggregation

index: filebeat-*

metric_agg_key: project
metric_agg_type: value_count

#query_key: "name.keyword"
doc_type: _type

max_threshold: 32
min_threshold: 19

filter:
- query:
    query_string:
      query: "srctype: geth AND project: hr AND mined AND geth_ip: \"xxx.xxx.xxx.xxx\""

#alert_subject: "No data on dashboard"
# "|" means remove useless characters
alert_text: |
    test attach
alert_text_args: []

alert:
- "email"
email:
- "1803110@narlabes.org.tw"


ElastAlert/config/rule_templates

copy file from github or not copy.
https://github.com/Yelp/elastalert/tree/master/example_rules


run ElastAlert or ElastAlert test




cd /opt/elastalert

a. elastalert

b. elastalert-test-rule ./rules/test_metric.yaml --start 2019-04-10T08:40:00.000

#At /opt/elastalert run command, it auto load config.yaml on this path. You can find "ls config.yaml".

And rules (test_metric.yaml) put on path /opt/elastalert/rules

elastalert.yml and config.json put on path /opt/elastalert-server/config

Docker-compose build Alpine image apk update fetch hangs

Alpine image apk update fetch hangs


At apk --no-cache upgrade or RUN apk update no respone

Try to login docker container run command line:


wget http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz

Get status is "stalled".

PS:Error is different "no respone" or "hang"


Way one:

Answer:

apk fetch hangs
https://github.com/gliderlabs/docker-alpine/issues/307

10G mtu or switch mtu

So

Into directory


docker build --network host .


Way two:

Answer:

https://mlohr.com/docker-mtu/
https://medium.com/@sylwit/how-we-spent-a-full-day-figuring-out-a-mtu-issue-with-docker-4d81fdfe2caf





nano /etc/docker/daemon.json

{
  "mtu": 1450
}

[轉]HyperLedger Fabric 架构设计中的模式创新

https://www.chongdongshequ.com/article/1544005544333.html

flutter new hard

https://book.flutterchina.club/

flutter dart Streams Future

https://www.appcoda.com.tw/flutter-introduction/

Dart 內建支援 Streams 及 Future。我的 RxJava 經驗有助我了解 Streams,而在 ES6 Promise 方面的經驗則有助我理解 Futures 和 Async/Await 的概念

flutter printing

https://github.com/DavBfr/dart_pdf/tree/master/printing/example/lib

Problem is here.


image: const fw.NetworkImage('https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&s=200'),


Change to


import 'package:flutter/painting.dart' as fp;

find this and change

image: new fp.AssetImage("images/a123.png"),



OK~

flutter Error PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

Flutter and google_sign_in plugin: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

https://stackoverflow.com/questions/54557479/flutter-and-google-sign-in-plugin-platformexceptionsign-in-failed-com-google

1、add google-service


A:add classpath 'com.google.gms:google-services:4.2.0'


%app%/android/build.gradle



buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }
}

B:add apply plugin: 'com.google.gms.google-services'


%app%/android/app/build.gradle



apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'



2、 get google-service.json

https://firebase.google.com/docs/flutter/setup
https://developers.google.com/android/guides/client-auth

create app


A:create test project

go https://console.firebase.google.com/


B:create application





Where get app name


Open %app%/android/app/build.gradle find applicationId


    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_sqlite"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

Here is com.example.flutter_sqlite

put com.example.flutter_sqlite in app name, then next.



Download google-service.json



next next...




Copy google.service.json to %app%/android/app/


C:test app in local emu need to fingerprint.

find java jdk\bin\keytool
password use: android

C:\Program Files\Java\jdk1.8.0_201\bin>keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore


copy sha1 to here





Run your flutter app. Now is ok.