Wednesday, September 14, 2022

The complete book on angular 11 - Chapter 2 TypeScript

 Chapter 2 TypeScript

1. 

npm install -g typescript

npm install -g tsun (TypeScript Upgraded Node)

tsun

> var fullName: string = 'Nate Murray'

> console.log(fullName)

var jobs: Array<string> = ['IBM', 'Microsoft', 'Google']; equals with the below

var jobs: string[] = ['Apple', 'Dell', 'HP'];

enum Role {Employee, Manager, Admin};

var role: Role = Role.Employee;

console.log('Roles: ', Role[0], ',', Role[1], 'and', Role[2]);

any is the default type if we omit typing for a given variable. Having a variable of

type any allows it to receive any kind of value.

var something: any = 'as string';

something = 1;

something = [1, 2, 3];

2. 

//ES5-like example

var data = ['Alice Green', 'Paul Pfifer', 'Louis Blakenship'];

data.forEach(function(line) { console.log(line); });

However with the fat arrow => syntax we can instead rewrite it like so:

// Typescript example

var data: string[] = ['Alice Green', 'Paul Pfifer', 'Louis Blakenship'];

data.forEach( (line) => console.log(line) );

Parentheses are optional when there’s only one parameter.

data.forEach( line => console.log(line) );

3.

var firstName = "Nate";

var lastName = "Murray";

// interpolate a string (enclose your string in backticks)

var greeting = `Hello ${firstName} ${lastName}`;

console.log(greeting);

TODO: page 121

Sunday, September 11, 2022

The complete book on angular 11 - Chapter 1 Writing Your First Angular Web Application

Chapter 1: Writing Your First Angular Web Application


1. To get help, go to community chat room:

https://newline.co/discord/ng-book

https://github.com/srdeleon/angular-reddit ?

2.

To get started with Angular, you’ll need to have Node.js installed.

The Node Package Manager (npm for short) is installed as a part of Node.js.

To check, run

npm -v

Once you have Node.js setup, the next step is to install TypeScript.

npm install -g typescript

tsc -v

Install Angular CLI:

npm install -g @angular/cli

Once it’s installed you’ll be able to run it from the command line using the ng

command.

ng help

3.

ng new angular-hello-world

ng serve/ng serve --port 9001

ng will look at the file angular.json to find the entry point to our app.

angular.json specifies a "main" file, which in this case is main.ts

main.ts is the entry-point for our app and it bootstraps our application

We use the AppModule to bootstrap the app. AppModule is specified in src/app/app.module.ts

AppModule specifies which component to use as the top-level component. In this case it is AppComponent

4.

ng generate component hello-world

Using backticks `` for multiline strings makes it easy to put templates inside your code files.

5.

<ul>

    <li *ngFor="let name of names">Hello {{ name }}</li>

</ul>

6.

@Input() name: string | undefined;


<ul>

    <li *ngFor="let individualUserName of names">

        <app-user-item [name]="individualUserName"></app-user-item>

    </li>

</ul>

7.

ng new angular-reddit

Notice that in the input tags we used the # (hash) to tell Angular to assign those tags

to a local variable. By adding the #newtitle and #newlink to the appropriate <input/> elements, we can pass 

them as variables into the addArticle() function on the button!

console.log(`Adding article title: ${title.value} and link: ${link.value}`);

8.

@HostBinding('attr.class') cssClass = 'row';

9.

JavaScript, by default, propagates the click event to all the parent components.

Because the click event is propagated to parents, our browser is trying to follow the

empty link, which tells the browser to reload.

To fix that, we need to make the click event handler to return false

10.

The votes parameter is optional (denoted by

the ? at the end of the name) and defaults to zero.

    constructor(title: string,link: string, votes?: number){

        this.title = title;

        this.link = link;

        this.votes = votes || 0;

    }

11.

ng build --prod -> deprecated and removed

ng build --configuration production

Thursday, September 8, 2022

RxJS and NgRx

1. RxJS

2. NgRx

Each reducer function is a listener of actions.
 


Tuesday, August 2, 2022

会攻打台湾吗?

https://www.zhihu.com/question/546647347

有很大可能借此收复台湾。平时调兵遣将容易引起注意和怀疑,此时可以随意调动和部署军队。把台湾团团围住,都不会有人在意。信息如此透明公开,都能做到出其不意。

  1. 1. 反正也主要靠内循环了,不怕制裁。
  2. 2 可以和俄罗斯抱团。
  3. 3. 有利于树立威信、巩固政权。
  4. 4. 美军刚走,敌人紧张了几天,最松懈的时候。

  5. 要是不准备采取有效行动,应该不会舆论宣传做这么足,而且放任各平台讨论。很难有比这更好的机会了。股市关注航天发展、长城军工,回调可以买入。




Wednesday, June 22, 2022

interview

 

1. How to log all the requests and responses for all restful APIs?

2. How to log all the requests and responses for the SOAP web services?

3. How to disable the log in PRD?

Spring cloud config

context-path for JBoss/Spring boot

what's the advantage/disadvantage of Spring boot?

what's CORS, how would you in Spring boot?

Exception Spring boot

Spring Session + Redis 来实现 session 共享 micro services

RestTemplate/Apache http client/webclient (spring 5)

How and why you can get a POJO object instead of a String?

Say you developed a new endpoint, how do you test it? If there's unexpected issue, how would you debug/fix?


Friday, June 10, 2022

Send gmail using OAuth2 - Java

 1.

Login to https://console.cloud.google.com/ to create the project and the client_id, oauth consent screen...

2.

Run the oauth2.py to get the refresh token.

I updated the file to support python 3.

3.

From Java,

call the below to exchange back the access token:

public static String getNewToken(String refreshToken, String clientId, String clientSecret) throws IOException {

List<String> scopes = new ArrayList<>();

TokenResponse tokenResponse = new GoogleRefreshTokenRequest(new NetHttpTransport(), new JacksonFactory(),

refreshToken, clientId, clientSecret).setScopes(scopes).setGrantType("refresh_token").execute();

return tokenResponse.getAccessToken();

}

4. With the access token, call the below to send email:

SMTPTransport transport = new SMTPTransport(session, null);

transport.connect(SMTP_SERVER_HOST, FROM_USER_EMAIL, null);

transport.issueCommand(

"AUTH XOAUTH2 " + new String(BASE64EncoderStream.encode(

String.format("user=%s\1auth=Bearer %s\1\1", FROM_USER_EMAIL, newAccessToken).getBytes())),

235);

transport.sendMessage(msg, msg.getAllRecipients());

Refer:

https://hellokoding.com/sending-email-through-gmail-smtp-server-with-java-mail-api-and-oauth-2-authorization/

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

Saturday, April 9, 2022

Netflix Human pulse Climbing

When I'm at the top, I feel a sense of relief for sure, a sense of complishment. 

Climbing is a form of therapy for me because I can just escape.