javascript - Cannot delete property '1' of [object Array] - Stack Overflow


I've faced the same issue and according to this article the problem is that user array has non configurable properties. I suppose angular Inputs are set as non configurable. When you do: this.users = this.usersInput you simply pass the reference of input to this.users. The solution is to simply copy input array before splicing. In your case:

    this.users = [...this.usersInput];

Btw. do it in deleteUser method instead of afterViewInit with local variable. You do not need two class props referring to the same object.

How do I make `ls` show file sizes in megabytes?

 linux - How do I make `ls` show file sizes in megabytes? - Unix & Linux Stack Exchange


ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.


If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.

If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.


If you simply want file sizes in "reasonable" units, rather than specifically megabytes, then you can use -lh to get a long format listing and human readable file size presentation. This will use units of file size to keep file sizes presented with about 1-3 digits (so you'll see file sizes like 6.1K, 151K, 7.1M, 15M, 1.5G and so on.


The --block-size parameter is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as a number of 429-byte blocks if you want to).

Note that both --block-size and -h are GNU extensions on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU Coreutils 8.5 does support --block-size and -h as described above. Thanks to kojiro for pointing this out.

Do I need Content-Type: application/octet-stream for file download?

 http - Do I need Content-Type: application/octet-stream for file download? - Stack Overflow

Hence:

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="picture.png"

Means "I don't know what the hell this is. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: attachment; filename="picture.png"

Means "This is a PNG image. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: inline; filename="picture.png"

Means "This is a PNG image. Please display it unless you don't know how to display PNG images. Otherwise, or if the user chooses to save it, we recommend the name picture.png for the file you save it as".

Of those browsers that recognise inline some would always use it, while others would use it if the user had selected "save link as" but not if they'd selected "save" while viewing (or at least IE used to be like that, it may have changed some years ago).

 Linux tar Command and How To Tar A Directory – POFTUT


Generally used to make multiple files and directories one file. We will tar a directory

$ tar cvf dymerge.tar dymerge 
dymerge/ 
dymerge/txt/ 
dymerge/txt/archive_formats.txt 
dymerge/txt/logo.txt
  • c for compress but actually it is not compressed
  • v for verbosity to see what happens
  • f for archive file name
  • dymerge.tar is new tar file name
  • dymerge is the source directory name

Compress While Archiving

We can compress archived with with z parameter. z is used to gzip format

$ tar cvfz dymerge.tar.gz dymerge
  • z is for gzip compression other options are default for our usage

To compress with bzip2 j parameter should be provided.

List Files in Tar Archive

We can list files without opening the tar. t parameter is used to list. But if the archive is gzip we should provide z too. As we see tar.gz is extension for tarred and gzipped files.

$ tar tvfz dymerge.tar.gz
  • t list files
  • z archive is gzip format
List Files in Tar Archive
List Files in Tar Archive

If the archive is bzip2 we can use following command

$ tar tvfj dymerge.tar.gz

Extract Single File From Archive

With tar a single file can be extracted from archive. x is the parameter to be used for this operation

$ tar xvfz  dymerge.tar.gz dymerge/surnames.txt 
dymerge/surnames.txt
  • dymerge.tar.gz is our archive that contains our single file
  • dymerge/surnames.txt is the file we want to extract

Extract Multiple Files From Archive with tar

We can extract multiple files with tar. We need too provide –wildcards parameter and related files for this. Here * is used for globing

$ tar xvfz  dymerge.tar.gz --wildcards *.txt  
dymerge/txt/archive_formats.txt 
dymerge/txt/logo.txt 
dymerge/surnames.txt 
dymerge/vbscan/reports/forum.doom9.org/forum.doom9.org_report_2016-10-16_at_4.56.1.txt 
dymerge/vbscan/reports/hello.txt 
dymerge/vbscan/love.txt 
dymerge/vbscan/exploit/vbscandb.txt 
dymerge/dymerged.txt 
dymerge/names.txt
  • –wildcards is the parameter
  • *.txt is the file names we want to exract

Untar Command

We can create some alias to create new untar command like below.

$ export alias untar="tar dvf $1"
Untar Command
Untar Command

Adding File into Archive

After creating an archive we may need to update or add new files and folders to the existing archive. We can use r option to add new file or folder by specifying file and folder names at the end of the command like below. In this example we will add file named test.txtinto the existing archive named dymerge.tar.gz

$ tar rvfz  dymerge.tar.gz test.txt
  • We append test.txt file with r option
  • We can add directories too

Estimate Archive Size

Before archiving a directory with tar command we can learn the size of the archive with the help of wc command. We will tar the directory in to the starndard output which will be redirected to the wc command. wc command will count the bytes and provide estimated size of the given archived file.

$ tar -cf - dymerge | wc -c 
573440

 

Linux tar Command and How To Tar A Directory Infografic

Linux tar Command and How To Tar A Directory Infografic


rxjs pipe not working on valueChanges

 Angular 6 - rxjs pipe not working on valueChanges - Stack Overflow


You need to subscribe to activate the Observable,

ngOnInit() {
   this.filteredOptions = this.myControl.valueChanges
       .pipe(
          startWith(''),
          map(val => this.filter(val))
       ).subscribe();
}

Async Pipe all the things!

 Async Pipe all the things!. Quick tutorial of how you can easily… | by joaquin cid | Medium


Never .subscribe() again, | async instead

When dealing with Observables in Angular we need to subscribe to them to unwrap the data stream and do what we need to do with each emitted value.

The most common way to this is to:

And on our template:

This pattern requires you to remember to unsubscribe on the ngOnDestroy event to avoid memory leaks and undesired behavior on your app.

You can simplify this by using the async pipe, here’s how it looks like now:

And the template:

Now, the | async is subscribing for us on the template and not only it does that, ¡it automatically unsubscribes for us on the ngOnDestroy event!

How async pipe works

async pipe receives the Observable we define on the template, subscribes to it, and every time it receives a new emission of data it triggers the ChangeDetection cycle to update the view accordingly.

More important, async pipe implements the ngOnDestroy event and unsubscribes from your observable.

You can take a look that the source code here:

Goodbye .unsubscribe()

So now that we know this we can kiss .unsubscribe() goodbye!

If you are wondering how to subscribe to an Observable that you don’t actually want to display data on the template or it doesn’t stream any data, here’s how you can do it.

Let’s consider a FormGroup to which we want to perform an operation every time its value changes.

Instead of subscribing to it, we can | async to it inside an ng-container. This way we wont need to subscribe and unsubscribe to the Observable without also displaying any data in the page.

Conclusion

We’ve learned how to use the async pipe to subscribe to any Observable on Angular, and how this eliminates the need to unsubscribe from it.


How To Open A Port In CentOS 7 With Firewalld

 How To Open A Port In CentOS 7 With Firewalld (rootusers.com)


Open Specific Port

Opening a port in firewalld is fairly straightforward, in the below example we allow traffic in from any source IP address to TCP port 100. First we modify the persistent configuration, then we reload firewall-cmd to load this change into the running configuration.

[root@centos7 ~]# firewall-cmd --permanent --add-port=100/tcp
success
[root@centos7 ~]# firewall-cmd --reload
success

If the --permanent flag is not specified, this will only change the running configuration but will not be saved.

We can check the ports that are opened in the current default zone with ‘--list-ports’.

[root@centos7 ~]# firewall-cmd --list-ports
100/tcp

As expected we see that TCP port 100 is open.

Should we wish to remove a port, we can use ‘--remove-port=’ instead.

We can also open a range of ports in the same way.

[root@centos7 ~]# firewall-cmd --permanent --add-port=200-300/tcp
success

Open Predefined Service

Rather than manually specifying a port number to allow through the firewall, we can make use of a bunch of predefined services which may be easier. For example instead of opening TCP port 80, we can use the ‘http’ service.

[root@centos7 ~]# firewall-cmd --permanent --add-service=http
success
[root@centos7 ~]# firewall-cmd --reload
success

Now if we list the services that are accepted through the firewall, we will see http listed along with ssh and dhcpv6-client, which are allowed through by default.

[root@centos7 ~]# firewall-cmd --list-services
dhcpv6-client http ssh

This is a predefined service and can be found as an XML file in the /usr/lib/firewalld/services/ directory. Here’s what the http service we just used looks like.

[root@centos7 ~]# cat /usr/lib/firewalld/services/http.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>WWW (HTTP)</short>
  <description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>
  <port protocol="tcp" port="80"/>
</service>

We can create custom services by copying one of these into the /etc/firewalld/services/ directory and then customizing it. The services in the /usr/lib/firewalld/services/ directory should NOT be modified, changes should be copied into /etc/firewalld/services/ followed by a reload of firewall-cmd to pick up the changes.

Services Or Manual Ports?

Why would we want to use services if we can just specify the port? Modules can be specified in a service, for example samba.xml loads the module “nf_conntrack_netbios_ns” for us when it’s enabled, along with four different ports which is a lot easier than doing all of this ourselves as we don’t need to memorize all of the ports required for a service.

Still not a fan of firewalld? Don’t worry, you can always install ifconfig in CentOS 7 instead, however note that this is considered deprecated.

AWS: SMS text message-based MFA

 Using multi-factor authentication (MFA) in AWS - AWS Identity and Access Management (amazon.com)

SMS text message-based MFA. A type of MFA in which the IAM user settings include the phone number of the user's SMS-compatible mobile device. When the user signs in, AWS sends a six-digit numeric code by SMS text message to the user's mobile device. The user is required to type that code on a second webpage during sign-in. Note that SMS-based MFA is available only for IAM users. You cannot use this type of MFA with the AWS account root user. For more information about enabling SMS text messaging-based MFA, see PREVIEW – Enabling SMS text message MFA devices.


Note

AWS will soon end support for SMS multi-factor authentication (MFA). We are not allowing new customers to preview this feature. We recommend that existing customers switch to one of the following alternative methods of MFA: virtual (software-based) MFA device, U2F security key, or hardware MFA device. You can view users in your account with an assigned SMS MFA device. To do so, go to the IAM console, choose Users from the navigation pane, and look for users with SMS in the MFA column of the table.

Double question mark in Typescript & Javascript

 Double question mark in Typescript & Javascript | Nullish Coalescing (??) Operator (shareablecode.com)


Usage of ?? Sign in JavaScript and TypeScript

It returns second parameter when first parameter happens to be undefined or null. 

const value = firstParam ?? secondParam;

What's the difference between ?? and || in JavaScript / TypeScript

A common approach to achieve similar thing we use:

const value = firstParam || secondParam;

But problem is logical operator evaluates false value as well, which is not null or undefined

const foo = false
const baz = foo || 'default value'; // returns 'default value'
const value = foo ?? 'default value'// returns false;

TypeError: Cannot read property 'split' of undefined at defaultUrlMatcher

 javascript - Angular2 v3 component router: TypeError: Cannot read property 'split' of undefined - Stack Overflow


I figured out what was going on. In case anyone else hits a similar issue, the problem in this case was in WorkspaceRoutes.

export const WorkspaceRoutes: RouterConfig = [
  {path: 'workspace/:id', component: WorkspaceRootComponent},
  {children: [    // this should not be the start of a new object
    {path: 'projects', component: WorkspaceDashboardComponent},
    {path: 'newproject', component: ProjectNewComponent},
    {path: '', redirectTo: 'projects', terminal: true},
  ]}
];

Should be

export const WorkspaceRoutes: RouterConfig = [
  {path: 'workspace/:id', 
  component: WorkspaceRootComponent,
  children: [
    {path: 'projects', component: WorkspaceDashboardComponent},
    {path: 'newproject', component: ProjectNewComponent},
    {path: '', redirectTo: 'projects', terminal: true},
  ]}
];

The children item of WorkspaceRootComponent was not under that item, but on the same level.

replaceUrl: true

 Using "replaceUrl" In Order To Honor The Back-Button While Chaining Absolute Redirects In Angular 7.2.13 (bennadel.com)


this.router.navigateByUrl(

this.redirectTo,

// By replacing the current URL in the history, we keep the Browser's Back

// Button behavior in tact. This will allow the user to easily navigate back

// to the previous URL without getting caught in a redirect.

{

replaceUrl: true

}

);

anti-pattern là gì

  Trong công nghệ và lập trình, Anti-pattern (mẫu phản diện) là những giải pháp bề ngoài có vẻ hiệu quả để giải quyết một vấn đề phổ biến, ...