问:
Find all exact occurrences of multiple strings in R
I have a large data frame that contains causes of death from 2000 to 2020. It has many of the major causes of death broken into subgroups but I only want the main groups. For example cancers are "malignant neoplasms" but there are "malignant neoplasms of the lungs" "... of the kidneys" etc. All I want is "malignant neoplasms" so that I am not double counting deaths. I have been trying grepl but that doesn't seem to be working yet. Here is what I was working on:

```<code>keyword.list <- list("Malignant neoplasms [C00-C97]",
                 "Diabetes mellitus [E10-E14]",
                 "Alzheimer's disease [G30]",
                 "Major cardiovascular diseases [I00-I78]",
                 "Cerebrovascular diseases [I60-I69]",
                 "Influenza and pneumonia [J09-J18]",
                 "Chronic lower respiratory diseases [J40-J47]",
                 "Nephritis, nephrotic syndrome and nephrosis [N00-N07, N17-N19, N25-N27]",
                 "Accidents (unintentional injuries) [V01-X59, Y85-Y86]")
deaths2 <- NULL
for(i in 1:length(keyword.list)){
   deaths2 <- filter(deaths, grepl(i, `Cause of death (ICD-10)`))
}
</code>```

So how do I make a new dataframe that contains all the rows that have the nine causes of death listed above? Then I can do some more filtering and make a chart

答:
Thank you Ronak Shah! That worked perfectly</p>
```<code>deaths2<- subset(deaths, `Cause of death (ICD-10)` %in% unlist(keyword.list))
</code>```

Body:
I have a large data frame that contains causes of death from 2000 to 2020. It has many of the major causes of death broken into subgroups but I only want the main groups. For example cancers are "malignant neoplasms" but there are "malignant neoplasms of the lungs" "... of the kidneys" etc. All I want is "malignant neoplasms" so that I am not double counting deaths. I have been trying grepl but that doesn't seem to be working yet. Here is what I was working on:

keyword.list <- list("Malignant neoplasms [C00-C97]",
                 "Diabetes mellitus [E10-E14]",
                 "Alzheimer's disease [G30]",
                 "Major cardiovascular diseases [I00-I78]",
                 "Cerebrovascular diseases [I60-I69]",
                 "Influenza and pneumonia [J09-J18]",
                 "Chronic lower respiratory diseases [J40-J47]",
                 "Nephritis, nephrotic syndrome and nephrosis [N00-N07, N17-N19, N25-N27]",
                 "Accidents (unintentional injuries) [V01-X59, Y85-Y86]")
deaths2 <- NULL
for(i in 1:length(keyword.list)){
   deaths2 <- filter(deaths, grepl(i, `Cause of death (ICD-10)`))
}

So how do I make a new dataframe that contains all the rows that have the nine causes of death listed above? Then I can do some more filtering and make a chart

Body:
Thank you Ronak Shah! That worked perfectly

deaths2<- subset(deaths, `Cause of death (ICD-10)` %in% unlist(keyword.list))


来源: stackexchange

问:
How to have a factor outside the axis for an arrow in ggplot
I want to make an annotation with an arrow that goes outside a plot in ggplot. Using geom_curve changes the order of the factor, and I do not understand why.

Here is the example: let's consider the following plot:

```<code>df <- data.frame(ID = factor(c("A","B","C"),level = c("AA","B","C","A")),
           y = 1:3)

ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  coord_flip(clip = "off")+
  scale_x_discrete(breaks = c("B","C","A"))
</code>```

I want to keep the order of the vertical axis (B,C,A), and have an arrow pointing at the first point but from above the plot. I thus want to ass a factor before A that goes outside the plot:

```<code>ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  geom_curve(data = data.frame(ID = factor("AA",level = c("AA","B","C","A")),
                               ID_end = "A",
                               y = 2,y_end = 1),
             aes(x = ID,xend = ID_end,
                 y = y ,yend = y_end),
             curvature = -.1,
             arrow =arrow(length = unit(2, "mm"),type = "closed"),
             color = "grey20" ,size = .2)+
  coord_flip(clip = "off")+
  scale_x_discrete(breaks = c("B","C","A"))
</code>```

Here the vertical axis has the factors reordered, although I specified the same order in geom_curve. My arrow lies in the middle instead of being on the top/outside the plot.

How can I solve this problem?

答:
Does this help you? The arrow is not really "outside" the plot, but the order on the axis is maintained the way you want

```<code>df <- data.frame(
  ID = factor(c(1,2,3), labels=c("B","C","A")),
  y =c(2,3,1)
)

curvedata = data.frame(
  ID = 4,
  ID_end = 3,
  y = 2,y_end = 1)

ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  geom_curve(data=curvedata,
             aes(x = ID,xend = ID_end,
                 y = y ,yend = y_end),
             curvature = -.1,
             arrow =arrow(length = unit(2, "mm"),type = "closed"),
             color = "grey20" ,size = .2)+
  coord_flip(clip = "off")
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I want to make an annotation with an arrow that goes outside a plot in ggplot. Using geom_curve changes the order of the factor, and I do not understand why.

Here is the example: let's consider the following plot:

df <- data.frame(ID = factor(c("A","B","C"),level = c("AA","B","C","A")),
           y = 1:3)

ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  coord_flip(clip = "off")+
  scale_x_discrete(breaks = c("B","C","A"))

I want to keep the order of the vertical axis (B,C,A), and have an arrow pointing at the first point but from above the plot. I thus want to ass a factor before A that goes outside the plot:

ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  geom_curve(data = data.frame(ID = factor("AA",level = c("AA","B","C","A")),
                               ID_end = "A",
                               y = 2,y_end = 1),
             aes(x = ID,xend = ID_end,
                 y = y ,yend = y_end),
             curvature = -.1,
             arrow =arrow(length = unit(2, "mm"),type = "closed"),
             color = "grey20" ,size = .2)+
  coord_flip(clip = "off")+
  scale_x_discrete(breaks = c("B","C","A"))

Here the vertical axis has the factors reordered, although I specified the same order in geom_curve. My arrow lies in the middle instead of being on the top/outside the plot.

How can I solve this problem?

Body:
Does this help you? The arrow is not really "outside" the plot, but the order on the axis is maintained the way you want

df <- data.frame(
  ID = factor(c(1,2,3), labels=c("B","C","A")),
  y =c(2,3,1)
)

curvedata = data.frame(
  ID = 4,
  ID_end = 3,
  y = 2,y_end = 1)

ggplot(df,aes(ID,y,color = ID))+
  geom_point()+
  geom_curve(data=curvedata,
             aes(x = ID,xend = ID_end,
                 y = y ,yend = y_end),
             curvature = -.1,
             arrow =arrow(length = unit(2, "mm"),type = "closed"),
             color = "grey20" ,size = .2)+
  coord_flip(clip = "off")


问:
How do I flip this sprite in pygame?
EDIT: I've now flipped the sprite, but when the animation plays on the flipped sprite, it has a black background instead of blending in with the major background. Just updated my code to the current situation. (2/8/2021)

I'm trying to flip a sprite in pygame, for example, I don't want them running left but looking right, which is what is happening right now.

The part that is giving me issues is the second comment that says ISSUES.

Here is my code (spritesheet is a class that transforms the image into a surface):

```<code>import pygame
import os
import sys
import random
from pygame.locals import *
import spritesheet
import time

pygame.init()

clock = pygame.time.Clock()
FPS = 60
prev_time = time.time()

pygame.display.set_caption('Platformer')

BG_COLOR = (50, 50, 50)
BLACK = (0, 0, 0)

WIN_SIZE = [1920,1080]

WIN = pygame.display.set_mode((WIN_SIZE[0], WIN_SIZE[1]), 0, 32)

# CONFIGURING Animations

IDLE_INDEX = 0

RUN_INDEX = 0

moving_right = False
moving_left = False

lookingRight = True

speed = 4
animation_tick = 8

player_location = [50, 50]
player_y_momentum = 0

player_rect = pygame.Rect(player_location[0] + 155, player_location[1] + 140, 70, 133)

def retrieve_list(animType, image):
    if animType == "idle":
        IDLE_FRAMES = []
        IDLE_STEPS = 9
        sprite_sheet = spritesheet.SpriteSheet(image)
        for step in range(IDLE_STEPS):
            newFRAME = sprite_sheet.get_image(step, 120, 80, 3.5, BLACK)
            IDLE_FRAMES.append(newFRAME)
        return IDLE_FRAMES
    if animType == "run":
        RUN_FRAMES = []
        RUN_STEPS = 9
        sprite_sheet = spritesheet.SpriteSheet(image)
        for step in range(RUN_STEPS):
            newFRAME = sprite_sheet.get_image(step, 120, 80, 3.5, BLACK)
            RUN_FRAMES.append(newFRAME)
        return RUN_FRAMES

sprite_sheet_img_IDLE = pygame.image.load('Spritesheets/Outline/120x80_PNGSheets/_Idle.png')
sprite_sheet_img_RUN = pygame.image.load('Spritesheets/Outline/120x80_PNGSheets/_Run.png')
IDLE_FRAMES = retrieve_list("idle", sprite_sheet_img_IDLE)
RUN_FRAMES = retrieve_list("run", sprite_sheet_img_RUN)
currentANIMATION = "idle"
playingAnim = None

while True:

    clock.tick(FPS)
    now = time.time()
    dt = now - prev_time
    prev_time = now
    WIN.fill(BG_COLOR)

    if currentANIMATION == "idle":
        if player_location[1] > WIN_SIZE[1] - IDLE_FRAMES[IDLE_INDEX].get_height():
            player_y_momentum = -player_y_momentum
        else:
            player_y_momentum += 0.2
        player_location[1] += player_y_momentum
    elif currentANIMATION == "run":
        if player_location[1] > WIN_SIZE[1] - RUN_FRAMES[RUN_INDEX].get_height():
            player_y_momentum = -player_y_momentum
        else:
            player_y_momentum += 0.2
        player_location[1] += player_y_momentum

    if moving_right:
        currentANIMATION = "run"
        if not lookingRight:
            lookingRight = True
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(RUN_FRAMES[RUN_INDEX], (player_location[0], player_location[1]))
        player_location[0] += speed
    if moving_left:
        currentANIMATION = "run"
        if lookingRight:
            lookingRight = False
        leftFrame = pygame.transform.flip(RUN_FRAMES[RUN_INDEX], True, False)
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(leftFrame, (player_location[0], player_location[1]))
        player_location[0] -= speed
    elif moving_right != True and moving_left != True:
        currentANIMATION = "idle"
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(IDLE_FRAMES[IDLE_INDEX], (player_location[0], player_location[1]))

    player_rect.x = player_location[0] + 155
    player_rect.y = player_location[1] + 140

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_RIGHT or event.key == ord('d'):
                moving_right = True
            if event.key == K_LEFT or event.key == ord('a'):
                moving_left = True
        if event.type == KEYUP:
            if event.key == K_RIGHT or event.key == ord('d'):
                moving_right = False
            if event.key == K_LEFT or event.key == ord('a'):
                moving_left = False

    pygame.display.update()
    if animation_tick == 8:  # change 20 to how ever many ticks in between animation frames
        if currentANIMATION == "idle":
            if IDLE_INDEX < 8:
                IDLE_INDEX += 1
            else:
                IDLE_INDEX = 0
        if currentANIMATION == "run":
            if RUN_INDEX < 8:
                RUN_INDEX += 1
            else:
                RUN_INDEX = 0
        animation_tick = 0  # reset tick back to 0 after changing frame
    else:
        animation_tick += 1  # add 1 each iteration of the while loop
</code>```

Here are the spritesheets if you want to replicate my situation:
running spritesheet:

idle spritesheet:

I've tried flipping the original surface, but then the image gets messed up with black around it, and it doesn't play the animation.

答: Forgot to add .convert_alpha() when I was flipping the image. Apparently when the image is flipped it recreates the black rectangle.</p>

Title: How do I flip this sprite in pygame?

Body:
EDIT: I've now flipped the sprite, but when the animation plays on the flipped sprite, it has a black background instead of blending in with the major background. Just updated my code to the current situation. (2/8/2021)

I'm trying to flip a sprite in pygame, for example, I don't want them running left but looking right, which is what is happening right now.

The part that is giving me issues is the second comment that says ISSUES.

Here is my code (spritesheet is a class that transforms the image into a surface):

import pygame
import os
import sys
import random
from pygame.locals import *
import spritesheet
import time

pygame.init()

clock = pygame.time.Clock()
FPS = 60
prev_time = time.time()

pygame.display.set_caption('Platformer')

BG_COLOR = (50, 50, 50)
BLACK = (0, 0, 0)

WIN_SIZE = [1920,1080]

WIN = pygame.display.set_mode((WIN_SIZE[0], WIN_SIZE[1]), 0, 32)

# CONFIGURING Animations

IDLE_INDEX = 0

RUN_INDEX = 0

moving_right = False
moving_left = False

lookingRight = True

speed = 4
animation_tick = 8

player_location = [50, 50]
player_y_momentum = 0

player_rect = pygame.Rect(player_location[0] + 155, player_location[1] + 140, 70, 133)

def retrieve_list(animType, image):
    if animType == "idle":
        IDLE_FRAMES = []
        IDLE_STEPS = 9
        sprite_sheet = spritesheet.SpriteSheet(image)
        for step in range(IDLE_STEPS):
            newFRAME = sprite_sheet.get_image(step, 120, 80, 3.5, BLACK)
            IDLE_FRAMES.append(newFRAME)
        return IDLE_FRAMES
    if animType == "run":
        RUN_FRAMES = []
        RUN_STEPS = 9
        sprite_sheet = spritesheet.SpriteSheet(image)
        for step in range(RUN_STEPS):
            newFRAME = sprite_sheet.get_image(step, 120, 80, 3.5, BLACK)
            RUN_FRAMES.append(newFRAME)
        return RUN_FRAMES

sprite_sheet_img_IDLE = pygame.image.load('Spritesheets/Outline/120x80_PNGSheets/_Idle.png')
sprite_sheet_img_RUN = pygame.image.load('Spritesheets/Outline/120x80_PNGSheets/_Run.png')
IDLE_FRAMES = retrieve_list("idle", sprite_sheet_img_IDLE)
RUN_FRAMES = retrieve_list("run", sprite_sheet_img_RUN)
currentANIMATION = "idle"
playingAnim = None

while True:

    clock.tick(FPS)
    now = time.time()
    dt = now - prev_time
    prev_time = now
    WIN.fill(BG_COLOR)

    if currentANIMATION == "idle":
        if player_location[1] > WIN_SIZE[1] - IDLE_FRAMES[IDLE_INDEX].get_height():
            player_y_momentum = -player_y_momentum
        else:
            player_y_momentum += 0.2
        player_location[1] += player_y_momentum
    elif currentANIMATION == "run":
        if player_location[1] > WIN_SIZE[1] - RUN_FRAMES[RUN_INDEX].get_height():
            player_y_momentum = -player_y_momentum
        else:
            player_y_momentum += 0.2
        player_location[1] += player_y_momentum

    if moving_right:
        currentANIMATION = "run"
        if not lookingRight:
            lookingRight = True
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(RUN_FRAMES[RUN_INDEX], (player_location[0], player_location[1]))
        player_location[0] += speed
    if moving_left:
        currentANIMATION = "run"
        if lookingRight:
            lookingRight = False
        leftFrame = pygame.transform.flip(RUN_FRAMES[RUN_INDEX], True, False)
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(leftFrame, (player_location[0], player_location[1]))
        player_location[0] -= speed
    elif moving_right != True and moving_left != True:
        currentANIMATION = "idle"
        WIN.fill(BG_COLOR)
        playingAnim = WIN.blit(IDLE_FRAMES[IDLE_INDEX], (player_location[0], player_location[1]))

    player_rect.x = player_location[0] + 155
    player_rect.y = player_location[1] + 140

    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_RIGHT or event.key == ord('d'):
                moving_right = True
            if event.key == K_LEFT or event.key == ord('a'):
                moving_left = True
        if event.type == KEYUP:
            if event.key == K_RIGHT or event.key == ord('d'):
                moving_right = False
            if event.key == K_LEFT or event.key == ord('a'):
                moving_left = False

    pygame.display.update()
    if animation_tick == 8:  # change 20 to how ever many ticks in between animation frames
        if currentANIMATION == "idle":
            if IDLE_INDEX < 8:
                IDLE_INDEX += 1
            else:
                IDLE_INDEX = 0
        if currentANIMATION == "run":
            if RUN_INDEX < 8:
                RUN_INDEX += 1
            else:
                RUN_INDEX = 0
        animation_tick = 0  # reset tick back to 0 after changing frame
    else:
        animation_tick += 1  # add 1 each iteration of the while loop

Here are the spritesheets if you want to replicate my situation:
running spritesheet:

idle spritesheet:

I've tried flipping the original surface, but then the image gets messed up with black around it, and it doesn't play the animation.


问:
Python to .cpp and back again with ctypes via an .so
I'm doing something stupid, but not seeing what... I've reduced my problem to the below (absurd) example - but it highlights where my issue is - I'm clearly not able to pass data into and/or return from, c++, coherently.

test.cpp

```<code>extern "C"
double reflect(double inp){
    return inp;
}
</code>```

The above is compiled with:

```<code>g++ -c -Wall - Werror -fPIC test.cpp -o testO.o
g++ -shared -o testSO.so testO.o
</code>```

Output file definitions are included only as I'd use them in real-problem

.py

```<code>import ctypes
hdl = ctypes.cdll.LoadLibrary(r"C:\Windows\path\to\testSO.so")
</code>```

So, my returns

```<code>hdl.reflect(1)
>>> 1    (no ctypes conversion, but erm, OK)

hdl.reflect(1.1)
>>> Failure (this is expected)

hdl.reflect(ctypes.c_int(1))
>>> 1   (right well, c_int to c_double looks like it could implicitly work)

hdl.reflect(ctypes.c_float(1.1))
>>> 1006192077   (WTF?!?)

hdl.reflect(ctypes.c_double(1.2))
>>> 858993459    (WTF?!?!)
</code>```

OS is windows 10, compiler is minGW-W64  8.1.0, python is 3.8 (anaconda)

I've ran DLLs before and I've compiled my own .c into python modules before - but for the life of me I cannot see what I'm doing wrong here.....!?!

edit: Corrected typo as pointed out by Topological Sort (path to .so was correct in code, was missing trailing " here)

答:
Object files and shared libraries do not contain any information about the types of function parameters or return types, at least not for C linkage functions.

Therefore ctypes has no way of knowing that the function is supposed to take a double argument and return a double.

If you call it with anything else than ctypes.c_double as argument, you will have undefined behavior. But you can set the argument types up for automatic conversion to the correct ctypes type (see below).

ctypes also assumes that the return type is int. If that is not the case, you are supposed to set the return types correctly before calling. In the following I also set up the argument types so that ctypes automatically uses the correct type in calls:

```<code>reflect = hdl.reflect
reflect.argtypes = [ctypes.c_double]
reflect.restype = ctypes.c_double
reflect(1.2)
</code>```

Body:
I'm doing something stupid, but not seeing what... I've reduced my problem to the below (absurd) example - but it highlights where my issue is - I'm clearly not able to pass data into and/or return from, c++, coherently.

test.cpp

extern "C"
double reflect(double inp){
    return inp;
}

The above is compiled with:

g++ -c -Wall - Werror -fPIC test.cpp -o testO.o
g++ -shared -o testSO.so testO.o

Output file definitions are included only as I'd use them in real-problem

.py

import ctypes
hdl = ctypes.cdll.LoadLibrary(r"C:\Windows\path\to\testSO.so")

So, my returns

hdl.reflect(1)
>>> 1    (no ctypes conversion, but erm, OK)

hdl.reflect(1.1)
>>> Failure (this is expected)

hdl.reflect(ctypes.c_int(1))
>>> 1   (right well, c_int to c_double looks like it could implicitly work)

hdl.reflect(ctypes.c_float(1.1))
>>> 1006192077   (WTF?!?)

hdl.reflect(ctypes.c_double(1.2))
>>> 858993459    (WTF?!?!)

OS is windows 10, compiler is minGW-W64  8.1.0, python is 3.8 (anaconda)

I've ran DLLs before and I've compiled my own .c into python modules before - but for the life of me I cannot see what I'm doing wrong here.....!?!

edit: Corrected typo as pointed out by Topological Sort (path to .so was correct in code, was missing trailing " here)

Body:
Object files and shared libraries do not contain any information about the types of function parameters or return types, at least not for C linkage functions.

Therefore ctypes has no way of knowing that the function is supposed to take a double argument and return a double.

If you call it with anything else than ctypes.c_double as argument, you will have undefined behavior. But you can set the argument types up for automatic conversion to the correct ctypes type (see below).

ctypes also assumes that the return type is int. If that is not the case, you are supposed to set the return types correctly before calling. In the following I also set up the argument types so that ctypes automatically uses the correct type in calls:

reflect = hdl.reflect
reflect.argtypes = [ctypes.c_double]
reflect.restype = ctypes.c_double
reflect(1.2)


问:
Slow SQL Query / Displaying (PHP / jQuery)
I have a request to get data in my mySQL database (36,848 entries).
Then I format and append them with jQuery on my web page.

These two operations take 2 minutes and 30 seconds.
During this time, no other operation is possible on the page.

Is there a way to optimize this to speed up the process?
Like this, it's unusable.

My PHP function

```<code><?php
function get_my_customers() {
    $req = $bdd->prepare("SELECT * FROM clients ORDER BY raison_sociale");
    $req->execute();
    $customers = $req->fetchAll(PDO::FETCH_ASSOC);

    return $customers;
}

if(isset($_POST['ajax'])){
    $result = get_my_customers();
    echo json_encode($result);
}
?>
</code>```

Data retrieval in jQuery (Ajax)

```<code>function get_my_customers(){
    var customers;
    $.ajax({
        url: "model/application/*******/customers/get_my_customers.php",
        async: false,
        type: "POST",
        dataType: 'json',
        data: {ajax: 'true'},
        success: function(data)
        {
            customers = data;
        }
    });
    return customers;
}

var my_customers = get_my_customers();

$('#customers_list').append('<div class="list_card" card="customers_list"></div>');

$.each(my_customers, function(key, val){
    if(val.enseigne == null){
        var enseigne = '';
    }else{
        var enseigne = ',' + val.enseigne;
    }

    $('.list_card[card="customers_list"]').append(''+
        '<div class="list_card_element">'+
            '<div><b>'+ val.numero_client +'</b></div>'+
            '<div>'+
                '<b>'+ val.raison_sociale +'</b>' + enseigne +
                '<br>'+
                val.cp_livraison + ', ' + val.adresse_livraison +
            '</div>'+
        '</div>'
    );
});
</code>```

Do you know what I can do to speed up processing time?
I've tried limiting the SELECT query to only the fields I need but that doesn't improve processing time.

I wonder if it's not rather the jQuery layout that takes time rather than the SQL query.

Thank you !

答: Use devtools in your browser to determine which step is causing the slowdown. The Network tab will show you the Ajax request and the time interval of the data fetch. If that time interval is not the issue, it's likely with the Javascript. You can get deeper on the Javascript performance using the Performance tab.</p>

Body:
I have a request to get data in my mySQL database (36,848 entries).
Then I format and append them with jQuery on my web page.

These two operations take 2 minutes and 30 seconds.
During this time, no other operation is possible on the page.

Is there a way to optimize this to speed up the process?
Like this, it's unusable.

My PHP function

<?php
function get_my_customers() {
    $req = $bdd->prepare("SELECT * FROM clients ORDER BY raison_sociale");
    $req->execute();
    $customers = $req->fetchAll(PDO::FETCH_ASSOC);

    return $customers;
}

if(isset($_POST['ajax'])){
    $result = get_my_customers();
    echo json_encode($result);
}
?>

Data retrieval in jQuery (Ajax)

function get_my_customers(){
    var customers;
    $.ajax({
        url: "model/application/*******/customers/get_my_customers.php",
        async: false,
        type: "POST",
        dataType: 'json',
        data: {ajax: 'true'},
        success: function(data)
        {
            customers = data;
        }
    });
    return customers;
}

var my_customers = get_my_customers();

$('#customers_list').append('

');

$.each(my_customers, function(key, val){
    if(val.enseigne == null){
        var enseigne = '';
    }else{
        var enseigne = ',' + val.enseigne;
    }

    $('.list_card[card="customers_list"]').append(''+
        '
'+
            '
'+ val.numero_client +'
'+
            '
'+
                ''+ val.raison_sociale +'' + enseigne +
                '
'+
                val.cp_livraison + ', ' + val.adresse_livraison +
            '
'+
        '
'
    );
});

Do you know what I can do to speed up processing time?
I've tried limiting the SELECT query to only the fields I need but that doesn't improve processing time.

I wonder if it's not rather the jQuery layout that takes time rather than the SQL query.

Thank you !


问:
asyncTask and progressDialog : Freeze
please see my code .. and if you can, tell me why my progressDialog stopped when the function is halfway done in the background, the screen hangs (nothing is displayed, the logcat shows all logs i put in the background function).

Then, right before the end, the progressDialog starts animating again and closes after a couple seconds (the function is finished and the result is displayed normally)

```<code>public class changeWall extends AsyncTask<Integer, Integer, Integer> {
        protected Integer doInBackground(Integer... urls) {
            int totalSize=0;
            try {

                 if(s.loadBoolean() == false)
                {
                     log("IF = false");
                     log("tempLogin = "+tempLogin);
                     log("tempPassword = "+tempPassword);
                     getNewResponse(tempLogin,tempPassword);
                if(needSave)
                {
                 s.saveBoolean(true);
                }

                }
                 else
                 {
                if(s.loadLogin()==null)
                {
                   getNewResponse(tempLogin,tempPassword);
                }else
                {
                    getNewResponse(s.loadLogin(),s.loadPassowrd());
                }
                 }
                parser.setLol(0);

                parser.startParse(RESULT_STRING);

             log("end parse");
            } catch (ClientProtocolException e) {
                log("internet connection lost");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log(" connection lost");
            }
            log("count = "+parser.getFacebookId(1));
            publishProgress();
            totalSize=1;
            log("end of start");
            return totalSize;
        }

        protected void onProgressUpdate(Integer... progress) {
            log("wall click ON PROGRESS UPDATE");
            wall.setBackgroundResource(R.drawable.tabbuttonon);
            messages.setBackgroundResource(0);
            activity.setBackgroundResource(0);
            profile.setBackgroundResource(0);
            l1_1.setBackgroundResource(R.drawable.tabbuttononleft);
            l1_2.setBackgroundResource(R.drawable.tabbuttononright);
            l2_1.setBackgroundResource(0);
            l2_2.setBackgroundResource(0);
            l3_1.setBackgroundResource(0);
            l3_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            wall.setTextColor(Color.BLACK);
            messages.setTextColor(Color.WHITE);
            profile.setTextColor(Color.WHITE);
            activity.setTextColor(Color.WHITE);

            try {
                loadWall();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            }
               wallProgres.dismiss();
        }

        protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");

           }
        }
    }
</code>```

simple map as this showed :

```<code>----start progress(progress.show())
----start function
--- animation (progressDialog)
---animation(---)
---animation(---)
---FREEZ
---FREEZ(Function steel working normal, progressDialog in freeze mode)
---animation
---end function
---progress.dismis();//
</code>```

similar problem i found here..(this problem = my problem but without download) Freezing UI Thread with AsyncTask
Regards,Peter.

答:
put this line

```<code>wallProgres.dismiss();
</code>```

in onPostExecute() method

```<code>protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");
               wallProgres.dismiss();
           }
        }
</code>```

ContentLicense: CC BY-SA 3.0

Title: asyncTask and progressDialog : Freeze

Body:
please see my code .. and if you can, tell me why my progressDialog stopped when the function is halfway done in the background, the screen hangs (nothing is displayed, the logcat shows all logs i put in the background function).

Then, right before the end, the progressDialog starts animating again and closes after a couple seconds (the function is finished and the result is displayed normally)

public class changeWall extends AsyncTask<Integer, Integer, Integer> {
        protected Integer doInBackground(Integer... urls) {
            int totalSize=0;
            try {

                 if(s.loadBoolean() == false)
                {
                     log("IF = false");
                     log("tempLogin = "+tempLogin);
                     log("tempPassword = "+tempPassword);
                     getNewResponse(tempLogin,tempPassword);
                if(needSave)
                {
                 s.saveBoolean(true);
                }

                }
                 else
                 {
                if(s.loadLogin()==null)
                {
                   getNewResponse(tempLogin,tempPassword);
                }else
                {
                    getNewResponse(s.loadLogin(),s.loadPassowrd());
                }
                 }
                parser.setLol(0);

                parser.startParse(RESULT_STRING);

             log("end parse");
            } catch (ClientProtocolException e) {
                log("internet connection lost");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log(" connection lost");
            }
            log("count = "+parser.getFacebookId(1));
            publishProgress();
            totalSize=1;
            log("end of start");
            return totalSize;
        }

        protected void onProgressUpdate(Integer... progress) {
            log("wall click ON PROGRESS UPDATE");
            wall.setBackgroundResource(R.drawable.tabbuttonon);
            messages.setBackgroundResource(0);
            activity.setBackgroundResource(0);
            profile.setBackgroundResource(0);
            l1_1.setBackgroundResource(R.drawable.tabbuttononleft);
            l1_2.setBackgroundResource(R.drawable.tabbuttononright);
            l2_1.setBackgroundResource(0);
            l2_2.setBackgroundResource(0);
            l3_1.setBackgroundResource(0);
            l3_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            l4_2.setBackgroundResource(0);
            wall.setTextColor(Color.BLACK);
            messages.setTextColor(Color.WHITE);
            profile.setTextColor(Color.WHITE);
            activity.setTextColor(Color.WHITE);

            try {
                loadWall();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

            }
               wallProgres.dismiss();
        }

        protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");

           }
        }
    }

simple map as this showed :

----start progress(progress.show())
----start function
--- animation (progressDialog)
---animation(---)
---animation(---)
---FREEZ
---FREEZ(Function steel working normal, progressDialog in freeze mode)
---animation
---end function
---progress.dismis();//

similar problem i found here..(this problem = my problem but without download) Freezing UI Thread with AsyncTask
Regards,Peter.

Body:
put this line

wallProgres.dismiss();

in onPostExecute() method

protected void onPostExecute(Long result) {
           if(result==1)
           {
               log("end WallChange");
               wallProgres.dismiss();
           }
        }


问:
How can i merge two mysql databases of same characteristics with out losing any data
Here is the issue. I have an app that was installed on two different servers with DB 1 and DB2. Each has the same schema and auto incremental key. but DB2 has more data input than DB1 while DB1 has some important data that is not in DB2.

How can I merge the two databases without losing my data in any of them?

I have searched and come across a guide that suggested this

```<code>INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1
</code>```

But my problem is that the databases have up to 106 tables.

is there a way to merge all the tables at once?

答:
This is all depends on how your auto incrementing keys are setup and how normalized/relational your data is. The more normalized your data is, the harder it will be. This isn't exactly an answer, but a general idea. This isn't an easy way, but probably the easiest.

Find the table with the largest auto incremented ID value in DB2. Lets pretend that you find that the Customer table's ID field has the most records and it's highest ID value is 91,365.

Find the table in DB1 that has the highest ID value. It's likely to be the same table, so again, let's pretend that it is Customer and it's highest ID is 7,104. Which specific table it is isn't important though.

Rounds up both values to give yourself some wiggle room:
DB2: 100,000
DB1: 10,000

Write a query that disables auto increment on all DB2 tables, and reseeds each one of them to start incrementing at 120,000.

Write queries to import all records in DB1 tables, but add 100,000 to each DB1 key/foreignkey field. So record ids 1, 2, 15, 876, 1294 would become 100001, 100002, 100015, 100876, 101294.

Reenable auto incrementing. You should now have all of DB2s original records with ids below 100000, all of DB1s original records between 100000-120000, and all newly created records after the merge with IDs at 120000 and above.

This has the added advantage of giving you an easy way to segregate the old data from each database from the new data for trouble shooting in the future.

This is the easiest way to keep keys and foreign keys consistent without lots of lots of custom code.

Body:
Here is the issue. I have an app that was installed on two different servers with DB 1 and DB2. Each has the same schema and auto incremental key. but DB2 has more data input than DB1 while DB1 has some important data that is not in DB2.

How can I merge the two databases without losing my data in any of them?

I have searched and come across a guide that suggested this

INSERT INTO DB1.TABLE1 SELECT * FROM DB2.TABLE1

But my problem is that the databases have up to 106 tables.

is there a way to merge all the tables at once?


问:
Detect when a child form is closed
I have he following Form:

An Initialize Function that is called when the Form1 is created.

A button that opens another Form (Form2)

What I need is to call Initialize() not only when Form1 is created, but whenever Form2 is closed, since Form2 might have modified some stuff that makes Initialize need to be called again.

How can I detect when the form2 is closed?

```<code>public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Initialize();
    }

    void Initialize()
    {
        // Read a config file and initialize some stuff
    }

    // Clicking this button will open a Form2
    private void button1_Click(object sender, EventArgs e)
    {
        var form2 = new Form2().Show();
    }
}

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
        // some stuff that Form2 does which involves modifying the config file
    }
}
</code>```

答:
In addition to Steve's excellent answer, you may consider displaying Form2 as a modal dialog. This would mean code execution in Form1 STOPS until Form2 is dismissed. This may or may not work well with your application, we have no idea what it does.

At any rate, you'd use ShowDialog() instead of Show() like this:

```<code>// Clicking this button will open a Form2
private void button1_Click(object sender, EventArgs e)
{
    var form2 = new Form2().ShowDialog(); // <-- code STOPS here until form2 is closed
    Initialize(); // form2 was closed, update everything
}
</code>```

Title: Detect when a child form is closed

Body:
I have he following Form:

An Initialize Function that is called when the Form1 is created.

A button that opens another Form (Form2)

What I need is to call Initialize() not only when Form1 is created, but whenever Form2 is closed, since Form2 might have modified some stuff that makes Initialize need to be called again.

How can I detect when the form2 is closed?

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        Initialize();
    }

    void Initialize()
    {
        // Read a config file and initialize some stuff
    }

    // Clicking this button will open a Form2
    private void button1_Click(object sender, EventArgs e)
    {
        var form2 = new Form2().Show();
    }
}

public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
        // some stuff that Form2 does which involves modifying the config file
    }
}

Body:
In addition to Steve's excellent answer, you may consider displaying Form2 as a modal dialog. This would mean code execution in Form1 STOPS until Form2 is dismissed. This may or may not work well with your application, we have no idea what it does.

At any rate, you'd use ShowDialog() instead of Show() like this:

// Clicking this button will open a Form2
private void button1_Click(object sender, EventArgs e)
{
    var form2 = new Form2().ShowDialog(); // <-- code STOPS here until form2 is closed
    Initialize(); // form2 was closed, update everything
}


问:
Backing property vs. getter for returning a less specific type
This is a follow up question to my previous question I have a hard time understanding the purpose of a "backing property"

I understand that sometimes, we want to to have a private mutable list inside a class, and expose an immutable list to outside classes. Like this:

```<code>class Demo {
    private val _myList: MutableList<String> = mutableListOf()
    val myList: List<String> get() = _myList
}

fun main() {
    val list = Demo().myList
}
</code>```

In this case, list is an immutable list, as desired.

But what about this code:

```<code>class Demo {
    private val myList: MutableList<String> = mutableListOf()

    fun getList(): List<String> = myList.toList()
}

fun main() {
    val list = Demo().getList()
}
</code>```

In this case, we don't have an extra property, and list is also an immutable list. This is kind of the Java way of doing this.

What's the real difference between the two?

答:
This:

```<code>    private val _myList: MutableList<String> = mutableListOf()
    val myList: List<String> get() = _myList
</code>```

gives you a reference to _myList, but exposed as the immutable List supertype. It basically makes it a read-only view of the list.

But this:

```<code>    private val myList: MutableList<String> = mutableListOf()
    fun getList(): List<String> = myList.toList()
</code>```

is creating a new list every time you call it. You get a read-only copy of the current internal list. You won't see any changes to the original's contents unless you access that property again (i.e. call its getter) to get a new copy of the list.

Body:
This is a follow up question to my previous question I have a hard time understanding the purpose of a "backing property"

I understand that sometimes, we want to to have a private mutable list inside a class, and expose an immutable list to outside classes. Like this:

class Demo {
    private val _myList: MutableList<String> = mutableListOf()
    val myList: List<String> get() = _myList
}

fun main() {
    val list = Demo().myList
}

In this case, list is an immutable list, as desired.

But what about this code:

class Demo {
    private val myList: MutableList<String> = mutableListOf()

    fun getList(): List<String> = myList.toList()
}

fun main() {
    val list = Demo().getList()
}

In this case, we don't have an extra property, and list is also an immutable list. This is kind of the Java way of doing this.

What's the real difference between the two?

Body:
This:

    private val _myList: MutableList<String> = mutableListOf()
    val myList: List<String> get() = _myList

gives you a reference to _myList, but exposed as the immutable List supertype. It basically makes it a read-only view of the list.

But this:

    private val myList: MutableList<String> = mutableListOf()
    fun getList(): List<String> = myList.toList()

is creating a new list every time you call it. You get a read-only copy of the current internal list. You won't see any changes to the original's contents unless you access that property again (i.e. call its getter) to get a new copy of the list.


问:
Java Record - Tests - Modify Fields
I have a framework used exclusively for testing that sets fields at runtime. The purpose is to set up test cases. Looking forward to upgrading to Java 14+ records I am noticing that existing utilities such as ReflectionTestUtils.setField and PropertyAccessorFactory.forDirectFieldAccess which work on normal private final fields, do not work for record fields.

Is this a limitation of the JVM, or is a limitation of these utilities?

答:
Since modifying the private final fields of a record is intentionally unsupported, it’s not a limitation of the JVM or Java execution environment, so relying on the ability to modify such fields is a limitation of these utilities.

The documentation of setAccessible says:

This method cannot be used to enable write access to a non-modifiable final field. The following fields are non-modifiable:

static final fields declared in any class or interface

final fields declared in a hidden class

final fields declared in a record

The original intent of supporting to write a final instance field via access override, was to allow fixing the object state after cloning or deserializing. Neither is necessary for a record.

Deserializing a record instance will invoke its constructor, so the constructor can apply all necessary validation and fixes before the final fields are assigned.

Creating a shallow clone of a record has no point at all. For all other copying purposes, you can read all of its components, as each field has a corresponding accessor method, adapt them, and pass the adapted values to the always existing canonical constructor.

Title: Java Record - Tests - Modify Fields


问:
Running dotnet ef migrations for class library gives error MSB4006
I have an ASP.NET Core Web Application (.NET Framework) project targeting .NET Framework 4.6.2.

I have introduced Entity Framework into the web project and have set up and run

```<code>dotnet ef migrations add Initial
</code>```

from the web project directory. The migration is created, all is good.

I want to refactor the code so that my entities and db context are in a class library instead. So I have created a separate Class Library (.NET Framework) project, also targeting .NET Framework 4.6.2.

Still from the web project directory I run

```<code>dotnet ef migrations add Initial --startup-project . --project ..\MigrationTest.Entities
</code>```

where MigrationTest.Entities is my class library.

This time I get:

C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\obj\MigrationTest.Entities.csproj.EntityFrameworkCore.targets(4,5):
error MSB4006: There is a circular dependency in the target dependency
graph involving target "GetEFProjectMetadata".
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\MigrationTest.Entities.csproj]
Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

It isn't a .NET Core project, so I try creating a .NET Core project instead. Running the migrations command then gives:

C:\Program
Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5):
error : Project
'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj'
targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a
project that targets '.NETFramework,Version=v4.6.2'.
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj]
C:\Program
Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5):
error : Cannot find project info for
'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj'.
This can indicate a missing project reference.
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Web\MigrationTest.Web.csproj]

And of course, the Core project cannot be referenced by the .NET project.

Is what I am trying to do a supported scenario? Is there some problem with my command line usage? Something else?

答:
Select the in "Default Project" window  if you are targeting the expected project

Check which is current directory

In my case it was NOT the expected directory where was my project located, so I had to navigate to it manually. This solved my issue.

Body:
I have an ASP.NET Core Web Application (.NET Framework) project targeting .NET Framework 4.6.2.

I have introduced Entity Framework into the web project and have set up and run

dotnet ef migrations add Initial

from the web project directory. The migration is created, all is good.

I want to refactor the code so that my entities and db context are in a class library instead. So I have created a separate Class Library (.NET Framework) project, also targeting .NET Framework 4.6.2.

Still from the web project directory I run

dotnet ef migrations add Initial --startup-project . --project ..\MigrationTest.Entities

where MigrationTest.Entities is my class library.

This time I get:

C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\obj\MigrationTest.Entities.csproj.EntityFrameworkCore.targets(4,5):
error MSB4006: There is a circular dependency in the target dependency
graph involving target "GetEFProjectMetadata".
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities\MigrationTest.Entities.csproj]
Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

It isn't a .NET Core project, so I try creating a .NET Core project instead. Running the migrations command then gives:

C:\Program
Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5):
error : Project
'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj'
targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a
project that targets '.NETFramework,Version=v4.6.2'.
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj]
C:\Program
Files\dotnet\sdk\1.0.3\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5):
error : Cannot find project info for
'C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Entities.Core\MigrationTest.Entities.Core.csproj'.
This can indicate a missing project reference.
[C:\Projects\Experiments\MigrationTestNoIdentity\MigrationTest.Web\MigrationTest.Web.csproj]

And of course, the Core project cannot be referenced by the .NET project.

Is what I am trying to do a supported scenario? Is there some problem with my command line usage? Something else?


问:
How can I read the data in firebase with flutter
I tried some things but I cant read the data. I'm a beginner in flutter and I have to do a project that it shows the data in firebase. Can you show a beginner project that it only shows the datas in direbase?

I tried this too but this code have some errors on await (how it's possible I copied this from flutter official site)

```<code>import 'package:firebase_database/firebase_database.dart';
DatabaseReference ref = FirebaseDatabase.instance.ref("users/123");
// Get the data once
DatabaseEvent event = await ref.once();
// Print the data of the snapshot
print(event.snapshot.value);
</code>```

Thanks for replys I checked the await keyword and correct them (I think)
But I dont know how to print this
Can you show me that too
And I edited code to this =>

```<code>Future<Object?> GetData() async {
  FirebaseDatabase database = FirebaseDatabase.instance;

  DatabaseReference ref = FirebaseDatabase.instance.ref("litre");

// Get the data once
  DatabaseEvent event = await ref.once();

// Print the data of the snapshot
  print(event.snapshot.value); // { "name": "John" }
  return event.snapshot.value;
}
</code>```

答:
Wherever you're calling the GetData method you need to await it...or if it is a widget which needs to display data after fetching it from firebase you can wrap it with a future builder.

I hope this solves your problem, if it still doesn't, post with the specific error you're getting.

```<code>FutureBuilder(
    future: GetData(),
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return Center(
          child: CircularProgressIndicator(),
        );
      } else {
        if (snapshot.error != null) {
          return Center(
            child: Text('An error occured'),
          );
        } else {
          return Text(snapshot.data); // Or whatever widget you want to return or display
        }
      }
    },
  ),
</code>```

Body:
I tried some things but I cant read the data. I'm a beginner in flutter and I have to do a project that it shows the data in firebase. Can you show a beginner project that it only shows the datas in direbase?

I tried this too but this code have some errors on await (how it's possible I copied this from flutter official site)

import 'package:firebase_database/firebase_database.dart';
DatabaseReference ref = FirebaseDatabase.instance.ref("users/123");
// Get the data once
DatabaseEvent event = await ref.once();
// Print the data of the snapshot
print(event.snapshot.value);

Thanks for replys I checked the await keyword and correct them (I think)
But I dont know how to print this
Can you show me that too
And I edited code to this =>

Future<Object?> GetData() async {
  FirebaseDatabase database = FirebaseDatabase.instance;

  DatabaseReference ref = FirebaseDatabase.instance.ref("litre");

// Get the data once
  DatabaseEvent event = await ref.once();

// Print the data of the snapshot
  print(event.snapshot.value); // { "name": "John" }
  return event.snapshot.value;
}

Body:
Wherever you're calling the GetData method you need to await it...or if it is a widget which needs to display data after fetching it from firebase you can wrap it with a future builder.

I hope this solves your problem, if it still doesn't, post with the specific error you're getting.

FutureBuilder(
    future: GetData(),
    builder: (context, snapshot) {
      if (snapshot.connectionState == ConnectionState.waiting) {
        return Center(
          child: CircularProgressIndicator(),
        );
      } else {
        if (snapshot.error != null) {
          return Center(
            child: Text('An error occured'),
          );
        } else {
          return Text(snapshot.data); // Or whatever widget you want to return or display
        }
      }
    },
  ),


问:
nginx.conf and nginx.pid users and permissions
I'm embarking on watching my NGINX error.log files at level: warn... probably a silly idea and will cause me to crash my server as I work out any bugs happening, but hey, we're nerds and this is why we're here.

I'm noticing a [warn] and an [emerg] pop up every time I restart my server, which shows:

```<code>[warn] 8041#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
[emerg] 8041#0: open() "/run/nginx.pid" failed (13: Permission denied)
</code>```

The top of my nginx.conf file reads:

```<code>user www-data;
worker_processes auto;
pid /run/nginx.pid;
</code>```

Which to me, shows me a few things.

I'm running NGINX with the user: www-data.

The number of worker processes that are allowed is automatically adjusted.

my PID file/information is being stored in /run/nginx.pid.

The error tells me that NGINX doesn't have permission to access /run/nginx.pid, which led me to see the user permissions for said file.

```<code>sudo ls -la /run/nginx.pid
</code>```

reveals:

```<code>-rw-r--r-- 1 root root 5 Jun 18 05:34 /run/nginx.pid
</code>```

Then trying:

```<code>ps -ef | grep nginx
</code>```

produces:

```<code>root      5914     1  0 05:34 ?        00:00:00 nginx: master process /u
www-data  5917  5914  0 05:34 ?        00:00:00 nginx: worker process
</code>```

scratches head

Now, can somebody out there tell me why, or how the hell NGINX has managed to create the master process with root ownership, and now the worker processes are owned by www-data?

Or more to the point, anybody have some suggestions on what to do about this [emerg] error I'm getting?

My first thought is to just try and change the ownership of the /run/nginx.pid file and see how NGINX likes it, but I kind of feel that even if I do that manually this time, when I restart the server, I'll run into the same problem.

My second thought is maybe there is somewhere else that I define my worker process initiation within NGINX..

Thanks.

EDIT

The contents of the /etc/systemd/system/multi-user.target.wants/nginx.service file are:

```<code>[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target
</code>```

答:
For Ubuntu 20.04+

I got the exact same error while I was using sudo systemctl reload nginx

Using sudo service nginx restart instead throws no error

Body:
I'm embarking on watching my NGINX error.log files at level: warn... probably a silly idea and will cause me to crash my server as I work out any bugs happening, but hey, we're nerds and this is why we're here.

I'm noticing a [warn] and an [emerg] pop up every time I restart my server, which shows:

[warn] 8041#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
[emerg] 8041#0: open() "/run/nginx.pid" failed (13: Permission denied)

The top of my nginx.conf file reads:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

Which to me, shows me a few things.

I'm running NGINX with the user: www-data.

The number of worker processes that are allowed is automatically adjusted.

my PID file/information is being stored in /run/nginx.pid.

The error tells me that NGINX doesn't have permission to access /run/nginx.pid, which led me to see the user permissions for said file.

sudo ls -la /run/nginx.pid

reveals:

-rw-r--r-- 1 root root 5 Jun 18 05:34 /run/nginx.pid

Then trying:

ps -ef | grep nginx

produces:

root      5914     1  0 05:34 ?        00:00:00 nginx: master process /u
www-data  5917  5914  0 05:34 ?        00:00:00 nginx: worker process

scratches head

Now, can somebody out there tell me why, or how the hell NGINX has managed to create the master process with root ownership, and now the worker processes are owned by www-data?

Or more to the point, anybody have some suggestions on what to do about this [emerg] error I'm getting?

My first thought is to just try and change the ownership of the /run/nginx.pid file and see how NGINX likes it, but I kind of feel that even if I do that manually this time, when I restart the server, I'll run into the same problem.

My second thought is maybe there is somewhere else that I define my worker process initiation within NGINX..

Thanks.

EDIT

The contents of the /etc/systemd/system/multi-user.target.wants/nginx.service file are:

[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target


问:
Outlook Add-in that just directs to a website
I want to program a simple Outlook add-in that opens a browser and take the user to a specific site.
I've had a look at using Yeoman, but this add-in opens a task pane where I'm just looking to take that single actions.
Is there a simple way to do this?

EDIT:

I managed to get this done, but I not have the following issue: I have a single button (via Yeoman's generator) that when clicked executes the following:

```<code>function action(event) {

const message = {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Window opened.",
    icon: "Icon.80x80",
    persistent: true,
  };

  // Show a notification message
  window.open("https://myurl.com");
  Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);

  // Be sure to indicate when the add-in command function is complete
  event.completed();
}
</code>```

I get the following error in Outlook itself:

We deployed the app using the MS 365 admin center, but I'm not sure if there is something additional that I need to do in this case to run the webserver?

答:
If you want to display any web site to the user as a result of the button click or some action on the pane, try doing window.open('https://yoursite.com'). This should work if the domain is whitelisted in your manifest. For example:

```<code>function redirectFunction() {
    window.open("https://othersite.com")
    //window.location.href = "https://othersite.com";
}
</code>```

Body:
I want to program a simple Outlook add-in that opens a browser and take the user to a specific site.
I've had a look at using Yeoman, but this add-in opens a task pane where I'm just looking to take that single actions.
Is there a simple way to do this?

EDIT:

I managed to get this done, but I not have the following issue: I have a single button (via Yeoman's generator) that when clicked executes the following:

function action(event) {

const message = {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Window opened.",
    icon: "Icon.80x80",
    persistent: true,
  };

  // Show a notification message
  window.open("https://myurl.com");
  Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);

  // Be sure to indicate when the add-in command function is complete
  event.completed();
}

I get the following error in Outlook itself:

We deployed the app using the MS 365 admin center, but I'm not sure if there is something additional that I need to do in this case to run the webserver?

Body:
If you want to display any web site to the user as a result of the button click or some action on the pane, try doing window.open('https://yoursite.com'). This should work if the domain is whitelisted in your manifest. For example:

function redirectFunction() {
    window.open("https://othersite.com")
    //window.location.href = "https://othersite.com";
}


问:
Redux-observable dispatching multiple actions
I'm learning to use redux-observable and RxJS in react-native then I face a problem with dispatching multiple actions after performing a Firestore get document request.

This is my epic:

```<code>const getUserEpic: Epic = action$ => {
  return action$.pipe(
    filter(signIn.match),
    switchMap(action => {
      let usecase = container.resolve<SignInUseCase>('SignInUseCase');
      return concat(
        of(signInBegin()),
        usecase.call(action.payload).pipe(
          map(res => {
            if (res !== undefined) return saveUser(res);
            return signInFailed();
          }),
        ),
      );
    }),
  );
};
</code>```

Basically, I'm trying to dispatch many actions after an action named "signIn" is dispatched. The "usecase" is performing a Firestore get document. After the response
is received, I want to dispatch two actions, "saveUser" and "signInSuccess". However, if the response is undefined, action "signInFailed" must be dispatched instead of those two above.

The code should be something like this:

```<code>...
        usecase.call(action.payload).pipe(
          map(res => {
            if (res !== undefined)
               return {
                   saveUser(res);
                   signInSuccess();
               }
            return signInFailed();
          }),
        ),
</code>```

Please help me correct the code! Thank you for spending your time!

Btw, this is the SignInUseCase:

```<code>@injectable()
export class SignInUseCase implements UseCase<SignInResult, any> {
  constructor(
    @inject('AuthenticationRepository')
    private readonly authenticationRepository: AuthenticationRepository,
  ) {}

  call(param?: any): Observable<SignInResult> {
    return this.authenticationRepository.signIn(param);
  }
}
</code>```

The implementation of AuthenticationRepository:

```<code>export class AuthenticationRepositoryImpl implements AuthenticationRepository {
  signIn(credential: any): Observable<SignInResult> {
    return from(getUser(credential.phone_number));
  }
}
</code>```

And this is the function "getUser" which get doc from Firestore:

```<code>export const getUser = async (phoneNumber: string) => {
  const doc = await firestore()
    .collection('users')
    .doc(phoneNumber)
    .get()
    .catch(e => {
      Alert.alert('Error: ', e);
    });

  return doc.data();
};
</code>```

答:
You can return an array in a switchMap, so the solution is simple:

```<code>    usecase.call(action.payload).pipe(
      switchMap(res => {
        if (res !== undefined)
           return [
               saveUser(res),
               signInSuccess()
           ]
        return [signInFailed()]
      }),
    ),
</code>```

This will emit all the actions in the array.

Remember that if you use switchMap, then everything you return from it must be an "ObservableLike". An Array is an ObservableLike, an Observable too, but you can't return a single action without wrapping it.

Body:
I'm learning to use redux-observable and RxJS in react-native then I face a problem with dispatching multiple actions after performing a Firestore get document request.

This is my epic:

const getUserEpic: Epic = action$ => {
  return action$.pipe(
    filter(signIn.match),
    switchMap(action => {
      let usecase = container.resolve<SignInUseCase>('SignInUseCase');
      return concat(
        of(signInBegin()),
        usecase.call(action.payload).pipe(
          map(res => {
            if (res !== undefined) return saveUser(res);
            return signInFailed();
          }),
        ),
      );
    }),
  );
};

Basically, I'm trying to dispatch many actions after an action named "signIn" is dispatched. The "usecase" is performing a Firestore get document. After the response
is received, I want to dispatch two actions, "saveUser" and "signInSuccess". However, if the response is undefined, action "signInFailed" must be dispatched instead of those two above.

The code should be something like this:

...
        usecase.call(action.payload).pipe(
          map(res => {
            if (res !== undefined)
               return {
                   saveUser(res);
                   signInSuccess();
               }
            return signInFailed();
          }),
        ),

Please help me correct the code! Thank you for spending your time!

Btw, this is the SignInUseCase:

@injectable()
export class SignInUseCase implements UseCase<SignInResult, any> {
  constructor(
    @inject('AuthenticationRepository')
    private readonly authenticationRepository: AuthenticationRepository,
  ) {}

  call(param?: any): Observable<SignInResult> {
    return this.authenticationRepository.signIn(param);
  }
}

The implementation of AuthenticationRepository:

export class AuthenticationRepositoryImpl implements AuthenticationRepository {
  signIn(credential: any): Observable<SignInResult> {
    return from(getUser(credential.phone_number));
  }
}

And this is the function "getUser" which get doc from Firestore:

export const getUser = async (phoneNumber: string) => {
  const doc = await firestore()
    .collection('users')
    .doc(phoneNumber)
    .get()
    .catch(e => {
      Alert.alert('Error: ', e);
    });

  return doc.data();
};

Body:
You can return an array in a switchMap, so the solution is simple:

    usecase.call(action.payload).pipe(
      switchMap(res => {
        if (res !== undefined)
           return [
               saveUser(res),
               signInSuccess()
           ]
        return [signInFailed()]
      }),
    ),

This will emit all the actions in the array.

Remember that if you use switchMap, then everything you return from it must be an "ObservableLike". An Array is an ObservableLike, an Observable too, but you can't return a single action without wrapping it.


问:
How do you stop SVN Checkout from bringing back files that were deleted from the project?
We are new to the subversion, tortoisesvn, ankhsvn stack.   While in Studio 2008 we have deleted files from our project problem is when we do an svn checkout in our CI build we get the deleted files.   How do I prevent these files from being included in the checkout?

Thanks in advance.

答:
In Visual Studio there's a difference between 'Remove' and 'Delete'. Delete is the default action when you press the 'del' key when in a C# project; in a C++ project the default is 'Remove'.

In case of a remove event, AnkhSVN doesn't svn delete the file, because without AnkhSVN installed, VS wouldn't remove it from disk either.

OwnerDisplayName: Dave

ContentLicense: CC BY-SA 2.5

OwnerDisplayName: Sander Rijken


问:
how to sum hours to a start shift column that contains a text
I'm trying to add 9 hours to this column and if there's a text like (off, annual, ..etc), then put the same text. but i found an error in the generated column, is there any one have an idea to to solve this problem

答:
Perhaps:</p>
```<code>try Time.From([Start Shift]) + #duration(0, 9, 0, 0) otherwise [Start Shift]
</code>```

Body:
Perhaps:

try Time.From([Start Shift]) + #duration(0, 9, 0, 0) otherwise [Start Shift]


问:
Add custom property in userinfo endpoint in Identity Server 4
I have an Identity Server 4 solution. All of the client apps requesting login, requires to know the Orgs assigned to a user. For instance, a user can have 2 restaurants & 2 supplier orgs assigned to it. Can I add this info to a property called "Orgs" with the array value on userinfo endpoint in Identity Server 4?</p>

答:
Yes, you can add as many customs properties/claims in token. So basically IdS4 provided this connect/userinfo endpoint to fetch user-specific additional properties and you can extend this behavior by implementing IProfileService interface. So whenever the client requests the new token or hits userinfo endpoint additional properties it will hit this extended helper class and you will be able to add custom properties/claims here.

Sample code: This is really minimal code that will fulfill your requirement, but there are more dependencies that you can inject into the constructor.

```<code>public class ProfileService : IProfileService
{
  public async Task GetProfileDataAsync(ProfileDataRequestContext context)
  {
     context.IssuedClaims.Add(new Claim("YourCustomClaimType", "YourCustomClaimValue"));
  }
}
</code>```

Body:
Yes, you can add as many customs properties/claims in token. So basically IdS4 provided this connect/userinfo endpoint to fetch user-specific additional properties and you can extend this behavior by implementing IProfileService interface. So whenever the client requests the new token or hits userinfo endpoint additional properties it will hit this extended helper class and you will be able to add custom properties/claims here.

Sample code: This is really minimal code that will fulfill your requirement, but there are more dependencies that you can inject into the constructor.

public class ProfileService : IProfileService
{
  public async Task GetProfileDataAsync(ProfileDataRequestContext context)
  {
     context.IssuedClaims.Add(new Claim("YourCustomClaimType", "YourCustomClaimValue"));
  }
}


问:
How do I incorporate Luxon timezone options with chart.js?
I have a line chart displayed on a webpage with chart.js but my time data is in UTC.  I would like to convert it to the Denver timezone for display on the graph.  Chart.js has a luxon adapter but I have no idea how to use it.

I have included the following scripts:

```<code><script src="./chart.js/dist/Chart.bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@1.15.0"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@0.2.0"></script>
</code>```

My time data formatted as a json string:

```<code>var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ...
</code>```

And here are my chart "Options":

options: {
    scales: {
        xAxes: [{
            type: 'time',
            distribution: 'series',
        }]
    }
}
```

So where and how do I implement a timezone definition?
I have also looked through the Luxon timezone documentation.

答:
I spent a while trying to get this to work with more recent versions of Chart.js, and the solution turned out to be pretty simple – the zone option now needs to be specified under options.scales[scaleId].adapters.date, like so:

```<code>options: {
  scales: {
    xAxes: [{
      adapters: {
        date: {
          zone: 'America/Denver',
        },
      },
      type: 'time',
      distribution: 'series',
    }],
  },
}
</code>```

Body:
I have a line chart displayed on a webpage with chart.js but my time data is in UTC.  I would like to convert it to the Denver timezone for display on the graph.  Chart.js has a luxon adapter but I have no idea how to use it.

I have included the following scripts:

My time data formatted as a json string:

var data = [{"x":"2019-07-23 01:16:11","y":83.97},{"x":"2019-07-23 01:07:13","y":82.74},{"x":"2019-07-23 00:58:21","y":83.86}, ...

And here are my chart "Options":

options: {
    scales: {
        xAxes: [{
            type: 'time',
            distribution: 'series',
        }]
    }
}

So where and how do I implement a timezone definition?
I have also looked through the Luxon timezone documentation.

Body:
I spent a while trying to get this to work with more recent versions of Chart.js, and the solution turned out to be pretty simple – the zone option now needs to be specified under options.scales[scaleId].adapters.date, like so:

options: {
  scales: {
    xAxes: [{
      adapters: {
        date: {
          zone: 'America/Denver',
        },
      },
      type: 'time',
      distribution: 'series',
    }],
  },
}


问:
Is there a way to create an array of an element that contains a specific CSS style?
I'm trying to capture the elements that do not contain a display type of none.

```<code>let pfCard = document.getElementsByClassName("PortfolioCard").style.display = 'block';
</code>```

This doesn't seem to be working as I believe it is attempting to modify the style type instead of retrieve it.

答:
You can do this by getting all your elements by class name and then using filter on that list.

 const blockElements = [...document.getElementsByClassName("PortfolioCard")].filter(x => x.style.display == "block");
 console.log(blockElements.length);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="PortfolioCard" style="display:block">block</div>
<div class="PortfolioCard">not block</div>
<div class="PortfolioCard" style="display:block">block</div></code>```

Body:
I'm trying to capture the elements that do not contain a display type of none.

let pfCard = document.getElementsByClassName("PortfolioCard").style.display = 'block';

This doesn't seem to be working as I believe it is attempting to modify the style type instead of retrieve it.

Body:
You can do this by getting all your elements by class name and then using filter on that list.

 const blockElements = [...document.getElementsByClassName("PortfolioCard")].filter(x => x.style.display == "block");
 console.log(blockElements.length);

<div class="PortfolioCard" style="display:block">block</div>
<div class="PortfolioCard">not block</div>
<div class="PortfolioCard" style="display:block">block</div>


问:
Spark structured stream with tumbling window delayed and duplicate data
I am attempting to read from a kafka topic, aggregate some data over a tumbling window and write that to a sink (I've been trying both with Kafka and console).

The problems I'm seeing are

a long delay between sending data and receiving aggregate records for a window on the sink (minutes after the expected triggers should fire)

duplicate records from previous window aggregations appearing in subsequent windows

Why is the delay so long, and what can I do to reduce it?

Why are duplicates records from previous windows showing up and how can I remove them?

The delays seem to be especially bad as the window gets shorter - it was 3+ minutes when I had the window duration set to 10 seconds, around 2 minutes when the window duration was set to 60 seconds.

With the shortest window times I'm also seeing the records getting "bunched up" so that when records are received by the sink I receive those for several windows at a time.

On the duplicate aggregate records I do have the output mode set to complete but my understanding is records should only be repeated withing the current window assuming the trigger fires multiple times within it, which mine shouldn't be.

I have a processing trigger set up matching the window time and a watermark threshold of 10% (1 or 6 seconds) and I know the stream itself works fine if I remove the tumbling window.

I get why spark might not be able to hit a certain frequency of triggers but I'd think 10 and certainly 60 seconds would be more than enough time to process the very limited amount of data I am testing with.

An example of sending data with a 60 second tumbling window and processing time trigger

send 6 payloads

wait a minute

send 1 payload

wait a while

send 3 payloads

(CreateTime is coming from kafka-console-consumer with --property print.timestamp=true). These arrive a couple of minutes after I would expect the trigger to fire based on the CreateTime timestamp and window.

```<code>// First record fine
CreateTime:1644329432464        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}

// Duplicate of first record with second sent by spark even though the window is over
CreateTime:1644329505265        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}
CreateTime:1644329523901        {"window":{"start":"2022-02-08T14:10:00.000Z","end":"2022-02-08T14:11:00.000Z"},"account_id":"acc0","totalAmount":111}

// Duplicate of first 2 records with third
CreateTime:1644330082974        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}
CreateTime:1644330105990        {"window":{"start":"2022-02-08T14:10:00.000Z","end":"2022-02-08T14:11:00.000Z"},"account_id":"acc0","totalAmount":111}
CreateTime:1644330125375        {"window":{"start":"2022-02-08T14:20:00.000Z","end":"2022-02-08T14:21:00.000Z"},"account_id":"acc0","totalAmount":333}

</code>```

I do sometimes see messages like below but there's no other WARN or ERROR level messages indicating problems:

```<code>2022-02-08 14:24:45 WARN  ProcessingTimeExecutor:69 - Current batch is falling behind. The trigger interval is 60000 milliseconds, but spent 99770 milliseconds
</code>```

Application data/code

Sample data looks like below and is generated by a python script with ts set to the current time:

```<code>{"account_id": "acc0", "txn_id": "1234500001", "amount": 111, "ts": 1644258052800}
</code>```

Application code (running embedded with spark.master=local[*])

    public void execute() throws Exception {
        final SparkSession spark = SparkSession.builder().appName("test").getOrCreate();

        final Trigger trigger = Trigger.ProcessingTime(60000);
        final OutputMode outputMode = OutputMode.Complete();
        final String windowDuration = "60 seconds";
        final String watermarkThreshold = "6 seconds";

        final String kafkaHost = "localhost:9092";
        final String kafkaInTopic = "topic-in";
        final String kafkaOutTopic = "topic-out";

        final StructType schema = new StructType(
            new StructField[] {
                new StructField("account_id", DataTypes.StringType, false, null),
                new StructField("txn_id", DataTypes.StringType, false, null),
                new StructField("amount", DataTypes.LongType, false, null),
                new StructField("ts", DataTypes.LongType, false, null)
            }
        );

        final Dataset<Row> in = spark
            .readStream()
            .format("kafka")
            .option("kafka.bootstrap.servers", kafkaHost)
            .option("subscribe", kafkaInTopic)
            .option("startingOffsets", "latest")
            .option("includeHeaders", "true")
            .load();

        in.printSchema();

        final Dataset<Row> process = in
            // convert kafka value payload to structured data
            .withColumn("value", functions.from_json(functions.column("value").cast(DataTypes.StringType), schema))

            .withColumn("account_id", functions.column("value.account_id"))
            .withColumn("txn_id", functions.column("value.txn_id"))
            .withColumn("amount", functions.column("value.amount"))
            .withColumn("ts", functions.column("value.ts"))

            // conversion to timestamp is by second, not ms
            .withColumn("datetime", functions.col("ts").divide(1000).cast(DataTypes.TimestampType))
            .withWatermark("datetime", watermarkThreshold)

            .groupBy(
                functions.window(functions.col("datetime"), windowDuration),
                functions.col("account_id")
            )
            .agg(functions.sum("amount").as("totalAmount"));

        process.printSchema();

        final DataStreamWriter<Row> out = process
            // required for kafka output
            .select(functions.to_json(functions.struct("*")).as("value"))

            .writeStream()
            .outputMode(outputMode)
            .trigger(trigger)
            .format("kafka")
            .option("kafka.bootstrap.servers", kafkaHost)
            .option("topic", kafkaOutTopic)
            .option("checkpointLocation", "/tmp/spark-kafka");

        LOGGER.info("STARTING STREAM");
        out.start().awaitTermination();
    }

```

答:
For long delays, it's likely caused by not enough resources to process messages according to the warning message. You could check spark UI to understand why. It could be data skew between partitions or more memory or cores needed.

For duplicate records, you may want to try update or append mode. Complete mode means the whole Result Table will be outputted to the sink after every trigger. That's the reason why you have deplicates. You can refer https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#output-modes

Body:
I am attempting to read from a kafka topic, aggregate some data over a tumbling window and write that to a sink (I've been trying both with Kafka and console).

The problems I'm seeing are

a long delay between sending data and receiving aggregate records for a window on the sink (minutes after the expected triggers should fire)

duplicate records from previous window aggregations appearing in subsequent windows

Why is the delay so long, and what can I do to reduce it?

Why are duplicates records from previous windows showing up and how can I remove them?

The delays seem to be especially bad as the window gets shorter - it was 3+ minutes when I had the window duration set to 10 seconds, around 2 minutes when the window duration was set to 60 seconds.

With the shortest window times I'm also seeing the records getting "bunched up" so that when records are received by the sink I receive those for several windows at a time.

On the duplicate aggregate records I do have the output mode set to complete but my understanding is records should only be repeated withing the current window assuming the trigger fires multiple times within it, which mine shouldn't be.

I have a processing trigger set up matching the window time and a watermark threshold of 10% (1 or 6 seconds) and I know the stream itself works fine if I remove the tumbling window.

I get why spark might not be able to hit a certain frequency of triggers but I'd think 10 and certainly 60 seconds would be more than enough time to process the very limited amount of data I am testing with.

An example of sending data with a 60 second tumbling window and processing time trigger

send 6 payloads

wait a minute

send 1 payload

wait a while

send 3 payloads

(CreateTime is coming from kafka-console-consumer with --property print.timestamp=true). These arrive a couple of minutes after I would expect the trigger to fire based on the CreateTime timestamp and window.

// First record fine
CreateTime:1644329432464        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}

// Duplicate of first record with second sent by spark even though the window is over
CreateTime:1644329505265        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}
CreateTime:1644329523901        {"window":{"start":"2022-02-08T14:10:00.000Z","end":"2022-02-08T14:11:00.000Z"},"account_id":"acc0","totalAmount":111}

// Duplicate of first 2 records with third
CreateTime:1644330082974        {"window":{"start":"2022-02-08T14:09:00.000Z","end":"2022-02-08T14:10:00.000Z"},"account_id":"acc0","totalAmount":666}
CreateTime:1644330105990        {"window":{"start":"2022-02-08T14:10:00.000Z","end":"2022-02-08T14:11:00.000Z"},"account_id":"acc0","totalAmount":111}
CreateTime:1644330125375        {"window":{"start":"2022-02-08T14:20:00.000Z","end":"2022-02-08T14:21:00.000Z"},"account_id":"acc0","totalAmount":333}

I do sometimes see messages like below but there's no other WARN or ERROR level messages indicating problems:

2022-02-08 14:24:45 WARN  ProcessingTimeExecutor:69 - Current batch is falling behind. The trigger interval is 60000 milliseconds, but spent 99770 milliseconds

Application data/code

Sample data looks like below and is generated by a python script with ts set to the current time:

{"account_id": "acc0", "txn_id": "1234500001", "amount": 111, "ts": 1644258052800}

Application code (running embedded with spark.master=local[*])

    public void execute() throws Exception {
        final SparkSession spark = SparkSession.builder().appName("test").getOrCreate();

        final Trigger trigger = Trigger.ProcessingTime(60000);
        final OutputMode outputMode = OutputMode.Complete();
        final String windowDuration = "60 seconds";
        final String watermarkThreshold = "6 seconds";

        final String kafkaHost = "localhost:9092";
        final String kafkaInTopic = "topic-in";
        final String kafkaOutTopic = "topic-out";

        final StructType schema = new StructType(
            new StructField[] {
                new StructField("account_id", DataTypes.StringType, false, null),
                new StructField("txn_id", DataTypes.StringType, false, null),
                new StructField("amount", DataTypes.LongType, false, null),
                new StructField("ts", DataTypes.LongType, false, null)
            }
        );

        final Dataset<Row> in = spark
            .readStream()
            .format("kafka")
            .option("kafka.bootstrap.servers", kafkaHost)
            .option("subscribe", kafkaInTopic)
            .option("startingOffsets", "latest")
            .option("includeHeaders", "true")
            .load();

        in.printSchema();

        final Dataset<Row> process = in
            // convert kafka value payload to structured data
            .withColumn("value", functions.from_json(functions.column("value").cast(DataTypes.StringType), schema))

            .withColumn("account_id", functions.column("value.account_id"))
            .withColumn("txn_id", functions.column("value.txn_id"))
            .withColumn("amount", functions.column("value.amount"))
            .withColumn("ts", functions.column("value.ts"))

            // conversion to timestamp is by second, not ms
            .withColumn("datetime", functions.col("ts").divide(1000).cast(DataTypes.TimestampType))
            .withWatermark("datetime", watermarkThreshold)

            .groupBy(
                functions.window(functions.col("datetime"), windowDuration),
                functions.col("account_id")
            )
            .agg(functions.sum("amount").as("totalAmount"));

        process.printSchema();

        final DataStreamWriter<Row> out = process
            // required for kafka output
            .select(functions.to_json(functions.struct("*")).as("value"))

            .writeStream()
            .outputMode(outputMode)
            .trigger(trigger)
            .format("kafka")
            .option("kafka.bootstrap.servers", kafkaHost)
            .option("topic", kafkaOutTopic)
            .option("checkpointLocation", "/tmp/spark-kafka");

        LOGGER.info("STARTING STREAM");
        out.start().awaitTermination();
    }


问:
Azure Static Web Apps multi language websites that use microformat (eg en-GB , it-IT )
It is possible to cleanly support URLs such as

https://www.myawsomeapp.com/en-GB/
https://www.myawsomeapp.com/it-IT/

routes are angular routes and we need the fallback to fallback to the countries content.

the file system has a folder for each microformat and each folder has the translated index.html with accompanying translated JavaScript files.

to make it work you would need two fall backs, one for en-GB and one for it-IT.

You can sort of get it to work with the following

```<code>"routes" : [
        {
            "route": "/it-IT/search",
            "rewrite": "it-IT/index.html"
        },
        {
            "route": "/it-IT/customer",
            "rewrite": "it-IT/index.html"
        },
        {
            "route": "/it-IT/about",
            "rewrite": "it-IT/index.html"
        }
]
</code>```

Where search, customer and about are routes within the app, but for the above you need to repeat this for every language and every route so you soon hit the max file size / max routes for the config.

It would be better if we could do something with fallbacks maybe add baseref and have a collection   or allow exclude on the route.

eg

```<code>  "navigationFallbacks": [
      {
          "navigationFallback": {
              "baseRef": "en-GB",
              "rewrite": "en-GB/index.html",
              "exclude": [
                  "*.css",
                  "*.js",
                  "*.ico",
                  "*.txt",
                  "*.xml"
              ]
          }
      },
      {
          "navigationFallback": {
              "baseRef": "it-IT",
              "rewrite": "it-IT/index.html",
              "exclude": [
                  "*.css",
                  "*.js",
                  "*.ico",
                  "*.txt",
                  "*.xml"
              ]
          }
      }
  ]

</code>```

or allow excludes

```<code>    "routes" : [
        {
            "route": "/it-IT/*",
            "rewrite": "it-IT/index.html",
            "exclude": [ "*.{js,css}", "/assets/*"]
        }
      ]
</code>```

My less than perfect work around is to have a route entry in the config for every route but we will soon run out, we could also use # fragments rather than / eg #/about rather than /about but this is less than ideal.

答:
This is a known limitation and is discussed here

https://github.com/Azure/static-web-apps/issues/527

I hope it will be resolved as it does limit the use of Static Web Apps

Body:
It is possible to cleanly support URLs such as

https://www.myawsomeapp.com/en-GB/
https://www.myawsomeapp.com/it-IT/

routes are angular routes and we need the fallback to fallback to the countries content.

the file system has a folder for each microformat and each folder has the translated index.html with accompanying translated JavaScript files.

to make it work you would need two fall backs, one for en-GB and one for it-IT.

You can sort of get it to work with the following

"routes" : [
        {
            "route": "/it-IT/search",
            "rewrite": "it-IT/index.html"
        },
        {
            "route": "/it-IT/customer",
            "rewrite": "it-IT/index.html"
        },
        {
            "route": "/it-IT/about",
            "rewrite": "it-IT/index.html"
        }
]

Where search, customer and about are routes within the app, but for the above you need to repeat this for every language and every route so you soon hit the max file size / max routes for the config.

It would be better if we could do something with fallbacks maybe add baseref and have a collection   or allow exclude on the route.

eg

  "navigationFallbacks": [
      {
          "navigationFallback": {
              "baseRef": "en-GB",
              "rewrite": "en-GB/index.html",
              "exclude": [
                  "*.css",
                  "*.js",
                  "*.ico",
                  "*.txt",
                  "*.xml"
              ]
          }
      },
      {
          "navigationFallback": {
              "baseRef": "it-IT",
              "rewrite": "it-IT/index.html",
              "exclude": [
                  "*.css",
                  "*.js",
                  "*.ico",
                  "*.txt",
                  "*.xml"
              ]
          }
      }
  ]

or allow excludes

    "routes" : [
        {
            "route": "/it-IT/*",
            "rewrite": "it-IT/index.html",
            "exclude": [ "*.{js,css}", "/assets/*"]
        }
      ]

My less than perfect work around is to have a route entry in the config for every route but we will soon run out, we could also use # fragments rather than / eg #/about rather than /about but this is less than ideal.


问:
Constant time to access first and last node
How would you modify a linked list based queue so that first and last node can be accessed in a constant time regardless of data nodes in queue?</p>

答:
You will keep two pointers/reference variables, one for head of queue and other for tail. When you insert an item, you will set the tail to last inserted item, and when you remove an item, your head will obviously go to next item in queue.  Since you have two variables for head and tail, it will be a constant time operation to access them.

This is the general way to create a queue with linked list itself, this will be needed to insert items and remove items from queue, nothing special here.


问:
Question about querying/cleaning Apache Pulsar's state without key
I know that in Pulsar functions we have some limited access to the Bookkeeper's state store, with methods like context.getState(key), putState(key), deleteState(key), etc.

My question though is: Do we have a means of querying and cleaning state without having to use any kind of key?

Reason:

We'd for example would like to implement a delta function.
E.g. on day 1 we send events/objects to the delta function, and they're stored in state via unique keys.

On day 2 we send again the same type of objects, where most of them are the same, some might have changed an attribute, some might be new and some might be missing compared to day 1.

For each received object we'd like to query the state to see if there have been changes to that object (and in that case send an event). If there are no changes we don't send anything.

Now as you see, the problem is that the state storage would gradually increase over time.
And I don't know any way to clean objects from the state which aren't delivered any more, because that object is gone, so is its key which I would need for deleteState().

--> Question again:
Are there other ways to access / query / clean the function's state, which don't rely on having any key? Maybe use the Bookkeeper's API directly?

What would help would be a way to loop over the whole state, or getEverything() and then work with that.

答: Let me check on that.    An iterator and a clean seem really useful.</p>


问:
How to get-adgroup members by their Name or SamAccountName
i would like to extract members from an AD Group that contains Members and security group.

```<code>Example, Group_A:
User1
User2
User3
Group_B
</code>```

When I run my script, it shows:

CN=User1,OU=Users,DC=Contoso,DC=com
CN=User2,OU=Users,DC=Contoso,DC=com
CN=User3,OU=Users,DC=Contoso,DC=com
CN=Group_B,OU=Users,DC=Contoso,DC=com

Is there another way to show their Name and/or SamAccountname?

```<code>$Groups =
@"
GroupNames;
Group_A
"@ | ConvertFrom-Csv -Delimiter ';'

$ADGroups =
Foreach ($Group in $Groups){
Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members }

$ADGroups.Members
</code>```

答:
You could run a query against the returned values using Get-ADObject since it accepts DistinguishedNames as a value and isn't limited by object class:

```<code>foreach ($Group in $Groups)
{
    (Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members).Members |
        ForEach-Object -Process {
            Get-ADObject -Identity $_ -Properties DisplayName | Select-Object -Property DisplayName
        }
}
</code>```

...or, you can split the results at the desired entry:

```<code>foreach ($Group in $Groups)
{
    (Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members).Members |
        ForEach-Object -Process {
            $_.Split(',',2).Split("=")[1]
        }
}
</code>```

Disclaimer: I don't have the AD Module installed on my system so I can't confirm if this is all that is needed.

Body:
i would like to extract members from an AD Group that contains Members and security group.

Example, Group_A:
User1
User2
User3
Group_B

When I run my script, it shows:

CN=User1,OU=Users,DC=Contoso,DC=com
CN=User2,OU=Users,DC=Contoso,DC=com
CN=User3,OU=Users,DC=Contoso,DC=com
CN=Group_B,OU=Users,DC=Contoso,DC=com

Is there another way to show their Name and/or SamAccountname?

$Groups =
@"
GroupNames;
Group_A
"@ | ConvertFrom-Csv -Delimiter ';'

$ADGroups =
Foreach ($Group in $Groups){
Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members }

$ADGroups.Members

Body:
You could run a query against the returned values using Get-ADObject since it accepts DistinguishedNames as a value and isn't limited by object class:

foreach ($Group in $Groups)
{
    (Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members).Members |
        ForEach-Object -Process {
            Get-ADObject -Identity $_ -Properties DisplayName | Select-Object -Property DisplayName
        }
}

...or, you can split the results at the desired entry:

foreach ($Group in $Groups)
{
    (Get-ADGroup $Group.GroupNames -Server contoso.com -Properties Members).Members |
        ForEach-Object -Process {
            $_.Split(',',2).Split("=")[1]
        }
}

Disclaimer: I don't have the AD Module installed on my system so I can't confirm if this is all that is needed.


问:
Difference between datetime and timestamp in sqlserver?
What is the difference between Timestamp and Datetime SQL Server?

I thought Both formats are capable of storing date + time. Then, Where the difference is lying between them?

But Timestamp is not capable of storing date, time information.

Still Whats the difference?

答:
Datetime is a datatype.

Timestamp is a method for row versioning. In fact, in sql server 2008 this column type was renamed (i.e. timestamp is deprecated) to rowversion. It basically means that every time a row is changed, this value is increased. This is done with a database counter which automatically increase for every inserted or updated row.

For more information:

http://www.sqlteam.com/article/timestamps-vs-datetime-data-types

http://msdn.microsoft.com/en-us/library/ms182776.aspx