Source: https://www.techiediaries.com/angular-dom-queries-viewchild/
@ViewChildren(MyComponent) components: QueryList<MyComponent>
Angular Material Datepicker only MM/YYYY
Source:
can be found in the LICENSE file at http://angular.io/license */
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a month" [formControl]="date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker (monthSelected)="monthSelected($event)" startView="multi-year"></mat-datepicker>
</mat-form-field>
import { Component, ViewChild } from '@angular/core';
import { FormControl } from '@angular/forms';
import { NativeDateAdapter, DateAdapter, MatDatepicker } from '@angular/material';
import * as _moment from 'moment';
import { default as _rollupMoment } from 'moment';
const moment = _rollupMoment || _moment;
class CustomDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
var formatString = 'MMMM YYYY';
return moment(date).format(formatString);
}
}
@Component({
selector: 'app-month-picker-example',
templateUrl: './month-picker-example.component.html',
styleUrls: ['./month-picker-example.component.css'],
providers: [
{
provide: DateAdapter, useClass: CustomDateAdapter
}
]
})
export class MonthPickerExampleComponent{
@ViewChild(MatDatepicker) picker;
date = new FormControl();
constructor() { }
monthSelected(params) {
this.date.setValue(params);
this.picker.close();
}
}
/** Copyright 2018 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
Angular @ViewChild() error: Expected 2 arguments, but got 1
Source: https://stackoverflow.com/questions/56704164/angular-viewchild-error-expected-2-arguments-but-got-1
In Angular 8 , ViewChild takes 2 parameters
@ViewChild(ChildDirective, {static: false}) Component
Javascript: remove html tags
Source: https://stackoverflow.com/questions/51195143/is-there-a-way-to-remove-html-tags-from-a-string-in-angular-2/51195294
You can achieve this by
JavaScript
.
Try this!!
var plainText = content.replace(/<[^>]*>/g, '');
This will return you plain text.
MYSQL: UNSIGNED vs SIGNED
Source: https://stackoverflow.com/questions/11515594/when-should-i-use-unsigned-and-signed-int-in-mysql
UNSIGNED
only stores positive numbers (or zero). On the other hand, signed can store negative numbers (i.e., may have a negative sign).UNSIGNED
ranges from 0
to n
, while signed ranges from about -n/2
to n/2
.
In this case, you have an
AUTO_INCREMENT
ID column, so you would not have negatives. Thus, use UNSIGNED
. If you do not use UNSIGNED
for the AUTO_INCREMENT
column, your maximum possible value will be half as high (and the negative half of the value range would go unused).Upload a binary file to S3 using AWS SDK for Node.js
Source: https://stackoverflow.com/questions/13807339/upload-a-binary-file-to-s3-using-aws-sdk-for-node-js
https://www.mydatahack.com/uploading-and-downloading-files-in-s3-with-node-js/
You don't need to convert the buffer to a base64 string. Just set body to data and it will work.
https://www.mydatahack.com/uploading-and-downloading-files-in-s3-with-node-js/
You don't need to convert the buffer to a base64 string. Just set body to data and it will work.
AWS S3 is probably the most utilised AWS storage services. It is affordable, highly available, convenient and easy to use. To interact with any AWS services, Node.js requires AWS SDK for JavaScript.
Let’s first create a project folder called nodeS3 and install SDK. Then, create the main program file and data folder. In the data folder, drop any file you want. In this example, I am using a json file called data.json.
mkdir nodeS3 npm init -y npm install aws-sdk touch app.js mkdir data
Next, you need to create a bucket for uploading a file (after configuring your AWS CLI). Let’s create a bucket with the s3 command.
aws s3 mb s3://your.bucket.name
Uploading File
First of all, you need to import the aws-sdk module and create a new S3 object. It uses the credentials that you set for your AWS CLI. Locking in API version for S3 object is optional. Here is the further document on the S3 class.
There are two methods you can use to upload a file, upload() and putObject(). Both methods are using different API calls. The major difference is upload() allows you to define concurrency and part size for large files while putObject() has lesser control. For a smaller file, both methods are fine. In general, I recommend to use upload().
Simple File Upload Example
In this example, we are using the async readFile function and uploading the file in the callback. As the file is read, the data is converted to a binary format and passed it to the upload Body parameter.
const AWS = require('aws-sdk'); | |
const fs = require('fs'); | |
var s3 = new AWS.S3(); | |
const filePath = './data/data.json'; | |
const bucketName = 'your.bucket.name'; | |
const key = 'data/data.json'; | |
const uploadFile = (filePath, bucketName, key) => { | |
fs.readFile(filePath, (err, data) => { | |
if (err) console.error(err); | |
var base64data = new Buffer(data, 'binary'); | |
var params = { | |
Bucket: bucketName, | |
Key: key, | |
Body: base64data | |
}; | |
s3.upload(params, (err, data) => { | |
if (err) console.error(`Upload Error ${err}`); | |
console.log('Upload Completed'); | |
}); | |
}); | |
}; | |
uploadFile(filePath, bucketName, key); |
Downloading File
To download a file, we can use getObject().The data from S3 comes in a binary format. In the example below, the data from S3 gets converted into a String object with toString() and write to a file with writeFileSync method. Alternatively, you can create the stream reader on getObject method and pipe to a stream writer as described here.
const AWS = require('aws-sdk'); | |
const fs = require('fs'); | |
const filePath = './data/downloaded.json'; | |
const bucketName = 'your.bucket.name'; | |
const key = 'data/data.json'; | |
var s3 = new AWS.S3(); | |
const downloadFile = (filePath, bucketName, key) => { | |
const params = { | |
Bucket: bucketName, | |
Key: key | |
}; | |
s3.getObject(params, (err, data) => { | |
if (err) console.error(err); | |
fs.writeFileSync(filePath, data.Body.toString()); | |
console.log(`${filePath} has been created!`); | |
}); | |
}; | |
downloadFile(filePath, bucketName, key); |
How to kill a nodejs process in Linux?
Source: https://stackoverflow.com/questions/31649267/how-to-kill-a-nodejs-process-in-linux
pkill is the easiest command line utility
pkill -f node
or
pkill -f nodejs
whatever name the process runs as for your os
ngx-translate: Translate strings in html
Source: https://stackoverflow.com/questions/50027311/ngx-translate-translate-strings-in-html
<label for="user-terms" [innerHTML]="'i-agree' | translate: {termLink: 'javascript:void(0)'}"></label>
This is how you can use parametric translation with filters:
// define translation with parameter
'TRANSLATION_KEY': '{{days}} days'
// use it in template
<span>{{ 'TRANSLATION_KEY' | translate: { days: followUpInDays | positiveNumber } }}</span>
If you want to have the whole sentence as a translation (including the HTML), you will need to use
innerHTML
property binding:// define translation with parameter
'TRANSLATION_KEY': 'Follow-up is <span class="{{className}}">{{days}} days</span> past due'
// use it in template
<span *ngIf="Days < 0 && !shortSentence"
[innerHTML]="'TRANSLATION_KEY' | translate: { className: (highlightContent ? 'font-bold' : ''), days: followUpInDays | positiveNumber }"> </span>
RegEx Ignore Case
Source: https://stackoverflow.com/questions/24395542/regex-ignore-case/36593305
Flags go at the end.
/regex/i
i
is for case-Insensitive (or ignore-case)When should I use UNSIGNED and SIGNED INT in MySQL?
Source: https://stackoverflow.com/questions/11515594/when-should-i-use-unsigned-and-signed-int-in-mysql
UNSIGNED
only stores positive numbers (or zero). On the other hand, signed can store negative numbers (i.e., may have a negative sign).
Here's a table of the ranges of values each
INTEGER
type can store:UNSIGNED
ranges from 0
to n
, while signed ranges from about -n/2
to n/2
.
In this case, you have an
AUTO_INCREMENT
ID column, so you would not have negatives. Thus, use UNSIGNED
. If you do not use UNSIGNED
for the AUTO_INCREMENT
column, your maximum possible value will be half as high (and the negative half of the value range would go unused).
Đăng ký:
Bài đăng (Atom)
StaticImage
import React , { useEffect , useRef } from "react" import { StaticImage } from "gatsby-plugin-image" impor...
-
letsencrypt "Certbot doesn't know how to automatically configure the web server on this system" (repusic.com) sudo yum inst...
-
Modify File Permissions with chmod | Linode Modify File Permissions with chmod The chmod command allows users to change read and write per...
-
https://www.cloudflare.com/learning/dns/dns-records/dns-a-record/ The "A" stands for "address" and this is the most fun...