问:
How to insert the records into postgresql python?
I am trying to insert the pandas dataframe into postgresql table. What I am doing is inserting the record of dataframe loop by loop. I am recursively getting errors, Code is shown below:
Code:

```<code>    import psycopg2
    df = pd.read_csv('dataframe.csv')

    conn = psycopg2.connect(database = "postgres",
                            user = "postgres",
                            password = "12345",
                            host = "127.0.0.1",
                            port = "5432")

    cur = conn.cursor()

    for i in range(0,len(df)):
        cur.execute("INSERT INTO stock_market_forecasting_new (date, open, high, low, close) \
          VALUES (df['date'][i], df['open'][i], df['high'][i], df['low'][i], df['close'][i])")

    conn.commit()
    print("Records created successfully")
    conn.close()
</code>```

Error:

```<code>UndefinedColumn: column "df" does not exist
LINE 1: ..._new (date, open, high, low, close)       VALUES (df['date']...
</code>```

Edit1:

I am doing like this,

```<code>cur.execute("SELECT * from STOCK_MARKET_FORECASTING")
rows = cur.fetchall()
for row in rows:
    print(row)
print("Operation done successfully")
conn.close()
</code>```

Output giving:

```<code>('2021-12-07 00:00:00', 1.12837, 1.12846, 1.1279, 1.128)
('2021-12-07 01:00:00', 1.12799, 1.12827, 1.1276, 1.1282)
</code>```

Output which I want should be with column names:

```<code>       **Date          open      high     low   close**
    ('2021-12-07 00:00:00', 1.12837, 1.12846, 1.1279, 1.128)
    ('2021-12-07 01:00:00', 1.12799, 1.12827, 1.1276, 1.1282)
</code>```

答:
You didn't use a formatted string. It should be f"VALUES ({df['date'][i]}," ect depending on your data type, but that always leads to issues with quotation marks. I recommend inserting with tuples instead as seen in the documentation:

import psycopg2
df = pd.read_csv('dataframe.csv')

conn = psycopg2.connect(database = "postgres",
                        user = "postgres",
                        password = "12345",
                        host = "127.0.0.1",
                        port = "5432")

cur = conn.cursor()

for i in range(0 ,len(df)):
    values = (df['date'][i], df['open'][i], df['high'][i], df['low'][i], df['close'][i])
    cur.execute("INSERT INTO stock_market_forecasting_new (date, open, high, low, close) VALUES (%s, %s, %s, %s, %s)",
                values)

conn.commit()
print("Records created successfully")
conn.close()

```
<p>Alternatively, you could see if <code>df.to_sql()</code> (documentation) supports psycopg2 connections:</p>
<pre class="lang-py prettyprint-override"><code>df.to_sql('stock_market_forecasting_new', con=conn, if_exists='append', index=False)
</code>```

Body:
I am trying to insert the pandas dataframe into postgresql table. What I am doing is inserting the record of dataframe loop by loop. I am recursively getting errors, Code is shown below:
Code:

    import psycopg2
    df = pd.read_csv('dataframe.csv')

    conn = psycopg2.connect(database = "postgres",
                            user = "postgres",
                            password = "12345",
                            host = "127.0.0.1",
                            port = "5432")

    cur = conn.cursor()

    for i in range(0,len(df)):
        cur.execute("INSERT INTO stock_market_forecasting_new (date, open, high, low, close) \
          VALUES (df['date'][i], df['open'][i], df['high'][i], df['low'][i], df['close'][i])")

    conn.commit()
    print("Records created successfully")
    conn.close()

Error:

UndefinedColumn: column "df" does not exist
LINE 1: ..._new (date, open, high, low, close)       VALUES (df['date']...

Edit1:

I am doing like this,

cur.execute("SELECT * from STOCK_MARKET_FORECASTING")
rows = cur.fetchall()
for row in rows:
    print(row)
print("Operation done successfully")
conn.close()

Output giving:

('2021-12-07 00:00:00', 1.12837, 1.12846, 1.1279, 1.128)
('2021-12-07 01:00:00', 1.12799, 1.12827, 1.1276, 1.1282)

Output which I want should be with column names:

       **Date          open      high     low   close**
    ('2021-12-07 00:00:00', 1.12837, 1.12846, 1.1279, 1.128)
    ('2021-12-07 01:00:00', 1.12799, 1.12827, 1.1276, 1.1282)

Body:
You didn't use a formatted string. It should be f"VALUES ({df['date'][i]}," ect depending on your data type, but that always leads to issues with quotation marks. I recommend inserting with tuples instead as seen in the documentation:

import psycopg2
df = pd.read_csv('dataframe.csv')

conn = psycopg2.connect(database = "postgres",
                        user = "postgres",
                        password = "12345",
                        host = "127.0.0.1",
                        port = "5432")

cur = conn.cursor()

for i in range(0 ,len(df)):
    values = (df['date'][i], df['open'][i], df['high'][i], df['low'][i], df['close'][i])
    cur.execute("INSERT INTO stock_market_forecasting_new (date, open, high, low, close) VALUES (%s, %s, %s, %s, %s)",
                values)

conn.commit()
print("Records created successfully")
conn.close()

Alternatively, you could see if df.to_sql() (documentation) supports psycopg2 connections:

df.to_sql('stock_market_forecasting_new', con=conn, if_exists='append', index=False)


来源: stackexchange

问:
Control .fadeOut() with jQuery
I have the following jquery code:

```<code><script type="text/javascript">
$(function(){
    $('.gallery-slider li:gt(0)').hide();
    setInterval(function(){
      $('.gallery-slider li:first-child').fadeOut("slow")
         .next('.gallery-slider li').fadeIn(1000)
         .end().appendTo('.gallery-slider');},
      2000);
});
</script>
</code>```

The .fadeIn seems to be working, however the .fadeOut does not seem to be properly accepting the speed parameter. What do I need to change such that it will properly work? Thank you.

答:
Try this:</p>

```<code>$('.gallery-slider li:gt(0)').hide();
setInterval(function(){
    $('.gallery-slider li:first-child').fadeOut("slow", function() {
        $(this).next('.gallery-slider li').fadeIn(1000)
    }).appendTo('.gallery-slider');},
    2000);
</code>```

ContentLicense: CC BY-SA 3.0

Title: Control .fadeOut() with jQuery

Body:
I have the following jquery code:

The .fadeIn seems to be working, however the .fadeOut does not seem to be properly accepting the speed parameter. What do I need to change such that it will properly work? Thank you.

Body:
Try this:

$('.gallery-slider li:gt(0)').hide();
setInterval(function(){
    $('.gallery-slider li:first-child').fadeOut("slow", function() {
        $(this).next('.gallery-slider li').fadeIn(1000)
    }).appendTo('.gallery-slider');},
    2000);


问:
How can I get an Entity with its referenced entity ids in a ManyToMany relation?
I have an basic spring application that uses hibernate and mapstruct

There are two Entities, each are implemented to have their subchild entities as List attribute in a ManyToMany relation

So there is

```<code>EntityA.class
with List<EntityB> (fetchType Lazy)
</code>```

and vice versa

Now when my client calls, it wants to get a DTO that represents like following:

```<code>EntityADTO
with List<Long> entityBIds
</code>```

How can I get my EntityA with only the Ids of EntityB most efficient and without loading the complete EntityB and post process it after?

Thanks a lot!

答:
The @ManyToMany association information is persisted in a dedicated (join-)table and is loaded lazily on collection access, so there needs to be another query.

Instead of querying for the complete information of all associated entities, you could specifically query only for the needed id property.

Possible queries could look e.g. like this:

```<code>// Spring-Data repository (requires an extra interface for the result):
interface IdOnly(){
  Long getId();
}
interface EntityBRepository extends JpaRepository<EntityB, Long> {
  List<IdOnly> getIdByEntityAId(Long enitityAId);
}

// alternative JPQL query (does not need the interface):
@Query("SELECT b.id FROM EntityB b JOIN b.entityAs as a WHERE a.id=:entityAId")
List<Long> getIdByEntityAIdJpaQuery(@Param("enitityAId") Long enitityAId);
</code>```

This way, only the needed EntityB ids for an associated EntityA are loaded from the DB.

For even further tuning, one could also write a native query directly accessing only the join-table, which avoids all joins:

```<code>@Query(nativeQuery = true, //
        value = "SELECT entityBId FROM entityA_entityB WHERE enitityAId=:enitityAId")
List<Long> getIdByEntityAIdNative(@Param("enitityAId") Long enitityAId);
</code>```

For executing the query when mapping with mapstruct, you can use the spring repository bean e.g. as described here: https://stackoverflow.com/a/51292920

ContentLicense: CC BY-SA 4.0

Body:
I have an basic spring application that uses hibernate and mapstruct

There are two Entities, each are implemented to have their subchild entities as List attribute in a ManyToMany relation

So there is

EntityA.class
with List<EntityB> (fetchType Lazy)

and vice versa

Now when my client calls, it wants to get a DTO that represents like following:

EntityADTO
with List<Long> entityBIds

How can I get my EntityA with only the Ids of EntityB most efficient and without loading the complete EntityB and post process it after?

Thanks a lot!

Body:
The @ManyToMany association information is persisted in a dedicated (join-)table and is loaded lazily on collection access, so there needs to be another query.

Instead of querying for the complete information of all associated entities, you could specifically query only for the needed id property.

Possible queries could look e.g. like this:

// Spring-Data repository (requires an extra interface for the result):
interface IdOnly(){
  Long getId();
}
interface EntityBRepository extends JpaRepository<EntityB, Long> {
  List<IdOnly> getIdByEntityAId(Long enitityAId);
}

// alternative JPQL query (does not need the interface):
@Query("SELECT b.id FROM EntityB b JOIN b.entityAs as a WHERE a.id=:entityAId")
List<Long> getIdByEntityAIdJpaQuery(@Param("enitityAId") Long enitityAId);

This way, only the needed EntityB ids for an associated EntityA are loaded from the DB.

For even further tuning, one could also write a native query directly accessing only the join-table, which avoids all joins:

@Query(nativeQuery = true, //
        value = "SELECT entityBId FROM entityA_entityB WHERE enitityAId=:enitityAId")
List<Long> getIdByEntityAIdNative(@Param("enitityAId") Long enitityAId);

For executing the query when mapping with mapstruct, you can use the spring repository bean e.g. as described here: https://stackoverflow.com/a/51292920


问:
How can i strip unwanted keys and containers from my array of objects
I have an array of objects that i need in a particular format. Currently it contains it's nested in such a way that it contains unwanted keys and container objects.

```<code>badArray = [
{
    "college": {
        "id": 1,
        "location": "Victoria",
        "rating": 10,
        "alumni": [
            {
                "alumni_id": 1,
                "alumni_position": 1
            },
            {
                "alumni_id": 2,
                "alumni_position": 3
            },
        ]
    }
},
{
    "college": {
        "id": 2,
        "location": "New York",
        "rating": 9,
        "alumni": [
            {
                "alumni_id": 5,
                "alumni_position": 7
            }
        ]
    }
}
]
</code>```

What I'd like to get to is a less nested object with the following structure

```<code>goodArray = [
{
"id": 1,
"location": "Victoria",
"rating": 10,
"alumni": [
        {
         "alumni_id": 1,
         "alumni_position": 1
        },
        {
         "alumni_id": 2,
         "alumni_position": 3
        },
    ]
},
{
"id": 2,
"location": "New York",
"rating": 9,
"alumni": [
        {
         "alumni_id": 5,
         "alumni_position": 7
        }
    ]
}
]
</code>```

I can remove the unwanted key using

```<code> Object.values(badArray[0])
</code>```

But I'm really struggling to find a way to remove the unwanted outer container aswell.

Any help REALLY appreciated

答:
You can just do an array map and return your desired array in this situation instead of trying to delete keys

badArray = [
{
    "college": {
        "id": 1,
        "location": "Victoria",
        "rating": 10,
        "alumni": [
            {
                "alumni_id": 1,
                "alumni_position": 1
            },
            {
                "alumni_id": 2,
                "alumni_position": 3
            },
        ]
    }
},
{
    "college": {
        "id": 2,
        "location": "New York",
        "rating": 9,
        "alumni": [
            {
                "alumni_id": 5,
                "alumni_position": 7
            }
        ]
    }
}
]

let goodArray = badArray.map(el =>  el.college)
console.log(goodArray)```

Body:
I have an array of objects that i need in a particular format. Currently it contains it's nested in such a way that it contains unwanted keys and container objects.

badArray = [
{
    "college": {
        "id": 1,
        "location": "Victoria",
        "rating": 10,
        "alumni": [
            {
                "alumni_id": 1,
                "alumni_position": 1
            },
            {
                "alumni_id": 2,
                "alumni_position": 3
            },
        ]
    }
},
{
    "college": {
        "id": 2,
        "location": "New York",
        "rating": 9,
        "alumni": [
            {
                "alumni_id": 5,
                "alumni_position": 7
            }
        ]
    }
}
]

What I'd like to get to is a less nested object with the following structure

goodArray = [
{
"id": 1,
"location": "Victoria",
"rating": 10,
"alumni": [
        {
         "alumni_id": 1,
         "alumni_position": 1
        },
        {
         "alumni_id": 2,
         "alumni_position": 3
        },
    ]
},
{
"id": 2,
"location": "New York",
"rating": 9,
"alumni": [
        {
         "alumni_id": 5,
         "alumni_position": 7
        }
    ]
}
]

I can remove the unwanted key using

 Object.values(badArray[0])

But I'm really struggling to find a way to remove the unwanted outer container aswell.

Any help REALLY appreciated


问:
Is there any way to inject Interceptor from external library in Spring?
I'm developing a jar library and trying to inject an interceptor from external jar library to Application.

For example:

External Lib

MyExternalInterceptor.java

public class MyExternalInterceptor implements HandlerInterceptor {
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        // Do something
    }
}
```
<p>I tried to using AOP in external libs but it's not working.</p>
<h3>InterceptorAspect.java</h3>
<pre class="lang-java prettyprint-override"><code>@Around("execution(* org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.addInterceptors(..))")
public Object aspect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // Tried to inject MyExternalInterceptor here
    Object result = proceedingJoinPoint.proceed();
    return result;
}
</code>```

In Application using that lib:

Application

MyConfiguration.java

@Configuration
public MyConfiguration extends WebMvcConfigurationSupport {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
        /* Add MyExternalInterceptor not explicitly but implicitly using AOP or other things */
    }
}
```

Is there any way to inject an interceptor from external lib to App?

I know the question is very obscure (sorry for that), but could you give me any advice or hint to make it work?

Thank you for anyone who read my question :)

(I updated few more details for clarification)

答:
Summary

Use WebMvcConfigurer in both Client and library side instead of WebMvcConfigurationSupport

AoP is not needed

I use WebMvcConfigurer instead of WebMvcConfigurationSupport and change some codes like below:

External Lib

MyExternalInterceptor.java

Same as before

InterfaceAspect.java

Don't needed it anymore

MyExternalLibConfiguration.java

@Configuration
public class MyExternalLibConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyExternalInterceptor());
    }
}
```
<br>
<h3>Application (client)</h3>
<h4>MyConfiguration.java</h4>
<pre class="lang-java prettyprint-override"><code>@Configuration
public MyConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
        /* No need to add MyExternalInterceptor in here */
    }
}
</code>```

That's all! Everything is working well as M. Deinum said in comment.

Thank you again Deinum!

Body:
I'm developing a jar library and trying to inject an interceptor from external jar library to Application.

For example:

External Lib

MyExternalInterceptor.java

public class MyExternalInterceptor implements HandlerInterceptor {
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        // Do something
    }
}

I tried to using AOP in external libs but it's not working.

InterceptorAspect.java

@Around("execution(* org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.addInterceptors(..))")
public Object aspect(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // Tried to inject MyExternalInterceptor here
    Object result = proceedingJoinPoint.proceed();
    return result;
}

In Application using that lib:

Application

MyConfiguration.java

@Configuration
public MyConfiguration extends WebMvcConfigurationSupport {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
        /* Add MyExternalInterceptor not explicitly but implicitly using AOP or other things */
    }
}

Is there any way to inject an interceptor from external lib to App?

I know the question is very obscure (sorry for that), but could you give me any advice or hint to make it work?

Thank you for anyone who read my question :)

(I updated few more details for clarification)

Body:
Summary

Use WebMvcConfigurer in both Client and library side instead of WebMvcConfigurationSupport

AoP is not needed

I use WebMvcConfigurer instead of WebMvcConfigurationSupport and change some codes like below:

External Lib

MyExternalInterceptor.java

Same as before

InterfaceAspect.java

Don't needed it anymore

MyExternalLibConfiguration.java

@Configuration
public class MyExternalLibConfiguration implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyExternalInterceptor());
    }
}

Application (client)

MyConfiguration.java

@Configuration
public MyConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SpringTestInterceptor()); // client's own interceptor
        /* No need to add MyExternalInterceptor in here */
    }
}

That's all! Everything is working well as M. Deinum said in comment.

Thank you again Deinum!


问:
I've been having this issue for a while now, and I'm new to flutter, and the output shows a null check operator
This is my code when i use null initialization its giving me a error of Null check operator on document!exists condition</p>

答:
document can have null value, when it is null, trying to use it will cause exception. You need to check null before using it.

Never put network call or similar method inside Build. Build is designed to call whenever Flutter want, without your controll.


问:
Why my mp4 videos are not displayed in a html page?
I have read similar questions as this, but not with a solution to my problem. For example this one does not have a solution and this one I am already doing it. So

I have a simple html page and a video, in the same folder and the code is

```<code><!DOCTYPE html>
<html>
   <head>
      <title>HTML Video embed</title>
   </head>
   <body>
      <p>Learn Eclipse</p>
      <br />
      <iframe width="560" height="315" src="./pelicula.mp4" frameborder-"0" allowfullscreen></iframe>
      <video controls muted >  <source src="./pelicula.mp4" type="video/mp4"></video>
      <video controls>  <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4" type="video/mp4"></video>
   </body>
</html>
</code>```

As a result I have (this screen is in Windows 10)

As you can see, the video is not shown.
Btw, in windows when I double click the video I can watch it.
In linux this video has problems to play and I see an error message but in windows I see no error message, only the screen above

How can this be solved?

答:
The problem was solved by processing the video</p>
```<code>ffmpeg -i pelicula.mp4 -vcodec h264 pelicula_264.mp4
</code>```

Body:
I have read similar questions as this, but not with a solution to my problem. For example this one does not have a solution and this one I am already doing it. So

I have a simple html page and a video, in the same folder and the code is

<!DOCTYPE html>

      <title>HTML Video embed</title>

Learn Eclipse

      <video controls muted >  <source src="./pelicula.mp4" type="video/mp4"></video>
      <video controls>  <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerEscapes.mp4" type="video/mp4"></video>

As a result I have (this screen is in Windows 10)

As you can see, the video is not shown.
Btw, in windows when I double click the video I can watch it.
In linux this video has problems to play and I see an error message but in windows I see no error message, only the screen above

How can this be solved?

Body:
The problem was solved by processing the video

ffmpeg -i pelicula.mp4 -vcodec h264 pelicula_264.mp4


问:
(network sockets) bytes stuck in Send Queue for 15 minutes; why?
I have a Java program running on Windows (a Citrix machine), that dispatches a request to Java application servers on Linux; this dispatching mechanism is all custom.

The Windows Java program (let's call it W) opens a listen socket to a port given by the OS, say 1234 to receive results.  Then it invokes a "dispatch" service on the server with a "business request". This service splits the request and sends it to other servers (let's call them S1 ... Sn), and returns the number of jobs to the client synchronously.

In my tests, there are 13 jobs, dispatched to a number of servers and within 2 seconds, all servers have finished processing their jobs and try to send the results back to the W's socket.

I can see in the logs that 9 jobs are received by W (this number varies from test to test). So, I try to look for the 4 remaining jobs.  If I do a netstat on this Windows box, I see that 4 sockets are open:

```<code>TCP    W:4373       S5:48197  ESTABLISHED
TCP    W:4373       S5:48198  ESTABLISHED
TCP    W:4373       S6:57642  ESTABLISHED
TCP    W:4373       S7:48295  ESTABLISHED
</code>```

If I do a thread dump of W, I see 4 threads trying to read from these sockets, and apparently stuck in java.net.SocketInputStream.socketRead0(Native Method).

If I go on each of the S boxes and do a netstat, I see that some bytes are still in the Send Queue. This number of bytes does not move for 15 minutes. (The following is the aggregation of netstats on the different machines):

```<code>Proto Recv-Q Send-Q Local Address               Foreign Addr   State
tcp        0   6385 S1:48197                          W:4373   ESTABLISHED
tcp        0   6005 S1:48198                          W:4373   ESTABLISHED
tcp        0   6868 S6:57642                          W:4373   ESTABLISHED
tcp        0   6787 S7:48295                          W:4373   ESTABLISHED
</code>```

If I do a thread dump of the servers, I see the threads are also stuck in
java.net.SocketInputStream.socketRead0(Native Method).  I would expect a write, but maybe they're waiting for an ACK? (Not sure here; would it show in Java? Shouldn't it be handled by the TCP protocol directly?)

Now, the very strange thing is: after 15 minutes (and it's always 15 minutes), the results are received, sockets are closed, and everything continues as normal.

This used to always work before. The S servers moved to a different data center, so W and S are no longer in the same data center. Also, S is behind a firewall. All ports should be authorized between S and W (I'm told). The mystery is really the 15 minute delay. I thought that it could be some protection against DDOS?

I'm no network expert so I asked for help, but nobody's available to help me. I spent 30 minutes with a guy capturing packets with Wireshark (formerly Ethereal), but for "security reasons," I cannot look at the result. He has to analyze this and get back to me. I asked for the firewall logs; same story.

I'm not root or administrator on these boxes, now I don't know what to do... I'm not expecting a solution from you guys, but some ideas on how to progress would be great!

答: Right.  If you're using a BufferedOutputStream you need to call flush() unless you reach the max buffer size.</p>

OwnerDisplayName: Nicolas

ContentLicense: CC BY-SA 2.5

Body:
I have a Java program running on Windows (a Citrix machine), that dispatches a request to Java application servers on Linux; this dispatching mechanism is all custom.

The Windows Java program (let's call it W) opens a listen socket to a port given by the OS, say 1234 to receive results.  Then it invokes a "dispatch" service on the server with a "business request". This service splits the request and sends it to other servers (let's call them S1 ... Sn), and returns the number of jobs to the client synchronously.

In my tests, there are 13 jobs, dispatched to a number of servers and within 2 seconds, all servers have finished processing their jobs and try to send the results back to the W's socket.

I can see in the logs that 9 jobs are received by W (this number varies from test to test). So, I try to look for the 4 remaining jobs.  If I do a netstat on this Windows box, I see that 4 sockets are open:

TCP    W:4373       S5:48197  ESTABLISHED
TCP    W:4373       S5:48198  ESTABLISHED
TCP    W:4373       S6:57642  ESTABLISHED
TCP    W:4373       S7:48295  ESTABLISHED

If I do a thread dump of W, I see 4 threads trying to read from these sockets, and apparently stuck in java.net.SocketInputStream.socketRead0(Native Method).

If I go on each of the S boxes and do a netstat, I see that some bytes are still in the Send Queue. This number of bytes does not move for 15 minutes. (The following is the aggregation of netstats on the different machines):

Proto Recv-Q Send-Q Local Address               Foreign Addr   State
tcp        0   6385 S1:48197                          W:4373   ESTABLISHED
tcp        0   6005 S1:48198                          W:4373   ESTABLISHED
tcp        0   6868 S6:57642                          W:4373   ESTABLISHED
tcp        0   6787 S7:48295                          W:4373   ESTABLISHED

If I do a thread dump of the servers, I see the threads are also stuck in
java.net.SocketInputStream.socketRead0(Native Method).  I would expect a write, but maybe they're waiting for an ACK? (Not sure here; would it show in Java? Shouldn't it be handled by the TCP protocol directly?)

Now, the very strange thing is: after 15 minutes (and it's always 15 minutes), the results are received, sockets are closed, and everything continues as normal.

This used to always work before. The S servers moved to a different data center, so W and S are no longer in the same data center. Also, S is behind a firewall. All ports should be authorized between S and W (I'm told). The mystery is really the 15 minute delay. I thought that it could be some protection against DDOS?

I'm no network expert so I asked for help, but nobody's available to help me. I spent 30 minutes with a guy capturing packets with Wireshark (formerly Ethereal), but for "security reasons," I cannot look at the result. He has to analyze this and get back to me. I asked for the firewall logs; same story.

I'm not root or administrator on these boxes, now I don't know what to do... I'm not expecting a solution from you guys, but some ideas on how to progress would be great!

LastEditorDisplayName: Eddie

OwnerDisplayName: Nick


答:
Logic

Array.map through array.

Take Object.values of each Object in the array

Return the first value.

I have considered you have only one key in each object of the array. This solution will work for any valye for your key.

Working Fiddle

const badArray = [
  {
    college: {
      id: 1, location: "Victoria", rating: 10,
      alumni: [
        { alumni_id: 1, alumni_position: 1 },
        { alumni_id: 2, alumni_position: 3 },
      ],
    },
  },
  {
    college: {
      id: 2, location: "New York", rating: 9,
      alumni: [
        { alumni_id: 5, alumni_position: 7 },
      ],
    },
  },
];

const goodArray = badArray.map(item => Object.values(item)[0]);
console.log(goodArray);```
</div>
</div>
</p>
<p>If your key is constant as "college" you can perform this as.</p>
```const goodArray = badArray.map(item => item.college);
```

Title: How can i strip unwanted keys and containers from my array of objects

Body:
Logic

Array.map through array.

Take Object.values of each Object in the array

Return the first value.

I have considered you have only one key in each object of the array. This solution will work for any valye for your key.

Working Fiddle

const badArray = [
  {
    college: {
      id: 1, location: "Victoria", rating: 10,
      alumni: [
        { alumni_id: 1, alumni_position: 1 },
        { alumni_id: 2, alumni_position: 3 },
      ],
    },
  },
  {
    college: {
      id: 2, location: "New York", rating: 9,
      alumni: [
        { alumni_id: 5, alumni_position: 7 },
      ],
    },
  },
];

const goodArray = badArray.map(item => Object.values(item)[0]);
console.log(goodArray);

If your key is constant as "college" you can perform this as.

const goodArray = badArray.map(item => item.college);


问:
Ability to draw lines with snap to angle KonvaJs
Is there any ability to draw lines with snap to angle?
I want to allow draw lines only with following angles: 0, 45, 90, 135, 180...</p>

答: No. There is nothing built-in to Konva to snap lines when they are being drawn.  I am assuming these are straight lines ? You would have to do the math yourself to work where to snap to. Then you could apply that in the appropriate mouseevents to get you what you need.</p>


问:
Is pkce able to protect agaisnt the compromise of mobile app secret hash and access code?
I understand the Oauth code flow which involves the mobile app, app server, auth server, resource server. The app server is registered with auth server using the clientidand secret. The idea being that mobile app calls an endpoint of the app server which triggers the code flow eventually resulting in callback from the auth server to the app server with the auth code. The app server presents the secret and code to auth server to get the access token.

The other legacy option where there is no clientid and secret is the implicit flow wherein the mobile app receives the redirect url with the auth code (assuming redirect url destination is a SPA) which will invoke auth server endpoint to get the access token.

This is insecure because anyone can steal the access code from the url.

The solution to this for clients like mobile app is to use pkce. A random number hash is sent in the initial request which is verified later on when the auth code is passed to retrieve the access token.

This prevents the compromise of the access code from the url if an attacker is snooping because without initial hash the auth code is useless.

However how can the situation where the mobile phone is hacked and the secret and auth code is recorded by an attacker be handled to prevent misuse?

答:
These are the standard options:

PKCE uses a different code_verifier and code_challenge for every login attempt. If an authorization code is somehow captured from the system browser by an attacker it cannot be exhanged for tokens. No client secret is used, since a mobile app is a public client.

Use HTTPS redirect URIs (based on mobile deep links) so that if an attacker steals your client_id and redirect_uri they cannot receive the response containing the authorization code and will not be able to get tokens.

See this previous answer of mine for some further details, though claimed HTTPS schemes are tricky to implement.

Of course if an attacker has full control over a device, including authentication factors such as autofilled passwords, there may still be attack vectors


问:
error when creating "deployment.yaml", Deployment in version "v1" cannot be handled as a Deployment
I am new to DevOps. I wrote a deployment.yaml file for a Kubernetes cluster I just created on AWS. Creating the deployment keeps bringing up errors that I can't decode for now. This is just a test deployment in preparation for the migration of my company's web apps to kubernetes.

I tried editing the content of the deployment to look like conventional examples I've found. I can't even get this simple example to work. You may find the deployment.yaml content below.

```<code>apiVersion: v1
kind: Service
metadata:
  name: ghost
  labels:
    app: ghost
spec:
  ports:
  - port: 80
  selector:
    app: ghost
    tier: frontend
  type: LoadBalancer
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: ghost
  labels:
    app: ghost
spec:
  selector:
    matchLabels:
      app: ghost
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ghost
        tier: frontend
    spec:
      containers:
      - image: ghost:4-alpine
        name: ghost
        env:
        - name: database_client
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: client
        - name: database_connection_host
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: host
        - name: database_connection_user
          valueFrom:
            secretKeyRef:tha
        - name: database_connection_password
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key:  ghostdcp
        - name: database_connection_database
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: ghostdcd
        ports:
        - containerPort: 2368
          name: ghost
        volumeMounts:
        - name: ghost-persistent-storage
          mountPath: /var/lib/ghost
      volumes:
      - name: ghost-persistent-storage
        persistentVolumeClaim:
          claimName: efs-ghost
</code>```

I ran this line on cmd in the folder container:

kubectl create -f deployment-ghost.yaml --validate=false

service/ghost created
Error from server (BadRequest): error when creating "deployment-ghost.yaml": Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.ValueFrom: readObjectStart: expect { or n, but found ", error found in #10 byte of ...|lueFrom":"secretKeyR|..., bigger context ...|},{"name":"database_connection_user","valueFrom":"secretKeyRef:tha"},{"name":"database_connection_pa|...

I couldn't even get any information on this from my search. I can't just get the deployment created. Pls, who understands and can put me through?

答:
{"name":"database_connection_user","valueFrom":"secretKeyRef:tha"},

Your spec has error:

```<code>...
- name: database_connection_user  # <-- The error message points to this env variable
  valueFrom:
    secretKeyRef:
      name: <secret name, eg. eks-keys>
      key: <key in the secret>
...
</code>```

Body:
I am new to DevOps. I wrote a deployment.yaml file for a Kubernetes cluster I just created on AWS. Creating the deployment keeps bringing up errors that I can't decode for now. This is just a test deployment in preparation for the migration of my company's web apps to kubernetes.

I tried editing the content of the deployment to look like conventional examples I've found. I can't even get this simple example to work. You may find the deployment.yaml content below.

apiVersion: v1
kind: Service
metadata:
  name: ghost
  labels:
    app: ghost
spec:
  ports:
  - port: 80
  selector:
    app: ghost
    tier: frontend
  type: LoadBalancer
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: ghost
  labels:
    app: ghost
spec:
  selector:
    matchLabels:
      app: ghost
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: ghost
        tier: frontend
    spec:
      containers:
      - image: ghost:4-alpine
        name: ghost
        env:
        - name: database_client
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: client
        - name: database_connection_host
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: host
        - name: database_connection_user
          valueFrom:
            secretKeyRef:tha
        - name: database_connection_password
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key:  ghostdcp
        - name: database_connection_database
          valueFrom:
            secretKeyRef:
              name: eks-keys
              key: ghostdcd
        ports:
        - containerPort: 2368
          name: ghost
        volumeMounts:
        - name: ghost-persistent-storage
          mountPath: /var/lib/ghost
      volumes:
      - name: ghost-persistent-storage
        persistentVolumeClaim:
          claimName: efs-ghost

I ran this line on cmd in the folder container:

kubectl create -f deployment-ghost.yaml --validate=false

service/ghost created
Error from server (BadRequest): error when creating "deployment-ghost.yaml": Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.ValueFrom: readObjectStart: expect { or n, but found ", error found in #10 byte of ...|lueFrom":"secretKeyR|..., bigger context ...|},{"name":"database_connection_user","valueFrom":"secretKeyRef:tha"},{"name":"database_connection_pa|...

I couldn't even get any information on this from my search. I can't just get the deployment created. Pls, who understands and can put me through?

Body:
{"name":"database_connection_user","valueFrom":"secretKeyRef:tha"},

Your spec has error:

...
- name: database_connection_user  # <-- The error message points to this env variable
  valueFrom:
    secretKeyRef:
      name: <secret name, eg. eks-keys>
      key: <key in the secret>
...


问:
Is it possible to force Text widget to use two line space?
I need to find out a method to force Flutter Text widget to use two text lines space even if the line is only one.
For example in the below photo one card is lower than the other one due to the fact that Text widget use only one line space.

Does anyone know some trick to force Text widget to use maxLines space even if only one line is needed?

答:
you can use \n to set minimum lines (it is a trick)

this issue is still open Github: Add minLines to Text (flutter issue)

```<code>          Text(
            '${product.name}\n\n', //equal minlines: 3
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
            style:
                const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
          ),
</code>```

Body:
you can use \n to set minimum lines (it is a trick)

this issue is still open Github: Add minLines to Text (flutter issue)

          Text(
            '${product.name}\n\n', //equal minlines: 3
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
            style:
                const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
          ),


问:
Django web site URLS gets "?next=" randomly after deployed to heroku
After deploying django app on heroku the url after every form submission or link in site been press resulting with "?next=" inserts into the URL address, I don't understand from where it comes and why heroku keep inserting them in a random way, running the application locally just working perfectly.

I've deleted the application from heroku and upload it again, the fault persists.

There's no http errors what so ever. If I keep submitting the form eventually will works.

For example: pressing the log button in the django admin console results with this URL: https://appname.herokuapp.com/admin/login/?next=/admin/login/admin/, hitting it quite a bit will finally make it work with the correct url display: https://mishnayot.herokuapp.com/admin/.

Switching from heroku postgres to AWS RDS postgres didn't help.

Help will be very appreciated.

答:
When a user hits a page requiring authentication, they get redirected to the login URL with a ?next= indicating the page they were trying to access.  This way, after they've logged in, they'll get the page they intended to access.

In your case, it seems like /admin/login/admin/ requires a login and the login is actually at /admin/login/.  I'm guessing you have a bad link to /admin/login/admin/ somewhere when you intended to just have /admin/login/?


问:
Why does my array print more than I want?
I'm trying to write an array in c++, which consist of 10 integers that are all 1, unless changed through keyboard input. For some reason my code prints out way more than 10 integers and I'm not sure why.

```<code>int main()
{
    int index, value;
    int count = 0;
    int myData [10];
    for (int i = 0; i < sizeof(myData); i++)
    {
        myData[i] = 1;
    }

    do
    {
        for (int i = 0; i < sizeof(myData); i++)
        {
            std::cout << myData[i] << " ";
        }

        std::cout << "Input index: ";
        std::cin >> index;
        std::cout << "Input value: ";
        std::cin >> value;

        myData[index] = value;

    } while ((0 <= index) && (index <= sizeof(myData)));

    std::cout << "Index out of range. Exit." << std::endl;

    return 0;
}
</code>```

EDIT
I got it to work thank you :D but for some reason now I'm getting a buffer overflow. Anyway to fix this?

答:
sizeof returns the number of bytes, not the number of ints. Consider

```<code>for (int i = 0; i < sizeof(myData) / sizeof(int); i++) {
  std::cout << myData[i] << " ";
}
</code>```

This will only work if the array is statically-sized like yours is. If the array is dynamically-allocated, as in new int[10], then C++ doesn't keep track of its size so that's your job. Of course, you should never be using new int[10] anyway, since std::vector is a thing and does keep track of size.

Body:
I'm trying to write an array in c++, which consist of 10 integers that are all 1, unless changed through keyboard input. For some reason my code prints out way more than 10 integers and I'm not sure why.

int main()
{
    int index, value;
    int count = 0;
    int myData [10];
    for (int i = 0; i < sizeof(myData); i++)
    {
        myData[i] = 1;
    }

    do
    {
        for (int i = 0; i < sizeof(myData); i++)
        {
            std::cout << myData[i] << " ";
        }

        std::cout << "Input index: ";
        std::cin >> index;
        std::cout << "Input value: ";
        std::cin >> value;

        myData[index] = value;

    } while ((0 <= index) && (index <= sizeof(myData)));

    std::cout << "Index out of range. Exit." << std::endl;

    return 0;
}

EDIT
I got it to work thank you :D but for some reason now I'm getting a buffer overflow. Anyway to fix this?

Body:
sizeof returns the number of bytes, not the number of ints. Consider

for (int i = 0; i < sizeof(myData) / sizeof(int); i++) {
  std::cout << myData[i] << " ";
}

This will only work if the array is statically-sized like yours is. If the array is dynamically-allocated, as in new int[10], then C++ doesn't keep track of its size so that's your job. Of course, you should never be using new int[10] anyway, since std::vector is a thing and does keep track of size.


问:
Closest subsequent index for a specified value
Consider a vector:

int = c(1, 1, 0, 5, 2, 0, 0, 2)
```
<p>I'd like to get the closest subsequent index (not the difference) for a specified value. The first parameter of the function should be the vector, while the second should be the value one wants to see the closest subsequent elements.</p>
<p>For instance,</p>
<pre class="lang-r prettyprint-override"><code>f(int, 0)
# [1] 2 1 0 2 1 0 0 NA
</code>```

Here, the first element of the vector (1) is two positions away from the first subsequent 0, (3 - 1 = 2), so it should return 2. Then the second element is 1 position away from a 0 (2 - 1 = 1). When there is no subsequent values that match the specified value, return NA (here it's the case for the last element, because no subsequent value is 0).

Other examples:

f(int, 1)
# [1] 0 0 NA NA NA NA NA NA

f(int, 2)
# [1] 4 3 2 1 0 2 1 0

f(int, 3)
# [1] NA NA NA NA NA NA NA NA
```
<p>This should also work for character vectors:</p>
<pre class="lang-r prettyprint-override"><code>char = c("A", "B", "C", "A", "A")

f(char, "A")
# [1] 0 2 1 0 0
</code>```

答:
Using sequence:

f <- function(v, x){
  d = diff(c(0, which(v == x)))
  vec <- sequence(d, d-1, by = -1)
  length(vec) <- length(int)
  vec
}
```
<p><strong>Output</strong></p>
<pre class="lang-r prettyprint-override"><code>int = c(1, 1, 0, 5, 2, 0, 0, 2)
char = c("A", "B", "C", "A", "A")

f(int, 0)
# [1]  2  1  0  2  1  0  0 NA

f(int, 1)
# [1]  0  0 NA NA NA NA NA NA

f(int, 2)
# [1] 4 3 2 1 0 2 1 0

f(char, "A")
# [1] 0 2 1 0 0
</code>```

Benchmark (n = 1000):

set.seed(123)
int = sample(0:100, size = 1000, replace = T)

library(microbenchmark)
bm <- microbenchmark(
  fSequence(int, 0),
  fzx8754(int, 0),
  fRecursive(int, 0),
  fMartinMorgan(int, 0),
  fMap2dbl(int, 0),
  fReduce(int, 0),
  fAve(int, 0),
  fjblood94(int, 0),
  times = 10L,
  setup = gc(FALSE)
)
autoplot(bm)
```
<p>Martin Morgan's solution seems to be the quickest, followed by this answer's <code>sequence</code> solution, sbarbit's recursive solution, and jblood94's for loop solution.
<img src="https://i.stack.imgur.com/rV0Ur.png" alt="enter image description here" /></p>
<p>Functions used:</p>
<pre class="lang-r prettyprint-override"><code>fSequence <- function(v, x){
  vec <- sequence(diff(c(0, which(v == x))), diff(c(0, which(v == x))) - 1, by = -1)
  length(vec) <- length(v)
  vec
}

fzx8754 <- function(v, x){
  sapply(seq_along(v), function(i){
    which(v[ i:length(v) ] == x)[ 1 ] - 1
  })
}

fRecursive <- function(lookup,val ) {
  ind <- which(lookup == val)[1] -1
  if (length(lookup) > 1) {
    c(ind, f(lookup[-1], val))
  } else {
    ind
  }
}

fMartinMorgan <- function(x, value) {
  idx = which(x == value)
  nearest = rep(NA, length(x))
  nearest[1:max(idx)] = rep(idx, diff(c(0, idx)))
  abs(seq_along(x) - nearest)
}

fMap2dbl <- function(int, num)
{
  n <- length(int)

  map2_dbl(num, 1:n, ~ ifelse(length(which(.x == int[.y:n])) == 0, NA,
                              min(which(.x == int[.y:n])) - 1))
}

fReduce <- function(vec, value) {
  replace(
    Reduce(
      function(x, y)
        x  + (y * x) ,
      vec != value,
      right = TRUE,
      accumulate = TRUE
    ),
    max(tail(which(vec == value), 1), 0) < seq_along(vec),
    NA
  )
}

fAve <- function(init, k) {
  ave(
    seq_along(init),
    c(0, head(cumsum(init == k), -1)),
    FUN = function(x) if (any(x == k)) rev(seq_along(x) - 1) else NA
  )
}

fjblood94 <- function(v, val) {
  out <- integer(length(v))
  if (v[length(v)] != val) out[length(v)] <- NA_integer_

  for (i in (length(v) - 1L):1) {
    if (v[i] == val) {
      out[i] <- 0L
    } else {
      out[i] <- out[i + 1L] + 1L
    }
  }

  return(out)
}

</code>```

Body:
Consider a vector:

int = c(1, 1, 0, 5, 2, 0, 0, 2)

I'd like to get the closest subsequent index (not the difference) for a specified value. The first parameter of the function should be the vector, while the second should be the value one wants to see the closest subsequent elements.

For instance,

f(int, 0)
# [1] 2 1 0 2 1 0 0 NA

Here, the first element of the vector (1) is two positions away from the first subsequent 0, (3 - 1 = 2), so it should return 2. Then the second element is 1 position away from a 0 (2 - 1 = 1). When there is no subsequent values that match the specified value, return NA (here it's the case for the last element, because no subsequent value is 0).

Other examples:

f(int, 1)
# [1] 0 0 NA NA NA NA NA NA

f(int, 2)
# [1] 4 3 2 1 0 2 1 0

f(int, 3)
# [1] NA NA NA NA NA NA NA NA

This should also work for character vectors:

char = c("A", "B", "C", "A", "A")

f(char, "A")
# [1] 0 2 1 0 0

Body:
Using sequence:

f <- function(v, x){
  d = diff(c(0, which(v == x)))
  vec <- sequence(d, d-1, by = -1)
  length(vec) <- length(int)
  vec
}

Output

int = c(1, 1, 0, 5, 2, 0, 0, 2)
char = c("A", "B", "C", "A", "A")

f(int, 0)
# [1]  2  1  0  2  1  0  0 NA

f(int, 1)
# [1]  0  0 NA NA NA NA NA NA

f(int, 2)
# [1] 4 3 2 1 0 2 1 0

f(char, "A")
# [1] 0 2 1 0 0

Benchmark (n = 1000):

set.seed(123)
int = sample(0:100, size = 1000, replace = T)

library(microbenchmark)
bm <- microbenchmark(
  fSequence(int, 0),
  fzx8754(int, 0),
  fRecursive(int, 0),
  fMartinMorgan(int, 0),
  fMap2dbl(int, 0),
  fReduce(int, 0),
  fAve(int, 0),
  fjblood94(int, 0),
  times = 10L,
  setup = gc(FALSE)
)
autoplot(bm)

Martin Morgan's solution seems to be the quickest, followed by this answer's sequence solution, sbarbit's recursive solution, and jblood94's for loop solution.

Functions used:

fSequence <- function(v, x){
  vec <- sequence(diff(c(0, which(v == x))), diff(c(0, which(v == x))) - 1, by = -1)
  length(vec) <- length(v)
  vec
}

fzx8754 <- function(v, x){
  sapply(seq_along(v), function(i){
    which(v[ i:length(v) ] == x)[ 1 ] - 1
  })
}

fRecursive <- function(lookup,val ) {
  ind <- which(lookup == val)[1] -1
  if (length(lookup) > 1) {
    c(ind, f(lookup[-1], val))
  } else {
    ind
  }
}

fMartinMorgan <- function(x, value) {
  idx = which(x == value)
  nearest = rep(NA, length(x))
  nearest[1:max(idx)] = rep(idx, diff(c(0, idx)))
  abs(seq_along(x) - nearest)
}

fMap2dbl <- function(int, num)
{
  n <- length(int)

  map2_dbl(num, 1:n, ~ ifelse(length(which(.x == int[.y:n])) == 0, NA,
                              min(which(.x == int[.y:n])) - 1))
}

fReduce <- function(vec, value) {
  replace(
    Reduce(
      function(x, y)
        x  + (y * x) ,
      vec != value,
      right = TRUE,
      accumulate = TRUE
    ),
    max(tail(which(vec == value), 1), 0) < seq_along(vec),
    NA
  )
}

fAve <- function(init, k) {
  ave(
    seq_along(init),
    c(0, head(cumsum(init == k), -1)),
    FUN = function(x) if (any(x == k)) rev(seq_along(x) - 1) else NA
  )
}

fjblood94 <- function(v, val) {
  out <- integer(length(v))
  if (v[length(v)] != val) out[length(v)] <- NA_integer_

  for (i in (length(v) - 1L):1) {
    if (v[i] == val) {
      out[i] <- 0L
    } else {
      out[i] <- out[i + 1L] + 1L
    }
  }

  return(out)
}


问:
AndroidManifest.xml uses `android:name="io.flutter.app.FutterApplication"`
After upgrading to Flutter 2.10, I get the following error:

```<code>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project. You may also pass the --ignore-deprecation flag to
ignore this check and continue with the deprecated v1 embedding. However,
the v1 Android embedding will be removed in future versions of Flutter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The detected reason was:

  /android/app/src/main/AndroidManifest.xml uses `android:name="io.flutter.app.FutterApplication"`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
</code>```

I've already upgraded to Flutter embedding 2.  How to solve this error?

答:
I was able to solve this by setting android:name to

android:name="${applicationName}" in android/app/src/main/AndroidManifest.xml:

    <application
        android:name="${applicationName}"
```

Apparently Flutter 2.10 has stricter checks than previous versions.

Body:
After upgrading to Flutter 2.10, I get the following error:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project. You may also pass the --ignore-deprecation flag to
ignore this check and continue with the deprecated v1 embedding. However,
the v1 Android embedding will be removed in future versions of Flutter.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The detected reason was:

  /android/app/src/main/AndroidManifest.xml uses `android:name="io.flutter.app.FutterApplication"`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

I've already upgraded to Flutter embedding 2.  How to solve this error?

Body:
I was able to solve this by setting android:name to

android:name="${applicationName}" in android/app/src/main/AndroidManifest.xml:

    <application
        android:name="${applicationName}"

Apparently Flutter 2.10 has stricter checks than previous versions.


问:
How to make a collection view swipe to next item?
I'm using a horizontal collection view to display various quotes which users can swipe to scroll through. It works fine, but the scroll is more like one long continuous scroll (like Instagram). I would like to change this to have each quote stop in the center of the screen and then the user to swipe again to go to the next quote (more like TikToc). How can I make this happen? I'm new to coding, so I'm not sure if there is a function for this. I tried the func ScrollToitem but don't know how to get it to implement this behavior.</p>
```<code>import UIKit

class mainViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

@IBOutlet weak var checkcollectionview: UICollectionView!

override func viewDidLoad() {
    super.viewDidLoad()

    checkcollectionview.dataSource = self
    checkcollectionview.delegate = self
    checkcollectionview.collectionViewLayout = UICollectionViewFlowLayout()
    let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .horizontal
    self.checkcollectionview.collectionViewLayout = layout
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return quotes.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = checkcollectionview.dequeueReusableCell(withReuseIdentifier: "check", for: indexPath) as! checkCollectionViewCell
    cell.setup(with: quotes[indexPath.row])
    return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: 700, height: 200)
}
}
</code>```

答:
As recommended by Andrew, I found a solution in a different post (link to solution below). The snap is nice and smooth.

https://stackoverflow.com/a/48572117/17152459

Body:
I'm using a horizontal collection view to display various quotes which users can swipe to scroll through. It works fine, but the scroll is more like one long continuous scroll (like Instagram). I would like to change this to have each quote stop in the center of the screen and then the user to swipe again to go to the next quote (more like TikToc). How can I make this happen? I'm new to coding, so I'm not sure if there is a function for this. I tried the func ScrollToitem but don't know how to get it to implement this behavior.

import UIKit

class mainViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {

@IBOutlet weak var checkcollectionview: UICollectionView!

override func viewDidLoad() {
    super.viewDidLoad()

    checkcollectionview.dataSource = self
    checkcollectionview.delegate = self
    checkcollectionview.collectionViewLayout = UICollectionViewFlowLayout()
    let layout = UICollectionViewFlowLayout()
    layout.scrollDirection = .horizontal
    self.checkcollectionview.collectionViewLayout = layout
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return quotes.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = checkcollectionview.dequeueReusableCell(withReuseIdentifier: "check", for: indexPath) as! checkCollectionViewCell
    cell.setup(with: quotes[indexPath.row])
    return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: 700, height: 200)
}
}


问:
Previous fragment visible under the new fragment
I have a tab  + ViewPager layout and in one of these tabs I have a list view.  When I replace that list fragment upon the onclick I can still see the old fragment under the new fragment.  See:

Code:

```<code>FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
HallsInStateFragment hallsForState = new HallsInStateFragment();
transaction.replace(R.id.container, hallsForState);
transaction.addToBackStack(null);
transaction.commit();
</code>```

where the R.id.container is the FrameLayout in the view.

答:
In My Case , This was happening because I was using the static fragment as

```<code>    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<fragment
    android:name="com.example.android.FooFragment"
    android:id="@+id/fooFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>
</code>```

where foofragment is the initial fragment , Then Trying to replace the fragment using with other fragment , so that both fragment overlaps.

Instead , Problem is solved , when I used dynamic Linkage , in place of fragment in the xml , we need to use framelayout as

```<code><?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

  <FrameLayout
       android:id="@+id/your_placeholder"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
  </FrameLayout>

</LinearLayout>
</code>```

Then dynamically adding the fragment-1 and replacing with the fragment-2 , is working fine for me.

```<code>I did not find answer earlier, hence posting this solution.
</code>```

Body:
I have a tab  + ViewPager layout and in one of these tabs I have a list view.  When I replace that list fragment upon the onclick I can still see the old fragment under the new fragment.  See:

Code:

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
HallsInStateFragment hallsForState = new HallsInStateFragment();
transaction.replace(R.id.container, hallsForState);
transaction.addToBackStack(null);
transaction.commit();

where the R.id.container is the FrameLayout in the view.

Body:
In My Case , This was happening because I was using the static fragment as

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<fragment
    android:name="com.example.android.FooFragment"
    android:id="@+id/fooFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

where foofragment is the initial fragment , Then Trying to replace the fragment using with other fragment , so that both fragment overlaps.

Instead , Problem is solved , when I used dynamic Linkage , in place of fragment in the xml , we need to use framelayout as

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

  <FrameLayout
       android:id="@+id/your_placeholder"
       android:layout_width="match_parent"
       android:layout_height="match_parent">
  </FrameLayout>

</LinearLayout>

Then dynamically adding the fragment-1 and replacing with the fragment-2 , is working fine for me.

I did not find answer earlier, hence posting this solution.


问:
Keep absolute content's position inside scrollable div
I know this is a question that was asked many times, but I cannot find exactly my scenario. I want to put an overlay over a scrollable div. I cannot put it outside the scrolling container because it would disable it's scrolling possibilities. Using pointer-events: none isn't possible, since I want the content to by blocked from mouse events.

#con{
  height: 200px;
  overflow-y: auto;

  position: relative;
}

#content{
}

.fade{
  position: absolute;
  top: 0; right: 0; left: 0; bottom: 0;
  background-color: red;
  opacity: 0.3;
}

.spinnerContainer {
    position: absolute;
    z-index: 2;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>
    Some Content before
</p>

<div id="con">
    <div id="content">
        I need the mouseevents on me to be blocked but still being scrollable.<br>
        The overlay should keep it's position and shouldn't scroll with me.
        <br><br>
        DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
        CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>
    </div>
    <div class="fade">
        <div class="spinnerContainer">
            <div>
                [Spinner-Image here]
            </div>
        </div>
    </div>
</div>

<p>
    Some Content after
</p></code>```

Is someone able to adopt it to my needs?

答:
Use a pseudo element (::after) for this. I added the :after to the #a element. You can remove the #b element altogether.

Since the pseudo element will be essentially at a higher z-index, it will block mouse events on the content.

#con {
  height: 200px;
  overflow-y: auto;
  position: relative;
}

#a {
  position: relative;
}

#a::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background-color: red;
  opacity: 0.3;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>
  Some Content before
</p>

<div id="con">
  <div id="a">
    I need the mouseevents on me to be blocked but still being scrollable.<br> The overlay should keep it's position and shouldn't scroll with me.
    <br><br> DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>
  </div>
</div>
<p>
  Some Content after
</p></code>```

EDIT FOR UPDATED QUESTION

.con-wrapper {
  position: relative;
}

#con {
  height: 200px;
  overflow-y: auto;
  position: relative;
}

#content {
  position: relative;
  transform: translate(0, 0);
}

#content::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background-color: red;
  opacity: 0.3;
}

.spinnerContainer {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  z-index: 5;
}

.spinnerContainer img {
  margin: 0 auto;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>
  Some Content before
</p>

<div class="con-wrapper">
  <div id="con">
    <div id="content">
      I need the mouseevents on me to be blocked but still being scrollable.<br> The overlay should keep it's position and shouldn't scroll with me.
      <br><br> DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>
    </div>
  </div>

  <div class="spinnerContainer">
    <img src="https://c.tenor.com/tEBoZu1ISJ8AAAAC/spinning-loading.gif" width="50" height="30">
  </div>
</div>
<p>
  Some Content after
</p></code>```

Body:
I know this is a question that was asked many times, but I cannot find exactly my scenario. I want to put an overlay over a scrollable div. I cannot put it outside the scrolling container because it would disable it's scrolling possibilities. Using pointer-events: none isn't possible, since I want the content to by blocked from mouse events.

#con{
  height: 200px;
  overflow-y: auto;

  position: relative;
}

#content{
}

.fade{
  position: absolute;
  top: 0; right: 0; left: 0; bottom: 0;
  background-color: red;
  opacity: 0.3;
}

.spinnerContainer {
    position: absolute;
    z-index: 2;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

    Some Content before

        I need the mouseevents on me to be blocked but still being scrollable.

        The overlay should keep it's position and shouldn't scroll with me.

        DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY
        CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT
DUMMY CONTENT

                [Spinner-Image here]

    Some Content after

Is someone able to adopt it to my needs?

Body:
Use a pseudo element (::after) for this. I added the :after to the #a element. You can remove the #b element altogether.

Since the pseudo element will be essentially at a higher z-index, it will block mouse events on the content.

#con {
  height: 200px;
  overflow-y: auto;
  position: relative;
}

#a {
  position: relative;
}

#a::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background-color: red;
  opacity: 0.3;
}

<p>
  Some Content before
</p>

<div id="con">
  <div id="a">
    I need the mouseevents on me to be blocked but still being scrollable.<br> The overlay should keep it's position and shouldn't scroll with me.
    <br><br> DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY
    CONTENT
    <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>
  </div>
</div>
<p>
  Some Content after
</p>

EDIT FOR UPDATED QUESTION

.con-wrapper {
  position: relative;
}

#con {
  height: 200px;
  overflow-y: auto;
  position: relative;
}

#content {
  position: relative;
  transform: translate(0, 0);
}

#content::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  background-color: red;
  opacity: 0.3;
}

.spinnerContainer {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  z-index: 5;
}

.spinnerContainer img {
  margin: 0 auto;
}

<p>
  Some Content before
</p>

<div class="con-wrapper">
  <div id="con">
    <div id="content">
      I need the mouseevents on me to be blocked but still being scrollable.<br> The overlay should keep it's position and shouldn't scroll with me.
      <br><br> DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT
      <br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>DUMMY CONTENT<br>
    </div>
  </div>

  <div class="spinnerContainer">
    <img src="https://c.tenor.com/tEBoZu1ISJ8AAAAC/spinning-loading.gif" width="50" height="30">
  </div>
</div>
<p>
  Some Content after
</p>