问:
Why can the compiler not optimize floating point addition with 0?
I have four identity functions which do essentially nothing. Only multiplication with 1 could be optimized by clang to a single ret statement.

float id0(float x) {
    return x + 1 - 1;
}

float id1(float x) {
    return x + 0;
}

float id2(float x) {
    return x * 2 / 2;
}

float id3(float x) {
    return x * 1;
}
```

<p>And the following compiler output is: (clang 10, at -O3)</p>

```.LCPI0_0:
        .long   1065353216              # float 1
.LCPI0_1:
        .long   3212836864              # float -1
id0(float):                                # @id0(float)
        addss   xmm0, dword ptr [rip + .LCPI0_0]
        addss   xmm0, dword ptr [rip + .LCPI0_1]
        ret
id1(float):                                # @id1(float)
        xorps   xmm1, xmm1
        addss   xmm0, xmm1
        ret
.LCPI2_0:
        .long   1056964608              # float 0.5
id2(float):                                # @id2(float)
        addss   xmm0, xmm0
        mulss   xmm0, dword ptr [rip + .LCPI2_0]
        ret
id3(float):                                # @id3(float)
        ret
```

I can understand why id0 and id2 can't be optimized. They increase the value which could then turn into positive infinity and the second operation would not change it back.

But why can't id1 be optimized? Additon with infinity would yield infinity, addition with any regular number would yield that number and addition with NaN would yield NaN. So why is it not a "true" identity operation like * 1.

Example with Compiler Explorer

答:
Read the floating-number-gui.de web page, more about IEEE 754, the C11 standard n1570, the C++11 standard n3337.

```<code>float id1(float x) {
    return x + 0;
}
</code>```

If x happens to be a signaling NaN, your id1 might even not return (and probably should not return).

If x is a quiet NaN, then id1(x) != x since NaN != NaN (at least NaN == NaN should be false).

In some cases, you want costly arbitrary precision arithmetic. Then consider using GMPlib.

PS. Floating point numbers can give you nightmares or a PhD, at your choice. They sometimes kill people or at least make huge financial disasters (e.g. a loss of several hundred millions US$ or €).

Body:
I have four identity functions which do essentially nothing. Only multiplication with 1 could be optimized by clang to a single ret statement.

float id0(float x) {
    return x + 1 - 1;
}

float id1(float x) {
    return x + 0;
}

float id2(float x) {
    return x * 2 / 2;
}

float id3(float x) {
    return x * 1;
}

And the following compiler output is: (clang 10, at -O3)

.LCPI0_0:
        .long   1065353216              # float 1
.LCPI0_1:
        .long   3212836864              # float -1
id0(float):                                # @id0(float)
        addss   xmm0, dword ptr [rip + .LCPI0_0]
        addss   xmm0, dword ptr [rip + .LCPI0_1]
        ret
id1(float):                                # @id1(float)
        xorps   xmm1, xmm1
        addss   xmm0, xmm1
        ret
.LCPI2_0:
        .long   1056964608              # float 0.5
id2(float):                                # @id2(float)
        addss   xmm0, xmm0
        mulss   xmm0, dword ptr [rip + .LCPI2_0]
        ret
id3(float):                                # @id3(float)
        ret

I can understand why id0 and id2 can't be optimized. They increase the value which could then turn into positive infinity and the second operation would not change it back.

But why can't id1 be optimized? Additon with infinity would yield infinity, addition with any regular number would yield that number and addition with NaN would yield NaN. So why is it not a "true" identity operation like * 1.

Example with Compiler Explorer

Body:
Read the floating-number-gui.de web page, more about IEEE 754, the C11 standard n1570, the C++11 standard n3337.

float id1(float x) {
    return x + 0;
}

If x happens to be a signaling NaN, your id1 might even not return (and probably should not return).

If x is a quiet NaN, then id1(x) != x since NaN != NaN (at least NaN == NaN should be false).

In some cases, you want costly arbitrary precision arithmetic. Then consider using GMPlib.

PS. Floating point numbers can give you nightmares or a PhD, at your choice. They sometimes kill people or at least make huge financial disasters (e.g. a loss of several hundred millions US$ or €).


来源: stackexchange

问:
SSRS (report builder) sorting a row
My requirement is I have to sort a row Month Wise, that is Jan, Feb, Mar etc right now it is not sorted.

I have tried writing query under query window order by case when...

I have tried writing query in expression of month field i.e.

```<code>   IIF(Fields!Month_Y.Value = "Feb-19", 2,
   IIF(Fields!Month_Y.Value = "Mar-19", 3,
   IIF(Fields!Month_Y.Value = "Apr-19", 4,
   IIF(Fields!Month_Y.Value = "May-19", 5,
   IIF(Fields!Month_Y.Value = "Jun-19", 6,
   IIF(Fields!Month_Y.Value = "Jul-19", 7,
   IIF(Fields!Month_Y.Value = "Aug-19", 8,
   IIF(Fields!Month_Y.Value = "Sep-19", 9,
   IIF(Fields!Month_Y.Value = "Oct-19", 10,
IIF(Fields!Month_Y.Value = "Nov-19", 11, 12)))))))))))
</code>```

I have wrote same IIF condition query in Tablix - Sorting expression field too.

But still it is not sorting the report month wise. if anyone can have a look and give the solution please.

Thank you in advance.

答:
I understand from your question that you tried to use "case" on the "data set"

I have tried writing query under query window order by case when...

So the next thing that you need to do is:

Right-click on the column.

Go to "Shorting".

Press "Add".

Choose your "number" column(that you mapped - "Feb-19" etc.).

Choose your order method "Z-A" or "A-Z".

I simulated your case and it worked for me.

 See the image below

ContentLicense: CC BY-SA 4.0

Title: SSRS (report builder) sorting a row

Body:
My requirement is I have to sort a row Month Wise, that is Jan, Feb, Mar etc right now it is not sorted.

I have tried writing query under query window order by case when...

I have tried writing query in expression of month field i.e.

   IIF(Fields!Month_Y.Value = "Feb-19", 2,
   IIF(Fields!Month_Y.Value = "Mar-19", 3,
   IIF(Fields!Month_Y.Value = "Apr-19", 4,
   IIF(Fields!Month_Y.Value = "May-19", 5,
   IIF(Fields!Month_Y.Value = "Jun-19", 6,
   IIF(Fields!Month_Y.Value = "Jul-19", 7,
   IIF(Fields!Month_Y.Value = "Aug-19", 8,
   IIF(Fields!Month_Y.Value = "Sep-19", 9,
   IIF(Fields!Month_Y.Value = "Oct-19", 10,
IIF(Fields!Month_Y.Value = "Nov-19", 11, 12)))))))))))

I have wrote same IIF condition query in Tablix - Sorting expression field too.

But still it is not sorting the report month wise. if anyone can have a look and give the solution please.

Thank you in advance.


问:
CSS and javascript not working in Symfony project
I recently started a new project in Symfony and I did everything here
but it didn't help.

I work for first time with Symfony and this is my first project. I strictly follow the documentation and I am trying to add some CSS but its now working. I use Encore and downloaded Yarn as the documentation says to do.
Below I will upload some of my code. It seems fine but it's not.

html.twig

```<code><!DOCTYPE html>
<html lang="en" xmlns:th="http:thymeleaf.org">

<head>
<title>Events & People</title>
<meta charset="UTF-8">

{% block stylesheets %}
{#{% stylesheets '@AppBundle/public/build/app.css' %}#}
    {{ encore_entry_link_tags('app') }}
    <link src="/build/app.css" rel="stylesheet"/>

{#{% endstylesheets %}#}
{% endblock %}
</head>
</code>```

webpack.config.js

```<code>var Encore = require('@symfony/webpack-encore');

Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')

/*
 * ENTRY CONFIG
 *
 * Add 1 entry for each "page" of your app
 * (including one that's included on every page - e.g. "app")
 *
 * Each entry will result in one JavaScript file (e.g. app.js)
 * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
 */
.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()

/*
 * FEATURE CONFIG
 *
 * Enable & configure other features below. For a full
 * list of features, see:
 * https://symfony.com/doc/current/frontend.html#adding-more-features
 */
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

//11111111111
// .enableSassLoader()
//
// // processes files ending in .less
// .enableLessLoader()
//
// // processes files ending in .styl
// .enableStylusLoader()
//11111111111

// enables Sass/SCSS support
//.enableSassLoader()

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();
</code>```

Here is an image of my tree of files:

If it's done right it should load the files from my /build/app.css, but it's not loading it.

答:
For me, it was just a caching problem.
let's try to delete the cache.</p>

Body:
I recently started a new project in Symfony and I did everything here
but it didn't help.

I work for first time with Symfony and this is my first project. I strictly follow the documentation and I am trying to add some CSS but its now working. I use Encore and downloaded Yarn as the documentation says to do.
Below I will upload some of my code. It seems fine but it's not.

html.twig

<!DOCTYPE html>

<title>Events & People</title>
<meta charset="UTF-8">

{% block stylesheets %}
{#{% stylesheets '@AppBundle/public/build/app.css' %}#}
    {{ encore_entry_link_tags('app') }}
    <link src="/build/app.css" rel="stylesheet"/>

{#{% endstylesheets %}#}
{% endblock %}

webpack.config.js

var Encore = require('@symfony/webpack-encore');

Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')

/*
 * ENTRY CONFIG
 *
 * Add 1 entry for each "page" of your app
 * (including one that's included on every page - e.g. "app")
 *
 * Each entry will result in one JavaScript file (e.g. app.js)
 * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
 */
.addEntry('app', './assets/js/app.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/page2.js')

// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()

/*
 * FEATURE CONFIG
 *
 * Enable & configure other features below. For a full
 * list of features, see:
 * https://symfony.com/doc/current/frontend.html#adding-more-features
 */
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())

//11111111111
// .enableSassLoader()
//
// // processes files ending in .less
// .enableLessLoader()
//
// // processes files ending in .styl
// .enableStylusLoader()
//11111111111

// enables Sass/SCSS support
//.enableSassLoader()

// uncomment if you use TypeScript
//.enableTypeScriptLoader()

// uncomment if you're having problems with a jQuery plugin
//.autoProvidejQuery()
;

module.exports = Encore.getWebpackConfig();

Here is an image of my tree of files:

If it's done right it should load the files from my /build/app.css, but it's not loading it.


问:
How to prevent selection of a SortableJS item when clicking on one of its child elements?
The Issue

I'm using SortableJS to build a draggable tree component. Which means each of my sortable-items has a toggle-arrow as a child element that opens and closes a sub-tree (if there is one).

I'm attempting to use stopPropagation() to prevent the selection of the parent sortable-item if the toggle-arrow is clicked, but it's not working.

It looks like this when closed:

And looks like this when open:

The blue highlight you see in the open state (the second image) is the styling I've chosen for the selectedClass option when using the multiDrag plugin.

This is illustrating that when I click on the toggle-arrow it results in the parent sortable-item being selected.

I don't want this to happen.

The Code

The code for an item in my SortableJS tree component looks like so (using Vue.js, and Pug syntax):

```<code>div.sortable-item
    div.content
        div.toggle-arrow(@click.stop="toggleTree($event)")
        div.icon
        div.title
    div.sub-tree
</code>```

And then I've got a handler for the @click binding on my toggle-arrow element:

```<code>toggleTree = function($event) {
    $event.stopPropagation()
    /// Code for handling the sub-tree toggling goes here.
    /// The sub-tree toggling itself works just fine.
}
</code>```

You can see that I'm declaring @click.stop as the event binding, which should stop the click event from bubbling up from the toggle-arrow child element, but it's not working.

I'm even attempting to use $event.stopPropagation within the handler. But, the event seems to continue to bubble, and thus the parent sortable-item element ends up in a selected state.

I've also tried declaring @click.native.stop as the event binding, but it simply prevents my toggleTree method from firing at all. I'm assuming there's another event handler somewhere within SortableJS that's interfering with the @click.native.stop binding.

Questions

How do I stop propagation of an event when a child element of my sortable-item is clicked?

How is selection handled by the multiDrag plugin? I dug through the code and saw that the select event is fired within the handler of the drop event of the sortable-item, but I'm confused by that. Why is the drop event handler being used to toggle selection of a sortable-item?

Thanks in advance for any light you may be able to shed on this.

答:
Wrong Event

Looking at the source of SortableJS it seems that the event you want to stop from bubbling is not the click event, but rather the mouseup event.

The "Stuck" Drag Item Problem

As indicated in the comments of this answer, stopping propagation on the mouseup event causes an issue where the drag is started unintentionally, and the sortable-item becomes "stuck" to the pointer.

It seems that the "drag initiation" is triggered by either pointerdown, mousedown, or touchstart events, depending on the device.

It can be safely assumed that the pointerdown event is the one that does the triggering according to caniuse.com.

The Solution

So the actual way to solve this is to use a @pointerdown.stop event binding to trigger your toggleTree method without triggering either selection of the sortable-item, or the unintentional drag initiation.

```<code>div.sortable-item
    div.content
        div.toggle-arrow(@pointerdown.stop="toggleTree($event)")
        div.icon
        div.title
    div.sub-tree
</code>```

Body:
The Issue

I'm using SortableJS to build a draggable tree component. Which means each of my sortable-items has a toggle-arrow as a child element that opens and closes a sub-tree (if there is one).

I'm attempting to use stopPropagation() to prevent the selection of the parent sortable-item if the toggle-arrow is clicked, but it's not working.

It looks like this when closed:

And looks like this when open:

The blue highlight you see in the open state (the second image) is the styling I've chosen for the selectedClass option when using the multiDrag plugin.

This is illustrating that when I click on the toggle-arrow it results in the parent sortable-item being selected.

I don't want this to happen.

The Code

The code for an item in my SortableJS tree component looks like so (using Vue.js, and Pug syntax):

div.sortable-item
    div.content
        div.toggle-arrow(@click.stop="toggleTree($event)")
        div.icon
        div.title
    div.sub-tree

And then I've got a handler for the @click binding on my toggle-arrow element:

toggleTree = function($event) {
    $event.stopPropagation()
    /// Code for handling the sub-tree toggling goes here.
    /// The sub-tree toggling itself works just fine.
}

You can see that I'm declaring @click.stop as the event binding, which should stop the click event from bubbling up from the toggle-arrow child element, but it's not working.

I'm even attempting to use $event.stopPropagation within the handler. But, the event seems to continue to bubble, and thus the parent sortable-item element ends up in a selected state.

I've also tried declaring @click.native.stop as the event binding, but it simply prevents my toggleTree method from firing at all. I'm assuming there's another event handler somewhere within SortableJS that's interfering with the @click.native.stop binding.

Questions

How do I stop propagation of an event when a child element of my sortable-item is clicked?

How is selection handled by the multiDrag plugin? I dug through the code and saw that the select event is fired within the handler of the drop event of the sortable-item, but I'm confused by that. Why is the drop event handler being used to toggle selection of a sortable-item?

Thanks in advance for any light you may be able to shed on this.

Body:
Wrong Event

Looking at the source of SortableJS it seems that the event you want to stop from bubbling is not the click event, but rather the mouseup event.

The "Stuck" Drag Item Problem

As indicated in the comments of this answer, stopping propagation on the mouseup event causes an issue where the drag is started unintentionally, and the sortable-item becomes "stuck" to the pointer.

It seems that the "drag initiation" is triggered by either pointerdown, mousedown, or touchstart events, depending on the device.

It can be safely assumed that the pointerdown event is the one that does the triggering according to caniuse.com.

The Solution

So the actual way to solve this is to use a @pointerdown.stop event binding to trigger your toggleTree method without triggering either selection of the sortable-item, or the unintentional drag initiation.

div.sortable-item
    div.content
        div.toggle-arrow(@pointerdown.stop="toggleTree($event)")
        div.icon
        div.title
    div.sub-tree


问:
React/RCTEventEmitter.h file not found
I am trying to implement PushNotificationIOS with a detached Expo app. I am running SDK 21.0.0 (React Native 0.48).

I am getting React/RCTEventEmitter file not found

I have completed the following steps:

Open my .xcworkspace project

Drag the RCTPushNotification.xcodeproj into my Libraries folder

Added libRCTPushNotification.a into App > Build Phases > Link Binary With Libraries

Added $(SRCROOT)/../node_modules/react-native/Libraries under Header Search Paths - I also tried without the /../. I have a bunch of Pods in the Header Search Paths list too.

I then added the following into AppDelegate.m but when I click through to the file (⌘ + click), I get a question mark.

```<code>#import <React/RCTPushNotificationManager.h>
</code>```

If I change it to the below, it works, I can click through

```<code>#import "RCTPushNotificationManager.h"
</code>```

However, this is my problem

When I clean and build my project, I get the below error in RCTPushNotificationManager.h to say:

```<code>'React/RCTEventEmitter.h' file not found
</code>```

答:
Replace #import RCTEventEmitter.h or #import React/RCTEventEmitter.h with #import <React/RCTEventEmitter.h>

Its work for me

ContentLicense: CC BY-SA 3.0

Title: React/RCTEventEmitter.h file not found

Body:
I am trying to implement PushNotificationIOS with a detached Expo app. I am running SDK 21.0.0 (React Native 0.48).

I am getting React/RCTEventEmitter file not found

I have completed the following steps:

Open my .xcworkspace project

Drag the RCTPushNotification.xcodeproj into my Libraries folder

Added libRCTPushNotification.a into App > Build Phases > Link Binary With Libraries

Added $(SRCROOT)/../node_modules/react-native/Libraries under Header Search Paths - I also tried without the /../. I have a bunch of Pods in the Header Search Paths list too.

I then added the following into AppDelegate.m but when I click through to the file (⌘ + click), I get a question mark.

#import <React/RCTPushNotificationManager.h>

If I change it to the below, it works, I can click through

#import "RCTPushNotificationManager.h"

However, this is my problem

When I clean and build my project, I get the below error in RCTPushNotificationManager.h to say:

'React/RCTEventEmitter.h' file not found


问:
Angular PreloadAllModules for lazyloaded modules is not working
I have successfully implemented lazy loading for my modules Products and Customers, and I am able to see the chunks when I navigate to respective routing.

Now I want the above modules to preload, which can be done simply by adding

```<code>{ preloadingStrategy: PreloadAllModules }
</code>```

But this is not working, The above modules are still loading lazily (chunks are loading when I navigate to respective modules instead of initial load).

This is how Implemented

app.module.ts

```<code>@NgModule({
 imports: [LazyLoadModule]
})
</code>```

lazy-load.module.ts

```<code>@NgModule({
    imports: [RouterModule.forRoot([{
        path: 'products',
        data: {
            preload: false
        },
        loadChildren: './entities/products/products.module#ProductsModule',
    },
    {
        path: 'customers',
        data: {
            preload: true
        },
        loadChildren: './entities/customers/customers.module#CustomersModule',
    }], { useHash: true, preloadingStrategy: PreloadAllModules })]
})
</code>```

However if I add the configuration directly in app.module.ts, then it seems to work(I can see the individual chunks at initial load), But my routing paths are not working.

Update

First I tried with custom preloading strategy like this

preloading-strategy.service.ts

```<code>@Injectable()
export class PreloadingStrategyService implements PreloadingStrategy {

    preload(route: Route, load: () => Observable<any>) {
        console.log('Preloading called');
        return route.data && route.data.preload ? load() : of(null);
    }
}
</code>```

lazy-load.module.ts

```<code>{ preloadingStrategy: PreloadingStrategyService }
</code>```

But preload method is never called(No console log printed), So for testing purpose I added PreloadAllModules. This also doesn't work as I already explained above.

答:
Change your lazy-load.module.ts to </p>

```<code>@NgModule({
    imports: [RouterModule.forRoot([{
        path: 'products',
        data: {
            preload: false
        },
        loadChildren: './entities/products/products.module#ProductsModule',
    },
    {
        path: 'customers',
        data: {
            preload: true
        },
        loadChildren: './entities/customers/customers.module#CustomersModule',
    }], { useHash: true, preloadingStrategy: PreloadAllModules })],
    exports: [RoutingModule]
})
</code>```

Body:
I have successfully implemented lazy loading for my modules Products and Customers, and I am able to see the chunks when I navigate to respective routing.

Now I want the above modules to preload, which can be done simply by adding

{ preloadingStrategy: PreloadAllModules }

But this is not working, The above modules are still loading lazily (chunks are loading when I navigate to respective modules instead of initial load).

This is how Implemented

app.module.ts

@NgModule({
 imports: [LazyLoadModule]
})

lazy-load.module.ts

@NgModule({
    imports: [RouterModule.forRoot([{
        path: 'products',
        data: {
            preload: false
        },
        loadChildren: './entities/products/products.module#ProductsModule',
    },
    {
        path: 'customers',
        data: {
            preload: true
        },
        loadChildren: './entities/customers/customers.module#CustomersModule',
    }], { useHash: true, preloadingStrategy: PreloadAllModules })]
})

However if I add the configuration directly in app.module.ts, then it seems to work(I can see the individual chunks at initial load), But my routing paths are not working.

Update

First I tried with custom preloading strategy like this

preloading-strategy.service.ts

@Injectable()
export class PreloadingStrategyService implements PreloadingStrategy {

    preload(route: Route, load: () => Observable<any>) {
        console.log('Preloading called');
        return route.data && route.data.preload ? load() : of(null);
    }
}

lazy-load.module.ts

{ preloadingStrategy: PreloadingStrategyService }

But preload method is never called(No console log printed), So for testing purpose I added PreloadAllModules. This also doesn't work as I already explained above.

Body:
Change your lazy-load.module.ts to

@NgModule({
    imports: [RouterModule.forRoot([{
        path: 'products',
        data: {
            preload: false
        },
        loadChildren: './entities/products/products.module#ProductsModule',
    },
    {
        path: 'customers',
        data: {
            preload: true
        },
        loadChildren: './entities/customers/customers.module#CustomersModule',
    }], { useHash: true, preloadingStrategy: PreloadAllModules })],
    exports: [RoutingModule]
})


问:
I don't fully understand how containerisation doesn't lead to over provisioning instances from the start
I understand the basics how containers and how they differ from running virtual machines. I also get that auto scaling when resources are low and how services such as AWS can horizontally scale and provision more resources for you.

What I don't understand however is how containerisation management technologies such as swarm or kubernetes stop over provisioning.

In my mind -  you still have to have the resources available in order to add more containers as the container management solution is only managing the containers themselves. Correct?

So if I had an ec2 (in the AWS world) which I was using for my application and kubernetes was running on it to manage containers for my application I would still need to have a auto scaling and have to spin up another ec2 if vm itself was being pushed to capacity by my application.

Perhaps because I've not worked with container orchestration as yet I can't grasp the mechanics of this but in principal I don't see how this works harmoniously.

答:
So when you consider containers you cannot view it as a single application or service per host.

Traditionally people would have an individual or multiple instances all running a single application. With containers, you would have an application per containers. So an individual host instance may be running multiple applications, this makes better use of CPU and memory resources to ensure you are using less hosts across the board.

When you look at optimizing containers, this is when people start to break down larger applications into services and microservices to help distribute key functionality into smaller and more scalable pieces of code.

Depending on the containerisation layer you can also use dynamic port mappings, this would support you having multiple of the same containers on the same host but each with a unique port.

Finally when looking at AWS, if you don't want to be scaling physical hosts a service was released in 2018 and expanded in 2019 to include Kubernetes. This service is Fargate, and allows you to run your cluster in a serverless way.


问:
Cleanup old refs in Ruby Version Manager (RVM)
I need to free disk space on my local machine, which is almost allocated into my Ruby Version Manager (RVM) dir.

Now, it seems I got just one ruby version ( 1.9.2p136 ) :

```<code>lsoave@ubuntu:~/rails/github/gitwatcher$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]
lsoave@ubuntu:~/rails/github/gitwatcher$

lsoave@ubuntu:~/rails/github/gitwatcher$ rvm list
rvm rubies
=> ruby-1.9.2-p136 [ i386 ]
lsoave@ubuntu:~/rails/github/gitwatcher$

lsoave@ubuntu:~/rails/github/gitwatcher$ which ruby
/home/lsoave/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
lsoave@ubuntu:~/rails/github/gitwatcher$
</code>```

but my RVM dir, have many others unrelated dirs/versions :

```<code>lsoave@ubuntu:~/rails/github/gitwatcher$ ls -la ~/.rvm/gems
total 72
drwxr-xr-x 18 lsoave lsoave 4096 2011-05-21 15:44 .
drwxr-xr-x 23 lsoave lsoave 4096 2011-02-10 22:46 ..
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-29 19:50 cache
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-31 21:50 jruby-1.3.7
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-31 21:50 jruby-1.3.8
drwxr-xr-x  2 lsoave lsoave 4096 2011-05-21 15:44 ree-1.8.7-2010.02
drwxr-xr-x  8 lsoave lsoave 4096 2010-09-08 11:25 ruby-1.8.7-p302
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:00 ruby-1.8.7-p302@global
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:24 ruby-1.9.2-head
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:24 ruby-1.9.2-head@global
drwxr-xr-x  8 lsoave lsoave 4096 2010-08-31 23:47 ruby-1.9.2-p0
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 19:50 ruby-1.9.2-p0@global
drwxr-xr-x  8 lsoave lsoave 4096 2011-02-10 19:44 ruby-1.9.2-p136
drwxr-xr-x  7 lsoave lsoave 4096 2011-02-10 19:23 ruby-1.9.2-p136@global
drwxr-xr-x  7 lsoave lsoave 4096 2011-04-08 21:21 ruby-1.9.2-p136@greendog
drwxr-xr-x  7 lsoave lsoave 4096 2011-04-09 00:57 ruby-1.9.2-p136@greendog2
drwxr-xr-x  7 lsoave lsoave 4096 2011-02-15 00:09 ruby-1.9.2-p136@greendog99
drwxr-xr-x  2 lsoave lsoave 4096 2011-02-10 19:04 system
lsoave@ubuntu:~/rails/github/gitwatcher$
</code>```

is it save to remove all dirs remaining with just "ruby-1.9.2-p136" and "ruby-1.9.2-p136@global" dirs (ruby-1.9.2-p136@greendog* are old and "rvm system" return nothing) ? Will I use "rm" command, or are there RVM embodied commands to cleanup a better way ? Is it possible cleanup the cache dir ?

Thanks in advance.
luca

答:
... it turn out that some of the previous, not used refs, were just gemsets:

```<code>rvm gemset list
lsoave@ubuntu:~$ rvm gemset list

gemsets for ruby-1.9.2-p136 (found in /home/lsoave/.rvm/gems/ruby-1.9.2-p136)
global
greendog
greendog2
greendog99

lsoave@ubuntu:~$
</code>```

which I removed like following:

```<code>lsoave@ubuntu:~$ rvm gemset delete greendog99
Are you SURE you wish to remove the entire gemset directory 'greendog99' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog99)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$ rvm gemset delete greendog2
Are you SURE you wish to remove the entire gemset directory 'greendog2' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog2)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$ rvm gemset delete greendog
Are you SURE you wish to remove the entire gemset directory 'greendog' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$
</code>```

than I made a backup of one of the old 'lib' ( just in case ... ):

```<code>lsoave@ubuntu:~/.rvm/gems$ tar zcvf ruby-1.8.7-p302.gz ./ruby-1.8.7-p302
</code>```

and removed the relative directory as a previous comment talk, with stuartc:

```<code>lsoave@ubuntu:~/.rvm/gems$ rm -rf ./ruby-1.8.7-p302
</code>```

now back to work.

I'll wait a couple of days, looking for everything is right ...

Body:
I need to free disk space on my local machine, which is almost allocated into my Ruby Version Manager (RVM) dir.

Now, it seems I got just one ruby version ( 1.9.2p136 ) :

lsoave@ubuntu:~/rails/github/gitwatcher$ ruby -v
ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]
lsoave@ubuntu:~/rails/github/gitwatcher$

lsoave@ubuntu:~/rails/github/gitwatcher$ rvm list
rvm rubies
=> ruby-1.9.2-p136 [ i386 ]
lsoave@ubuntu:~/rails/github/gitwatcher$

lsoave@ubuntu:~/rails/github/gitwatcher$ which ruby
/home/lsoave/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
lsoave@ubuntu:~/rails/github/gitwatcher$

but my RVM dir, have many others unrelated dirs/versions :

lsoave@ubuntu:~/rails/github/gitwatcher$ ls -la ~/.rvm/gems
total 72
drwxr-xr-x 18 lsoave lsoave 4096 2011-05-21 15:44 .
drwxr-xr-x 23 lsoave lsoave 4096 2011-02-10 22:46 ..
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-29 19:50 cache
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-31 21:50 jruby-1.3.7
drwxr-xr-x  2 lsoave lsoave 4096 2010-08-31 21:50 jruby-1.3.8
drwxr-xr-x  2 lsoave lsoave 4096 2011-05-21 15:44 ree-1.8.7-2010.02
drwxr-xr-x  8 lsoave lsoave 4096 2010-09-08 11:25 ruby-1.8.7-p302
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:00 ruby-1.8.7-p302@global
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:24 ruby-1.9.2-head
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 22:24 ruby-1.9.2-head@global
drwxr-xr-x  8 lsoave lsoave 4096 2010-08-31 23:47 ruby-1.9.2-p0
drwxr-xr-x  7 lsoave lsoave 4096 2010-08-29 19:50 ruby-1.9.2-p0@global
drwxr-xr-x  8 lsoave lsoave 4096 2011-02-10 19:44 ruby-1.9.2-p136
drwxr-xr-x  7 lsoave lsoave 4096 2011-02-10 19:23 ruby-1.9.2-p136@global
drwxr-xr-x  7 lsoave lsoave 4096 2011-04-08 21:21 ruby-1.9.2-p136@greendog
drwxr-xr-x  7 lsoave lsoave 4096 2011-04-09 00:57 ruby-1.9.2-p136@greendog2
drwxr-xr-x  7 lsoave lsoave 4096 2011-02-15 00:09 ruby-1.9.2-p136@greendog99
drwxr-xr-x  2 lsoave lsoave 4096 2011-02-10 19:04 system
lsoave@ubuntu:~/rails/github/gitwatcher$

is it save to remove all dirs remaining with just "ruby-1.9.2-p136" and "ruby-1.9.2-p136@global" dirs (ruby-1.9.2-p136@greendog* are old and "rvm system" return nothing) ? Will I use "rm" command, or are there RVM embodied commands to cleanup a better way ? Is it possible cleanup the cache dir ?

Thanks in advance.
luca

Body:
... it turn out that some of the previous, not used refs, were just gemsets:

rvm gemset list
lsoave@ubuntu:~$ rvm gemset list

gemsets for ruby-1.9.2-p136 (found in /home/lsoave/.rvm/gems/ruby-1.9.2-p136)
global
greendog
greendog2
greendog99

lsoave@ubuntu:~$

which I removed like following:

lsoave@ubuntu:~$ rvm gemset delete greendog99
Are you SURE you wish to remove the entire gemset directory 'greendog99' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog99)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$ rvm gemset delete greendog2
Are you SURE you wish to remove the entire gemset directory 'greendog2' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog2)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$ rvm gemset delete greendog
Are you SURE you wish to remove the entire gemset directory 'greendog' (/home/lsoave/.rvm/gems/ruby-1.9.2-p136@greendog)?
(anything other than 'yes' will cancel) > yes
lsoave@ubuntu:~$

than I made a backup of one of the old 'lib' ( just in case ... ):

lsoave@ubuntu:~/.rvm/gems$ tar zcvf ruby-1.8.7-p302.gz ./ruby-1.8.7-p302

and removed the relative directory as a previous comment talk, with stuartc:

lsoave@ubuntu:~/.rvm/gems$ rm -rf ./ruby-1.8.7-p302

now back to work.

I'll wait a couple of days, looking for everything is right ...


问:
Is Date.now() okay to use, will it reach a number that JS can't handle?
Is there a possibility that Date.now() will start returning numbers in scientific notation?

It can possibly be a bug like Y2K. Is it safe to use it? Will it cross the biggest
number possible in JavaScript?

答:
That's not going to be a concern of yours:

Number.MAX_SAFE_INTEGER to Date:

Wed 12 Oct 287396

Relative: In 287.396 years

On the other hand

The actual range of times supported by ECMAScript Date objects is slightly smaller: exactly –100,000,000 days to 100,000,000 days measured relative to midnight at the beginning of 01 January, 1970 UTC.

However unrelated, there is the year 2038 problem which might set you off, but as mentioned is not related to JS

The Year 2038 problem (also called Y2038 or Y2k38 or Unix Y2K) relates to representing time in many digital systems as the number of seconds passed since 00:00:00 UTC on 1 January 1970 and storing it as a signed 32-bit integer. Such implementations cannot encode times after 03:14:07 UTC on 19 January 2038. Similar to the Y2K problem, the Year 2038 problem is caused by insufficient capacity used to represent time.

Date is funny :)


问:
How to undo a revert action to move back to my previous commit in git
I ran the revert command to undo my previous commit but then realized I had made a mistake.

How can I undo my revert action and restore to my previously committed state?

Example:

(1) In my project, I have two files A and B and then I committed the changes and push the changes to GitHub.

(2) I added file C and committed changes but didn't push the changes to Github.

(3) I ran the Revert which removed the file C from my project but it was a mistake.

How can I undo my last action of Revert to bring back the file C, which was committed and then reverted on my local repo but never pushed to Github?

答:
'git reflog' to list last few HEADS.
Choose commit id of the change you wanted.
git reset to that commit id.</p>


问:
Is there a way to get an array of the values of the properties in an object?
I have an object that stores URLs. In the example below the object has just 4 properties but in my case there are more so I want to know is there a way to do this with more elegant.

public final class MyObject: NSObject {

  private let firstURL: URL
  private let secondURL: URL
  private let thirdURL: URL
  private let fourthURL: URL

  public func values() -> [URL] {
    return // <--- I need to return URLs from properties like [firstURL, secondURL, thirdURL, fourthURL]
  }
}
```

<p>I've found an extension of <code>NSObject</code> to return an array of the name of the properties as a <code>String</code>.</p>

<p>Extension Source</p>

<pre class="lang-swift prettyprint-override"><code>
public extension NSObject {

  //
  // Retrieves an array of property names found on the current object
  // using Objective-C runtime functions for introspection:
  // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
  //
  func propertyNames() -> Array<String> {
    var results: Array<String> = []

    // retrieve the properties via the class_copyPropertyList function
    var count: UInt32 = 0
    let myClass: AnyClass = classForCoder
    let properties = class_copyPropertyList(myClass, &count)

    // iterate each objc_property_t struct
    for i in 0..<count {
      if let property = properties?[Int(i)] {
        // retrieve the property name by calling property_getName function
        let cname = property_getName(property)

        // covert the c string into a Swift string
        results.append(cname.debugDescription)
      }
    }

    // release objc_property_t structs
    free(properties)

    return results
  }
}
</code>```

But it returns array of the property names like ["firstURL", "secondURL", "thirdURL", "fourthURL"]. I want to return values instead of names.

答:
You can use Mirror and iterate over all children:

```<code>struct Foo {
    let a: String
    let b: String
    let x: Int

    func propsAsArray() -> [Any] {
        let mirror = Mirror(reflecting: self)
        return mirror.children.map { $0.value }
    }
}

let f = Foo(a: "foo", b: "bar", x: 42)
print(f.propsAsArray()) // ["foo", "bar", 42]
</code>```

Body:
I have an object that stores URLs. In the example below the object has just 4 properties but in my case there are more so I want to know is there a way to do this with more elegant.

public final class MyObject: NSObject {

  private let firstURL: URL
  private let secondURL: URL
  private let thirdURL: URL
  private let fourthURL: URL

  public func values() -> [URL] {
    return // <--- I need to return URLs from properties like [firstURL, secondURL, thirdURL, fourthURL]
  }
}

I've found an extension of NSObject to return an array of the name of the properties as a String.

Extension Source

public extension NSObject {

  //
  // Retrieves an array of property names found on the current object
  // using Objective-C runtime functions for introspection:
  // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
  //
  func propertyNames() -> Array<String> {
    var results: Array<String> = []

    // retrieve the properties via the class_copyPropertyList function
    var count: UInt32 = 0
    let myClass: AnyClass = classForCoder
    let properties = class_copyPropertyList(myClass, &count)

    // iterate each objc_property_t struct
    for i in 0..<count {
      if let property = properties?[Int(i)] {
        // retrieve the property name by calling property_getName function
        let cname = property_getName(property)

        // covert the c string into a Swift string
        results.append(cname.debugDescription)
      }
    }

    // release objc_property_t structs
    free(properties)

    return results
  }
}

But it returns array of the property names like ["firstURL", "secondURL", "thirdURL", "fourthURL"]. I want to return values instead of names.

Body:
You can use Mirror and iterate over all children:

struct Foo {
    let a: String
    let b: String
    let x: Int

    func propsAsArray() -> [Any] {
        let mirror = Mirror(reflecting: self)
        return mirror.children.map { $0.value }
    }
}

let f = Foo(a: "foo", b: "bar", x: 42)
print(f.propsAsArray()) // ["foo", "bar", 42]


问:
counting in for() count.forEach(i => i.innerHTML = +1+thx)?
I'm a beginner when it comes to Javascript. With click, the number should increase by one.
I don't want to use tag IDs here, but as if made in class

let clicks = document.querySelectorAll('.CounterTrigger'); // IE8
let count = Array.from(document.querySelectorAll('.CounterCount'));
let please = Array.from(document.querySelectorAll('.CounterPlease'));

let pleaseTxt = " Clicks! Please click!";
let i;
let thx = " Clicks! Thanks!";

please.forEach(i => i.innerHTML = pleaseTxt);

for (let i = 0; i < clicks.length; i++) {
  clicks[i].onclick = function () {

        let plus = +1;
        count.forEach(i => i.innerHTML = +plus+thx);
        please.forEach(i => i.innerHTML = "");
    }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="Counter">
  <button class="CounterTrigger">Button</button>
  <span class="CounterCount">1</span>
 <span class="CounterPlease"></span>
</div></code>```

What is wrong with these lines?

let plus = +1;
count.forEach(i => i.innerHTML = +plus+thx);
```

expected output before click

1 Clicks! Please click!

expected output after click

2 Clicks! Thanks!!

Here the Example Code on JSFiddle

答:
You can retrieve number value from your innerHTML with i.innerHTML.match(/\d+/)[0]. Use + as prefix so it will convert it to number. Then add 1 and append thx.

All you need to update is one line as count.forEach(i => i.innerHTML = ((+i.innerHTML.match(/\d+/)[0])+1) + thx);.

You can check output below.

let clicks = document.querySelectorAll('.CounterTrigger'); // IE8
let count = Array.from(document.querySelectorAll('.CounterCount'));
let please = Array.from(document.querySelectorAll('.CounterPlease'));

let pleaseTxt = " Clicks! Please click!";
let i;
let thx = " Clicks! Thanks!";

please.forEach(i => i.innerHTML = pleaseTxt);

for (let i = 0; i < clicks.length; i++) {
  clicks[i].onclick = function () {
        count.forEach(i => i.innerHTML = ((+i.innerHTML.match(/\d+/)[0])+1) + thx);
        please.forEach(i => i.innerHTML = "");
    }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="Counter">
  <button class="CounterTrigger">Button</button>
  <span class="CounterCount">1</span>
    <span class="CounterPlease"></span>
</div></code>```

Body:
I'm a beginner when it comes to Javascript. With click, the number should increase by one.
I don't want to use tag IDs here, but as if made in class

let clicks = document.querySelectorAll('.CounterTrigger'); // IE8
let count = Array.from(document.querySelectorAll('.CounterCount'));
let please = Array.from(document.querySelectorAll('.CounterPlease'));

let pleaseTxt = " Clicks! Please click!";
let i;
let thx = " Clicks! Thanks!";

please.forEach(i => i.innerHTML = pleaseTxt);

for (let i = 0; i < clicks.length; i++) {
  clicks[i].onclick = function () {

        let plus = +1;
        count.forEach(i => i.innerHTML = +plus+thx);
        please.forEach(i => i.innerHTML = "");
    }
}

  <button class="CounterTrigger">Button</button>
  1

What is wrong with these lines?

let plus = +1;
count.forEach(i => i.innerHTML = +plus+thx);

expected output before click

1 Clicks! Please click!

expected output after click

2 Clicks! Thanks!!

Here the Example Code on JSFiddle

Body:
You can retrieve number value from your innerHTML with i.innerHTML.match(/\d+/)[0]. Use + as prefix so it will convert it to number. Then add 1 and append thx.

All you need to update is one line as count.forEach(i => i.innerHTML = ((+i.innerHTML.match(/\d+/)[0])+1) + thx);.

You can check output below.

let clicks = document.querySelectorAll('.CounterTrigger'); // IE8
let count = Array.from(document.querySelectorAll('.CounterCount'));
let please = Array.from(document.querySelectorAll('.CounterPlease'));

let pleaseTxt = " Clicks! Please click!";
let i;
let thx = " Clicks! Thanks!";

please.forEach(i => i.innerHTML = pleaseTxt);

for (let i = 0; i < clicks.length; i++) {
  clicks[i].onclick = function () {
        count.forEach(i => i.innerHTML = ((+i.innerHTML.match(/\d+/)[0])+1) + thx);
        please.forEach(i => i.innerHTML = "");
    }
}

<div class="Counter">
  <button class="CounterTrigger">Button</button>
  <span class="CounterCount">1</span>
    <span class="CounterPlease"></span>
</div>


问:
Custom view with TextView and EditText doesn't work with android:fastForward
I created a custom view that has the following layout:

```<code><androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hintTextLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/hintTextInputText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        tools:text="hint"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <ImageView
        android:id="@+id/hintTextInputInputIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/hint_text_input_input_icon_margin_end"
        android:scaleType="centerInside"
        tools:src="@drawable/ic_eyeopen"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/hintTextInputEditText"
        app:layout_constraintBottom_toBottomOf="@+id/hintTextInputEditText"/>

    <TextView
        android:id="@+id/hintTextInputPlaceholder"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:lines="1"
        android:gravity="top"
        android:layout_marginEnd="@dimen/hint_text_input_input_placeholder_margin_end"
        tools:text="placeholder"
        app:layout_constraintTop_toTopOf="@+id/hintTextInputEditText"
        app:layout_constraintBottom_toBottomOf="@+id/hintTextInputEditText"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/hintTextInputInputIcon"/>

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/hintTextInputEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toStartOf="@+id/hintTextInputInputIcon"
        app:layout_constraintTop_toBottomOf="@+id/hintTextInputText"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginTop="@dimen/hint_text_input_input_margin_top"
        android:layout_marginEnd="@dimen/hint_text_input_input_margin_end"
        android:lines="1"
        android:background="@null"
        android:textCursorDrawable="@null"
        tools:text="edit"/
</androidx.constraintlayout.widget.ConstraintLayout>
</code>```

Also I defined the view in attrs.xml file:

```<code><declare-styleable name="HintTextInputView">
    <attr name="hint_text_size" format="dimension"/>
    <attr name="input_text_size" format="dimension"/>

    <attr name="hint_text_color" format="color"/>
    <attr name="input_text_color" format="color"/>
    <attr name="input_hint_text_color" format="color"/>
    <attr name="android:text"/>
    <attr name="android:nextFocusForward"/>

    <attr name="hint_text" format="string"/>
    <attr name="input_hint_text" format="string"/>

    <attr name="hint_text_style" format="enum">
        <enum name="normal" value="0"/>
        <enum name="bold" value="1"/>
        <enum name="italic" value="2"/>
    </attr>
    <attr name="input_text_style" format="enum">
        <enum name="normal" value="0"/>
        <enum name="bold" value="1"/>
        <enum name="italic" value="2"/>
    </attr>

    <attr name="enable_input_icon" format="boolean"/>
    <attr name="input_icon_enabled_image" format="integer"/>
    <attr name="input_icon_disabled_image" format="integer"/>
    <attr name="input_icon_tint_color" format="color"/>

    <attr name="enable_borders" format="boolean"/>
    <attr name="border_color" format="color"/>
    <attr name="focused_border_color" format="color"/>
    <attr name="border_radius" format="dimension"/>
    <attr name="android:inputType"/>
</declare-styleable>
</code>```

I'm also setting the attributes programmatically to the EdditText when they're defined at any layout:

```<code>private fun TextView.setFocusForward(attributes: TypedArray) {
    attributes.getResourceId(R.styleable.HintTextInputView_android_nextFocusForward, 0).let {
        if (it != 0) {
            this.nextFocusForwardId = it
        }
    }
}
</code>```

This is what the XML that has the views looks like:

```<code><br.sis.smb.base.ui.HintTextInputView
    android:id="@+id/name"
    style="@style/DefaultEditTextBorder"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/register_company_margin_start_end"
    android:layout_marginTop="@dimen/register_company_edittext_top_margin_top"
    android:layout_marginEnd="@dimen/register_company_margin_space_between"
    android:text="@={viewModel.name}"
    android:nextFocusForward="@id/firstNickname"
    app:hint_text="@string/register_edittext_name_hint"
    app:input_hint_text="@string/register_edittext_name"
    app:layout_constraintEnd_toStartOf="@+id/firstNickname"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.4"
/>

<br.sis.smb.base.ui.HintTextInputView
    android:id="@+id/firstNickname"
    style="@style/DefaultEditTextBorder"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/register_company_margin_space_between"
    android:layout_marginEnd="@dimen/register_company_margin_start_end"
    android:imeOptions="actionNext"
    android:nextFocusForward="@+id/secondNickname"
    android:text="@={viewModel.nickname}"
    app:hint_text="@string/register_edittext_nickname_first"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/name"
    app:layout_constraintTop_toTopOf="@+id/name"
    app:layout_constraintVertical_bias="0.4"
/>
</code>```

The problem is that the attribute android:nextFocusForward doesn't work at all. Even though I defined like above code, when I touch on next on my device's keyboard it doesn't lead to the right custom view but to the below custom view.

答: Make sure you have not been setting inputType:'none' or '0x00000000'

Body:
I created a custom view that has the following layout:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/hintTextLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:id="@+id/hintTextInputText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        tools:text="hint"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <ImageView
        android:id="@+id/hintTextInputInputIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="@dimen/hint_text_input_input_icon_margin_end"
        android:scaleType="centerInside"
        tools:src="@drawable/ic_eyeopen"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/hintTextInputEditText"
        app:layout_constraintBottom_toBottomOf="@+id/hintTextInputEditText"/>

    <TextView
        android:id="@+id/hintTextInputPlaceholder"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:lines="1"
        android:gravity="top"
        android:layout_marginEnd="@dimen/hint_text_input_input_placeholder_margin_end"
        tools:text="placeholder"
        app:layout_constraintTop_toTopOf="@+id/hintTextInputEditText"
        app:layout_constraintBottom_toBottomOf="@+id/hintTextInputEditText"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/hintTextInputInputIcon"/>

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/hintTextInputEditText"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toStartOf="@+id/hintTextInputInputIcon"
        app:layout_constraintTop_toBottomOf="@+id/hintTextInputText"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginTop="@dimen/hint_text_input_input_margin_top"
        android:layout_marginEnd="@dimen/hint_text_input_input_margin_end"
        android:lines="1"
        android:background="@null"
        android:textCursorDrawable="@null"
        tools:text="edit"/
</androidx.constraintlayout.widget.ConstraintLayout>

Also I defined the view in attrs.xml file:

<declare-styleable name="HintTextInputView">
    <attr name="hint_text_size" format="dimension"/>
    <attr name="input_text_size" format="dimension"/>

    <attr name="hint_text_color" format="color"/>
    <attr name="input_text_color" format="color"/>
    <attr name="input_hint_text_color" format="color"/>
    <attr name="android:text"/>
    <attr name="android:nextFocusForward"/>

    <attr name="hint_text" format="string"/>
    <attr name="input_hint_text" format="string"/>

    <attr name="hint_text_style" format="enum">
        <enum name="normal" value="0"/>
        <enum name="bold" value="1"/>
        <enum name="italic" value="2"/>
    </attr>
    <attr name="input_text_style" format="enum">
        <enum name="normal" value="0"/>
        <enum name="bold" value="1"/>
        <enum name="italic" value="2"/>
    </attr>

    <attr name="enable_input_icon" format="boolean"/>
    <attr name="input_icon_enabled_image" format="integer"/>
    <attr name="input_icon_disabled_image" format="integer"/>
    <attr name="input_icon_tint_color" format="color"/>

    <attr name="enable_borders" format="boolean"/>
    <attr name="border_color" format="color"/>
    <attr name="focused_border_color" format="color"/>
    <attr name="border_radius" format="dimension"/>
    <attr name="android:inputType"/>
</declare-styleable>

I'm also setting the attributes programmatically to the EdditText when they're defined at any layout:

private fun TextView.setFocusForward(attributes: TypedArray) {
    attributes.getResourceId(R.styleable.HintTextInputView_android_nextFocusForward, 0).let {
        if (it != 0) {
            this.nextFocusForwardId = it
        }
    }
}

This is what the XML that has the views looks like:

<br.sis.smb.base.ui.HintTextInputView
    android:id="@+id/name"
    style="@style/DefaultEditTextBorder"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/register_company_margin_start_end"
    android:layout_marginTop="@dimen/register_company_edittext_top_margin_top"
    android:layout_marginEnd="@dimen/register_company_margin_space_between"
    android:text="@={viewModel.name}"
    android:nextFocusForward="@id/firstNickname"
    app:hint_text="@string/register_edittext_name_hint"
    app:input_hint_text="@string/register_edittext_name"
    app:layout_constraintEnd_toStartOf="@+id/firstNickname"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.4"
/>

<br.sis.smb.base.ui.HintTextInputView
    android:id="@+id/firstNickname"
    style="@style/DefaultEditTextBorder"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/register_company_margin_space_between"
    android:layout_marginEnd="@dimen/register_company_margin_start_end"
    android:imeOptions="actionNext"
    android:nextFocusForward="@+id/secondNickname"
    android:text="@={viewModel.nickname}"
    app:hint_text="@string/register_edittext_nickname_first"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/name"
    app:layout_constraintTop_toTopOf="@+id/name"
    app:layout_constraintVertical_bias="0.4"
/>

The problem is that the attribute android:nextFocusForward doesn't work at all. Even though I defined like above code, when I touch on next on my device's keyboard it doesn't lead to the right custom view but to the below custom view.


问:
Use Vlookup across multiple sheets in Google sheets
I am using Vlookup formula to lookup data in V5 sheet of another google sheet, and it works perfectly. There is another tab named V7 in same google sheet which has similar data but column alignment is different. I want my vlookup function to lookup in the V7 tab as well.

```<code>=ARRAYFORMULA(If(A2:A="","",VLOOKUP(A2:A, {IMPORTRANGE("1MNRMKGkC-c0COugUWpXOe5OxJXfmdXGboxAPhf5SaLA", "V5!T3:T"), IMPORTRANGE("1MNRMKGkC-c0COugUWpXOe5OxJXfmdXGboxAPhf5SaLA", "V5!D3:D")} ,2,0)))
</code>```

This is my current formula, can I somehow modify the formula to include V7 tab as well, assume the column ordering of V7 to be the same as V5. I can modify that later.

Thanks a lot in advance

答:
If the data is spread across two spreadsheets you will need two vlookups simultaneously. You can do this by using the IFERROR or  IFNA formulas. The idea is to check if the 1st vlookup returns nothing and use the 2nd vlookup in that case.

I have put a simple examples below. Hope it helps.

```<code>=IFNA(VLOOKUP(1000,A1:B10,2,FALSE),VLOOKUP(1000,A11:B20,2,FALSE))

=IFERROR(VLOOKUP(1000,A1:B10,2,FALSE),VLOOKUP(1000,A11:B20,2,FALSE))

</code>```

Body:
I am using Vlookup formula to lookup data in V5 sheet of another google sheet, and it works perfectly. There is another tab named V7 in same google sheet which has similar data but column alignment is different. I want my vlookup function to lookup in the V7 tab as well.

=ARRAYFORMULA(If(A2:A="","",VLOOKUP(A2:A, {IMPORTRANGE("1MNRMKGkC-c0COugUWpXOe5OxJXfmdXGboxAPhf5SaLA", "V5!T3:T"), IMPORTRANGE("1MNRMKGkC-c0COugUWpXOe5OxJXfmdXGboxAPhf5SaLA", "V5!D3:D")} ,2,0)))

This is my current formula, can I somehow modify the formula to include V7 tab as well, assume the column ordering of V7 to be the same as V5. I can modify that later.

Thanks a lot in advance

Body:
If the data is spread across two spreadsheets you will need two vlookups simultaneously. You can do this by using the IFERROR or  IFNA formulas. The idea is to check if the 1st vlookup returns nothing and use the 2nd vlookup in that case.

I have put a simple examples below. Hope it helps.

=IFNA(VLOOKUP(1000,A1:B10,2,FALSE),VLOOKUP(1000,A11:B20,2,FALSE))

=IFERROR(VLOOKUP(1000,A1:B10,2,FALSE),VLOOKUP(1000,A11:B20,2,FALSE))


问:
python automatically pass variables to function
I have code like this

```<code>def function3():
    print(text)

def function2():
    text = "Hello"
    function3()

def function1():
    text = "World"
    function3()
</code>```

Like you see i want to automatically pass variable from function2 and function1 to function3. This variable should be visible only on this three functions (so I can't set it global). Also I don't want to pass this variable every time between round brackets, because I will use function3 thousands of times.
Is there a something like keyword use in php?

```<code>function3() use (text):
    print(text)
</code>```

答:
I'm not 100% sure I now what you want to do (don't know php), but is it just something like this?</p>

```<code>def function3(text):
    print(text)

def function2():
    text = "Hello"
    function3(text)

def function1():
    text = "World"
    function3(text)
</code>```

Body:
I have code like this

def function3():
    print(text)

def function2():
    text = "Hello"
    function3()

def function1():
    text = "World"
    function3()

Like you see i want to automatically pass variable from function2 and function1 to function3. This variable should be visible only on this three functions (so I can't set it global). Also I don't want to pass this variable every time between round brackets, because I will use function3 thousands of times.
Is there a something like keyword use in php?

function3() use (text):
    print(text)

Body:
I'm not 100% sure I now what you want to do (don't know php), but is it just something like this?

def function3(text):
    print(text)

def function2():
    text = "Hello"
    function3(text)

def function1():
    text = "World"
    function3(text)


问:
Anyone got a Date of Birth Validation Attribute for C# MVC?
Someone must have written this before :-)

I need a validation attribute for date of birth that checks if the date is within a specific range - i.e. the user hasn't inputted a date that hasn't yet happened or is 150 years in the past.

Thanks for any pointers!

答:
I made a Validate class where I can validate data. In my class I have 2 methods for validating date of birth: 1 that takes a string parameter and the other takes a date parameter.
Here is the basic method:

```<code>public static bool DateOfBirthDate(DateTime dtDOB) //assumes a valid date string
{
    int age = GetAge(dtDOB);
    if (age < 0 || age > 150) { return false; }
    return true;
}
</code>```

Here is the full class:

```<code>using System;
using System.Collections.Generic;
using System.Text;

namespace YourNamespaceHere
{
    public class Validate
    {
        public static bool DateOfBirthString(string dob) //assumes a valid date string
        {
            DateTime dtDOB = DateTime.Parse(dob);
            return DateOfBirthDate(dtDOB);
        }

        public static bool DateOfBirthDate(DateTime dtDOB) //assumes a valid date
        {
            int age = GetAge(dtDOB);
            if (age < 0 || age > 150) { return false; }
            return true;
        }

        public static int GetAge(DateTime birthDate)
        {
            DateTime today = DateTime.Now;
            int age = today.Year - birthDate.Year;
            if (today.Month < birthDate.Month || (today.Month == birthDate.Month && today.Day < birthDate.Day)) { age--; }
            return age;
        }

    }
}
</code>```

Here is how I'm calling the method in my Xamarin.Forms app:

```<code>bool valid = Validate.DateOfBirthDate(pickerDOB.Date);
</code>```

Where pickerDOB is a date picker on my form. This makes it easy to call the validation methods from anywhere and validate a string or DateTime object.

ContentLicense: CC BY-SA 2.5

Body:
I made a Validate class where I can validate data. In my class I have 2 methods for validating date of birth: 1 that takes a string parameter and the other takes a date parameter.
Here is the basic method:

public static bool DateOfBirthDate(DateTime dtDOB) //assumes a valid date string
{
    int age = GetAge(dtDOB);
    if (age < 0 || age > 150) { return false; }
    return true;
}

Here is the full class:

using System;
using System.Collections.Generic;
using System.Text;

namespace YourNamespaceHere
{
    public class Validate
    {
        public static bool DateOfBirthString(string dob) //assumes a valid date string
        {
            DateTime dtDOB = DateTime.Parse(dob);
            return DateOfBirthDate(dtDOB);
        }

        public static bool DateOfBirthDate(DateTime dtDOB) //assumes a valid date
        {
            int age = GetAge(dtDOB);
            if (age < 0 || age > 150) { return false; }
            return true;
        }

        public static int GetAge(DateTime birthDate)
        {
            DateTime today = DateTime.Now;
            int age = today.Year - birthDate.Year;
            if (today.Month < birthDate.Month || (today.Month == birthDate.Month && today.Day < birthDate.Day)) { age--; }
            return age;
        }

    }
}

Here is how I'm calling the method in my Xamarin.Forms app:

bool valid = Validate.DateOfBirthDate(pickerDOB.Date);

Where pickerDOB is a date picker on my form. This makes it easy to call the validation methods from anywhere and validate a string or DateTime object.


答:
Dangit, I did something terribly wrong, please tell me git has a magic time machine!?!

git reflog
# you will see a list of every thing you've
# done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything git reset HEAD@{index}
# magic time machine
```

You can use this to get back stuff you accidentally deleted, or just
  to remove some stuff you tried that broke the repo, or to recover
  after a bad merge, or just to go back to a time when things actually
  worked. I use reflog A LOT. Mega hat tip to the many many many many
  many people who suggested adding it!

Source: https://dangitgit.com/en#magic-time-machine

Title: How to undo a revert action to move back to my previous commit in git

Body:
I ran the revert command to undo my previous commit but then realized I had made a mistake.

How can I undo my revert action and restore to my previously committed state?

Example:

(1) In my project, I have two files A and B and then I committed the changes and push the changes to GitHub.

(2) I added file C and committed changes but didn't push the changes to Github.

(3) I ran the Revert which removed the file C from my project but it was a mistake.

How can I undo my last action of Revert to bring back the file C, which was committed and then reverted on my local repo but never pushed to Github?

Body:
Dangit, I did something terribly wrong, please tell me git has a magic time machine!?!

git reflog
# you will see a list of every thing you've
# done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything git reset HEAD@{index}
# magic time machine

You can use this to get back stuff you accidentally deleted, or just
  to remove some stuff you tried that broke the repo, or to recover
  after a bad merge, or just to go back to a time when things actually
  worked. I use reflog A LOT. Mega hat tip to the many many many many
  many people who suggested adding it!

Source: https://dangitgit.com/en#magic-time-machine


答:
There are two aspects regarding your question, first is the usage of the +:

The operator + can be a bit tricky in Javascript. At the same time it is used to concatenate strings, it is also use to cast a variable to Number. A good example is, if you have a string "1" and you apply the +, like +"1" this becomes 1, a Number instead of its original String type. If you write 1 + "7" this becomes "17", as concatenation is applied instead.

Secondly is the problem you reported. If I got right, your idea is to increase the counter every time a button is clicked. However, if you check the code, every time a button is clicked, you have an onclick event which runs the anonymous function.

clicks[i].onclick = function () {
    let plus = +1;
    count.forEach(i => i.innerHTML = +plus+thx);
    please.forEach(i => i.innerHTML = "");
}
```

<p>If you check carefully, on each click <code>plus</code> variable is always initiated with <code>1</code>. In order to increase this value on every click, you have to find a strategy to modify its value inside the click event instead of always declaring it. </p>

<p>The simplest way would be to declare the variable outside the function, e.g.:</p>

<pre class="lang-js prettyprint-override"><code>let plus = 1;
clicks[i].onclick = function () {
    count.forEach(i => i.innerHTML = plus + thx);
    please.forEach(i => i.innerHTML = "");
}
</code>```

Depending on the problem you can also to track multiple plus values using an array or other data structure which fits best, but the idea behind is the same: you need to access to the current value, increment it and store it for the next usage.

Title: counting in for() count.forEach(i => i.innerHTML = +1+thx)?

Body:
There are two aspects regarding your question, first is the usage of the +:

The operator + can be a bit tricky in Javascript. At the same time it is used to concatenate strings, it is also use to cast a variable to Number. A good example is, if you have a string "1" and you apply the +, like +"1" this becomes 1, a Number instead of its original String type. If you write 1 + "7" this becomes "17", as concatenation is applied instead.

Secondly is the problem you reported. If I got right, your idea is to increase the counter every time a button is clicked. However, if you check the code, every time a button is clicked, you have an onclick event which runs the anonymous function.

clicks[i].onclick = function () {
    let plus = +1;
    count.forEach(i => i.innerHTML = +plus+thx);
    please.forEach(i => i.innerHTML = "");
}

If you check carefully, on each click plus variable is always initiated with 1. In order to increase this value on every click, you have to find a strategy to modify its value inside the click event instead of always declaring it.

The simplest way would be to declare the variable outside the function, e.g.:

let plus = 1;
clicks[i].onclick = function () {
    count.forEach(i => i.innerHTML = plus + thx);
    please.forEach(i => i.innerHTML = "");
}

Depending on the problem you can also to track multiple plus values using an array or other data structure which fits best, but the idea behind is the same: you need to access to the current value, increment it and store it for the next usage.


问:
Babel useBuiltIns: 'usage', failing with core-js 3
I have recently started working with Webpack, and I am encountering an error with a build related to my Babel and Core js (v3) settings.

The error I am getting is the following:
Module not found: Error: Can't resolve 'core-js/modules/es.string.replace' in 'C:\path\'
 @ file.jsx

This is on a React project, and the function I am trying to use is on one of my jsx components.

My package.json looks like this:

```<code>    "devDependencies": {
        "@babel/cli": "^7.8.4",
        "@babel/core": "^7.9.6",
        "@babel/plugin-proposal-class-properties": "^7.8.3",
        "@babel/preset-env": "^7.9.6",
        "@babel/preset-react": "^7.9.4",
        "@babel/preset-typescript": "^7.9.0",
        "@babel/runtime-corejs3": "^7.10.1",
        "autoprefixer": "^9.8.0",
        "babel-loader": "^8.1.0",
        "core-js": "^3.6.5",
        "css-loader": "^3.5.3",
        "cssnano": "^4.1.10",
        "less-loader": "^6.1.0",
        "mini-css-extract-plugin": "^0.9.0",
        "node-sass": "^4.14.1",
        "optimize-css-assets-webpack-plugin": "^5.0.3",
        "postcss-loader": "^3.0.0",
        "resolve-url-loader": "^3.1.1",
        "sass-loader": "^8.0.2",
        "terser-webpack-plugin": "^3.0.1",
        "webpack": "^4.43.0",
        "webpack-cli": "^3.3.11",
        "webpack-manifest-plugin": "^2.2.0",
        "webpack-merge": "^4.2.2"
    },
    "dependencies": {
        "@babel/polyfill": "^7.8.7",
        "clean-webpack-plugin": "^3.0.0",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "regenerator-runtime": "^0.13.5"
    }
</code>```

And my babel settings looks like this:

```<code>    test: /(\.jsx|\.js|\.ts|\.tsx)$/,
        exclude: /(node_modules)/,
        use: {
            loader: 'babel-loader',
            options: {
                cacheDirectory: true,
                sourceType: 'unambiguous',
                presets: [
                    [
                        '@babel/preset-env', {
                            modules: false,
                            corejs:  {
                                version: 3.6,
                                proposals: true
                            },
                            useBuiltIns: 'usage',
                            targets: {
                                browsers: browserList,
                            },
                        }
                    ],
                    '@babel/preset-typescript',
                    '@babel/preset-react'
                ],
                plugins: [
                    '@babel/plugin-proposal-class-properties'
                ],
            },
        },
</code>```

In my searches, I have encountered a large number of people suffering a similar problem, but I have not yet been able to find a solution to the problem.

答:
After a couple of days of searching for an answer to this problem, I finally stumbled upon an answer on this Stack overflow post: https://stackoverflow.com/a/61446111/1820888 - this was my exact problem. To paraphrase the answer here for anybody who encounters this problem:

My file structure was incredibly complex - and the script files that were being transpiled were well outside the remit of my bundle set up.

Adding the following setting resolved the error - it explicitly defines where the node_modules package sits on your project, so it does not matter where in your file structure your files sit, they will be able to interpret the node_modules:

```<code>module.exports = {
    resolve: {
      modules: [
        path.resolve(__dirname, "node_modules")
      ],
  ...
</code>```

Body:
I have recently started working with Webpack, and I am encountering an error with a build related to my Babel and Core js (v3) settings.

The error I am getting is the following:
Module not found: Error: Can't resolve 'core-js/modules/es.string.replace' in 'C:\path\'
 @ file.jsx

This is on a React project, and the function I am trying to use is on one of my jsx components.

My package.json looks like this:

    "devDependencies": {
        "@babel/cli": "^7.8.4",
        "@babel/core": "^7.9.6",
        "@babel/plugin-proposal-class-properties": "^7.8.3",
        "@babel/preset-env": "^7.9.6",
        "@babel/preset-react": "^7.9.4",
        "@babel/preset-typescript": "^7.9.0",
        "@babel/runtime-corejs3": "^7.10.1",
        "autoprefixer": "^9.8.0",
        "babel-loader": "^8.1.0",
        "core-js": "^3.6.5",
        "css-loader": "^3.5.3",
        "cssnano": "^4.1.10",
        "less-loader": "^6.1.0",
        "mini-css-extract-plugin": "^0.9.0",
        "node-sass": "^4.14.1",
        "optimize-css-assets-webpack-plugin": "^5.0.3",
        "postcss-loader": "^3.0.0",
        "resolve-url-loader": "^3.1.1",
        "sass-loader": "^8.0.2",
        "terser-webpack-plugin": "^3.0.1",
        "webpack": "^4.43.0",
        "webpack-cli": "^3.3.11",
        "webpack-manifest-plugin": "^2.2.0",
        "webpack-merge": "^4.2.2"
    },
    "dependencies": {
        "@babel/polyfill": "^7.8.7",
        "clean-webpack-plugin": "^3.0.0",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "regenerator-runtime": "^0.13.5"
    }

And my babel settings looks like this:

    test: /(\.jsx|\.js|\.ts|\.tsx)$/,
        exclude: /(node_modules)/,
        use: {
            loader: 'babel-loader',
            options: {
                cacheDirectory: true,
                sourceType: 'unambiguous',
                presets: [
                    [
                        '@babel/preset-env', {
                            modules: false,
                            corejs:  {
                                version: 3.6,
                                proposals: true
                            },
                            useBuiltIns: 'usage',
                            targets: {
                                browsers: browserList,
                            },
                        }
                    ],
                    '@babel/preset-typescript',
                    '@babel/preset-react'
                ],
                plugins: [
                    '@babel/plugin-proposal-class-properties'
                ],
            },
        },

In my searches, I have encountered a large number of people suffering a similar problem, but I have not yet been able to find a solution to the problem.

Body:
After a couple of days of searching for an answer to this problem, I finally stumbled upon an answer on this Stack overflow post: https://stackoverflow.com/a/61446111/1820888 - this was my exact problem. To paraphrase the answer here for anybody who encounters this problem:

My file structure was incredibly complex - and the script files that were being transpiled were well outside the remit of my bundle set up.

Adding the following setting resolved the error - it explicitly defines where the node_modules package sits on your project, so it does not matter where in your file structure your files sit, they will be able to interpret the node_modules:

module.exports = {
    resolve: {
      modules: [
        path.resolve(__dirname, "node_modules")
      ],
  ...


问:
how can I figure out the output of a c# project file (.csproj)
I have a very large .NET solution with hundreds of projects (all c#) how can I figure out which of the projects is the application project to set as the start up project.

I was thinking of grepping the csproj files for some keyword that indicates it's an executable.

Thank you

答: Under Project -> Project Build Order, scroll to the bottom and start searching backwards.  The appropriate project is likely near the bottom if most of the other projects are dependencies.</p>


问:
Error "rule graph is not stratifiable" in Grakn
I'm trying to insert this rule (data is masked):

```<code>when {
    $d isa person;
    $a isa animal;
    $r (role-1: $d, role-2: $a) isa relation-1, has attr $ds;
    not {$r1 (role-3: $d, role-4: $a) isa relation-2; };
    $ds > 0.5;
}, then {
    (role-3: $a, role-4: $d, role-5: $ds) isa relation-2;
};
</code>```

However I keep getting this structural validation error after I do commit. Please help

```<code>INVALID_ARGUMENT: InvalidKBException-A structural validation error has occurred. Please correct the [`1`] errors found.
The rule graph is not stratifiable - it contains following cycles with negation: [[[Base Type [RELATION_TYPE] - Id [V65648]  - Label [relation-2] ]]]
. Please check server logs for the stack trace.
All uncommitted data is cleared
</code>```

答:
Rules that cause loops - for example, where the conclusion is negated in the when clause - are not allowed in Grakn.

Here's an example to demonstrate why.

```<code>define
person sub entity, plays employee;
employment sub relation, relates employee;

there-are-no-unemployed sub rule,
when {
    $p isa person;
    not {
        (employee: $p) isa employment;
    };
}, then {
    (employee: $p) isa employment;
}
</code>```

If we have a person who is not in an employment relation, then they are in an employment relation. But now, we've contradicted the initial premise of the rule - that they were not in an employment relation. Thus, we have a logical contradiction.

Body:
I'm trying to insert this rule (data is masked):

when {
    $d isa person;
    $a isa animal;
    $r (role-1: $d, role-2: $a) isa relation-1, has attr $ds;
    not {$r1 (role-3: $d, role-4: $a) isa relation-2; };
    $ds > 0.5;
}, then {
    (role-3: $a, role-4: $d, role-5: $ds) isa relation-2;
};

However I keep getting this structural validation error after I do commit. Please help

INVALID_ARGUMENT: InvalidKBException-A structural validation error has occurred. Please correct the [`1`] errors found.
The rule graph is not stratifiable - it contains following cycles with negation: [[[Base Type [RELATION_TYPE] - Id [V65648]  - Label [relation-2] ]]]
. Please check server logs for the stack trace.
All uncommitted data is cleared

Body:
Rules that cause loops - for example, where the conclusion is negated in the when clause - are not allowed in Grakn.

Here's an example to demonstrate why.

define
person sub entity, plays employee;
employment sub relation, relates employee;

there-are-no-unemployed sub rule,
when {
    $p isa person;
    not {
        (employee: $p) isa employment;
    };
}, then {
    (employee: $p) isa employment;
}

If we have a person who is not in an employment relation, then they are in an employment relation. But now, we've contradicted the initial premise of the rule - that they were not in an employment relation. Thus, we have a logical contradiction.


问:
what is the best way to dynamically show/hide elements base on filtering an array in vuejs
I want to show/hide some elements base on a multiple select in vuejs, currently, I am using methods, I am curious to know is there a better way to do that? like computed properties? and how to do that?

the code sandbox example:

https://codesandbox.io/s/dynamic-filter-bp72r?file=/src/pages/Index.vue

```<code><q-select
      filled
      outlined
      dense
      multiple
      options-dense
      v-model="groupBy.fields"
      :options="reporterlocationGroupByFileldOptions"
      label="fields"
      emit-value
      map-options
      option-value="value"
      option-label="name"
      color="orange"
    />

<!-- elements to show/hide -->
    <q-select
      v-if="visibleFilter('province')"
      filled
      outlined
      dense
      options-dense
      v-model="filtering.provinceId"
      :options="provinceOptions"
      label="province"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="red"
    />
    <q-select
      v-if="visibleFilter('city')"
      filled
      outlined
      dense
      options-dense
      v-model="filtering.cityId"
      :options="cityOptions"
      label="city"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="green"
    />
</code>```

my current solution with methods:

```<code>data() {
  return {
    filtering: {
      provinceId: '',
      cityId: ''
    },
    reporterlocationGroupByFileldOptions: [
      { name: 'province', orderByDesc: 'province', value: 'province' },
      { name: 'city', orderByDesc: 'city', value: 'city' }
    ]
  }
},
methods: {
    visibleFilter(filterName) {
      var field = this.groupBy.fields.find(x => x === filterName)
      if (field) return true
      return false
    }
  }
</code>```

答:
You can possibly v-for over your field property in the groupBy property and move your options and v-model under the same object:

```<code>  filtering: {
    provinceId: {
     value: '',
     option: yourOptions
    },
    cityId: {
     value: '',
     option: yourOptions
    },
    sectionId: {
     value: '',
     option: yourOptions
    },
  },

   <div class="col-xs-12 q-mb-sx" v-for="field in groupBy.fields">
    <q-select
      :key="field"
      filled
      outlined
      dense
      options-dense
      v-model="filtering[field].value"
      :options="filtering[field].option"
      label="green"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="green"
    />
  </div>
</code>```

PS you have a typo in your code, "fileds" instead of "fields"

Body:
I want to show/hide some elements base on a multiple select in vuejs, currently, I am using methods, I am curious to know is there a better way to do that? like computed properties? and how to do that?

the code sandbox example:

https://codesandbox.io/s/dynamic-filter-bp72r?file=/src/pages/Index.vue

<q-select
      filled
      outlined
      dense
      multiple
      options-dense
      v-model="groupBy.fields"
      :options="reporterlocationGroupByFileldOptions"
      label="fields"
      emit-value
      map-options
      option-value="value"
      option-label="name"
      color="orange"
    />

    <q-select
      v-if="visibleFilter('province')"
      filled
      outlined
      dense
      options-dense
      v-model="filtering.provinceId"
      :options="provinceOptions"
      label="province"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="red"
    />
    <q-select
      v-if="visibleFilter('city')"
      filled
      outlined
      dense
      options-dense
      v-model="filtering.cityId"
      :options="cityOptions"
      label="city"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="green"
    />

my current solution with methods:

data() {
  return {
    filtering: {
      provinceId: '',
      cityId: ''
    },
    reporterlocationGroupByFileldOptions: [
      { name: 'province', orderByDesc: 'province', value: 'province' },
      { name: 'city', orderByDesc: 'city', value: 'city' }
    ]
  }
},
methods: {
    visibleFilter(filterName) {
      var field = this.groupBy.fields.find(x => x === filterName)
      if (field) return true
      return false
    }
  }

Body:
You can possibly v-for over your field property in the groupBy property and move your options and v-model under the same object:

  filtering: {
    provinceId: {
     value: '',
     option: yourOptions
    },
    cityId: {
     value: '',
     option: yourOptions
    },
    sectionId: {
     value: '',
     option: yourOptions
    },
  },

   <div class="col-xs-12 q-mb-sx" v-for="field in groupBy.fields">
    <q-select
      :key="field"
      filled
      outlined
      dense
      options-dense
      v-model="filtering[field].value"
      :options="filtering[field].option"
      label="green"
      emit-value
      map-options
      option-value="id"
      option-label="name"
      class="q-my-sm"
      color="green"
    />
  </div>

PS you have a typo in your code, "fileds" instead of "fields"