问:
Build failed because of webpack errors at async Object.build
Since I have upgraded my next.js app from Next JS 9 to 11 . I am getting the error. We have a custom webpack config in our next config.js. Which I have below , I assume this is something related to Webpack. I have upgraded the webpack to Webpack 5 as well. Still getting the same issues.

```<code>> Build error occurred
Error: > Build failed because of webpack errors
    at ../node_modules/next/dist/build/index.js:397:19
    at async Span.traceAsyncFn (../node_modules/next/dist/telemetry/trace/trace.js:60:20)
    at async Object.build [as default] (../node_modules/next/dist/build/index.js:77:25)
</code>```

My Package.json is -

```<code>{
    "devDependencies": {
        "@babel/core": "^7.4.5",
        "@babel/plugin-proposal-optional-chaining": "^7.6.0",
        "@babel/plugin-transform-runtime": "^7.6.2",
        "@babel/preset-env": "^7.4.5",
        "@babel/preset-react": "^7.0.0",
        "@testing-library/react": "^10.0.4",
        "babel-loader": "^8.0.6",
        "browserslist": "^4.6.0",
        "jest": "^24.7.1",
        "node-sass": "^4.14.1",
        "nodemon": "^2.0.3",
        "prettier": "^1.16.4",
        "sass-loader": "^7.1.0",
        "stylelint": "^9.10.1",
        "stylelint-scss": "^3.6.1",
        "supertest": "^4.0.2"
    },
    "dependencies": {
        "@babel/runtime": "^7.4.4",
        "@contentful/rich-text-react-renderer": "^13.4.0",
        "@contentful/rich-text-types": "^13.4.0",
        "@fast-csv/parse": "^4.1.2",
        "@next/bundle-analyzer": "^9.4.4",
        "@yolkai/next-routes": "^3.0.0",
        "@zeit/next-css": "^1.0.1",
        "@zeit/next-sass": "^1.0.1",
        "animate.css": "^3.7.2",
        "appdynamics": "^4.5.23",
        "axios": "^0.23.0",
        "babel-plugin-transform-optional-chaining": "^7.0.0-beta.3",
        "babel-plugin-wildcard": "^6.0.0",
        "body-parser": "^1.19.0",
        "compression": "^1.7.4",
        "contentful": "^7.6.0",
        "cors": "^2.8.5",
        "date-fns": "^2.10.0",
        "dotenv": "^8.2.0",
        "enzyme": "^3.9.0",
        "enzyme-adapter-react-16": "^1.12.1",
        "enzyme-to-json": "^3.3.5",
        "express": "^4.17.1",
        "express-boom": "^3.0.0",
        "extract-text-webpack-plugin": "^3.0.2",
        "file-loader": "^3.0.1",
        "focus-trap-react": "^6.0.0",
        "google-auth-library": "^5.5.1",
        "googleapis": "^89.0.0",
        "helmet": "^4.4.1",
        "json-stringify-safe": "^5.0.1",
        "jwt-js-decode": "^1.4.1",
        "next": "^11.1.2",
        "next-compose-plugins": "^2.1.1",
        "next-fonts": "^0.18.0",
        "node-fetch": "^2.6.0",
        "prop-types": "^15.7.2",
        "pure-react-carousel": "^1.20.0",
        "query-string": "^6.8.1",
        "react": "^17.0.2",
        "react-countup": "^4.1.3",
        "react-datepicker": "^3.1.3",
        "react-device-detect": "^1.6.2",
        "react-dom": "^17.0.2",
        "react-medium-image-zoom": "^3.0.16",
        "react-modal": "^3.12.1",
        "react-transition-group": "^4.2.1",
        "sanitize-html": "^2.3.2",
        "slick-carousel": "^1.8.1",
        "stylelint-config-standard": "^18.3.0",
        "underscore": "^1.9.1",
        "webpack": "^5.1.3",
        "xml-js": "^1.6.11"
    },
    "resolutions": {
        "webpack": "5.41.1"
    },
    "jest": {
        "collectCoverageFrom": [
            "**/*.{js,jsx}",
            "!**/node_modules/**",
            "!**/vendor/**",
            "!**/src/.next/",
            "!**/setupTests.js",
            "!**/*.config.js",
            "!**/coverage/**",
            "!**/test_automation/**",
            "!**/src/static/**"
        ],
        "coverageThreshold": {
            "global": {
                "branches": 80,
                "functions": 80,
                "lines": 80
            }
        }
    }
}
</code>```

My next.config.js is -

```<code>const withPlugins = require('next-compose-plugins');
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
const withFonts = require('next-fonts');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.analyze === 'true',
});

const nextConfig = {
  env: {
    search_key: process.env.search_key,
    appDynamicsKey: process.env.appDynamicsKey,
    ENVIRONMENT: process.env.ENVIRONMENT,
  },
  // https://nextjs.org/docs#customizing-webpack-config
  webpack: (webpackConfig) => {
    const { module = {} } = webpackConfig;
    return {
      ...webpackConfig,
      module: {
        ...module,
        rules: [
          ...(module.rules || []),
          {
            test: /\.(txt|png|woff|woff2|eot|ttf|gif|jpg|ico|svg)$/,
            use: {
              loader: 'file-loader',
              options: {
                name: '[name]_[hash].[ext]',
                publicPath: '/_next/static/files',
                outputPath: 'static/files',
              },
            },
          },
          {
            test: /\.spec.jsx$/,
            loader: 'ignore-loader',
          },
        ],
      },
    };
  },
};

const sassOptions = {
  sassLoaderOptions: {
    outputStyle: 'compressed',
  },
};

module.exports = withPlugins(
  [[withSass, sassOptions], [withFonts], [withCSS], [withBundleAnalyzer]],
  nextConfig,
);
</code>```

Would appreciate some help, have been stuck on this for a while now. Tried to implement all the solutions over the internet nothing worked.

答:
I was getting similar error and solved it by using below next.config.js:</p>
```<code>const { withSentryConfig } = require('@sentry/nextjs');
const execSync = require("child_process").execSync;

const lastCommitCommand = "git rev-parse HEAD";

const moduleExports = {
 // Your existing module.exports
   async generateBuildId() {
     return execSync(lastCommitCommand).toString().trim();
   },
  /* Code for redirect Old URL to New URL */
 async redirects() {
   return [
     {
      source: "/seller/SERENDIPITY/",
      destination: "/",
      permanent: true,
     },
   ];
 },
 trailingSlash: true,
 // generateEtags: false,
 distDir: "dist",
 sentry: {
   disableServerWebpackPlugin: true,
   disableClientWebpackPlugin: true,
 },
};

module.exports = withSentryConfig(moduleExports);
</code>```

Body:
Since I have upgraded my next.js app from Next JS 9 to 11 . I am getting the error. We have a custom webpack config in our next config.js. Which I have below , I assume this is something related to Webpack. I have upgraded the webpack to Webpack 5 as well. Still getting the same issues.

> Build error occurred
Error: > Build failed because of webpack errors
    at ../node_modules/next/dist/build/index.js:397:19
    at async Span.traceAsyncFn (../node_modules/next/dist/telemetry/trace/trace.js:60:20)
    at async Object.build [as default] (../node_modules/next/dist/build/index.js:77:25)

My Package.json is -

{
    "devDependencies": {
        "@babel/core": "^7.4.5",
        "@babel/plugin-proposal-optional-chaining": "^7.6.0",
        "@babel/plugin-transform-runtime": "^7.6.2",
        "@babel/preset-env": "^7.4.5",
        "@babel/preset-react": "^7.0.0",
        "@testing-library/react": "^10.0.4",
        "babel-loader": "^8.0.6",
        "browserslist": "^4.6.0",
        "jest": "^24.7.1",
        "node-sass": "^4.14.1",
        "nodemon": "^2.0.3",
        "prettier": "^1.16.4",
        "sass-loader": "^7.1.0",
        "stylelint": "^9.10.1",
        "stylelint-scss": "^3.6.1",
        "supertest": "^4.0.2"
    },
    "dependencies": {
        "@babel/runtime": "^7.4.4",
        "@contentful/rich-text-react-renderer": "^13.4.0",
        "@contentful/rich-text-types": "^13.4.0",
        "@fast-csv/parse": "^4.1.2",
        "@next/bundle-analyzer": "^9.4.4",
        "@yolkai/next-routes": "^3.0.0",
        "@zeit/next-css": "^1.0.1",
        "@zeit/next-sass": "^1.0.1",
        "animate.css": "^3.7.2",
        "appdynamics": "^4.5.23",
        "axios": "^0.23.0",
        "babel-plugin-transform-optional-chaining": "^7.0.0-beta.3",
        "babel-plugin-wildcard": "^6.0.0",
        "body-parser": "^1.19.0",
        "compression": "^1.7.4",
        "contentful": "^7.6.0",
        "cors": "^2.8.5",
        "date-fns": "^2.10.0",
        "dotenv": "^8.2.0",
        "enzyme": "^3.9.0",
        "enzyme-adapter-react-16": "^1.12.1",
        "enzyme-to-json": "^3.3.5",
        "express": "^4.17.1",
        "express-boom": "^3.0.0",
        "extract-text-webpack-plugin": "^3.0.2",
        "file-loader": "^3.0.1",
        "focus-trap-react": "^6.0.0",
        "google-auth-library": "^5.5.1",
        "googleapis": "^89.0.0",
        "helmet": "^4.4.1",
        "json-stringify-safe": "^5.0.1",
        "jwt-js-decode": "^1.4.1",
        "next": "^11.1.2",
        "next-compose-plugins": "^2.1.1",
        "next-fonts": "^0.18.0",
        "node-fetch": "^2.6.0",
        "prop-types": "^15.7.2",
        "pure-react-carousel": "^1.20.0",
        "query-string": "^6.8.1",
        "react": "^17.0.2",
        "react-countup": "^4.1.3",
        "react-datepicker": "^3.1.3",
        "react-device-detect": "^1.6.2",
        "react-dom": "^17.0.2",
        "react-medium-image-zoom": "^3.0.16",
        "react-modal": "^3.12.1",
        "react-transition-group": "^4.2.1",
        "sanitize-html": "^2.3.2",
        "slick-carousel": "^1.8.1",
        "stylelint-config-standard": "^18.3.0",
        "underscore": "^1.9.1",
        "webpack": "^5.1.3",
        "xml-js": "^1.6.11"
    },
    "resolutions": {
        "webpack": "5.41.1"
    },
    "jest": {
        "collectCoverageFrom": [
            "**/*.{js,jsx}",
            "!**/node_modules/**",
            "!**/vendor/**",
            "!**/src/.next/",
            "!**/setupTests.js",
            "!**/*.config.js",
            "!**/coverage/**",
            "!**/test_automation/**",
            "!**/src/static/**"
        ],
        "coverageThreshold": {
            "global": {
                "branches": 80,
                "functions": 80,
                "lines": 80
            }
        }
    }
}

My next.config.js is -

const withPlugins = require('next-compose-plugins');
const withSass = require('@zeit/next-sass');
const withCSS = require('@zeit/next-css');
const withFonts = require('next-fonts');
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.analyze === 'true',
});

const nextConfig = {
  env: {
    search_key: process.env.search_key,
    appDynamicsKey: process.env.appDynamicsKey,
    ENVIRONMENT: process.env.ENVIRONMENT,
  },
  // https://nextjs.org/docs#customizing-webpack-config
  webpack: (webpackConfig) => {
    const { module = {} } = webpackConfig;
    return {
      ...webpackConfig,
      module: {
        ...module,
        rules: [
          ...(module.rules || []),
          {
            test: /\.(txt|png|woff|woff2|eot|ttf|gif|jpg|ico|svg)$/,
            use: {
              loader: 'file-loader',
              options: {
                name: '[name]_[hash].[ext]',
                publicPath: '/_next/static/files',
                outputPath: 'static/files',
              },
            },
          },
          {
            test: /\.spec.jsx$/,
            loader: 'ignore-loader',
          },
        ],
      },
    };
  },
};

const sassOptions = {
  sassLoaderOptions: {
    outputStyle: 'compressed',
  },
};

module.exports = withPlugins(
  [[withSass, sassOptions], [withFonts], [withCSS], [withBundleAnalyzer]],
  nextConfig,
);

Would appreciate some help, have been stuck on this for a while now. Tried to implement all the solutions over the internet nothing worked.

Body:
I was getting similar error and solved it by using below next.config.js:

const { withSentryConfig } = require('@sentry/nextjs');
const execSync = require("child_process").execSync;

const lastCommitCommand = "git rev-parse HEAD";

const moduleExports = {
 // Your existing module.exports
   async generateBuildId() {
     return execSync(lastCommitCommand).toString().trim();
   },
  /* Code for redirect Old URL to New URL */
 async redirects() {
   return [
     {
      source: "/seller/SERENDIPITY/",
      destination: "/",
      permanent: true,
     },
   ];
 },
 trailingSlash: true,
 // generateEtags: false,
 distDir: "dist",
 sentry: {
   disableServerWebpackPlugin: true,
   disableClientWebpackPlugin: true,
 },
};

module.exports = withSentryConfig(moduleExports);


来源: stackexchange

问:
How to unstage large number of files without deleting the content
I accidentally added a lot of temporary files using git add -A

I managed to unstage the files using the following commands and managed to remove the dirty index.

```<code>git ls-files -z | xargs -0 rm -f
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
</code>```

The above commands are listed in the git help rm. But sadly, my files were also deleted on execution, even though I had given cache option. How can I clear the index without losing the content?

Also it would be helpful if someone can explain the way this pipe operation works.

答:
I'm afraid that the first of those command lines unconditionally deleted from the working copy all the files that are in git's staging area.  The second one unstaged all the files that were tracked but have now been deleted.  Unfortunately this means that you will have lost any uncommitted modifications to those files.

If you want to get your working copy and index back to how they were at the last commit, you can (carefully) use the following command:

```<code>git reset --hard
</code>```

I say "carefully" since git reset --hard will obliterate uncommitted changes in your working copy and index.  However, in this situation it sounds as if you just want to go back to the state at your last commit, and the uncommitted changes have been lost anyway.

Update: it sounds from your comments on Amber's answer that you haven't yet created any commits (since HEAD cannot be resolved), so this won't help, I'm afraid.

As for how those pipes work: git ls-files -z and git diff --name-only --diff-filter=D -z both output a list of file names separated with the byte 0.  (This is useful, since, unlike newlines, 0 bytes are guaranteed not to occur in filenames on Unix-like systems.)  The program xargs essentially builds command lines from its standard input, by default by taking lines from standard input and adding them to the end of the command line.  The -0 option says to expect standard input to by separated by 0 bytes.  xargs may invoke the command several times to use up all the parameters from standard input, making sure that the command line never becomes too long.

As a simple example, if you have a file called test.txt, with the following contents:

```<code>hello
goodbye
hello again
</code>```

... then the command xargs echo whatever < test.txt will invoke the command:

```<code>echo whatever hello goodbye hello again
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I accidentally added a lot of temporary files using git add -A

I managed to unstage the files using the following commands and managed to remove the dirty index.

git ls-files -z | xargs -0 rm -f
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached

The above commands are listed in the git help rm. But sadly, my files were also deleted on execution, even though I had given cache option. How can I clear the index without losing the content?

Also it would be helpful if someone can explain the way this pipe operation works.

Body:
I'm afraid that the first of those command lines unconditionally deleted from the working copy all the files that are in git's staging area.  The second one unstaged all the files that were tracked but have now been deleted.  Unfortunately this means that you will have lost any uncommitted modifications to those files.

If you want to get your working copy and index back to how they were at the last commit, you can (carefully) use the following command:

git reset --hard

I say "carefully" since git reset --hard will obliterate uncommitted changes in your working copy and index.  However, in this situation it sounds as if you just want to go back to the state at your last commit, and the uncommitted changes have been lost anyway.

Update: it sounds from your comments on Amber's answer that you haven't yet created any commits (since HEAD cannot be resolved), so this won't help, I'm afraid.

As for how those pipes work: git ls-files -z and git diff --name-only --diff-filter=D -z both output a list of file names separated with the byte 0.  (This is useful, since, unlike newlines, 0 bytes are guaranteed not to occur in filenames on Unix-like systems.)  The program xargs essentially builds command lines from its standard input, by default by taking lines from standard input and adding them to the end of the command line.  The -0 option says to expect standard input to by separated by 0 bytes.  xargs may invoke the command several times to use up all the parameters from standard input, making sure that the command line never becomes too long.

As a simple example, if you have a file called test.txt, with the following contents:

hello
goodbye
hello again

... then the command xargs echo whatever < test.txt will invoke the command:

echo whatever hello goodbye hello again


问:
Why avro, or Parquet format is faster than csv?
I can read articles where I can read that csv is slower and bad for large dataset.

but I cant understand what is it with avro/parquet internally which makes it faster for larger dataset than csv.

答:
The ordering of preferred data formats (in a Hadoop context) is typically ORC, Parquet, Avro, SequenceFile, then PlainText.

Primary reason against CSV is that it is just a string, meaning the dataset is larger by storing all characters according to the file-encoding (UTF8, for example); there is no type-information or schema that is associated with the data, and it will always be parsed while deserialized. In other words, when storing a boolean field, for example, you really only need one bit in binary, but in CSV, you have to store the full bytes of "true", "false" or a string of "0", or "1", which as ASCII is still a full 8 bits.

ORC and Parquet, on the other hand, maintain type information and support columnar push-down predicates for faster analytics (like an RDBMS)

Avro is a row-based format. Primarily for network transfer, not long-term storage. Avro can easily be converted into Parquet. Since it is still typed and binary, it will consume less space than CSV and is still faster to process than plaintext.

SequenceFiles are a middle-ground for Hadoop, but aren't widely supported by other tooling.

ContentLicense: CC BY-SA 4.0


问:
Matcher doesn't return the matched regex, instead returns whole string in group(0) (Java)
The problem I'm facing is that upon following the question at this link, Using Regular Expressions to Extract a Value in Java, I am unable to extract the correct group of the String

```<code>Pattern p = Pattern.compile("I have .*");
Matcher m = p.matcher("I have apples");

if(m.find()){
    System.out.println(m.group(0));
}
</code>```

What I get:

```<code>I have apples
</code>```

What I want to get:

```<code>apples
</code>```

I've tried asking for m.group(1) as well but it throws me an exception.

How should I go about this?

答:
You have to define a capturing group to get m.group(...) work correctly.

Change your pattern to

```<code>Pattern p = Pattern.compile("I have (.*)");
</code>```

m.group(0) 'denotes the entire pattern'
m.group(1) now returns the expected 'apple'

Body:
The problem I'm facing is that upon following the question at this link, Using Regular Expressions to Extract a Value in Java, I am unable to extract the correct group of the String

Pattern p = Pattern.compile("I have .*");
Matcher m = p.matcher("I have apples");

if(m.find()){
    System.out.println(m.group(0));
}

What I get:

I have apples

What I want to get:

apples

I've tried asking for m.group(1) as well but it throws me an exception.

How should I go about this?

Body:
You have to define a capturing group to get m.group(...) work correctly.

Change your pattern to

Pattern p = Pattern.compile("I have (.*)");

m.group(0) 'denotes the entire pattern'
m.group(1) now returns the expected 'apple'


问:
binding objects with a string and getting the column names with the name of the object in R
I have multiple objects with a common string

```<code>resultsPetal.Length
resultsPetal.Width
resultsSetal.Length
resultsSetal.Width
</code>```

and when I use cbind on them, I get this list

```<code>          resultSepal.Length
statistic 138.9083
parameter Numeric,2
p.value   1.505059e-28
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          resultSepal.Width
statistic 45.01204
parameter Numeric,2
p.value   1.432735e-14
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
</code>```

However, I have multiple objects and would like to join them without having to write a line for each, so I used

```<code>test=do.call(cbind, lapply(ls(pattern ="result"), get))
</code>```

which gets me

```<code>          [,1]
statistic 1828.092
parameter Numeric,2
p.value   2.693327e-66
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,2]
statistic 1276.885
parameter Numeric,2
p.value   4.138739e-64
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,3]
statistic 138.9083
parameter Numeric,2
p.value   1.505059e-28
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,4]
statistic 45.01204
parameter Numeric,2
p.value   1.432735e-14
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"

</code>```

As you can see, I have lost the object name and I have absolutely no clue how to work around this. What can I do?

Here is the full code for reproducibility

```<code>dat <- iris# remove one level to have only two groups
#dat <- subset(dat, Species != "setosa")
dat$Species <- factor(dat$Species)# boxplots and t-tests for the 4 variables at once
for (i in 1:4) { # variables to compare are variables 1 to 4
  boxplot(dat[, i] ~ dat$Species, # draw boxplots by group
          ylab = names(dat[i]), # rename y-axis with variable's name
          xlab = "Species"
  )
  print(oneway.test(dat[, i] ~ dat$Species)) # print results of t-test
  assign(paste0("result", names(dat[i])), (oneway.test(dat[, i] ~ dat$Species)))
}

test=cbind(resultSepal.Length, resultSepal.Width)
test=do.call(cbind, lapply(ls(pattern ="result"), get))
</code>```

答:
There are few approaches you could use:

Use mget:

```<code>do.call(cbind, mget(ls(pattern = 'result')))
</code>```

Use sapply:

```<code>sapply(ls(pattern ="result"), get)
</code>```

Give names to the list:

```<code>l <- ls(pattern ="result")
do.call(cbind, lapply(setNames(l,l), get))
</code>```

Body:
I have multiple objects with a common string

resultsPetal.Length
resultsPetal.Width
resultsSetal.Length
resultsSetal.Width

and when I use cbind on them, I get this list

          resultSepal.Length
statistic 138.9083
parameter Numeric,2
p.value   1.505059e-28
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          resultSepal.Width
statistic 45.01204
parameter Numeric,2
p.value   1.432735e-14
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"

However, I have multiple objects and would like to join them without having to write a line for each, so I used

test=do.call(cbind, lapply(ls(pattern ="result"), get))

which gets me

          [,1]
statistic 1828.092
parameter Numeric,2
p.value   2.693327e-66
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,2]
statistic 1276.885
parameter Numeric,2
p.value   4.138739e-64
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,3]
statistic 138.9083
parameter Numeric,2
p.value   1.505059e-28
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"
          [,4]
statistic 45.01204
parameter Numeric,2
p.value   1.432735e-14
method    "One-way analysis of means (not assuming equal variances)"
data.name "dat[, i] and dat$Species"

As you can see, I have lost the object name and I have absolutely no clue how to work around this. What can I do?

Here is the full code for reproducibility

dat <- iris# remove one level to have only two groups
#dat <- subset(dat, Species != "setosa")
dat$Species <- factor(dat$Species)# boxplots and t-tests for the 4 variables at once
for (i in 1:4) { # variables to compare are variables 1 to 4
  boxplot(dat[, i] ~ dat$Species, # draw boxplots by group
          ylab = names(dat[i]), # rename y-axis with variable's name
          xlab = "Species"
  )
  print(oneway.test(dat[, i] ~ dat$Species)) # print results of t-test
  assign(paste0("result", names(dat[i])), (oneway.test(dat[, i] ~ dat$Species)))
}

test=cbind(resultSepal.Length, resultSepal.Width)
test=do.call(cbind, lapply(ls(pattern ="result"), get))

Body:
There are few approaches you could use:

Use mget:

do.call(cbind, mget(ls(pattern = 'result')))

Use sapply:

sapply(ls(pattern ="result"), get)

Give names to the list:

l <- ls(pattern ="result")
do.call(cbind, lapply(setNames(l,l), get))


问:
(this.internalValue || []).findIndex is not a function when enabling multiple selection on v-select
I am using Vue.js with Vuetify.

Following is my minimal reproducible example:

<template>
  <v-app>
    <v-select v-model="site" :items="sites" item-value="_id" item-text="name"></v-select>
    <v-btn @click="showSelections">Show Selections</v-btn>
  </v-app>
</template>

```
<p>This example works perfect until you want to enable multiple selection on the <code>v-select</code> component.</p>
```<v-select v-model="site" :items="sites" multiple item-value="_id" item-text="name"></v-select>
```
<p>As soon as you click the combobox, you'd get this:</p>
```vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler: "TypeError: (this.internalValue || []).findIndex is not a function"

found in

---> <VSelectList>
       <VThemeProvider>
         <VMenu>
           <VSelect>
             <VMain>
               <VApp>
                 <App> at src/App.vue
                   <Root>

TypeError: (this.internalValue || []).findIndex is not a function
    at VueComponent.findExistingIndex (VSelect.ts?1576:338)
    at VueComponent.selectItem (VSelect.ts?1576:816)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)
    at click (VSelectList.ts?7bd1:169)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
```

答:
I had the same issue when I was toggling the multiple property of the v-select. See the reproduction link: https://codepen.io/kkojot/pen/MWOpYqZ

To avoid this error you have to clear the property bound to v-model and change it empty object {} or empty array [] accordingly.

```<code>computed: {
 isMultiple() {
  //comment the if statment below to see the 'TypeError: (this.internalValue || []).findIndex is not a function'
  if (this.multiple) this.site = [];
  else this.site = {};
  return this.multiple;
},
</code>```

},

Body:
I am using Vue.js with Vuetify.

Following is my minimal reproducible example:

<template>
  <v-app>
    <v-select v-model="site" :items="sites" item-value="_id" item-text="name"></v-select>
    <v-btn @click="showSelections">Show Selections</v-btn>
  </v-app>
</template>

This example works perfect until you want to enable multiple selection on the v-select component.

<v-select v-model="site" :items="sites" multiple item-value="_id" item-text="name"></v-select>

As soon as you click the combobox, you'd get this:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler: "TypeError: (this.internalValue || []).findIndex is not a function"

found in

---> <VSelectList>
       <VThemeProvider>
         <VMenu>
           <VSelect>
             <VMain>
               <VApp>
                 <App> at src/App.vue
                   <Root>

TypeError: (this.internalValue || []).findIndex is not a function
    at VueComponent.findExistingIndex (VSelect.ts?1576:338)
    at VueComponent.selectItem (VSelect.ts?1576:816)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.Vue.$emit (vue.runtime.esm.js?2b0e:3888)
    at click (VSelectList.ts?7bd1:169)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)

Body:
I had the same issue when I was toggling the multiple property of the v-select. See the reproduction link: https://codepen.io/kkojot/pen/MWOpYqZ

To avoid this error you have to clear the property bound to v-model and change it empty object {} or empty array [] accordingly.

computed: {
 isMultiple() {
  //comment the if statment below to see the 'TypeError: (this.internalValue || []).findIndex is not a function'
  if (this.multiple) this.site = [];
  else this.site = {};
  return this.multiple;
},

},


问:
Pass a partition filter from outer query to inner
I have a query that joins data from 3 tables, table1 INNER JOIN table2 LEFT JOIN table3 .
All 3 tables MUST have a partition filter applied during query. Currently the filter is set to
WHERE _PARTITIONDATE IS NOT NULL . I want to save the inner query as a view, so that my end users can supply the partition date and the inner query only reads the partitions that the user requests data from. Is there a way to pass the partition date to the view definition ? For example: I want 2021-12-31 to be passed to the WHERE conditions on the WITH clauses, instead of WHERE _PARTITIONDATE IS NOT NULL

```<code>SELECT * FROM (
            WITH T1 AS (
                      SELECT column1, column2, _PARTITIONDATE
                      FROM `projectid.datasetid.table1`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )
             ,T2 AS  (

                      SELECT column3, column4, _PARTITIONDATE
                      FROM `projectid.datasetid.table2`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )
             ,T3 AS (
                      SELECT column5, column6,_PARTITIONDATE
                      FROM `projectid.datasetid.table3`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )

                  SELECT
                         T1.column1,
                         T1.column2,
                         T2.column3,
                         T2.column4,
                         T3.column5,
                         T3.column6,
                         T1._PARTITIONDATE AS PARTITIONDATE
                  FROM T1 INNER JOIN T2
                                        ON T1.column1 = T2.column3
                                           T1._PARTITIONDATE = T2._PARTITIONDATE
                             LEFT OUTER JOIN T3
                                        ON T3.column5 = T2.column3 AND
                                           T3._PARTITIONDATE = T2._PARTITIONDATE

)  WHERE PARTITIONDATE = '2021-12-31';
</code>```

答:
It is called push predicate, in oracle it is a hint /*+ push_pred */ in big query it is done automatically so you just need to create view without filter. Please refer the article

Advantages of standard SQL
Standard SQL complies with the SQL 2011 standard, and has extensions that support querying nested and repeated data. It has several advantages over legacy SQL, including:

Composability using WITH clauses and SQL functions

Subqueries in the SELECT list and WHERE clause Correlated subqueries

ARRAY and STRUCT data types Inserts, updates, and deletes

COUNT(DISTINCT ) is exact and scalable, providing the accuracy

of EXACT_COUNT_DISTINCT without its limitations Automatic predicate

push-down through JOINs Complex JOIN predicates, including arbitrary
expressions

Additionally you may try parametrized queries :

```<code>bq query \
--use_legacy_sql=false \
--parameter=corpus::romeoandjuliet \
--parameter=min_word_count:INT64:250 \
'SELECT
  word, word_count
FROM
  `bigquery-public-data.samples.shakespeare`
WHERE
  corpus = @corpus
AND
  word_count >= @min_word_count
ORDER BY
  word_count DESC'
</code>```

Body:
I have a query that joins data from 3 tables, table1 INNER JOIN table2 LEFT JOIN table3 .
All 3 tables MUST have a partition filter applied during query. Currently the filter is set to
WHERE _PARTITIONDATE IS NOT NULL . I want to save the inner query as a view, so that my end users can supply the partition date and the inner query only reads the partitions that the user requests data from. Is there a way to pass the partition date to the view definition ? For example: I want 2021-12-31 to be passed to the WHERE conditions on the WITH clauses, instead of WHERE _PARTITIONDATE IS NOT NULL

SELECT * FROM (
            WITH T1 AS (
                      SELECT column1, column2, _PARTITIONDATE
                      FROM `projectid.datasetid.table1`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )
             ,T2 AS  (

                      SELECT column3, column4, _PARTITIONDATE
                      FROM `projectid.datasetid.table2`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )
             ,T3 AS (
                      SELECT column5, column6,_PARTITIONDATE
                      FROM `projectid.datasetid.table3`
                      WHERE _PARTITIONDATE IS NOT NULL
                  )

                  SELECT
                         T1.column1,
                         T1.column2,
                         T2.column3,
                         T2.column4,
                         T3.column5,
                         T3.column6,
                         T1._PARTITIONDATE AS PARTITIONDATE
                  FROM T1 INNER JOIN T2
                                        ON T1.column1 = T2.column3
                                           T1._PARTITIONDATE = T2._PARTITIONDATE
                             LEFT OUTER JOIN T3
                                        ON T3.column5 = T2.column3 AND
                                           T3._PARTITIONDATE = T2._PARTITIONDATE

)  WHERE PARTITIONDATE = '2021-12-31';

Body:
It is called push predicate, in oracle it is a hint /*+ push_pred */ in big query it is done automatically so you just need to create view without filter. Please refer the article

Advantages of standard SQL
Standard SQL complies with the SQL 2011 standard, and has extensions that support querying nested and repeated data. It has several advantages over legacy SQL, including:

Composability using WITH clauses and SQL functions

Subqueries in the SELECT list and WHERE clause Correlated subqueries

ARRAY and STRUCT data types Inserts, updates, and deletes

COUNT(DISTINCT ) is exact and scalable, providing the accuracy

of EXACT_COUNT_DISTINCT without its limitations Automatic predicate

push-down through JOINs Complex JOIN predicates, including arbitrary
expressions

Additionally you may try parametrized queries :

bq query \
--use_legacy_sql=false \
--parameter=corpus::romeoandjuliet \
--parameter=min_word_count:INT64:250 \
'SELECT
  word, word_count
FROM
  `bigquery-public-data.samples.shakespeare`
WHERE
  corpus = @corpus
AND
  word_count >= @min_word_count
ORDER BY
  word_count DESC'


问:
Buttons are not spaced with css present
I'm having a problem with buttons in CSS.

Between the first two I get the right distance, but between the second and the third I get two buttons joined (attached) (as in the picture).

How can I solve this problem?

.buttons {
  display: flex;
}

.buttons form {
  margin: 0 10px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="buttons">
  <form action="createArt.html">
    <input type="submit" value="ADD" />
  </form>
  <input type="button" value="EDIT" onclick="confirmation_edit()" />
  <input type="button" value="DELETE" onclick="confirmation_delete()" />
</div></code>```

答:
Change .buttons form by .buttons > *

.buttons > * { margin: 0 10px; }

Title: Buttons are not spaced with css present

Body:
I'm having a problem with buttons in CSS.

Between the first two I get the right distance, but between the second and the third I get two buttons joined (attached) (as in the picture).

How can I solve this problem?

.buttons {
  display: flex;
}

.buttons form {
  margin: 0 10px;
}

  <form action="createArt.html">
    <input type="submit" value="ADD" />
  </form>
  <input type="button" value="EDIT" onclick="confirmation_edit()" />
  <input type="button" value="DELETE" onclick="confirmation_delete()" />


问:
How to find maximum number of occurrences for a character in a cell in a column in a CSV table in Python
I'm trying to find the maximum number of occurrences of '/' (a slash) in a cell in a column in a CSV file. Here's the table below. It has hundreds of rows.

Person Full Name
Person CRD Number
ID Number

Jack Johnson
32 / 54 / 57 / 87
5686

John Johnsen
11 / 22
6589

Luke Peterson
34
6978

Kyle Garcia
63 / 24 / 83
8957

Here's my code:

```<code>import pandas as pd

data = '/Users/myname/Downloads/tabularShell.csv'

df = pd.read_csv(data, index_col=0)

df1 = pd.DataFrame(df)['Person CRD Number']

df2 = df1.value_counts('/')

print(df2)
</code>```

The output should be 3 because the maximum number of occurrences of '/' is 3 in a cell in the "Person CRD Number" column in the table shown above.

Thank you!

答:
This gives you better control if you want to do more operations on your count</p>
```<code>import pandas as pd

# Ignore these lines, it is just to build the dataframe
data = [['Jack Johnson', '32 / 54 / 57 / 87', '5686'],
        ['John Johnsen', '11 / 22', '6589'],
        ['Luke Peterson', '34', '6978']]
df = pd.DataFrame(data)
df.columns = ['Person Full Name', 'Person CRD Number', 'ID Number']

# Define a small function to count the char in a string
def count_char(string, char=r'/'):
    return string.count(char)

# Apply the function to the CRD number and store in a new column
df['count'] = df['Person CRD Number'].apply(count_char)

# Get the maximum from the count
print(df['count'].max())
</code>```

Body:
I'm trying to find the maximum number of occurrences of '/' (a slash) in a cell in a column in a CSV file. Here's the table below. It has hundreds of rows.

Person Full Name
Person CRD Number
ID Number

Jack Johnson
32 / 54 / 57 / 87
5686

John Johnsen
11 / 22
6589

Luke Peterson
34
6978

Kyle Garcia
63 / 24 / 83
8957

Here's my code:

import pandas as pd

data = '/Users/myname/Downloads/tabularShell.csv'

df = pd.read_csv(data, index_col=0)

df1 = pd.DataFrame(df)['Person CRD Number']

df2 = df1.value_counts('/')

print(df2)

The output should be 3 because the maximum number of occurrences of '/' is 3 in a cell in the "Person CRD Number" column in the table shown above.

Thank you!

Body:
This gives you better control if you want to do more operations on your count

import pandas as pd

# Ignore these lines, it is just to build the dataframe
data = [['Jack Johnson', '32 / 54 / 57 / 87', '5686'],
        ['John Johnsen', '11 / 22', '6589'],
        ['Luke Peterson', '34', '6978']]
df = pd.DataFrame(data)
df.columns = ['Person Full Name', 'Person CRD Number', 'ID Number']

# Define a small function to count the char in a string
def count_char(string, char=r'/'):
    return string.count(char)

# Apply the function to the CRD number and store in a new column
df['count'] = df['Person CRD Number'].apply(count_char)

# Get the maximum from the count
print(df['count'].max())


问:
Getting a rank from ActiveRecord
If Users have points, how can I get the user rank, assuming standard positioning:

```<code>require 'active_record'

class User < ActiveRecord::Base
  def rank
    # ???
  end
end

User.all
# => [<User id:1 points:100>, <User id:2 points:400>, <User id:3 points:100>, <User id:4 points:250>]

User.find_by_id(2).rank
# => 1
User.find_by_id(3).rank
# => 3
User.find_by_id(1).rank
# => 3
</code>```

I get the distinct impression this will be database intensive. I'm not too worried about that, but obviously solutions which require less processing power are winners!

If giving two users with the same number of points the same rank is too complex, I'm prepared to accept that user 1 above may be rank 3, and user 3 may be rank 4.

EDIT:

I'm actually storin gmy scores in a seperate class - as each event warrants a certain amount of points.

```<code>class Event < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :events

  def points
    events.sum(:amount)
  end

  def rank
    # This seems a bit ham-handed
    Event.count_by_sql(['select count(*) from (select sum(amount) as points from events group by user_id) where points > ?',points]) + 1
  end
end
</code>```

Any ideas as to how to make this more succinct?

Thanks in advance

答:
You can count the number of users having less points, and add one.

```<code>def rank
  User.where("points > ?", points).count + 1
end
</code>```

This would return 3 for users 1 and 3.

Title: Getting a rank from ActiveRecord

Body:
If Users have points, how can I get the user rank, assuming standard positioning:

require 'active_record'

class User < ActiveRecord::Base
  def rank
    # ???
  end
end

User.all
# => [<User id:1 points:100>, <User id:2 points:400>, <User id:3 points:100>, <User id:4 points:250>]

User.find_by_id(2).rank
# => 1
User.find_by_id(3).rank
# => 3
User.find_by_id(1).rank
# => 3

I get the distinct impression this will be database intensive. I'm not too worried about that, but obviously solutions which require less processing power are winners!

If giving two users with the same number of points the same rank is too complex, I'm prepared to accept that user 1 above may be rank 3, and user 3 may be rank 4.

EDIT:

I'm actually storin gmy scores in a seperate class - as each event warrants a certain amount of points.

class Event < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :events

  def points
    events.sum(:amount)
  end

  def rank
    # This seems a bit ham-handed
    Event.count_by_sql(['select count(*) from (select sum(amount) as points from events group by user_id) where points > ?',points]) + 1
  end
end

Any ideas as to how to make this more succinct?

Thanks in advance

Body:
You can count the number of users having less points, and add one.

def rank
  User.where("points > ?", points).count + 1
end

This would return 3 for users 1 and 3.


问:
Appending Excel files to Python DataFrame
The below code goes through the excel files in the Regis folder and appends them into a new DataFrame. I need to make the following changes to the code:

The data starts in column 7 so I do not need to append the first 6 rows of each Excel file

Each Excel Sheet has a date at the end of the file name e.g. "Regis 30012022" The last 8 digits are the date (European format) and I would like to add a column so that I know which date the data refers to. This date should be added to column A.

```<code>import pandas as pd
import glob

# path of the folder
path = r'Regis'

# reading excel files
filenames = glob.glob(path + "\*.xlsx")
print('File names:', filenames)

# initializing empty data frame
finalexcelsheet = pd.DataFrame()

# interating through all excel files
for file in filenames:

    # combining multiple excel worksheets into single data frames
    df = pd.concat(pd.read_excel(file, sheet_name=None), ignore_index=True, sort=False)

    # appending excel files one by one
    finalexcelsheet = finalexcelsheet.append(df, ignore_index=True)

finalexcelsheet.to_excel(r'Final.xlsx', index=False)
</code>```

答:
For the first point, you can add the argument skiprows into your reading of the file:

```<code>df = pd.concat(pd.read_excel(file, sheet_name=None, skiprows = 6), ignore_index=True, sort=False)
</code>```

For the second issue, I would do the following:

```<code>for file in filenames:

    temp_df = pd.read_excel(file, sheet_name=None, skiprows=6)
    date_string = "".join(character for character in file if character.isdigit())
    date = datetime.datetime.strptime(date_string, "%d%M%Y")
    temp_df["date"]= date

    df = pd.concat(temp_df, ignore_index=True, sort=False)

    # appending excel files one by one
    finalexcelsheet = finalexcelsheet.append(df, ignore_index=True)
</code>```

This is reading in the excel file, creating a datetime object from the filename, and using that datetime object to create a new column for temp_df before using concat.

Body:
The below code goes through the excel files in the Regis folder and appends them into a new DataFrame. I need to make the following changes to the code:

The data starts in column 7 so I do not need to append the first 6 rows of each Excel file

Each Excel Sheet has a date at the end of the file name e.g. "Regis 30012022" The last 8 digits are the date (European format) and I would like to add a column so that I know which date the data refers to. This date should be added to column A.

import pandas as pd
import glob

# path of the folder
path = r'Regis'

# reading excel files
filenames = glob.glob(path + "\*.xlsx")
print('File names:', filenames)

# initializing empty data frame
finalexcelsheet = pd.DataFrame()

# interating through all excel files
for file in filenames:

    # combining multiple excel worksheets into single data frames
    df = pd.concat(pd.read_excel(file, sheet_name=None), ignore_index=True, sort=False)

    # appending excel files one by one
    finalexcelsheet = finalexcelsheet.append(df, ignore_index=True)

finalexcelsheet.to_excel(r'Final.xlsx', index=False)

Body:
For the first point, you can add the argument skiprows into your reading of the file:

df = pd.concat(pd.read_excel(file, sheet_name=None, skiprows = 6), ignore_index=True, sort=False)

For the second issue, I would do the following:

for file in filenames:

    temp_df = pd.read_excel(file, sheet_name=None, skiprows=6)
    date_string = "".join(character for character in file if character.isdigit())
    date = datetime.datetime.strptime(date_string, "%d%M%Y")
    temp_df["date"]= date

    df = pd.concat(temp_df, ignore_index=True, sort=False)

    # appending excel files one by one
    finalexcelsheet = finalexcelsheet.append(df, ignore_index=True)

This is reading in the excel file, creating a datetime object from the filename, and using that datetime object to create a new column for temp_df before using concat.


问:
TypeError: Cannot read properties of undefined (reading 'login')
My Index.js is having a error. I can't understand why.</p>
```<code>const { Client, Collection } = require("discord.js");
const { readdirSync } = require("fs");
const { join } = require("path");
const { TOKEN, PREFIX } = require("./util/Util");
const i18n = require("./util/i18n");

const { Intents, client } = require('discord.js');

client.login(TOKEN);
client.commands = new Collection();
client.prefix = PREFIX;
client.queue = new Map();
const cooldowns = new Collection();
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

client.on("ready", () => {
    console.log(`${client.user.username} ready!`);
    client.user.setActivity(`with ${client.guilds.cache.size} servers`);
  });
  client.on("warn", (info) => console.log(info));
  client.on("error", console.error);

  const commandFiles = readdirSync(join(__dirname, "commands")).filter((file) => file.endsWith(".js"));
  for (const file of commandFiles) {
    const command = require(join(__dirname, "commands", `${file}`));
    client.commands.set(command.name, command);
  }

client.on("message", async (message) => {
    if (message.author.bot) return;
    if (!message.guild) return;

    const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(PREFIX)})\\s*`);
    if (!prefixRegex.test(message.content)) return;

    const [, matchedPrefix] = message.content.match(prefixRegex);

    const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
    const commandName = args.shift().toLowerCase();

    const command =
      client.commands.get(commandName) ||
      client.commands.find((cmd) => cmd.aliases && cmd.aliases.includes(commandName));

    if (!command) return;

    if (!cooldowns.has(command.name)) {
      cooldowns.set(command.name, new Collection());
    }

    const now = Date.now();
    const timestamps = cooldowns.get(command.name);
    const cooldownAmount = (command.cooldown || 1) * 1000;

    if (timestamps.has(message.author.id)) {
      const expirationTime = timestamps.get(message.author.id) + cooldownAmount;

      if (now < expirationTime) {
        const timeLeft = (expirationTime - now) / 1000;
        return message.reply(
          i18n.__mf("common.cooldownMessage", { time: timeLeft.toFixed(1), name: command.name })
        );
      }
    }

    timestamps.set(message.author.id, now);
    setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);

    try {
      command.execute(message, args);
    } catch (error) {
      console.error(error);
      message.reply(i18n.__("common.errorCommand")).catch(console.error);
    }
  });

  client.login(TOKEN);

</code>```

答:
The import is called Client instead of client. So change your import and instantiate the client like so:

```<code>const { Intents, Client } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
</code>```

You will have to set the intents according to your own use case, as per this answer.

Body:
My Index.js is having a error. I can't understand why.

const { Client, Collection } = require("discord.js");
const { readdirSync } = require("fs");
const { join } = require("path");
const { TOKEN, PREFIX } = require("./util/Util");
const i18n = require("./util/i18n");

const { Intents, client } = require('discord.js');

client.login(TOKEN);
client.commands = new Collection();
client.prefix = PREFIX;
client.queue = new Map();
const cooldowns = new Collection();
const escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

client.on("ready", () => {
    console.log(`${client.user.username} ready!`);
    client.user.setActivity(`with ${client.guilds.cache.size} servers`);
  });
  client.on("warn", (info) => console.log(info));
  client.on("error", console.error);

  const commandFiles = readdirSync(join(__dirname, "commands")).filter((file) => file.endsWith(".js"));
  for (const file of commandFiles) {
    const command = require(join(__dirname, "commands", `${file}`));
    client.commands.set(command.name, command);
  }

client.on("message", async (message) => {
    if (message.author.bot) return;
    if (!message.guild) return;

    const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|${escapeRegex(PREFIX)})\\s*`);
    if (!prefixRegex.test(message.content)) return;

    const [, matchedPrefix] = message.content.match(prefixRegex);

    const args = message.content.slice(matchedPrefix.length).trim().split(/ +/);
    const commandName = args.shift().toLowerCase();

    const command =
      client.commands.get(commandName) ||
      client.commands.find((cmd) => cmd.aliases && cmd.aliases.includes(commandName));

    if (!command) return;

    if (!cooldowns.has(command.name)) {
      cooldowns.set(command.name, new Collection());
    }

    const now = Date.now();
    const timestamps = cooldowns.get(command.name);
    const cooldownAmount = (command.cooldown || 1) * 1000;

    if (timestamps.has(message.author.id)) {
      const expirationTime = timestamps.get(message.author.id) + cooldownAmount;

      if (now < expirationTime) {
        const timeLeft = (expirationTime - now) / 1000;
        return message.reply(
          i18n.__mf("common.cooldownMessage", { time: timeLeft.toFixed(1), name: command.name })
        );
      }
    }

    timestamps.set(message.author.id, now);
    setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);

    try {
      command.execute(message, args);
    } catch (error) {
      console.error(error);
      message.reply(i18n.__("common.errorCommand")).catch(console.error);
    }
  });

  client.login(TOKEN);

Body:
The import is called Client instead of client. So change your import and instantiate the client like so:

const { Intents, Client } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

You will have to set the intents according to your own use case, as per this answer.


问:
How set cookies in dev tools in Google Chrome 98 version?
after update google chrome up to 98 version, I can't set cookies

it looks like a red stripe and after the refresh, it disappears. Even you fill all fields, it disappears.

Maybe any know how it disables the feature?
This feature describes in their blog, but I can't find how to fix it

答: Based on the comment in this diff - https://chromium.googlesource.com/devtools/devtools-frontend/+/20ed4f2bd282537f404af9d45df1333d5aeb21f5%5E%21/#F0, I felt this has something to do with Partitioned cookies. So I opened chrome://flags and set the value of "Partitioned Cookies" to Enabled" and relaunched the browser. After that the red row did not appear and I am able to set the cookies like before.


问:
Conditional join in marklogic
I need to do conditional join in marklogic like in this sql question conditional join in sql

I have template with nullable columns and if value of first column is null I want to use second column for join.

I use optic api with op:from-view() method.

答:
There are a few choices.

On the join clause, you could skip the second option(keys) and use a condition my sample is a join-inner() :

```<code>xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
 at "/MarkLogic/optic.xqy";

let $plan-t1 := op:from-literals((
        map:entry("col1", 1) => map:with("col2", "A"),
        map:entry("col2", "B")
        ), "T1")

let $plan-t2 := op:from-literals((
        map:entry("col3", 1) => map:with("col4", "C"),
        map:entry("col3", 2) => map:with("col4", "B")
        ), "T2")

let $join := $plan-t2
        =>op:join-inner(
          $plan-t1,
          (),
            op:or((
              op:and((
                op:is-defined(op:view-col("T1", "col1")),
                op:eq(op:view-col("T1", "col1"), op:view-col("T2", "col3"))
                )),
              op:and((
                op:not(op:is-defined(op:view-col("T1", "col1"))),
                op:eq(op:view-col("T1", "col2"), op:view-col("T2", "col4"))
                ))
            ))
          )

return $join=> op:result()
</code>```

As a second option, one might consider a SQL COALESCE() style approach with op:bind() and op:case() on the first table to resolve the key in advance and then use the join keys. This would be interesting as it may perform quite differently on a database with multiple forests and multiple nodes.

Title: Conditional join in marklogic

Body:
There are a few choices.

On the join clause, you could skip the second option(keys) and use a condition my sample is a join-inner() :

xquery version "1.0-ml";

import module namespace op="http://marklogic.com/optic"
 at "/MarkLogic/optic.xqy";

let $plan-t1 := op:from-literals((
        map:entry("col1", 1) => map:with("col2", "A"),
        map:entry("col2", "B")
        ), "T1")

let $plan-t2 := op:from-literals((
        map:entry("col3", 1) => map:with("col4", "C"),
        map:entry("col3", 2) => map:with("col4", "B")
        ), "T2")

let $join := $plan-t2
        =>op:join-inner(
          $plan-t1,
          (),
            op:or((
              op:and((
                op:is-defined(op:view-col("T1", "col1")),
                op:eq(op:view-col("T1", "col1"), op:view-col("T2", "col3"))
                )),
              op:and((
                op:not(op:is-defined(op:view-col("T1", "col1"))),
                op:eq(op:view-col("T1", "col2"), op:view-col("T2", "col4"))
                ))
            ))
          )

return $join=> op:result()

As a second option, one might consider a SQL COALESCE() style approach with op:bind() and op:case() on the first table to resolve the key in advance and then use the join keys. This would be interesting as it may perform quite differently on a database with multiple forests and multiple nodes.


问:
Vertex AI forecasting AutoML giving different answers for same input data
I trained Vertex AI forecasting AutoML model one with target column as String and other numeric input features as String then I trained another AutoML model with target column as float and other input features as Integer.

The predictions are different for both the models. The data is same only the datatypes/schema changed.

Google documentation says:

When you train a model with a feature with a numeric transformation,
Vertex AI applies the following data transformations to the feature,
and uses any that provide signal for training:

The value converted to float32.

So both the data should be same even after transformation.
Why would results be different? Is it possible?

答:
I have follow the steps to have a forecasting model as show on Build an AutoML Forecasting Model with Vertex AI and reach the conclusion that vertex AI compress a lot of the steps of the prediction model generation so it can be easily operate by users.

I think the most reasonable answer for your observation among strings and numeric values resides in the way data processing is performed to generate our prediction models. I think you will not find inside vertex AI documentation as it would mean to disclose how vertex AI code works and handles its Feature Engineering and train steps to generate the models, which is protected.

Regardless, Lets speculate a bit, I think the difference among datatypes conversion might occur when datatype is converted and passed to the algorithm for processing. Lets said a linear regression sample, you will find that the slightest variation on data conversion can affect the outcome of your prediction model which could also be what is happening here.


问:
How to remove bell curved shape from image using opencv
I hope you are doing well. I want to remove the bell-curved shape in the image. I have used OpenCV. I have implemented the following code which detects the curve shape, Now How can remove that curve shape and save the new image in the folder.

Input Image 1

I want to remove the area shown in the image below

Area i want to remove

```<code>import cv2
import numpy as np
    # load image as grayscale
cell1 = cv2.imread("/content/savedImage.jpg",0)
    # threshold image
ret,thresh_binary = cv2.threshold(cell1,107,255,cv2.THRESH_BINARY)
    # findcontours
contours, hierarchy = cv2.findContours(image =thresh_binary , mode = cv2.RETR_TREE,method = cv2.CHAIN_APPROX_SIMPLE)

    # create an empty mask
mask = np.zeros(cell1.shape[:2],dtype=np.uint8)

    # loop through the contours
for i,cnt in enumerate(contours):
            # if the contour has no other contours inside of it
    if hierarchy[0][i][2] == -1 :
                    # if the size of the contour is greater than a threshold
       if  cv2.contourArea(cnt) > 10000:
             cv2.drawContours(mask,[cnt], 0, (255), -1)
fig, ax = plt.subplots(1,2)
ax[0].imshow(cell1,'gray');
ax[1].imshow(mask,'gray');
</code>```

Ouput Image after the above Code

How can I process to remove that curve shape?

答:
Here is one way to do that in Python/OpenCV.

Get the external contours. Then find the one that has the largest w/h aspect ratio. Draw that contour filled on a black background as a mask. Dilate it a little. Then invert it and use it to blacken out that region.

Input:

```<code>import cv2
import numpy as np

# read image
img = cv2.imread('the_image.jpg')
ht, wd = img.shape[:2]

# convert to grayscale
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# threshold
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]

# get external contours
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]

max_aspect=0
for cntr in contours:
    x,y,w,h = cv2.boundingRect(cntr)
    aspect = w/h
    if aspect > max_aspect:
        max_aspect = aspect
        max_contour = cntr

# create mask from max_contour
mask = np.zeros((ht,wd), dtype=np.uint8)
mask = cv2.drawContours(mask, [max_contour], 0, (255), -1)

# dilate mask
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
mask = cv2.morphologyEx(mask, cv2.MORPH_DILATE, kernel)

# invert mask
mask = 255 - mask

# mask out region in input
result = img.copy()
result = cv2.bitwise_and(result, result, mask=mask)

# save resulting image
cv2.imwrite('the_image_masked.png',result)

# show thresh and result
cv2.imshow("mask", mask)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()
</code>```

Result:

Body:
I hope you are doing well. I want to remove the bell-curved shape in the image. I have used OpenCV. I have implemented the following code which detects the curve shape, Now How can remove that curve shape and save the new image in the folder.

Input Image 1

I want to remove the area shown in the image below

Area i want to remove

import cv2
import numpy as np
    # load image as grayscale
cell1 = cv2.imread("/content/savedImage.jpg",0)
    # threshold image
ret,thresh_binary = cv2.threshold(cell1,107,255,cv2.THRESH_BINARY)
    # findcontours
contours, hierarchy = cv2.findContours(image =thresh_binary , mode = cv2.RETR_TREE,method = cv2.CHAIN_APPROX_SIMPLE)

    # create an empty mask
mask = np.zeros(cell1.shape[:2],dtype=np.uint8)

    # loop through the contours
for i,cnt in enumerate(contours):
            # if the contour has no other contours inside of it
    if hierarchy[0][i][2] == -1 :
                    # if the size of the contour is greater than a threshold
       if  cv2.contourArea(cnt) > 10000:
             cv2.drawContours(mask,[cnt], 0, (255), -1)
fig, ax = plt.subplots(1,2)
ax[0].imshow(cell1,'gray');
ax[1].imshow(mask,'gray');

Ouput Image after the above Code

How can I process to remove that curve shape?

Body:
Here is one way to do that in Python/OpenCV.

Get the external contours. Then find the one that has the largest w/h aspect ratio. Draw that contour filled on a black background as a mask. Dilate it a little. Then invert it and use it to blacken out that region.

Input:

import cv2
import numpy as np

# read image
img = cv2.imread('the_image.jpg')
ht, wd = img.shape[:2]

# convert to grayscale
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# threshold
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)[1]

# get external contours
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]

max_aspect=0
for cntr in contours:
    x,y,w,h = cv2.boundingRect(cntr)
    aspect = w/h
    if aspect > max_aspect:
        max_aspect = aspect
        max_contour = cntr

# create mask from max_contour
mask = np.zeros((ht,wd), dtype=np.uint8)
mask = cv2.drawContours(mask, [max_contour], 0, (255), -1)

# dilate mask
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
mask = cv2.morphologyEx(mask, cv2.MORPH_DILATE, kernel)

# invert mask
mask = 255 - mask

# mask out region in input
result = img.copy()
result = cv2.bitwise_and(result, result, mask=mask)

# save resulting image
cv2.imwrite('the_image_masked.png',result)

# show thresh and result
cv2.imshow("mask", mask)
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

Result:


问:
git pushes with wrong user from terminal
I have an issue with git and my terminal.

Here's a gallery to show you my issue : http://imgur.com/a/6RrEY

When I push commits from my terminal, git says I push them with another username, that's a user from my organisation (my company) with no commit at all and it seems it belongs to no one : (check gallery first pic)

But this doesn't happen when I use Github for mac, in the feed I see the commits pushed by myself.

The problem also affects my personal repositories, my terminal says that I don't have the permission to push commits on those repositories (which is obviously wrong) since it tries to push it with this user : (check gallery second pic)

Guess what ? This doesn't happen with Github for mac too.

I changed my computer to a brand new one few days ago, so I reset'ed all my ssh key of github and left only a new one generated by Github for Mac so I don't think that there's some ghost user/ssh key hidden somewhere, this hdd is brand new : (check gallery third pic)

My .gitconfig file is all clear, there's only my credentials : (check gallery fourth pic)

I really don't get it, help, StackOverflow, you're my only hope.

(My apologies for my poor Gimp skills and the Star Wars reference)

EDIT : ssh-add -l only shows the good ssh key created by github for mac and I have only one github account

EDIT2 : ssh -T git@github.com recognize me as the good user.

EDIT3 : After a few tests it looks like my terminal does the commits with my username, but pushes them with the other one, Github for mac commits and pushes with the good username.This situation happen with every repo I have/make (even new ones).

EDIT4 : In a personal repository git log --pretty="%h %an %ae" shows my good username

EDIT5 : No sign of environment variables that would override my credentials in my env. Even if I try to set those variables with the good credentials problem persists.

EDIT6 : Things work back normally if I force the user in the path of /.git/config of a repository but I don't think that's the good option : http://USER@github.com/USER/REPO.git

EDIT7 : We deleted the git user that pushed the commits for me and this brings another error : remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/USER/REPO.git/'

FINAL EDIT : I installed git with homebrew, typed git config --global push.default simple and now it takes my credentials even without forceing the user. That's strange. Thanks everybody for your help, you're great guys !

答:
This is how you debug and fix it for ssh url

First, check which user is via ssh:

```<code>ssh -T git@github.com
</code>```

Hi <your_current_github_username>! You've successfully authenticated, but GitHub does not provide shell access.

Login GitHub with the above your_current_github_username
Check all configured ssh keys: https://github.com/settings/keys

Method 1:

Remove the ssh key from your_current_github_username

Method 2:

determine which key was associated with your_current_github_username

```<code>cat ~/.ssh/id_*.pub
</code>```

Assumming id_rsa is the SSH key of your target github username, in your case it's might be a different file name.

```<code>eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa
</code>```

Method 3:

If no public key was found on your machine (or you've lost it)
Then create a new ssh key by ssh-keygen and place it here: ~/.ssh/id_new_keyyyy

```<code>eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_new_keyyyy
</code>```

Body:
This is how you debug and fix it for ssh url

First, check which user is via ssh:

ssh -T git@github.com

Hi <your_current_github_username>! You've successfully authenticated, but GitHub does not provide shell access.

Login GitHub with the above your_current_github_username
Check all configured ssh keys: https://github.com/settings/keys

Method 1:

Remove the ssh key from your_current_github_username

Method 2:

determine which key was associated with your_current_github_username

cat ~/.ssh/id_*.pub

Assumming id_rsa is the SSH key of your target github username, in your case it's might be a different file name.

eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa

Method 3:

If no public key was found on your machine (or you've lost it)
Then create a new ssh key by ssh-keygen and place it here: ~/.ssh/id_new_keyyyy

eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_new_keyyyy


问:
Pyspark inner join 3 tables
My goal is joining 3 tables in Pyspark dataframes,

TableA, TableB and TableC all have an ID like a Key to merge.

I want to join three tables and create a new Pyspark dataframe.

Do you have any suggestions?

答:
You can simply join them as below:</p>
```<code>final_table = (tableA.join(tableB, on = [tableA.ID == tableB.ID], how = 'inner')
                     .join(tableC, on = [tableA.ID == tableB.ID], how = 'inner'))
</code>```

Title: Pyspark inner join 3 tables

Body:
You can simply join them as below:

final_table = (tableA.join(tableB, on = [tableA.ID == tableB.ID], how = 'inner')
                     .join(tableC, on = [tableA.ID == tableB.ID], how = 'inner'))


问:
switch between two databases for different users in codeigniter
I need to change the database name in database.php passing value from the controller. I tried sessions and env variable. but in the database.php cannot access the value from sessions and env variable. also, i need to use the default database to load the page and when user has been logged in need to switch the database. i'm doing this for reducing size of the database data is there any solution really glad someone can help me.

databse.php

```<code>$active_group = 'default';
$query_builder = TRUE;

if($db_val==""){
    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'sliate_srs',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
}
else{

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => getenv("DB_year"),
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
}
</code>```

controller.php
function loginSubmit() {

```<code>   $DB_year=$this->input->post('year_select');
    //$this->session->unset_userdata('DB_year');

    //$this->session->set_userdata('DB_year',$DB_year);
    $DB_year="srs_2019";
    putenv("DB_year=$DB_year");
    // $_ENV["DB_year"]="srs_2019";
    print_r(getenv("DB_year"));
    // $DB_year="srs_2019";

    $result = $this->Login_model->authenticateLogin();

    if (!empty($result)) {
        $now = date('Y-m-d H:i:s');
        $ip = $this->input->ip_address();
        $data = array(
            'u_id' => $this->session->userdata('u_id'),
            'u_name' => $this->session->userdata('u_name'),
            'center_name' => $this->session->userdata('u_branch'),
            'last_login_ip' => $this->input->ip_address('ip'),
            'last_login_date_time' => $now
        );
        $name = $this->session->userdata('DB_year');
        print_r($name);
        $this->Login_model->last_login($data);
        redirect('Admin/dashboard');
    } else {

        redirect('Login?login=invalid');
    }

}
</code>```

答: Instead of changing the config group in Database.php, why not create a custom connection in your model, as explained in Connecting with Custom Settings?</p>

Body:
I need to change the database name in database.php passing value from the controller. I tried sessions and env variable. but in the database.php cannot access the value from sessions and env variable. also, i need to use the default database to load the page and when user has been logged in need to switch the database. i'm doing this for reducing size of the database data is there any solution really glad someone can help me.

databse.php

$active_group = 'default';
$query_builder = TRUE;

if($db_val==""){
    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'sliate_srs',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
}
else{

    $db['default'] = array(
        'dsn'   => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => getenv("DB_year"),
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => FALSE,
        'db_debug' => (ENVIRONMENT !== 'production'),
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt'  => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
    );
}

controller.php
function loginSubmit() {

   $DB_year=$this->input->post('year_select');
    //$this->session->unset_userdata('DB_year');

    //$this->session->set_userdata('DB_year',$DB_year);
    $DB_year="srs_2019";
    putenv("DB_year=$DB_year");
    // $_ENV["DB_year"]="srs_2019";
    print_r(getenv("DB_year"));
    // $DB_year="srs_2019";

    $result = $this->Login_model->authenticateLogin();

    if (!empty($result)) {
        $now = date('Y-m-d H:i:s');
        $ip = $this->input->ip_address();
        $data = array(
            'u_id' => $this->session->userdata('u_id'),
            'u_name' => $this->session->userdata('u_name'),
            'center_name' => $this->session->userdata('u_branch'),
            'last_login_ip' => $this->input->ip_address('ip'),
            'last_login_date_time' => $now
        );
        $name = $this->session->userdata('DB_year');
        print_r($name);
        $this->Login_model->last_login($data);
        redirect('Admin/dashboard');
    } else {

        redirect('Login?login=invalid');
    }

}


问:
Karma1.7 + AngularJS1.8.2 using $compile method causes unconfigurable property error
Recently updated angularjs app from 1.5.11 to 1.8.2

This broke several of our unit tests. All seem to be throwing the error:

```<code> TypeError: Attempting to configurable attribute of unconfigurable property.
</code>```

After some debugging, this happens whenever one of our directive specs calls $compile()

Here's a copy of one of the calls a directive spec makes:

```<code>    element = angular.element('<input id="labels" type="hidden" ui-select2="select2Options" ng-model="labels">');
    compiled = $compile(element)(scope);
    $(document.body).append(element);
    element.scope().$apply();
</code>```

I've looked through the documentation and the only reference I found relating to a change in $compile has to do with the removal of the preAssignBindingsEnabled function. It looks like before 1.6, this was on by default. In 1.6 it was turned off by default, but supported if you explicitly set the flag. Starting in 1.7, you were no longer able to set the flag.

I am unsure if this is the cause of my issue, but reading through the documentation, I'm not sure that this change is actually relevant?
The code compiles and works as expected, it's just the test that complains. Any help is greatly appreciated!

答:
This is a quick work around, but might help for determining the final solution:

To work around this problem we downgraded angular-mocks-1.8.2.js to angular-mocks-1.6.4.js, as it appears something in our unit testing chain appears to be using the compileProvider.preAssignBindingsEnabled() method.

We also upgraded Jasmin/Karma to the latest version, but not sure if this is really part of the solution.

Body:
Recently updated angularjs app from 1.5.11 to 1.8.2

This broke several of our unit tests. All seem to be throwing the error:

 TypeError: Attempting to configurable attribute of unconfigurable property.

After some debugging, this happens whenever one of our directive specs calls $compile()

Here's a copy of one of the calls a directive spec makes:

    element = angular.element('<input id="labels" type="hidden" ui-select2="select2Options" ng-model="labels">');
    compiled = $compile(element)(scope);
    $(document.body).append(element);
    element.scope().$apply();

I've looked through the documentation and the only reference I found relating to a change in $compile has to do with the removal of the preAssignBindingsEnabled function. It looks like before 1.6, this was on by default. In 1.6 it was turned off by default, but supported if you explicitly set the flag. Starting in 1.7, you were no longer able to set the flag.

I am unsure if this is the cause of my issue, but reading through the documentation, I'm not sure that this change is actually relevant?
The code compiles and works as expected, it's just the test that complains. Any help is greatly appreciated!


问:
Bad Boy Did Not Backup And Deleted a Column, How to Restore
I have a database with 5 columns plus an Unique Key id. The columns are id (PRIMARY KEY), customer_id. state (ENUM of all 50 US states), type (ENUM of various healthcare practitioner license types), number (varchar(18) license number that is associated with the type), and expires (date for future use).

I accidentally deleted the number field for ONLY one type ( APRN, all other entries in the number column are intact). I last updated a wek ago and so if I can get the number fields from the type APRN back into the live database, I will save myself a great hassle of having to manually enter 5,500 number one at a time.

Statistics from phpMyAdmin are as follows:

Row statistics Format   dynamic
Collation   utf8_general_ci
Rows    124,470
Row length  21 B
Row size    37 B
Next autoindex  135,635
Creation    Feb 08, 2022 at 09:42 AM
Last update     Feb 08, 2022 at 09:42 AM
Last check  Feb 08, 2022 at 09:50 AM

There would only be 8 total loss APRN number fields and I can reconstruct them manually looking them up on the Florida licensing website.

I CAN update every number field for EVERY type, but not sure how to get the backed up licenses table into the live database to run the UPDATE query on it for on type APRN or all types.

Any help would be most appreciated. Easiest and quickest is preferred.

答:
Load the data from the website into a new table (you can use LOAD DATA INFILE to load from a CSV file into a table). Then merge the missing information into your table:

```<code>UPDATE yourTable AS t1
JOIN websiteTable AS t2 ON t1.id = t2.id
SET t1.number = t2.number
WHERE t1.type = 'APRN'
</code>```

Make sure you make a backup before doing this.

Body:
Load the data from the website into a new table (you can use LOAD DATA INFILE to load from a CSV file into a table). Then merge the missing information into your table:

UPDATE yourTable AS t1
JOIN websiteTable AS t2 ON t1.id = t2.id
SET t1.number = t2.number
WHERE t1.type = 'APRN'

Make sure you make a backup before doing this.


问:
Making a Grid pixel editor in iPad
I need to make a pixel editor in iPad similar like Microsoft Paint when displaying per pixel of the image, would like some advise on approach :

Should I make a series of UIButtons stacked in grid fashion in a UIScrollView? (sounds pretty resourceful and laggy), tapping the uibutton will toggle state to display the pixel.

Should I draw line grids using coregraphic and detect taps using gesturerecognizer (I like this, but need some code samples).

Or should I look into using UITableView and making use of reusable cells for the editor? (This seems like how apple would advise).

Hope to get some interesting responses!

答: I think using GridView will be more efficient, ref : DTGridView</p>

Title: Making a Grid pixel editor in iPad


问:
subscriber.next() is not firing after subscriber.error statement
Based on the input data I want to decide whether it is valid data or not and send the observable to the to end.

I have tried to create a observable and sequential subscribe.next() is working correctly but any error is coming then after that no statement is working.

```<code>const observable = new Observable((subscriber) => {
  subscriber.next(1);
  subscriber.next(2);
  subscriber.error('failed this after second');
  subscriber.next(3);
  subscriber.next(4);
  subscriber.complete();
});

observable.subscribe({
  next(x) {
    console.log('got value ' + x);
  },
  error(err) {
    console.error('something wrong occurred: ' + err);
  },
  complete() {
    console.log('done');
  },
});
</code>```

Current output:

got value 1

got value 2

something wrong occurred: failed this after second

Expected output

got value 1

got value 2

something wrong occurred: failed this after second

got value 3

got value 4

done

Here is the stackblitz link
https://stackblitz.com/edit/zlksm5?devtoolsheight=50&file=index.ts

答:
I don't think it's possible with an Observable, cause the observable will be closed if any error occurred.

I have tried couple of ways, putting it for reference

```<code>//interval(1000)
observable
  //.pipe(switchMap(() => observable))
  .pipe(
    catchError((d) => {
      observable.subscribe((nd) => {
        console.log('--again--', nd);
      });
      return of(d);
    })
    //retry(1)
  )
  .subscribe({
    next(x) {
      console.log('got value ' + x);
    },
    error(err) {
      console.error('something wrong occurred: ' + err);
    },
    complete() {
      console.log('done');
    },
  });

// interval(1000)
//   .pipe(switchMap(_ => observable))
//   .pipe(
//     catchError((d) => {return of(d)}),
//     switchMap(_ => observable)
//   )
// .subscribe(d => {
//   console.log(d)
// })
</code>```

For your use case it's better to use a behavior subject instead.

Body:
Based on the input data I want to decide whether it is valid data or not and send the observable to the to end.

I have tried to create a observable and sequential subscribe.next() is working correctly but any error is coming then after that no statement is working.

const observable = new Observable((subscriber) => {
  subscriber.next(1);
  subscriber.next(2);
  subscriber.error('failed this after second');
  subscriber.next(3);
  subscriber.next(4);
  subscriber.complete();
});

observable.subscribe({
  next(x) {
    console.log('got value ' + x);
  },
  error(err) {
    console.error('something wrong occurred: ' + err);
  },
  complete() {
    console.log('done');
  },
});

Current output:

got value 1

got value 2

something wrong occurred: failed this after second

Expected output

got value 1

got value 2

something wrong occurred: failed this after second

got value 3

got value 4

done

Here is the stackblitz link
https://stackblitz.com/edit/zlksm5?devtoolsheight=50&file=index.ts

Body:
I don't think it's possible with an Observable, cause the observable will be closed if any error occurred.

I have tried couple of ways, putting it for reference

//interval(1000)
observable
  //.pipe(switchMap(() => observable))
  .pipe(
    catchError((d) => {
      observable.subscribe((nd) => {
        console.log('--again--', nd);
      });
      return of(d);
    })
    //retry(1)
  )
  .subscribe({
    next(x) {
      console.log('got value ' + x);
    },
    error(err) {
      console.error('something wrong occurred: ' + err);
    },
    complete() {
      console.log('done');
    },
  });

// interval(1000)
//   .pipe(switchMap(_ => observable))
//   .pipe(
//     catchError((d) => {return of(d)}),
//     switchMap(_ => observable)
//   )
// .subscribe(d => {
//   console.log(d)
// })

For your use case it's better to use a behavior subject instead.


问:
How to group columns and sum them, in a large CSV?
I have a large CSV (hundreds of millions of rows) and I need to sum the Value column based on the grouping of the ID, Location, and Date columns.

My CSV is similar to:

    ID Location        Date  Value
 1   1     Loc1  2022-01-27      5
 2   1     Loc1  2022-01-27      4
 3   1     Loc1  2022-01-28      7
 4   1     Loc2  2022-01-29      8
 5   2     Loc1  2022-01-27     11
 6   2     Loc2  2022-01-28      4
 7   2     Loc2  2022-01-29      6
 8   3     Loc1  2022-01-28      9
 9   3     Loc1  2022-01-28      9
10   3     Loc2  2022-01-29      1
```
<ul>
<li><code>{ID: 1, Location: Loc1, Date: 2022-01-27}</code> is one such group, and its sub values <code>5</code> and <code>4</code> should be summed to <code>9</code></li>
<li><code>{ID: 3, Location: Loc1, Date: 2022-01-28}</code> is another group and its sum should be <code>18</code></li>
</ul>
<p>Here's what that sample input should look like, processed/summed, and written to a new CSV:</p>
<pre class="lang-none prettyprint-override"><code>ID Location        Date  Value
1     Loc1  2022-01-27      9
1     Loc1  2022-01-28      7
1     Loc2  2022-01-29      8
2     Loc1  2022-01-27     11
2     Loc2  2022-01-28      4
2     Loc2  2022-01-29      6
3     Loc1  2022-01-28     18
3     Loc2  2022-01-29      1
</code>```

I know using df.groupby([columns]).sum() would give the desired result, but the CSV is so big I keep getting memory errors. I've tried looking at other ways to read/manipulate CSV data but have still not been successful, so if anyone knows a way I can do this in python without maxing out my memory that would be great!

NB: I know there is a unnamed first column in my initial csv, this is irrelevant and doesn't need to be in the outputted, but doesn't matter if it is :)

答:
There are a number of answers already that may suffice: @MartinEvans and @Corralien both recommend breaking-up/chunking the input-output.
I'm especially curious if @MartinEvans's answer works within your memory constraints: it's the simplest and still-correct solution so far (as I see it).

If either of those don't work, I think you'll be faced with the question:

What makes a chunk with all the ID/Loc/Date groups I need to count contained in that chunk, so no group crosses over a chunk and gets counted multiple times (end up with smaller sub sums, instead of a single and true sum)?

In a comment on the OP you said the input was sorted by "week number".  I think this is the single deciding factor for when you have all the counts you'll get for a group of ID/Loc/Date.  As the readers crosses week-group boundaries, it'll know it's "safe" to stop counting any of the groups encountered so far, and flush those counts to disk (to avoid holding on to too many counts in memory).

This solution relies on the pre-sorted-ness of your input CSV.  Though, if your input was a bit out of sorts: you could run this, test for duplicate groups, re-sort, and re-run this (I see this problem as making a big, memory-constrained reducer):

import csv
from collections import Counter
from datetime import datetime

# Get the data out...
out_csv = open('output.csv', 'w', newline='')
writer = csv.writer(out_csv)

def write_row(row):
    global writer
    writer.writerow(row)

# Don't let counter get too big (for memory)
def flush_counter(counter):
    for key, sum_ in counter.items():
        id_, loc, date = key
        write_row([id_, loc, date, sum_])

# You said "already grouped by week-number", so:
# -   read and sum your input CSV in chunks of "week (number) groups"
# -   once the reader reads past a week-group, it concludes week-group is finished
#     and flushes the counts for that week-group

last_wk_group = None
counter = Counter()

# Open input
with open('input.csv', newline='') as f:
    reader = csv.reader(f)

    # Copy header
    header = next(reader)
    write_row(header)

    for row in reader:
        # Get "base" values
        id_, loc, date = row[0:3]
        value = int(row[3])

        # 2022-01-27  ->  2022-04
        wk_group = datetime.strptime(date, r'%Y-%m-%d').strftime(r'%Y-%U')

        # Decide if last week-group has passed
        if wk_group != last_wk_group:
            flush_counter(counter)
            counter = Counter()
            last_wk_group = wk_group

        # Count/sum this week-groups
        key = tuple([id_, loc, date_])
        counter[key] += value

# Flush remaining week-group counts
flush_counter(counter)
```
<p>As a basic test, I moved the first row of your sample input to the last row, like @Corralien was asking:</p>
<pre class="lang-none prettyprint-override"><code>ID,Location,Date,Value
1,Loc1,2022-01-27,5
1,Loc1,2022-01-28,7
1,Loc2,2022-01-29,8
2,Loc1,2022-01-27,11
2,Loc2,2022-01-28,4
2,Loc2,2022-01-29,6
3,Loc1,2022-01-28,9
3,Loc1,2022-01-28,9
3,Loc2,2022-01-29,1
1,Loc1,2022-01-27,4
</code>```

and I still get the correct output (even in the correct order, because 1,Loc1,2022-01-27 appeared first in the input):

ID,Location,Date,Value
1,Loc1,2022-01-27,9
1,Loc1,2022-01-28,7
1,Loc2,2022-01-29,8
2,Loc1,2022-01-27,11
2,Loc2,2022-01-28,4
2,Loc2,2022-01-29,6
3,Loc1,2022-01-28,18
3,Loc2,2022-01-29,1
```

Body:
I have a large CSV (hundreds of millions of rows) and I need to sum the Value column based on the grouping of the ID, Location, and Date columns.

My CSV is similar to:

    ID Location        Date  Value
 1   1     Loc1  2022-01-27      5
 2   1     Loc1  2022-01-27      4
 3   1     Loc1  2022-01-28      7
 4   1     Loc2  2022-01-29      8
 5   2     Loc1  2022-01-27     11
 6   2     Loc2  2022-01-28      4
 7   2     Loc2  2022-01-29      6
 8   3     Loc1  2022-01-28      9
 9   3     Loc1  2022-01-28      9
10   3     Loc2  2022-01-29      1

{ID: 1, Location: Loc1, Date: 2022-01-27} is one such group, and its sub values 5 and 4 should be summed to 9

{ID: 3, Location: Loc1, Date: 2022-01-28} is another group and its sum should be 18

Here's what that sample input should look like, processed/summed, and written to a new CSV:

ID Location        Date  Value
1     Loc1  2022-01-27      9
1     Loc1  2022-01-28      7
1     Loc2  2022-01-29      8
2     Loc1  2022-01-27     11
2     Loc2  2022-01-28      4
2     Loc2  2022-01-29      6
3     Loc1  2022-01-28     18
3     Loc2  2022-01-29      1

I know using df.groupby([columns]).sum() would give the desired result, but the CSV is so big I keep getting memory errors. I've tried looking at other ways to read/manipulate CSV data but have still not been successful, so if anyone knows a way I can do this in python without maxing out my memory that would be great!

NB: I know there is a unnamed first column in my initial csv, this is irrelevant and doesn't need to be in the outputted, but doesn't matter if it is :)

Body:
There are a number of answers already that may suffice: @MartinEvans and @Corralien both recommend breaking-up/chunking the input-output.
I'm especially curious if @MartinEvans's answer works within your memory constraints: it's the simplest and still-correct solution so far (as I see it).

If either of those don't work, I think you'll be faced with the question:

What makes a chunk with all the ID/Loc/Date groups I need to count contained in that chunk, so no group crosses over a chunk and gets counted multiple times (end up with smaller sub sums, instead of a single and true sum)?

In a comment on the OP you said the input was sorted by "week number".  I think this is the single deciding factor for when you have all the counts you'll get for a group of ID/Loc/Date.  As the readers crosses week-group boundaries, it'll know it's "safe" to stop counting any of the groups encountered so far, and flush those counts to disk (to avoid holding on to too many counts in memory).

This solution relies on the pre-sorted-ness of your input CSV.  Though, if your input was a bit out of sorts: you could run this, test for duplicate groups, re-sort, and re-run this (I see this problem as making a big, memory-constrained reducer):

import csv
from collections import Counter
from datetime import datetime

# Get the data out...
out_csv = open('output.csv', 'w', newline='')
writer = csv.writer(out_csv)

def write_row(row):
    global writer
    writer.writerow(row)

# Don't let counter get too big (for memory)
def flush_counter(counter):
    for key, sum_ in counter.items():
        id_, loc, date = key
        write_row([id_, loc, date, sum_])

# You said "already grouped by week-number", so:
# -   read and sum your input CSV in chunks of "week (number) groups"
# -   once the reader reads past a week-group, it concludes week-group is finished
#     and flushes the counts for that week-group

last_wk_group = None
counter = Counter()

# Open input
with open('input.csv', newline='') as f:
    reader = csv.reader(f)

    # Copy header
    header = next(reader)
    write_row(header)

    for row in reader:
        # Get "base" values
        id_, loc, date = row[0:3]
        value = int(row[3])

        # 2022-01-27  ->  2022-04
        wk_group = datetime.strptime(date, r'%Y-%m-%d').strftime(r'%Y-%U')

        # Decide if last week-group has passed
        if wk_group != last_wk_group:
            flush_counter(counter)
            counter = Counter()
            last_wk_group = wk_group

        # Count/sum this week-groups
        key = tuple([id_, loc, date_])
        counter[key] += value

# Flush remaining week-group counts
flush_counter(counter)

As a basic test, I moved the first row of your sample input to the last row, like @Corralien was asking:

ID,Location,Date,Value
1,Loc1,2022-01-27,5
1,Loc1,2022-01-28,7
1,Loc2,2022-01-29,8
2,Loc1,2022-01-27,11
2,Loc2,2022-01-28,4
2,Loc2,2022-01-29,6
3,Loc1,2022-01-28,9
3,Loc1,2022-01-28,9
3,Loc2,2022-01-29,1
1,Loc1,2022-01-27,4

and I still get the correct output (even in the correct order, because 1,Loc1,2022-01-27 appeared first in the input):

ID,Location,Date,Value
1,Loc1,2022-01-27,9
1,Loc1,2022-01-28,7
1,Loc2,2022-01-29,8
2,Loc1,2022-01-27,11
2,Loc2,2022-01-28,4
2,Loc2,2022-01-29,6
3,Loc1,2022-01-28,18
3,Loc2,2022-01-29,1


问:
How to deploy weblogic application as docker container completely using Dockerfile?
I've a simple REST API in the weblogic application. I've to deploy the application as the docker container. But, I'm facing a problem in defining the Dockerfile.

Dockerfile

```<code>FROM store/oracle/weblogic:12.2.1.4
COPY target/app.war /u01/oracle
</code>```

Above is my current Dockerfile. With the current dockerfile, I have to manually deploy the application on the weblogic server. We would like to automate the application deployment using Dockerfile and didn't get the exact examples.

Please advise.

答:
This is a complex task, so it is hard to explain the whole process here.

The high-level steps that you need to execute are the followings:

Start a properly configured WebLogic domain in Docker. This task involves the creation of the admin and managed servers and WL cluster, etc.

Build the application that you wanna deploy

Configure the database properly if you have any

Create the WL resources like connection pool, JMS, etc manually or via WLST script

Deploy your artifact via the WL web console or with WLST script or copy the file under the autodeploy directory

Be careful because the tasks that you executed manually will be lost if you drop your docker container.

You can find concrete examples, use cases, automated scripts that you can use and well prepared, ready for use WebLogic Docker images here: https://github.com/zappee/docker-images

If you have a concrete question, not a general one, like this, then please start a new thread.

Body:
I've a simple REST API in the weblogic application. I've to deploy the application as the docker container. But, I'm facing a problem in defining the Dockerfile.

Dockerfile

FROM store/oracle/weblogic:12.2.1.4
COPY target/app.war /u01/oracle

Above is my current Dockerfile. With the current dockerfile, I have to manually deploy the application on the weblogic server. We would like to automate the application deployment using Dockerfile and didn't get the exact examples.

Please advise.