text:
Q: Error generating a chi-square test with data that was converted from wide to long I am using Demographic and Health Survey data. My end goal is to run multivariate logistic regressions. Since I am using complex data, I converted the data from wide to long. I continued with analyses and ran a chi-square test. I successfully ran this using two variables. Because I want to run an analyses using four variables that describe the same undernutrition indicator for four children and cross it with the urban and rural variable, I ran another chi-square, considering my data is correctly converted from wide to long to do this. Unfortunately, I got an error this time. Please be aware I am running analyses adjusting for survey design. Below codes and data output. Can you support me with the correct coding to run an appropiate conversion from wide to long and a code to run a chi-square test appropiately?
`library(haven)`

`HNIR62FL_data_2 <- readta that has been converted from wide to long?_sav("~/DHS/HNIR62SV/HNIR62FL_data_2.SAV")`

`View(HNIR62FL_data_2)`

`obsHNIR62FL_data_2 <- subset(HNIR62FL_data_2, !is.na(V021) & !is.na(V022) & !is.na(D005))`

`myvars <- c("CASEID", "V013", "V021", "V022", "V025", "V106", "V137", "V190", "V714", "D005", "D104", "D106", "D107", "D108","v1014", "v1016", "v1021", "v1023", "v1038", "v1039", "v1045", "v1113", "V701", "v1007_1", "v1007_2", "v1007_3", "v1007_4", "v1008_1", "v1008_2", "v1008_3", "v1008_4", "v1009_1", "v1009_2", "v1009_3", "v1009_4", "v1010_1", "v1010_2", "v1010_3", "v1010_4", "v1020_1", "v1020_2", "v1020_3", "v1020_4", "v1071_1", "v1071_2", "v1071_3", "v1071_4", "v1088_1", "v1088_2", "v1088_3", "v1088_4", "v1096_1", "v1096_2", "v1096_3", "v1096_4", "v1104_1", "v1104_2", "v1104_3", "v1104_4", "v1111_1", "v1111_2", "v1111_3", "v1111_4", "v1112_1", "v1112_2", "v1112_3", "v1112_4")`

`newobsHNIR62FL_data_2 <- obsHNIR62FL_data_2[myvars]`

`dhsdesign <- svydesign(newobsHNIR62FL_data_2$V021, strata = newobsHNIR62FL_data_2$V022, weights = newobsHNIR62FL_data_2$D005/1000000, data = newobsHNIR62FL_data_2)`

`newobsHNIR62FL_data_2 %>%  mutate(across(starts_with(c("V", "v")), as.double)) %>% pivot_longer(cols=starts_with(c("V", "v")), names_to = c("name", "id"), values_to = "value", names_sep = "_")`

`A tibble: 379,237 x 9
   CASEID           D005     D104     D106    D107    D108 name  id    value
   <chr>           <dbl> <dbl+lb> <dbl+lb> <dbl+l> <dbl+l> <chr> <chr> <dbl>
 1 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V013  NA        2
 2 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V021  NA      564
 3 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V022  NA       16
 4 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V025  NA        1
 5 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V106  NA        1
 6 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V137  NA        2
 7 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V190  NA        3
 8 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] V714  NA        0
 9 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] v1014 NA        2
10 "      564 9~ 1758042   0 [No]   0 [No]  0 [No]  0 [No] v1016 NA        1
# ... with 379,227 more rows`

```
Warning message:
Expected 2 pieces. Missing pieces filled with `NA` in 17 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17].
```

`summary(svytable(~v1113+v1039, dhsdesign))`

```
v1039
v1113    1    2    3    4
    0 1087  934  626  646
    1  462  518  388  359

    Pearson's X^2: Rao & Scott adjustment

data:  svychisq(~v1113 + v1039, design = dhsdesign, statistic = "F")
F = 5.4626, ndf = 2.9836, ddf = 3243.1635, p-value = 0.0009852`
```

`summary(svytable(~v1007_1 + v1007_2+ v1007_3 + v1007_4 + V025, dhsdesign))`

```
Error in svychisq.survey.design(~v1007_1 + v1007_2 + v1007_3 + v1007_4 +  :
  Only 2-way tables at the moment
```

`dput(head(newobsHNIR62FL_data_2))`

```
`structure(list(CASEID = structure(c("      564 91  2", "      198 61  2",
"      267 21  1", "     1089 81  2", "      583 61  8", "      989101  2"
), label = "Case Identification", format.spss = "A15", display_width = 17L),
    V013 = structure(c(2, 4, 4, 4, 6, 3), label = "Age in 5-year groups", format.spss = "F1.0", display_width = 6L, labels = c(`15-19` = 1,
    `20-24` = 2, `25-29` = 3, `30-34` = 4, `35-39` = 5, `40-44` = 6,
    `45-49` = 7), class = c("haven_labelled", "vctrs_vctr", "double"
    )), V021 = structure(c(564, 198, 267, 1089, 583, 989), label = "Primary sampling unit", format.spss = "F4.0", display_width = 6L),
    V022 = structure(c(16, 8, 9, 37, 17, 33), label = "Sample strata for sampling errors", format.spss = "F4.0", display_width = 6L, labels = c(`Atlántida Urbano` = 1,
    `Atlántida Rural` = 2, `Colón Urbano` = 3, `Colón Rural` = 4,
    `Comayagua Urbano` = 5, `Comayagua Rural` = 6, `Copán Urbano` = 7,
    `Copán Rural` = 8, `San Pedro Sula Urbano` = 9, `Cortés Resto Urbano` = 10,
    `Cortés Resto Rural` = 11, `Choluteca Urbano` = 12, `Choluteca Rural` = 13,
    `El Paraíso Urbano` = 14, `El Paraíso Rural` = 15, `Tegucigalpa Urbano` = 16,
    `Morazán Resto Urbano` = 17, `Morazán Resto Rural` = 18,
    `Gracias a Dios Urbano` = 19, `Gracias a Dios Rural` = 20,
    `Intibucá Urbano` = 21, `Intibucá Rural` = 22, `Islas de Bahía Urbano` = 23,
    `Islas de Bahía Rural` = 24, `La Paz Urbano` = 25, `La Paz Rural` = 26,
    `Lempira Urbano` = 27, `Lempira Rural` = 28, `Ocotepeque Urbano` = 29,
    `Ocotepeque Rural` = 30, `Olancho Urbano` = 31, `Olancho Rural` = 32,
    `Santa Bárbara Urbano` = 33, `Santa Bárbara Rural` = 34,
    `Valle Urbano` = 35, `Valle Rural` = 36, `Yoro Urbano` = 37,
    `Yoro Rural` = 38), class = c("haven_labelled", "vctrs_vctr",
    "double")), V025 = structure(c(1, 2, 1, 1, 1, 1), label = "Type of place of residence", format.spss = "F1.0", display_width = 6L, labels = c(Urban = 1,
    Rural = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), V106 = structure(c(1, 0, 1, 1, 1, 2), label = "Highest educational level", format.spss = "F1.0", display_width = 6L, labels = c(`No education` = 0,
    Primary = 1, Secondary = 2, Higher = 3), class = c("haven_labelled",
    "vctrs_vctr", "double")), V137 = structure(c(2, 2, 2, 1,
    0, 1), label = "Number of children 5 and under in household (de jure)", format.spss = "F2.0", display_width = 6L),
    V190 = structure(c(3, 1, 2, 4, 2, 4), label = "Wealth index", format.spss = "F1.0", display_width = 6L, labels = c(Poorest = 1,
    Poorer = 2, Middle = 3, Richer = 4, Richest = 5), class = c("haven_labelled",
    "vctrs_vctr", "double")), V714 = structure(c(0, 0, 1, 1,
    0, 0), label = "Respondent currently working", format.spss = "F1.0", display_width = 6L, labels = c(No = 0,
    Yes = 1), class = c("haven_labelled", "vctrs_vctr", "double"
    )), D005 = structure(c(1758042, 927099, 1296895, 1087346,
    1005935, 1112882), label = "Weight for Domestic Violence (6 decimals)", format.spss = "F8.0", display_width = 10L),
    D104 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any emotional violence", format.spss = "F1.0", display_width = 6L, labels = c(No = 0,
    Yes = 1), class = c("haven_labelled", "vctrs_vctr", "double"
    )), D106 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any less severe violence (D105A-C,J) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0,
    `Yes (D105A-D)` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), D107 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any severe violence (D105D-F) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0,
    `Yes (D105E-G)` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), D108 = structure(c(0, 0, 0, 0, 0, 0), label = "Experienced any sexual violence (D105H-I,K) by husband/partner", format.spss = "F1.0", display_width = 6L, labels = c(No = 0,
    `Yes (D105H-I)` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1014 = structure(c(2, 2, 2, 4, 2, 4), label = "women BMI category", format.spss = "F8.0", labels = c(underweight = 1,
    `normal weight` = 2, overweight = 3, obese = 4), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1016 = structure(c(1, 0, 0, 1,
    0, 1), label = "women height category", format.spss = "F8.0", labels = c(`woman height <150 cm` = 0,
    `woman height 150 cm or more ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1021 = structure(c(4, 3, 1, 1,
    4, 3), label = "region category", format.spss = "F8.0", labels = c(Northern = 1,
    Southern = 2, Western = 3, Central = 4, Eastern = 5), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1023 = structure(c(2, 5, 3, 2,
    4, 1), label = "parity", format.spss = "F8.0", labels = c(`0` = 0,
    `1` = 1, `2` = 2, `3` = 3, `4` = 4, `5 or more` = 5), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1038 = structure(c(2, 1, 3, 2,
    2, 2), label = "marital status", format.spss = "F8.0", labels = c(`Never in union` = 0,
    Married = 1, `Living with partner ` = 2, `Divorced, widowed or separated/no longer living together` = 3
    ), class = c("haven_labelled", "vctrs_vctr", "double")),
    v1039 = structure(c(2, 4, 3, 2, 3, 1), label = "marital duration", format.spss = "F8.0", labels = c(`Never in a union` = 0,
    `0-4 years` = 1, `5-9 years` = 2, `10-14 years` = 3, `15 years or more` = 4
    ), class = c("haven_labelled", "vctrs_vctr", "double")),
    v1045 = structure(c(4, 4, NA, 3, 1, 4), label = "Women decision making scale", format.spss = "F8.0", labels = c(`No decision making skills` = 0,
    `Respondent alone/respondent and husband/partner decide on one issue` = 1,
    `Respondent alone/respondent and husband/partner decide on two issues` = 2,
    `Respondent alone/respondent and husband/partner decide on three issues` = 3,
    `Respondent alone/respondent and husband/partner decide on four issues` = 4
    ), class = c("haven_labelled", "vctrs_vctr", "double")),
    v1113 = structure(c(0, 0, 0, 0, 0, 0), label = "Any intimate partner violence", format.spss = "F8.0", labels = c(`Has not experienced any form of intimate partner violence` = 0,
    `Has experienced any form of intimate partner violence` = 1
    ), class = c("haven_labelled", "vctrs_vctr", "double")),
    V701 = structure(c(2, 1, 1, 2, 2, 2), label = "Husband/partner's education level", format.spss = "F1.0", display_width = 6L, labels = c(`No education` = 0,
    Primary = 1, Secondary = 2, Higher = 3, `Don't know` = 8), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1007_1 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child stunting category", format.spss = "F8.0", labels = c(`stunted child ` = 0,
    `not stunted child` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1007_2 = structure(c(1, 0, 0, NA, NA, NA), label = "stunting category (second to youngest child)", format.spss = "F8.0", labels = c(stunted = 0,
    `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1007_3 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "stunting category (third to youngest child)", format.spss = "F8.0", labels = c(stunted = 0,
    `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1007_4 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "stunting category (fourth to youngest child)", format.spss = "F8.0", labels = c(stunted = 0,
    `not stunted` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1008_1 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "youngest child underweight category", format.spss = "F8.0", labels = c(`underweight child` = 0,
    `not underweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1008_2 = structure(c(1, 1, 0,
    NA, NA, NA), label = "underweight category (second to youngest child)", format.spss = "F8.0", labels = c(underweight = 0,
    `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1008_3 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "underweight category (third to youngest child)", format.spss = "F8.0", labels = c(underweight = 0,
    `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1008_4 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "underweight category (fourth to youngest child)", format.spss = "F8.0", labels = c(underweight = 0,
    `not underweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1009_1 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "youngest child wasting category", format.spss = "F8.0", labels = c(`wasted child` = 0,
    `not wasted child ` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1009_2 = structure(c(1, 1, 1, NA, NA, NA), label = "wasting category (second to youngest child)", format.spss = "F8.0", labels = c(wasted = 0,
    `not wasted` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1009_3 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "wasting category (third to youngest child)", format.spss = "F8.0", labels = c(wasted = 0,
    `not wasted ` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1009_4 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "wasting category (fourth to youngest child)", format.spss = "F8.0", labels = c(wasted = 0,
    `not wasted` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1010_1 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "youngest child overweight category", format.spss = "F8.0", labels = c(`overweight child` = 0,
    `not overweight child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1010_2 = structure(c(1, 1, 1,
    NA, NA, NA), label = "overweight category (second to youngest child)", format.spss = "F8.0", labels = c(overweight = 0,
    `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1010_3 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "overweight category (third to youngest child)", format.spss = "F8.0", labels = c(overweight = 0,
    `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1010_4 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "overweight category (fourth to youngest child)", format.spss = "F8.0", labels = c(overweight = 0,
    `not overweight` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1020_1 = structure(c(1, 0, 1, 0, 1, 0), label = "youngest child morbidity category", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0,
    `youngest child with morbidity ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1020_2 = structure(c(1, 0, 1,
    NA, NA, NA), label = "Morbidity category (second to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0,
    `youngest child with morbidity` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1020_3 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Morbidity category (third to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0,
    `youngest child with morbidity` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1020_4 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Morbidity category (fourth to youngest child)", format.spss = "F8.0", labels = c(`youngest child with no morbidity` = 0,
    `youngest child with morbidity` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1071_1 = structure(c(0, NA, 1,
    1, 1, 1), label = "anemia category (youngest child)", format.spss = "F8.0", labels = c(anemic = 0,
    `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1071_2 = structure(c(1, 1, 0, NA, NA, NA), label = "anemia category (second to youngest child)", format.spss = "F8.0", labels = c(anemic = 0,
    `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1071_3 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "anemia category (third to youngest child)", format.spss = "F8.0", labels = c(anemic = 0,
    `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1071_4 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "anemia category (fourth to youngest child)", format.spss = "F8.0", labels = c(anemic = 0,
    `not anemic` = 1), class = c("haven_labelled", "vctrs_vctr",
    "double")), v1088_1 = structure(c(NA_real_, NA_real_, NA_real_,
    NA_real_, NA_real_, NA_real_), label = "youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child` = 0,
    `not stunted and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1088_2 = structure(c(1, 1, NA,
    NA, NA, NA), label = "second to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child` = 0,
    `not stunted and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1088_3 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child ` = 0,
    `not stunted and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1088_4 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child stunting + overweight category", format.spss = "F8.0", labels = c(`stunted and overweight child ` = 0,
    `not stunted and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1096_1 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0,
    `not anemic and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1096_2 = structure(c(1, 1, 1,
    NA, NA, NA), label = "second to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0,
    `not anemic and overweight child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1096_3 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0,
    `not anemic and overweight child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1096_4 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child anemic + overweight category", format.spss = "F8.0", labels = c(`anemic and overweight child ` = 0,
    `not anemic and overweight child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1104_1 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child` = 0,
    `not anemic and not stunted child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1104_2 = structure(c(1, 1, NA,
    NA, NA, NA), label = "second to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child ` = 0,
    `not anemic and stunted child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1104_3 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "third to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`anemic and stunted child ` = 0,
    `not anemic and stunted child ` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1104_4 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "fourth to youngest child anemic + stunted category", format.spss = "F8.0", labels = c(`stunted and anemic child` = 0,
    `not stunted and anemic child` = 1), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1111_1 = structure(c(3, 1, 4,
    4, 5, 6), label = "Child age (youngest child)", format.spss = "F8.0", labels = c(`0-5 months` = 1,
    `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4,
    `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1111_2 = structure(c(6, 5, 6,
    NA, NA, NA), label = "Child age (second to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1,
    `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4,
    `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1111_3 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Child age (third to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1,
    `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4,
    `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1111_4 = structure(c(NA_real_,
    NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), label = "Child age (fourth to youngest)", format.spss = "F8.0", labels = c(`0-5 months` = 1,
    `6-11 months` = 2, `12-23 months` = 3, `24-35 months` = 4,
    `36-47 months` = 5, `48-59 months` = 6), class = c("haven_labelled",
    "vctrs_vctr", "double")), v1112_1 = structure(c(2, 2, 1,
    1, 1, 1), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1,
    Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), v1112_2 = structure(c(1, 2, 1, 2, 1, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1,
    Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), v1112_3 = structure(c(NA, 2, 1, NA, 2, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1,
    Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    )), v1112_4 = structure(c(NA, 2, NA, NA, 1, NA), label = "Sex of child", format.spss = "F1.0", display_width = 7L, labels = c(Male = 1,
    Female = 2), class = c("haven_labelled", "vctrs_vctr", "double"
    ))), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))`
```

A: As the error message says, svychisq() only does two-way tables. You can use svyloglin(), which does the Rao-Scott score and likelihood ratio tests.   The Rao-Scott score test is the default for svychisq(), and in a two-way table, the results for svychisq() and the loglinear model will match
One additional complication is that you need to specify what alternative you want to test: do you want to compare to the model with two-way interactions or the model with all possible interactions.  When you have only two variables there are only two-way interactions, so there's no ambiguity.
If it helps, Rao and Scott were looking at comparisons to the full model.
null_model<-svyloglin(~A+B+C+D,design)
twoway_model<-update(null_model,~.^2)
full_model <- update(null_model,~.^4)

anova(null_model, full_model)
anova(null_model, twoway_model)


text:
Q: Ошибка vk_api.exceptions.ApiError Есть код:
session.method('messages.send', {'user_id' : id, 'message' : 'test', 'random_id' : '0'})

При выполнении кода получаю ошибку:

vk_api.exceptions.ApiError: [17] Validation required: please open redirect_uri in browser

A: В документации VK API по коду ошибки 17 сказано:

Действие требует подтверждения — необходимо перенаправить пользователя на служебную страницу для валидации.

В библиотеке vk_api получить redirect_uri можно в объекте ApiError
from vk_api.exceptions import ApiError

try:
    session.method('messages.send', {'user_id': id, 'message': 'test', 'random_id': '0'})
except ApiError as e:
    print(e.error["redirect_uri"])

Эту ссылку уже открывает пользователь токена в браузере. Пользователь подтверждает и метод можно использовать снова.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Regex to join numbers when they have spaces between them I'm trying to build a regex that joins numbers in a string when they have spaces between them, ex:
$string = "I want to go home 8890 7463 and then go to 58639 6312 the cinema"

The regex should output:
"I want to go home 88907463 and then go to 586396312 the cinema"

The regex can be either in python or php language.
Thanks!

A: Python:
import re
text = 'abc 123 456 789 xyz'
text = re.sub(r'(\d+)\s+(?=\d)', r'\1', text)  # abc 123456789 xyz

This works for any number of consecutive number groups, with any amount of spacing in-between.

A: Use a look-ahead to see if the next block is a set of numbers and remove the trailing space.  That way, it works for any number of sets (which I suspected you might want):
$string = "I want to go home 8890 7463 41234 and then go to 58639 6312 the cinema";

$newstring = preg_replace("/\b(\d+)\s+(?=\d+\b)/", "$1", $string);
// Note: Remove the \b on both sides if you want any words with a number combined.
// The \b tokens ensure that only blocks with only numbers are merged.

echo $newstring;
// I want to go home 8890746341234 and then go to 586396312 the cinema


text:
Q: mail is delivering without subject when calling from function in python I have a sample code like following:
import smtplib
def send_mail(PASS,FAIL):
    me = "XXXX"
    you = "YYYY"
    print "Start of program"
    server = smtplib.SMTP('ZZZ', 25)
    total_testcase = "15/12"
    print total_testcase
    message = """From: From Person <XXXX>
    To: To Person <YYYY>
    Subject: mail testing

    %s
    """ %total_testcase
    print message
    server.sendmail(me, you, message)

send_mail(8,9)

when I am sending the email it is delivering without the subject
But if I use the code instead of a function call - then it is delivering fine with subject. Anything I am missing in a function call. Please suggest.

A: The issue you're having is with the triple-quoted multi-line string. When you put it in your function, you're indenting all of its lines so that they line up with the rest of the code. However, this results in unnecessary (and inappropriate) spaces at the start of each line of the message after the first.
Leading spaces in the headers of an SMTP message indicate that the previous header should be continued. This means that all of your first three lines are combined into the From header.
You can fix this either by leaving out the leading spaces:
def send_mail(PASS,FAIL):
    #...
    message = """From: From Person <XXXX>
To: To Person <YYYY>
Subject: mail testing

%s
""" % total_testcase
    #...

Or by using \n instead of real newlines in your string:
message = "From: From Person <XXXX>\nTo: To Person <YYYY>\nSubject: mail testing\n\n%s" % total_testcase

Or finally, you could keep the current code for the generation of the message, but strip out the leading whitespace afterwards:
def send_mail(PASS,FAIL):
    #...
    message = """From: From Person <XXXX>
    To: To Person <YYYY>
    Subject: mail testing

    %s
    """ % total_testcase
    message = "\n".join(line if not line.startswith("    ") else line[4:]
                        for line in message.splitlines())
    #...

This last option is a bit fragile, as it may strip out desired whitespace from lines in your total_testcase string (if it had multiple lines), not only the spaces added due to the multi-line string. It also will break if you're using tabs for indentation, or really anything other than four spaces. I'm not sure I'd actually recommend this approach.
A better version of the last approach is to use the textwrap.dedent function from the the standard library. It removes any indentation that is present at the start of every line in a string (but only the indentation that is common to all lines). This does require a small change to how you were creating message, as you need the first line to have the same leading spaces as all the rest (you'll also need to avoid adding any newlines without indentation in the extra text that comes from total_testcase).
Here's the code:
import textwrap

def send_mail(PASS,FAIL):
    #...
    # backslash after the quotes on the first line avoids a empty line at the start
    message = """\
    From: From Person <XXXX>
    To: To Person <YYYY>
    Subject: mail testing

    %s
    """ % total_testcase
    message = textwrap.dedent(message)
    #...


text:
Q: Auto-indent new line when hitting enter to expand one-line tag in HTML I would like to have this work flow working with HTML in Sublime Text 2:

*

*Create HTML tag (e.g. ctrl + shift + W)

*TAB (putting the cursor in the content area)

*ENTER

Resulting with this (the word "HERE" indicates where the cursor should be):

    HERE

But instead this is what I get (the word "HERE" still indicating the cursor's position):

HERE

Which demands you to

*

*ENTER (again)

*ARROW-UP + TAB

*ARROW-UP + TAB (a second time)

A: Try adding the following in your user key bindings.
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "context":
    [
        { "key": "setting.auto_indent", "operator": "equal", "operand": true },
        { "key": "selector", "operator": "equal", "operand": "meta.scope.between-tag-pair", "match_all": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
    ]
}


text:
Q: How can I sort a column in excel ignoring leading characters? I have a column in Excel with entries like
TI/303
BA/045
BA/009
AB/123

I would like to sort it by the numbers ignoring the first three characters like
BA/009
BA/045
AB/123
TI/303

How can I achieve such a custom sorting in Excel?

A: Use a "helper" column........with your data in column A, in B1 enter:
=--MID(A1,4,9999)  and copy down
Then sort cols A & B by B.

A: An addition to Gary's solution,
=Mid(A1,SEARCH("/",A1)+1,999)
will work for any length behind the slash (just in case someone else finds that helpful)


text:
Q: How to refresh the properties view in Eclipse RCP? I am using the properties view in RCP, i.e org.eclipse.ui.views.properties.PropertySheet.
I want to be able to refresh the content of these properties programmatically. It seems RCP is geared towards the use case where this changes only when a selection changes.
Is there any way I can fire a dummy event to get this to refresh (without having ugly UI artifacts such as visibly switching between parts) ?

A: The main problem is that the API hides all the pages (PropertySheetPage) and therefore viewers (PropertySheetViewer) within the properties view.
Good news is, you can tell the properties view to use a page of your desire. So I supply the page that it would normally use by default (PropertySheetPage), except when I supply it, I keep a reference to it (obviously), and then you can call propertySheetPageRef.refresh() to update the model (thankfully this method is public).
public Object getAdapter(Class adapter) {
        if (adapter == IPropertySource.class) {
            return resultProvider;
        } else if (adapter == IPropertySheetPage.class) {
            return propertySheetPage;
        }
        return null;
    }

A: Correction on geejay's answer: the getAdapter method is in the view (not in the object you are showing properties for).
Sample implementation (in your view's class):
//IPropertySheetPage doesn't implement refresh()
private PropertySheetPage propertyPage;

/**
 * If called from UI thread, refreshes property page from model
 * (an IPropertySource). If called from non-UI thread, does nothing.
 */
public void refreshPropertyPage() {
    if (propertyPage != null) {
        propertyPage.refresh();
    }
}

@Override
public Object getAdapter(Class adapter) {
    if (adapter == IPropertySheetPage.class) {
        if (propertyPage == null) {
            propertyPage = new PropertySheetPage();
        }
        return propertyPage;
    }
    //use platform's adapter manager for other classes
    return super.getAdapter(adapter);
}


text:
Q: Prime as an argument of command Suppose we are in math-mode and I want to use command \E with the following behaviour. If one or two primes follow the command, i.e. \E' or \E'', then I want to have in these cases certain expressions, say A or B. In all the other cases I want to have merely E independently what precedes or follows the \E. Here are exames

*

*$any \E' some$ -> any A some

*$any \E'' some$ -> any B some

*$any \E some$ -> any E some

I dont want to use the command in a longer form like \E{arg1}{arg2} but only  in  \E', \E'' forms. Let, for example,
\def\E#1#2{my code}

Then the problem arises when using something like
$$
 x \E' \sin x
$$

Or
$$
A \E b
$$

Because "b" should not be considered as an argument of \E in the latter case and the same reason for a slash in front of sine in the former case.

A: You might enjoy a generic interface for defining as many commands of the same kind as you want:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\declareprimedcommand} { m m m m }
 {% #1 = command to define
  % #2 = text for no prime
  % #3 = text for one prime
  % #4 = text for two primes
  \maximav_primedcommand:Nnnn #1 { #2 } { #3 } { #4 }
 }
\cs_new_protected:Npn \maximav_primedcommand:Nnnn #1 #2 #3 #4
 {
  \cs_new_protected:Npn #1
   {
    \peek_charcode_remove:NTF '
     { \peek_charcode_remove:NTF ' { #4 } { #3 } }
     { #2 }
   }
 }
\ExplSyntaxOff

\declareprimedcommand{\E}{x}{y}{z}

\begin{document}
$a \E b$

$a \E' b$

$a \E'' b$
\end{document}

A: Here an approach:
\documentclass{article}
\makeatletter
\def\@ifprime#1{\@ifnextchar'{\@firstoftwo{#1}}}
\newcommand\E{\@ifprime\E@i\E@}
\def\E@i{\@ifprime{B}{A}}
\def\E@{E}
\makeatother
\begin{document}
\[ x \E' \sin x  \]

\[ x \E'' \sin x  \]

\[ x \E \sin x  \]
\end{document}


text:
Q: How to set regular expression parameter constraints for Route float parameter on Lumen I tried to Lumen API for GPS Tracking Project. the Router can't allow to pass float parameter
$router->get('api/{lat}', function ($lat){
    return $lat;
})->where('lat','.*');

how to pass Flot Parameter on Lumen micro-Framework

A: I thought Laravel was the same as Lumen at first, but I was wrong. :(
First, it does not support where(<pattern>), so you have to do this. (doc)
$router->get('api/{lat:\d*\..\d*}', function ($lat) {
    return $lat;
});

Next, you can't use php -S localhost:8000 -t public to run, because xxx.xxx will be treated as a static file
You have two ways to run it, php -S localhost:8000 public/index.php or http server.


text:
Q: Combine git add . and git commit How to combine two git command. In particular, I want to combine git add . and git commit -m "message". For example,
gaddmit "message"

should be equivalent to:
git add .

git commit -m "message"

where gaddmit is the alias I want to use.

A: You can create an alias in your .gitconfig, something like this perhaps:
[alias]
    addmit = !git add . && git commit -m

Then just do:
git addmit "my commit message"

A: Edited
Create a function in your .bashrc file and add an alias
add_and_commit() {
  git add .
  git commit -m "$1"
}
alias gaddmit=add_and_commit

Now you should be able to call gaddmit "message"

A: Just make an alias (put this line into your .bashrc):
alias gaddmit='git add . && git commit -m'

A: git commit -a -m "message"

will work similarly to what you want. The difference is that this will not stage files that you have never previously added to git.
If you really need an alias, you can use the suggestions in the other answers.

Note: I recommend adding files individually instead of doing it all at once with git add . or git commit -a. Adding files individually (I'd recommend using the cool patch (-p) option) lets you review and make sure that changes should actually be added to the commit


text:
Q: Pass 'Windows Authentication' through IIS Proxy Server I have three web applications sitting behind an IIS server configured as a reverse proxy. I would like to authenticate users using 'Windows Authentication' (since our only users are intranet users) and I would prefer to only authenticate them once to the reverse proxy server, but have at least an authenticated username available to my .NET MVC controllers on the back for authorization.
The problem is that the NTLM protocol is not really designed to do this. As I have looked into the problem, I have frequently come across descriptions of the 'double hop problem'.
I'm open to any suggestions you may have, including suggestions on where or how to authenticate.


text:
Q: Angular file upload is not working with formData I am trying to upload multiple file upload in Angular 7 here is the html code
<form [formGroup]="exceptionChangeStatusForm" (ngSubmit)="submitChangeStatusForm()" enctype="multipart/form-data">

            Documents:
            <input type="file" name="documents" multiple (change)="exceptionCommentFileChange($event)"/>

            <button type="submit" class="btn btn-primary">Save</button>

    </form>

Here is the javascript code
exceptionCommentFileChange(event) {
    if (event.target.files.length > 0) {
        this.addExceptionCommentForm.get('documents').setValue(event.target.files);
    }
}

I created formData for sending files through api
submitChangeStatusForm() {

    const formData = new FormData();
    const documents = this.addExceptionCommentForm.get('documents').value;
    for ( let i = 0; i < documents.length; i++) {
        formData.append('documents', documents[i], documents[i]['name']);
    }
    this.http.post(environment.exceptionsApiUrl, formData).pipe();
}

Here is the header request
Accept: application/json
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Authorization: Bearer eyJ0eXAiOiJKV
Connection: keep-alive
Content-Length: 179473
Content-Type: application/json; charset=utf-8
Host: localhost
Origin: http://localhost:4200
Referer: http://localhost:4200/v2/exceptions/validation
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36

And i am trying to change content-type to multipart/form-data it is not changing
return this.http.post(environment.exceptionsApiUrl + url, params, {headers : {
    'Content-Type': 'multipart/form-data',
    'Accept': 'application/json',
  }}).pipe();

And my request payload is looking something like this
------WebKitFormBoundaryqe260o3UOMqEKW2A
Content-Disposition: form-data; name="documents"; filename="1.jpeg"
Content-Type: image/jpeg

When i try from postman it works, but from angular it is not working, I am getting 400 response from api when i try from angular. Please, let me know if there are any changes to be made.

A: Hi I found the solution here. When I removed the Content-type it works on my end. Hope this one will help
https://github.com/angular/angular/issues/13241


text:
Q: Convert json string image to numpy 2D array I'm having troubles with json.
I'm trying to convert an image that I'm receiving with json to a 2D numpy array.
I've tried a few things but nothing is working.
Here is how I get the image:
@app.route("/<path:fullurl>", methods=['GET', 'POST'])
def main(fullurl):
    height, width = [int(e) for e in fullurl.split('/')]
    jsonResponse = json.loads(request.data.decode('utf-8'))

I also tried to print jsonResponse['image'] and here is what i got:
"data:image/octet-stream;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAYAAAB91L6VAAAF9klEQVR4nO3dv4qU
VxjH8d8l5Ea8jb2CdBbZxlbsvITUAdPkKmxjIQGrpLAIhA1EJaCQTSIiS1jXP7tJMUrmPe5ugjrPM5
z5fOB0y/K81Zdz3jMzCQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQ7zTJ2YbXaZI3SQ6LngkAttpZ
kr+b17tIn2z4WQFga2xDgC+KMgBM69usjoe7gyvEAFDgMKvw/9
/4CzEAbNBJLj8WF2IA2LCLQizCAFDgvBADAEXsggGgwbgTBgAK/JRlgL
/uHQcAdodjaABo4DIWADQQYABoIMAA0ECAAaCBAANAAwEGgAY+hgQADdYD/KJ5FgDYGesB
/rJ5FgDYCd/H+18AKPciAgwA5dyABoBiT+IGNACUs/sFgGJjfJ
/0jgMA8xuPnu1+AaCA+AJAMUfPAFDM0TMANBBfACjm6BkAij2K3S8AlLoZ8QWAcmN87
/SOAwDze5llfF/2jgMA87sTR88AUG6M783ecQBgfmN8H
/WOAwDzO4ijZwAodT3iCwDlxvje7h0HAOZ3nGV8j3vHAYD53Y6jZwAoN8b3eu84ADC
/Mb4HveMAwHY6yOr97Lv1V5LnSZ5dsv7I6pj5qySfr/2vozh6BoD
/9FveD+anXHfPWd8k+azi4QBgW206wBet35N8UfB8ALCV9pL8nORkbR1ndQR92Xqa5M3b9TEhvrH5R
wSAOY1RfZ3k16zC/t056+na3+5XDgoAs/jQS1f7sfsFgA9yP248A0Cpa3k
/vtdaJwKAHTDG937vOAAwv/Hm81HvOAAwv6vx3hcAyokvABR7mGV8H
/aOAwC7we4XAIqN8b3aOw4AzO8sy
/i+6h0HAOY3xtfRMwBs2Bjfs95xAGB+ryO+AFDqXsQXAErtxTtfACg3xnevdxwAmN
/4Iwv3escBgPm9yjK+J73jAMD8xvie9o4DAPN7HN9yBQClrkR8AaDcUXzWFwBK3cpy93urdxwA2A3r3/N81DwLAOyEwyx3v1d6xwGA+f2SZXx/7B0HAOY3xvfP3nEAYH5jfB/0jgMA8xt/XlB8AWDD9iO+AFBuP//G94feUQBgt9x4uwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAPgHU+BofAK5zHIAAAAASUVORK5CYII="

A: Well, i figured out the solution to my problem. It's simple, the string i receive from the json object that represents my image is encoded in base64, that's true. Since i didn't know anything about json objects or base64 at that time, i didn't realise that there is a header at the beginning of the string. So, my solution is as follow:
jsonResponse = json.loads(request.data.decode('utf-8'))
image = jsonResponse['image']
png_recovered = base64.decodestring(image.split(',')[1])
f = open("temp.png","w")
f.write(png_recovered)
f.close()
tab = cv2.bitwise_not(cv2.imread("temp.png",0))

I simply use the comma to split the string: before it is the header, after it is the image. Then i write it inside of a png file and open it with cv2 to have the proper numpy array.
The bitewise_not function is just for my particular application and is not required.
I hope this will be helpfull for someone in the future ! =D


text:
Q: Fill a TStringList in a DLL I want to fill a TStringList inside a DLL. My approach seems to be wrong regarding memory management documentaion, but it works and doesn't cause an error or AV.
Can someone tell me, if that code is OK? Not sure how I can fill a class in general in a DLL.
programm EXE

function MyClass_Create: IMyClass; stdcall; external ...

var
  _myClass_DLL: IMyClass; //shared interface in exe and dll

procedure FillList;
var
  list: TStringList;
begin
  list := TStringList.Create(true); //memory allocated in EXE
  try
    _myClass_DLL.FillList(list);  //memory allocated in DLL???
    ShowMessage(list.Text);
  finally
    list.Free; //memory freed in EXE, frees also TObject created in DLL
  end;
end;

DLL Code:
library DLL

TMyClass = class(TInterfacedObject, IMyClass)
public
  procedure FillList(aList: TStringList);
end;

procedure TMyClass.FillList(aList: TStringList);
begin
  aList.AddObject('Text1', TObject.Create); //memory allocation in DLL?
  aList.AddObject('Text2', TObject.Create); //memory allocation in DLL?
end;

I don't use BORLNDMM.DLL or any other ShareMem unit.
Edit:
I expanded the aList.Add() call to aList.AddObject(). It also doesn't crash, altough the TObject is created in DLL and freed in EXE.
Answer:
Regarding the comments in the accepted answer below, that code is correct, since exe and dll are compiled with the same delphi version and only virtual methodes are invoked.
Conclusion:
As long as virtual methods or interfaces are used, there is no problem with memory management. That means, it doesn't matter where the object is created or freed.

A: If you want to pass classes across module boundaries then you need to link to the RTL/VCL with runtime packages. That's the only way to make sure that the TStringList class in your DLL is the exact same one as in your EXE. That is the fundamental problem with your current approach. On the other hand, if you are already linking to the RTL with runtime packages, then you are fine.
If you don't want to use runtime packages then you need to redesign your interface completely. You would need to stop passing classes across the module boundary. You can use interfaces, but not classes. And you would need to take control of the memory allocation to ensure that memory is always deallocated in the module that allocated it. Or start using ShareMem.

A: For this type of functionality, and to remain share-mem-free, package-free, I would use a callback with an enumerator method in the dll. This is how you retrieve the fonts from windows for example. Here is a mock up of what I'm referring to:
type
  TMyClass = class
  private
    FList: TStringList;  // obv you need to construct this

  public
    function EnumListItem(s: string): integer;
  end;

function TMyClass.EnumListItem(s: string): integer;
begin
  FList.Add(s);
end;

procedure TMyClass.FillList;
begin
  _myClass_DLL.FillList(@EnumListItem);
  ShowMessage(FList.Text);
end;

This is just to give you a starting point.... on the DLL side you use call back into your program using the function pointer and pass in the strings 1 at a time.

A: If you seriously oppose to BPLs then you'd better stick with COM conventions of DLLs and Interfaces.
In particular there are TStream-like interface in COM. And VCL has TStreamAdapter class to convert between COM IStream and VCL TStream.
That way your DLL should make a data stream, wrap it into COM IStream and pass to exe. EXE would convert back and fill stringlist from TStream.
More fast and lo-tech approach would be to feel memory buffers, like Windows API functions do. They either do feel it, or return program error asking for buffer of larger size. Well, then you would call function twice - to get buffer size and to do actual work. And if you mix the pointer types like PChar may be PAnsiChar or PWideChar, or pass wrong buffer size - you have no safety net from compiler, you just corrupted memory. But that would be faster than COM IStream.
Maybe you'd make COM-enabled Buffer object, which has special kind of destructor not freeing memory, but passing reference to DLL background idle memory recollection thread. So when you no more need it in main EXe it would sooner or later be freed in DLL itself. It is still not so comfort to use as TStream, but at least would hopefully not blow Heap manager.

A: The easiest way to get a string list from a dll is that way:
you have to create tStringList then fill it insside the Dll, then pass the text as return.
From Dll library:
function getDocuments(customer,depot:Pchar):Pchar;export;
var
 s:TstringList;
begin
 S:=TStringList.Create;
 S.Add('Row 1 '+customer);
 S.Add('Row 2 '+depot);
 S.Add('Row 3 ');
 S.Add('Row 4 ');
 S.Add('Row 5 ');
 Result:=pchar(s.Text);
 S.Free;
end;

From the EXE
function GetDLLExternalDocuments(customer,depot:pchar;out fList:TStringList):Word;
var GetDocumentsDLLExport:TGetDocumentsDLLExport;
var s:String;
var HandleDllExport :Thandle;
begin

  HandleDllExport := LoadLibrary('my_dll_library.dll');

  if HandleDllExport <> 0 then
   begin
    @GetDocumentsDLLExport := GetProcAddress(HandleDllExport, 'getDocuments');
    if @GetDocumentsDLLExport <> nil then
      begin
        s:=GetDocumentsDLLExport(cliente,impianto);
        fList.Text:=S;
        result:=0;
      end;

    FreeLibrary(HandleDllExport);
    HandleDllExport:=0;

   end;

end;

Usage:
procedure TfMain.Button1Click(Sender: TObject);
var
 S:tStringList;
begin
  S := tStringList.create;
  GetDLLExternalDocuments('123456','AAAAA',S);
  Showmessage(S.Text);
  s.Free;
end;


text:
Q: using innerHTML in a loop is not properly displaying the set of json results I'm using an HTML onclick event to call a function that will read a Javascript string containing JSON syntax and output the results, but only the last result is being shown.
var resorts = '{ "skiResorts" : [' +
    '{ "resortName":"Afton Alps" , "resortState":"Minnesota" },' +
    '{ "resortName":"Alpine Way" , "resortState":"Pennsylvania" },' +
    '{ "resortName":"Alyeska" , "resortState":"Alaska" } ]}';
var obj = JSON.parse(resorts);

function displaySkiResorts() {
    //code
    for (i = 0; i < obj.length; i++) {
        document.getElementById("req8").innerHTML = obj.skiResorts[i].resortName + " " + obj.skiResorts[i].resortState;
    }
}

Why doesn't this show the entire set of ski resorts?

A: You have an error. You must itterate over obj.skiResorts but not obj
So the result code would be
var resorts = '{ "skiResorts" : [' +
         '{ "resortName":"Afton Alps" , "resortState":"Minnesota" },' +
         '{ "resortName":"Alpine Way" , "resortState":"Pennsylvania" },' +
         '{ "resortName":"Alyeska" , "resortState":"Alaska" } ]}';

      var obj = JSON.parse(resorts);

      function displaySkiResorts() {
        //code
        for (i = 0; i < obj.skiResorts.length; i++) {
          document.getElementById("req8").innerHTML += obj.skiResorts[i].resortName + " " + obj.skiResorts[i].resortState + "
";
        }
      }

A: I changed the right acces to the array length obj.skiResorts.length, change the assignment to += and add a line break
.

var resorts = '{ "skiResorts" : [' +
         '{ "resortName":"Afton Alps" , "resortState":"Minnesota" },' +
         '{ "resortName":"Alpine Way" , "resortState":"Pennsylvania" },' +
         '{ "resortName":"Alyeska" , "resortState":"Alaska" } ]}';

var obj = JSON.parse(resorts);
function displaySkiResorts() {
    for (i = 0; i < obj.skiResorts.length; i++) { // obj.skiResorts.length right array
        document.getElementById("req8").innerHTML += obj.skiResorts[i].resortName + " " + obj.skiResorts[i].resortState + '
'; // += and

    }
}
displaySkiResorts();

A: Nina's answer correctly points out both issues (that your loop condition is incorrect, and that you are overwriting the innerHTML of the output element on each iteration).
I wanted to point out an optimization. In the body of your loop, on each iteration, you

*

*lookup an element by ID, and

*modify its innerHTML which will cause the browser to re-render.

Both of these operations can be done once, outside the loop. Build-up the HTML you would like to insert into the output element, and do it in one operation, like so

var resorts = '{ "skiResorts" : [' +
    '{ "resortName":"Afton Alps" , "resortState":"Minnesota" },' +
    '{ "resortName":"Alpine Way" , "resortState":"Pennsylvania" },' +
    '{ "resortName":"Alyeska" , "resortState":"Alaska" } ]}';
var obj = JSON.parse(resorts);

function displaySkiResorts() {
    // build array of lines of HTML
    var length = obj.skiResorts.length;
    var html = new Array(length);
    for (var i = 0; i < length; i++) {
        html[i] = obj.skiResorts[i].resortName + " " + obj.skiResorts[i].resortState
    }

    // insert into output, separated by line breaks
    document.getElementById('req8').innerHTML = html.join('
');
}
displaySkiResorts();

A: for (i = 0; i < obj.skiResorts.length; i++) {
    document.getElementById("req8").innerHTML= obj.skiResorts[i].resortName + " " + obj.skiResorts[i].resortState;
}

As @putvande points out, you are overwriting the same element each time. It's not clear what you were trying to do there. Did you mean to concatenate them?


text:
Q: while loop and printwriter only writes one line to file I have made a code of which gets a bunch of data from different files in a folder, I have then made sure to only look for a certain kind of word in the files. Then I have made sure the code prints out the results in the console.
All the things I have done up till now works perfectly, but here comes the issue. I want the code to also print/write the information to a .txt file. This sort of works, but it only prints one of the many lines from the different files. I am completely sure that there are more that one as the console print shows at least 20 different lines containing the right word.
I am not completely sure where I have gone wrong, I have also tried to add the .flush(); right before the .close(); but it still wont work. I have also tried to add the pToDocu.close(); underneath the sc.close();, but that doesn't work either, as that doesn't even write anything, that just creates a blank file.
So in short the code is supposed to write a bunch of lines, but it only writes one.
 public static void lisFilesF(final File folderV) throws IOException {
            PrintWriter pTD = new PrintWriter("eFile.txt");
            for (final File fileEntry : folderV.listFiles()) {
                if (fileEntry.isDirectory()) {
                    listFilesForFolder(fileEntry);
                } else {
                    System.out.println(fileEntry.getName());
                    try {
                        Scanner sc = new Scanner(fileEntry);
                        while (sc.hasNextLine()) {
                            String s = sc.nextLine();
                            if(s.contains("@"))
                            {
                            System.out.println(s);
                            pTD.println(s);
                            pTD.close();
                            }
                        }
                        sc.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                }
                }
            }
        }

UPDATE
I have changed the code to now have the pTD.close(); outside of the while loop like seen below. Only issue is that the file which is created now is blank, it has no information inside it.
public static void lisFilesF(final File folderV) throws IOException {
                PrintWriter pTD = new PrintWriter("eFile.txt");
                for (final File fileEntry : folderV.listFiles()) {
                    if (fileEntry.isDirectory()) {
                        listFilesForFolder(fileEntry);
                    } else {
                        System.out.println(fileEntry.getName());
                        try {
                            Scanner sc = new Scanner(fileEntry);
                            while (sc.hasNextLine()) {
                                String s = sc.nextLine();
                                if(s.contains("@"))
                                {
                                System.out.println(s);
                                pTD.println(s);
                                }
                            }
                            sc.close();
                            pTD.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                    }
                    }
                }
            }

A: You are closing the file (pTD) after the first time you write to it. You should extract the close() call from the loop and move it after it:
Scanner sc = new Scanner(fileEntry);
while (sc.hasNextLine()) {
    String s = sc.nextLine();
    if(s.contains("@")) {
        System.out.println(s);
        pTD.println(s);
    }
}
sc.close();
pTD.close();

A: Remove
pTD.close();

from your while loop. You close your Print Writer after the first write

A: It looks like you want to commit ALL of those records to your PrintWriter. Therefore, your pTD.close(); needs to be outside of your for loop, since you declared the PrintWriter before your for loop.


text:
Q: Install Mac OS Monterey on Mac OS Ventura beta So, I updated to beta software but had no Time Machine to go to. If possible, is there a way I can install Mac OS Monterey with the app? The new OS took over my only hope with the reinstall option.

A: Unfortunately, you will have to boot up to recovery mode, wipe the disk, then use internet recovery to reinstall Monterey. This will result in a loss of your data. If you do not want to lose your data, you could partition your disk, install Monterey on the new partition, and then use the Monterey partition until Ventura comes out as stable. Then you could upgrade your venture beta partition to stable venture & keep your data,


text:
Q: How can i make smaller js code in js? I have 5 css classes with different type of colors in a buttons for on hover function, in my page might be have 5 buttons with diffenent classes. When i hover the each button, color should be set as per respective class name so far its working fine for me. but now i can see huge code, i want to make it smaller. Please suggest anyone.
$('[class^="button"]').parent().each(function(){
    var parentElement = $(this);
    var buttonfullwidth = $(parentElement).hasClass('buttonfullwidth');
    var buttonfullwidth_1 = $(parentElement).hasClass('buttonfullwidth_1');
    var buttonfullwidth_2 = $(parentElement).hasClass('buttonfullwidth_2');
    var buttonfullwidth_3 = $(parentElement).hasClass('buttonfullwidth_3');
    var buttonfullwidth_4 = $(parentElement).hasClass('buttonfullwidth_4');

    if(buttonfullwidth_1 !== false) {
        $(parentElement).hover(function(){
            $(this).addClass('buttonfullwidth_1');

        }, function(){
            $(this).removeClass('buttonfullwidth_1');

        });
    }
    if(buttonfullwidth_2 !== false) {
        $(parentElement).hover(function(){
            $(this).addClass('buttonfullwidth_2');

        }, function(){
            $(this).removeClass('buttonfullwidth_2');

        });
    }
    if(buttonfullwidth_3 !== false) {
        $(parentElement).hover(function(){
            $(this).addClass('buttonfullwidth_3');

        }, function(){
            $(this).removeClass('buttonfullwidth_3');

        });
    }
    if(buttonfullwidth_4 !== false) {
        $(parentElement).hover(function(){
            $(this).addClass('buttonfullwidth_4');

        }, function(){
            $(this).removeClass('buttonfullwidth_4');

        });
    }
    if(buttonfullwidth !== false) {
        $(parentElement).hover(function(){
            $(this).addClass('buttonfullwidth');

        }, function(){
            $(this).removeClass('buttonfullwidth');

        });
    }
});

A: You need CSS for this job by using the :hover pseudo selector

The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, it is generally triggered when the user hovers over an element with the mouse pointer.

For example, if you want this button to turn blue when hovered:

.myButton {
  background-color: lightgreen;
}

.myButton:hover {
  background-color: lightblue;
}
<button class="myButton">Hover this button</button>

Notice how I can set properties to the element when it is in his hover state.
So for your code you simply need to use the following selectors:
buttonfullwidth
buttonfullwidth:hover

buttonfullwidth_1
buttonfullwidth_1:hover

buttonfullwidth_2
buttonfullwidth_2:hover

buttonfullwidth_3
buttonfullwidth_3:hover

buttonfullwidth_4
buttonfullwidth_4:hover

in the same manner as I did in my example.


text:
Q: What statistic procedure to use for analyzing my data? I'm currently a fourth year university student. As part of my studies, I'm taking a class called Capstone, where students design and carry out a research project. An essential part of formulating this research is choosing a statistical procedure with which to analyze and present your results.
My study focuses on studying the increase of middle school students' awareness on the subject of bullying.
To do that, we will have a group of students who will take an initial questionnaire which has multiple choice questions about different situations and what type of bullying they represent. After that test, the same students will be giving a workshop where we will discuss bullying: the types that exist, how to recognize them and the negative impact they can have. After those workshops, the students will take another test, consisting of exactly the same questions as the first.
The goal is that, by comparing the answers on both tests, we will find that students answers on that second test correspond to a better identification and understanding of what bullying is.
My question the is: what type of statistical test would you recommend I use to sort and analyze the data I recollect?

A: I think you should do a simple pairwise difference comparison (before and after workshop) for each question separately.
Since you will probably use some Likert scale in your questionnaire (such as "Strongly agree", "Agree", etc.) your data will be ordinal.
You can use the Wilcoxon signed rank test, to estimate whether there was a significant change in the responses for each question after the workshop.
I think any serious statistical package will support it. I'm sure you will have for example SPSS at school.
If you want to be able to claim that it was the workshop that caused the change, I would recommend you to go a step further. Let the class fill out the questionnaire, then split the class in two parts randomly, and send only half of the class to the workshop. Then let the entire class repeat the questionnaire. The part of the class not taking your workshop will be your control group. You can check whether there will be significant difference even without the workshop.
(if the workshop offers some real additional value for the students, send the other half to the workshop after they have finished filling out the questionnaire a second time)


text:
Q: Where is "The Zen of Python" located in the CPython source code? You of course know what happens when you import this, but where is the Zen located in the interpreter source code?
I'd searched the string "Readability counts" in a local clone but haven't found anything relevant.
Searching "zen of python" site:hg.python.org in Google gives me no result at all.

A: It ROT-13's it:
>>> import this # imports the file "this.py"
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
# ... etc ...
>>> this.s # encoded text
"Gur Mra bs Clguba, ol Gvz Crgref\n\nOrnhgvshy vf orggre guna htyl.\nRkcyvpvg vf orggre guna vzcyvpvg.\nFvzcyr vf orggre guna pbzcyrk.\nPbzcyrk vf orggre guna pbzcyvpngrq.\nSyng vf orggre guna arfgrq.\nFcnefr vf orggre guna qrafr.\nErnqnovyvgl pbhagf.\nFcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.\nNygubhtu cenpgvpnyvgl orngf chevgl.\nReebef fubhyq arire cnff fvyragyl.\nHayrff rkcyvpvgyl fvyraprq.\nVa gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.\nGurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.\nNygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.\nAbj vf orggre guna arire.\nNygubhtu arire vf bsgra orggre guna *evtug* abj.\nVs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.\nVs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.\nAnzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"
>>> this.d # dictionary
{'A': 'N', 'C': 'P', 'B': 'O', 'E': 'R', 'D': 'Q', 'G': 'T', 'F': 'S', 'I': 'V', 'H': 'U', 'K': 'X', 'J': 'W', 'M': 'Z', 'L': 'Y', 'O': 'B', 'N': 'A', 'Q': 'D', 'P': 'C', 'S': 'F', 'R': 'E', 'U': 'H', 'T': 'G', 'W': 'J', 'V': 'I', 'Y': 'L', 'X': 'K', 'Z': 'M', 'a': 'n', 'c': 'p', 'b': 'o', 'e': 'r', 'd': 'q', 'g': 't', 'f': 's', 'i': 'v', 'h': 'u', 'k': 'x', 'j': 'w', 'm': 'z', 'l': 'y', 'o': 'b', 'n': 'a', 'q': 'd', 'p': 'c', 's': 'f', 'r': 'e', 'u': 'h', 't': 'g', 'w': 'j', 'v': 'i', 'y': 'l', 'x': 'k', 'z': 'm'}

The actual code that decodes it is this:
d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)

print "".join([d.get(c, c) for c in s])

A: There's a file called this.py in the Lib directory.
The string is encoded using ROT-13 so it's not searchable. The code to decode it is in the file.


text:
Q: How to add an extra assert after the test methods run using python unittest? I have 92 tests and I want to make sure that no silent errors occurred during the calls.
Unfortunately error handing in OpenGL is not quite good. I want to test if glGetError() returns other then GL_NO_ERROR It is enough if I test it once per TestCase. It would be better if I could add an assert after every test methods. (I don't want to add it manually in 92 methods)
I made an example snippet that shows a solution that is not acceptable since the assert is done in the tearDownClass(cls) method and tearDownClass should not do any testing logic.
How can I add an extra assert after my tests?

The lines with comments show what I wan't to achieve.

import struct
import unittest

import ModernGL

class TestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.ctx = ModernGL.create_standalone_context()

    @classmethod
    def tearDownClass(cls):
        error = cls.ctx.error                   # Store error in a variable
        cls.ctx.release()                       # Then release the context
        cls.assertEqual(error, 'GL_NO_ERROR')   # Check if there were errors before the release

    def test_1(self):
        ...

    def test_2(self):
        ...

    def test_3(self):
        ...

if __name__ == '__main__':
    unittest.main()

NOTE:
cls.ctx.error is a property (glGetError() as a string) and the possible values are:
"GL_NO_ERROR"
"GL_INVALID_ENUM"
"GL_INVALID_VALUE"
"GL_INVALID_OPERATION"
"GL_INVALID_FRAMEBUFFER_OPERATION"
"GL_OUT_OF_MEMORY"
"GL_STACK_UNDERFLOW"
"GL_STACK_OVERFLOW"
"GL_UNKNOWN_ERROR"

A: You could do the test in the tearDown (as opposed to tearDownClass) method, as this is a regular instance method:
class TestCase(unittest.TestCase):

    def setUp(self):
        self.ctx = ModernGL.create_standalone_context()

    def tearDown(self):
        error = self.ctx.error                   # Store error in a variable
        self.ctx.release()                       # Then release the context
        self.assertEqual(error, 'GL_NO_ERROR')   # Check if there were errors before the release


text:
Q: inserting an image in owl slider in magento I want to insert an image in following code
jQuery(document).ready(function() {

jQuery("#owl-test-feature").owlCarousel({

navigation : true,

slideSpeed : 400,
paginationSpeed : 400,

items : 5,
itemsDesktop : false,
itemsDesktopSmall : false,
itemsTablet: false,
itemsMobile : true,
  navigation: true,
  navigationText: ["here prev.png","here next.png"]

});

});

I can't give media link inside the jquery.
can anyone help me?

A: you can call media link variable in the jquery script , like this
<?php
$image= 'image path';

<script type="text/javascript">
var simple = '<?php echo $simple; ?>';
 </script>

jQuery(document).ready(function() {

jQuery("#owl-test-feature").owlCarousel({

navigation : true,

slideSpeed : 400,
paginationSpeed : 400,

items : 5,
itemsDesktop : false,
itemsDesktopSmall : false,
itemsTablet: false,
itemsMobile : true,
  navigation: true,
  navigationText: ['<?php echo $image; ?>','<?php echo $image; ?>']

});

});

A: jQuery(document).ready(function() {
    var mediaPath = "<?php echo Mage::getBaseUrl('media').'YOUR/MEDIA/DIRECTORY/PATH' ?>";
    jQuery("#owl-test-feature").owlCarousel({

    navigation : true,

    slideSpeed : 400,
    paginationSpeed : 400,

    items : 5,
    itemsDesktop : false,
    itemsDesktopSmall : false,
    itemsTablet: false,
    itemsMobile : true,
      navigation: true,
      navigationText: [mediaPath+"here prev.png",mediaPath+"here next.png"]

    });

});

A: I would not move the entire JavaScript to one of the phtml files. First, I'd create a variable in your phtml file or in the head or just before your body closing tag, which is then available in all your JavaScript files. There are two options on where you can place the images: the media folder or your skin folder. Based on that, you need on of the following variables:
var MEDIA_URL = '<?php echo Mage::getBaseUrl('media'); ?>';
var SKIN_URL = '<?php echo Mage::getDesign()->getSkinUrl(); ?>';

For the skin URL, you might have to add some more parameters, like the area (frontend) and your current theme. You might want to check this when implementing the code.
Next, I'd create a JavaScript file for your owlCarousel:
jQuery(document).ready(function() {
    var prevImage = MEDIA_URL + 'slider/prev.png',
        nextImage = MEDIA_URL + 'slider/next.png';
    // Replace MEDIA_URL with SKIN_URL when using that location for the files.

    jQuery("#owl-test-feature").owlCarousel({
        navigation : true,
        slideSpeed : 400,
        paginationSpeed : 400,
        items : 5,
        itemsDesktop : false,
        itemsDesktopSmall : false,
        itemsTablet: false,
        itemsMobile : true,
        navigation: true,
        navigationText: [prevImage, nextImage]
    });
});


text:
Q: How to find out the validity of a URL in Flutter? I don't know of the title is completely appropriate, but here's what I actually want to do. I have urls which point to mp3 files, now some are valid and and some are not, as of now, so before I render the controls for playback of those audio files in my UI, I want to check whether the URL will give me the mp3 or result in a 404. How can I do that?

A: Make an HTTP request and check the response code
final response =
  await http.get(Uri.parse('https://jsonplaceholder.typicode.com/posts/1'));

if (response.statusCode == 200) {

See https://flutter.io/docs/cookbook/networking/fetch-data for more details.
A HEAD request will be more efficient though when you only want to check if the URL is valid because it doesn't actually download content.
final response =
  await http.head(Uri.parse('https://jsonplaceholder.typicode.com/posts/1'));

if (response.statusCode == 200) {

See also https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD


text:
Q: Why is my udev mounted device not staying put? I have a computer running CentOS 7.  I'm trying to set up a udev rule to automatically mount a USB drive (named 'sdb1') to /mnt/flash whenever it is connected.
The udev script was not working (see below), so I instead put my commands into a bash script and had udev run the bash script so I could see what was going on.
Problem #1:
If I try to directly create /mnt/flash from my bash script, it fails due to the root filesystem being read-only.  I can confirm the root filesystem is NOT read-only.  My system is already booted.  However, if I insert my USB drive, let udev run my script, sure enough when I run 'mount | logger' in my script it shows root is read only.
I worked around this issue by running 'mount -o remount,rw /' at the top of my script.
Problem #2:  I'm able to create /mnt/flash and mount /dev/sdb1 to /mnt/flash successfully.  I run 'mount | logger' after doing this and see it mounted in /var/log/messages.  However, when all is said and done, /dev/sdb1 is not mounted.  I even put a 5 second delay in my script and ran 'mount | logger' a second time.  Both times show /dev/sdb1 is mounted to /mnt/flash.  However, if I run 'mount' from a different terminal while all of this is going on, I never see /dev/sdb1 mounted anywhere.
Am I going crazy, or is udev doing some strange things to the filesystems while it runs?
udev script:  /etc/udev/rules.d/99-usb-automount.rules
#Only operate on sdb1
KERNEL!="sdb1", GOTO="usb-automount-end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="usb-automount-end"

#import useful variables from blkid program
IMPORT{program}="/sbin/blkid -o udev -p %N"

#ignore anything other than vfat filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="vfat", GOTO="usb-automount-end"

#remount root as read-write.  Not sure why we have to do this!
#ACTION=="add", RUN+="/bin/mount -o remount,rw /"

#mount to /mnt/flash
#ACTION=="add", RUN+="/bin/mkdir -p /mnt/flash"
#ACTION=="add", RUN+="/bin/mount -t vfat -o dmask=000,fmask=111 /dev/%k /mnt/flash"
ACTION=="add", RUN+="/root/test_run.sh", OPTIONS="last_rule"

#clean up after removal
#ACTION=="remove", RUN+="/bin/umount -l /mnt/flash"

#label for goto end
LABEL="usb-automount-end"

Here is /root/test_run.sh:
#!/bin/bash -x
logger "running mount"
mount | logger
logger "remounting root"
mount -o remount,rw /  2>&1 | logger
logger "remount done"
mount | logger
logger "Running script.  Adding dir"
mkdir -p /mnt/flash2 2>&1 | logger
logger "Directory added... mounting."
mount -t vfat -o dmask=000,fmask=111 /dev/sdb1 /mnt/flash2 2>&1 | logger
logger "Mounted"
mount | logger

logger "Sleeping 5 then re-checking"
sleep 5

mount | logger

Edit 1 : Disabling SELinux fixed problem #1.  However, I still cannot get the /dev/sdb1 to stay mounted after udev.  It still appears there is almost a second mount table that is maintained from within the udev context.

A: Problem #1 was caused by SELinux.  Since I don't need it for this system, I simply disabled it.
Problem #2 was caused by a udev setting (specified in systemd script) that makes the udev namespace keep a 'slave' copy of the mount flags.  Changing this to 'shared' fixed the problem.  See a more detailed answer here: https://unix.stackexchange.com/a/154318/41988


text:
Q: Refresh text after click and manipulate data plotly dash I am new to Plotly Dash (Python). My question might be wrongly asked or naive, so please guide me in the right dirction if thats the case.
In my IDE, I have a dataframe library with a few hundred short texts. What I would like to do is to create an interface in which users see one piece of text per time and submit an (binary) input for this text (this needs to be saved in a new column/dataframe). Then, after they have given the input, a new short text will show for which they are asked to give their binary input again. These steps continue until all texts have been read.
Since I am new to Plotly, Dash, I don't know:

*

*if this is possible

*what type of functions I need to look for

*how to write the code for this
So far, I have only found how to write a large piece of text:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

app = dash.Dash()

for text in library:
     markdown_text = text
     app.layout = html.Div([
         dcc.Markdown(children=markdown_text)
     ])

if __name__ == '__main__':
    app.run_server(debug=True)

So any answer that gets me closer to implementation is welcome.
Ps. This answer is specifically focused on plots, so therefore not relevant to my question

A: I presume you have library which has your initial texts to display and a user input.
Include an @app.callback with the user input value. Then the function for the callback can call the relevant text again from library and display in the div area of the layout.
Remember, you need to have id for all the elements on your page, so that callbacks can work correctly. Do refer to the examples given in dash documentation for callbacks.


text:
Q: Adding publishing page by powershell and custom page layout giving error I created custom html page layout with embedded web part in it. When I am trying to add page to pages library by powershell getting below error
Fail: Exception calling "AddPublishingPage" with "2" argument(s): "No parameterless constructor defined for this object."

at $Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)
Strange part is. When I create page manually with same page layout its getting created and once I create it manually. My Script is working fine. I can create pages withouts error once I create page manually.
Not sure what is happning here
Script below :
     $PageTitle = $newPage.NewPageTitle
     $Layouts = $PubSite.GetPageLayouts($False)
         foreach($layout in $Layouts){
             if($layout.Name -eq $PageLayoutRelUrl){
                 $PageLayout = $layout
             }
         }
    $Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)
    $Page.Title = $PageTitle
    $Page.Update();
    $Page.CheckIn("Deployment CheckIn")
    $Page.ListItem.File.Publish("Deplyment Pulish")

A: In your script, you have defined the $PageLayout but you didn't define the  $PageName so you got this error

Fail: Exception calling "AddPublishingPage" with "2" argument(s): "No parameterless constructor defined for this object."

Try to define the $PageName as the following
 $PageName = "Test.aspx"

Then use it at
$Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)