Explore all Learning open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Learning

leetcode

新书出版

wtfjs

v1.22.1

intro.js

v5.1.0

algorithms

v0.1.4

LeetCode-Go

1.7.0

Popular Libraries in Learning

freeCodeCamp

by freeCodeCamp doticonjavascriptdoticon

star image 344419 doticonBSD-3-Clause

freeCodeCamp.org's open-source codebase and curriculum. Learn to code for free.

javascript-algorithms

by trekhleb doticonjavascriptdoticon

star image 138596 doticonMIT

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

CS-Notes

by CyC2018 doticonjavadoticon

star image 137910 doticon

:books: 技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计

Python

by TheAlgorithms doticonpythondoticon

star image 117097 doticonMIT

All Algorithms implemented in Python

interviews

by kdn251 doticonjavadoticon

star image 53816 doticonMIT

Everything you need to know to get the job.

resume.github.com

by resume doticonjavascriptdoticon

star image 49535 doticon

Resumes generated using the GitHub informations

Java

by TheAlgorithms doticonjavadoticon

star image 45287 doticonMIT

All Algorithms implemented in Java

Web-Dev-For-Beginners

by microsoft doticonjavascriptdoticon

star image 44908 doticonMIT

24 Lessons, 12 Weeks, Get Started as a Web Developer

leetcode

by azl397985856 doticonjavascriptdoticon

star image 43986 doticonNOASSERTION

LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)

Trending New libraries in Learning

Web-Dev-For-Beginners

by microsoft doticonjavascriptdoticon

star image 44908 doticonMIT

24 Lessons, 12 Weeks, Get Started as a Web Developer

hello-algorithm

by geekxh doticonjavadoticon

star image 29811 doticon

🌍 针对小白的算法训练 | 包括四部分:①.算法基础 ②.力扣图解 ③.大厂面经 ④.CS_汇总 | 附:1、千本开源电子书 2、百张技术思维导图(项目花了上百小时,希望可以点 star 支持,🌹感谢~)

algorithm-pattern

by greyireland doticongodoticon

star image 12016 doticon

算法模板,最科学的刷题方式,最快速的刷题路径,你值得拥有~

algorithm-base

by chefyuan doticonjavadoticon

star image 8824 doticonMIT

专门为刚开始刷题的同学准备的算法基地,没有最细只有更细,立志用动画将晦涩难懂的算法说的通俗易懂!

basic-computer-games

by coding-horror doticoncsharpdoticon

star image 8118 doticonUnlicense

An updated version of the classic "Basic Computer Games" book, with well-written examples in a variety of common MEMORY SAFE, SCRIPTING programming languages. See https://coding-horror.github.io/basic-computer-games/

The-Complete-FAANG-Preparation

by AkashSingh3031 doticonjupyter notebookdoticon

star image 7378 doticonMIT

This repository contains all the DSA (Data-Structures, Algorithms, 450 DSA by Love Babbar Bhaiya, FAANG Questions), Technical Subjects (OS + DBMS + SQL + CN + OOPs) Theory+Questions, FAANG Interview questions, and Miscellaneous Stuff (Programming MCQs, Puzzles, Aptitude, Reasoning). The Programming languages used for demonstration are C++, Python, and Java.

easy_rust

by Dhghomon doticonshelldoticon

star image 6065 doticonMIT

Rust explained using easy English

LeetCode

by yuanguangxin doticonjavadoticon

star image 5890 doticon

LeetCode刷题记录与面试整理

content

by mdn doticonhtmldoticon

star image 4840 doticonNOASSERTION

The content behind MDN Web Docs

Top Authors in Learning

1

PacktPublishing

126 Libraries

star icon4879

2

SAP-samples

90 Libraries

star icon1933

3

apachecn

54 Libraries

star icon23695

4

microsoft

48 Libraries

star icon67554

5

tutsplus

35 Libraries

star icon463

6

googlearchive

35 Libraries

star icon2030

7

udacity

33 Libraries

star icon12103

8

raywenderlich

33 Libraries

star icon25961

9

SAP-archive

30 Libraries

star icon594

10

aws-samples

29 Libraries

star icon4333

1

126 Libraries

star icon4879

2

90 Libraries

star icon1933

3

54 Libraries

star icon23695

4

48 Libraries

star icon67554

5

35 Libraries

star icon463

6

35 Libraries

star icon2030

7

33 Libraries

star icon12103

8

33 Libraries

star icon25961

9

30 Libraries

star icon594

10

29 Libraries

star icon4333

Trending Kits in Learning

JavaScript libraries are collections of pre-written code that can be used to create web applications. They provide functions, features, and resources.


It makes the development process faster and easier They often create dynamic, interactive experiences on websites and applications. JavaScript libraries are used for various tasks, such as DOM manipulation, AJAX requests, data analysis and visualization, client-side storage, and more. It includes Creating Interactive Tours, Enhancing Customer Experience, Creating Interactive Tutorials, and Improving User Onboarding.  


Let us look at some of these famous libraries. 

webpack

  • Offers advanced features such as code-splitting, hot module replacement (HMR), tree-shaking, and dynamic loading.
  • Provides plugins and loaders that can be used to customize how code is transformed and bundled.
  • Allows to combine multiple modules into a single bundle.

mocha

  • Provides an asynchronous testing interface.
  • Supports a wide variety of testing styles with its flexible syntax.
  • Allows developers to create custom test interfaces and reporters.

intro.js

  • Supports auto-scroll and scroll-hijacking.
  • Allows developers to create custom tours in any language.
  • Provides a modern and lightweight interface, with a minimalistic design.

bower

  • Supports versioning and resolution of dependencies. 
  • Provides command line interface making it easy to instantly search, install, and manage packages in a project. 
  • Allows to manage both front-end and back-end packages. 

grunt

  • Provides wide range of plugins and third-party integrations.
  • Provides built-in support for popular frameworks and libraries.
  • Allows developers to easily configure and create tasks for automating common development workflows.

knockout

  • Provides an easy-to-use two-way data-binding system.
  • Provides a powerful templating system that makes it easy to display complex data structures. 
  • Provides a declarative binding syntax that simplifies linking the data to the HTML elements on the page. 

shepherd

  • Allows developers to create step-by-step product tours and walkthroughs intuitively.
  • Provides options for targeting specific users, including localization and different themes.
  • Supports integration with other libraries and frameworks, such as React and Vue.

mixitup

  • Provides built-in support for powerful animation effects.
  • Allows developers to create custom sorting and filtering rules.
  • Supports integration with external API's, allowing pulling in data from other sources. 

hopscotch

  • Is highly accessible, i.e., it is easy for people with disabilities to use.
  • Offers comprehensive documentation, making it easy for developers to get up and running quickly.
  • Is device-agnostic, meaning it works across different devices and browsers.

joyride

  • Provides a built-in feature called “Progress Indicator,” which allows the user to see their progress through the tour.  
  • A built-in analytics system provides valuable insights into how users interact with the tour. 
  • Allows developers to easily add triggers and custom CSS to enhance the user experience. 

class Question:

def __init__(self, prompt, options, correct_option):

self.prompt = prompt

self.options = options

self.correct_option = correct_option


def ask_question(self):

print(self.prompt)

for i, option in enumerate(self.options, 1):

print(f"{i}. {option}")

user_answer = input("Enter the number of your answer: ")

return int(user_answer) == self.correct_option



def run_quiz(questions):

score = 0

for question in questions:

if question.ask_question():

print("Correct!\n")

score += 1

else:

print("Incorrect. The correct answer was option", question.correct_option, "\n")


print("You got", score, "out of", len(questions), "questions correct.")



# Define your questions here

question1 = Question("What is the capital of France?", ["Paris", "Rome", "Berlin", "Madrid"], 1)

question2 = Question("What is the largest planet in our solar system?", ["Jupiter", "Mars", "Venus", "Saturn"], 1)

question3 = Question("What is 2 + 2?", ["3", "4", "5", "6"], 2)


# Add more questions if desired


questions = [question1, question2, question3]


# Run the quiz

run_quiz(questions)


Trending Discussions on Learning

How do purely functional languages handle index-based algorithms?

How can I fix this : Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif"

Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

How do I fix CLIENT_MISSING_INTENTS error?

Getting error 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'

Vue 3 passing array warning: Extraneous non-props attributes were passed to component but could not be automatically inherited

TypeError: match.loader.options.plugins is not a function

Group and create three new columns by condition [Low, Hit, High]

What should the result be when assigning a variable to a reference to itself, in-between modified and then returned by a function call?

Flutter (2.5) - A splash screen was provided to Flutter, but this is deprecated

QUESTION

How do purely functional languages handle index-based algorithms?

Asked 2022-Apr-05 at 12:51

I have been trying to learn about functional programming, but I still struggle with thinking like a functional programmer. One such hangup is how one would implement index-heavy operations which rely strongly on loops/order-of-execution.

For example, consider the following Java code:

1public class Main {
2    public static void main(String[] args) {
3        List<Integer> nums = Arrays.asList(1,2,3,4,5,6,7,8,9);
4        System.out.println("Nums:\t"+ nums);
5        System.out.println("Prefix:\t"+prefixList(nums));
6    }
7  
8    private static List<Integer> prefixList(List<Integer> nums){
9      List<Integer> prefix = new ArrayList<>(nums);
10      for(int i = 1; i < prefix.size(); ++i)
11        prefix.set(i, prefix.get(i) + prefix.get(i-1));
12      return prefix;
13    }
14}
15/*
16System.out: 
17Nums:   [1, 2, 3, 4, 5, 6, 7, 8, 9]
18Prefix: [1, 3, 6, 10, 15, 21, 28, 36, 45]
19*/
20

Here, in the prefixList function, the nums list is first cloned, but then there is the iterative operation performed on it, where the value on index i relies on index i-1 (i.e. order of execution is required). Then this value is returned.

What would this look like in a functional language (Haskell, Lisp, etc.)? I have been learning about monads and think they may be relevant here, but my understanding is still not great.

ANSWER

Answered 2022-Mar-07 at 21:17

This is not an index-heavy operation, in fact you can do this with a one-liner with scanl1 :: (a -> a -> a) -> [a] -> [a]:

1public class Main {
2    public static void main(String[] args) {
3        List<Integer> nums = Arrays.asList(1,2,3,4,5,6,7,8,9);
4        System.out.println("Nums:\t"+ nums);
5        System.out.println("Prefix:\t"+prefixList(nums));
6    }
7  
8    private static List<Integer> prefixList(List<Integer> nums){
9      List<Integer> prefix = new ArrayList<>(nums);
10      for(int i = 1; i < prefix.size(); ++i)
11        prefix.set(i, prefix.get(i) + prefix.get(i-1));
12      return prefix;
13    }
14}
15/*
16System.out: 
17Nums:   [1, 2, 3, 4, 5, 6, 7, 8, 9]
18Prefix: [1, 3, 6, 10, 15, 21, 28, 36, 45]
19*/
20prefixList = scanl1 (+)
21

indeed, for the list of Nums, we get:

1public class Main {
2    public static void main(String[] args) {
3        List<Integer> nums = Arrays.asList(1,2,3,4,5,6,7,8,9);
4        System.out.println("Nums:\t"+ nums);
5        System.out.println("Prefix:\t"+prefixList(nums));
6    }
7  
8    private static List<Integer> prefixList(List<Integer> nums){
9      List<Integer> prefix = new ArrayList<>(nums);
10      for(int i = 1; i < prefix.size(); ++i)
11        prefix.set(i, prefix.get(i) + prefix.get(i-1));
12      return prefix;
13    }
14}
15/*
16System.out: 
17Nums:   [1, 2, 3, 4, 5, 6, 7, 8, 9]
18Prefix: [1, 3, 6, 10, 15, 21, 28, 36, 45]
19*/
20prefixList = scanl1 (+)
21Prelude> prefixList [1 .. 9]
22[1,3,6,10,15,21,28,36,45]
23

scanl1 takes the first item of the original list as initial value for the accumulator, and yields that. Then each time it takes the accumulator and the next item of the given list, and sums these up as new accumulator, and yields the new accumulator value.

Often one does not need indexing, but enumerating over the list is sufficient. Imperative programming languages often work with for loops with indexes, but in many cases these can be replaced by foreach loops that thus do not take the index into account. In Haskell this also often helps to make algorithms more lazy.

If you really need random access lookups, you can work with data structures such as defined in the array and vector packages.

Source https://stackoverflow.com/questions/71387267

QUESTION

How can I fix this : Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif"

Asked 2022-Mar-27 at 13:54

system:Mac OS software:AnyLogic 8 Personal Learning Edition 8.7.6 language: Java

When I run my model, the console print this info:

Warning: the fonts "Times" and "Times" are not available for the Java logical font "Serif", which may have unexpected appearance or behavior. Re-enable the "Times" font to remove this warning.

ANSWER

Answered 2021-Aug-01 at 11:11

We also recently had this issue on a mac running the latest public beta of Monterey.

For some reason the Times font was no longer installed or active on the Mac.

You can check in FontBook

enter image description here

You can simply reinstall it

I struggled to find a source online - her is one suggestion - https://www.freebestfonts.com/timr45w-font

Source https://stackoverflow.com/questions/68608157

QUESTION

Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

Asked 2022-Mar-23 at 04:30

Im attempting to find model performance metrics (F1 score, accuracy, recall) following this guide https://machinelearningmastery.com/how-to-calculate-precision-recall-f1-and-more-for-deep-learning-models/

This exact code was working a few months ago but now returning all sorts of errors, very confusing since i havent changed one character of this code. Maybe a package update has changed things?

I fit the sequential model with model.fit, then used model.evaluate to find test accuracy. Now i am attempting to use model.predict_classes to make class predictions (model is a multi-class classifier). Code shown below:

1model = Sequential()
2model.add(Dense(24, input_dim=13, activation='relu'))
3model.add(Dense(18, activation='relu'))
4model.add(Dense(6, activation='softmax'))
5model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
6
7-
8
9history = model.fit(X_train, y_train, batch_size = 256, epochs = 10, verbose = 2, validation_split = 0.2)
10
11-
12
13score, acc = model.evaluate(X_test, y_test,verbose=2, batch_size= 256)
14print('test accuracy:', acc)
15
16-
17
18yhat_classes = model.predict_classes(X_test)
19 
20

last line returns error "AttributeError: 'Sequential' object has no attribute 'predict_classes'"

This exact code was working not long ago so struggling a bit, thanks for any help

ANSWER

Answered 2021-Aug-19 at 03:49

This function were removed in TensorFlow version 2.6. According to the keras in rstudio reference

update to

1model = Sequential()
2model.add(Dense(24, input_dim=13, activation='relu'))
3model.add(Dense(18, activation='relu'))
4model.add(Dense(6, activation='softmax'))
5model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
6
7-
8
9history = model.fit(X_train, y_train, batch_size = 256, epochs = 10, verbose = 2, validation_split = 0.2)
10
11-
12
13score, acc = model.evaluate(X_test, y_test,verbose=2, batch_size= 256)
14print('test accuracy:', acc)
15
16-
17
18yhat_classes = model.predict_classes(X_test)
19 
20predict_x=model.predict(X_test) 
21classes_x=np.argmax(predict_x,axis=1)
22

Or use TensorFlow 2.5 or later.

If you are using TensorFlow version 2.5, you will receive the following warning:

tensorflow\python\keras\engine\sequential.py:455: UserWarning: model.predict_classes() is deprecated and will be removed after 2021-01-01. Please use instead:* np.argmax(model.predict(x), axis=-1), if your model does multi-class classification (e.g. if it uses a softmax last-layer activation).* (model.predict(x) > 0.5).astype("int32"), if your model does binary classification (e.g. if it uses a sigmoid last-layer activation).

Source https://stackoverflow.com/questions/68836551

QUESTION

How do I fix CLIENT_MISSING_INTENTS error?

Asked 2022-Mar-11 at 10:51

I started learning about discord.js but now I am facing this issue. I tried some googling but couldn't manage to fix it.

1const Discord = require('discord.js');
2// const Discord = require('discord.js');
3
4// using Intents class
5const client = new Discord.Client();
6
7client.on('message', (msg) => {
8  // Send back a reply when the specific command has been written by a user.
9  if (msg.content === '!hello') {
10    msg.reply('Hello World!');
11  }
12});
13
14client.login('my_token');
15
16

This is the error I am getting:

enter image description here

ANSWER

Answered 2021-Aug-07 at 16:34

You need to specify the events which you want your bot to receive using gateway intents.

Instead of

const client = new Discord.Client();

Use

const client = new Discord.Client({ intents: [Enter intents here] })

For example

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })

Here's another useful link: https://discord.com/developers/docs/topics/gateway

Source https://stackoverflow.com/questions/68694195

QUESTION

Getting error 'digital envelope routines', reason: 'unsupported', code: 'ERR_OSSL_EVP_UNSUPPORTED'

Asked 2022-Mar-05 at 09:54

I got this error when learning Next.js, using npx create-next-app command according to site documentation here https://nextjs.org/docs/api-reference/create-next-app. Everything works until I start the server,

Error stack:

1$ npm run dev
2
3> devto-clone@0.1.0 dev
4> next dev
5
6ready - started server on 0.0.0.0:3000, url: http://localhost:3000
7info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
8Error: error:0308010C:digital envelope routines::unsupported
9    at new Hash (node:internal/crypto/hash:67:19)
10    at Object.createHash (node:crypto:130:10)
11    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
12    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
13    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
14    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
15    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
16    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
17    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
18    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
19Error: error:0308010C:digital envelope routines::unsupported
20    at new Hash (node:internal/crypto/hash:67:19)
21    at Object.createHash (node:crypto:130:10)
22    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
23    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
24    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
25    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
26    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
27    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
28    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
29    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
30node:internal/crypto/hash:67
31  this[kHandle] = new _Hash(algorithm, xofLen);
32                  ^
33
34Error: error:0308010C:digital envelope routines::unsupported
35    at new Hash (node:internal/crypto/hash:67:19)
36    at Object.createHash (node:crypto:130:10)
37    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
38    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
39    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
40    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
41    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
42    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
43    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
44    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
45  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
46  library: 'digital envelope routines',
47  reason: 'unsupported',
48  code: 'ERR_OSSL_EVP_UNSUPPORTED'
49}
50
51Node.js v17.0.1
52

package.json :

1$ npm run dev
2
3> devto-clone@0.1.0 dev
4> next dev
5
6ready - started server on 0.0.0.0:3000, url: http://localhost:3000
7info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
8Error: error:0308010C:digital envelope routines::unsupported
9    at new Hash (node:internal/crypto/hash:67:19)
10    at Object.createHash (node:crypto:130:10)
11    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
12    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
13    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
14    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
15    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
16    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
17    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
18    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
19Error: error:0308010C:digital envelope routines::unsupported
20    at new Hash (node:internal/crypto/hash:67:19)
21    at Object.createHash (node:crypto:130:10)
22    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
23    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
24    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
25    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
26    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
27    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
28    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
29    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
30node:internal/crypto/hash:67
31  this[kHandle] = new _Hash(algorithm, xofLen);
32                  ^
33
34Error: error:0308010C:digital envelope routines::unsupported
35    at new Hash (node:internal/crypto/hash:67:19)
36    at Object.createHash (node:crypto:130:10)
37    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
38    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
39    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
40    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
41    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
42    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
43    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
44    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
45  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
46  library: 'digital envelope routines',
47  reason: 'unsupported',
48  code: 'ERR_OSSL_EVP_UNSUPPORTED'
49}
50
51Node.js v17.0.1
52{
53  "name": "devto-clone",
54  "version": "0.1.0",
55  "private": true,
56  "scripts": {
57    "dev": "next dev",
58    "build": "next build",
59    "start": "next start",
60    "lint": "next lint"
61  },
62  "dependencies": {
63    "next": "11.1.2",
64    "react": "17.0.2",
65    "react-dom": "17.0.2"
66  },
67  "devDependencies": {
68    "eslint": "7.32.0",
69    "eslint-config-next": "11.1.2"
70  }
71}
72

ANSWER

Answered 2021-Nov-24 at 21:38

I found this solution https://github.com/webpack/webpack/issues/14532

  1. if using bash just run NODE_OPTIONS=--openssl-legacy-provider before any command

  2. adding NODE_OPTIONS=--openssl-legacy-provider to package.json

1$ npm run dev
2
3> devto-clone@0.1.0 dev
4> next dev
5
6ready - started server on 0.0.0.0:3000, url: http://localhost:3000
7info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
8Error: error:0308010C:digital envelope routines::unsupported
9    at new Hash (node:internal/crypto/hash:67:19)
10    at Object.createHash (node:crypto:130:10)
11    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
12    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
13    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
14    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
15    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
16    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
17    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
18    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
19Error: error:0308010C:digital envelope routines::unsupported
20    at new Hash (node:internal/crypto/hash:67:19)
21    at Object.createHash (node:crypto:130:10)
22    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
23    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
24    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
25    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
26    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
27    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
28    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
29    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5
30node:internal/crypto/hash:67
31  this[kHandle] = new _Hash(algorithm, xofLen);
32                  ^
33
34Error: error:0308010C:digital envelope routines::unsupported
35    at new Hash (node:internal/crypto/hash:67:19)
36    at Object.createHash (node:crypto:130:10)
37    at BulkUpdateDecorator.hashFactory (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138971:18)
38    at BulkUpdateDecorator.update (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:138872:50)
39    at OriginalSource.updateHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack-sources3\index.js:1:10264)
40    at NormalModule._initBuildHash (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68468:17)
41    at handleParseResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68534:10)
42    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68628:4
43    at processResult (C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68343:11)
44    at C:\xampp\htdocs\devto-clone\node_modules\next\dist\compiled\webpack\bundle5.js:68407:5 {
45  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
46  library: 'digital envelope routines',
47  reason: 'unsupported',
48  code: 'ERR_OSSL_EVP_UNSUPPORTED'
49}
50
51Node.js v17.0.1
52{
53  "name": "devto-clone",
54  "version": "0.1.0",
55  "private": true,
56  "scripts": {
57    "dev": "next dev",
58    "build": "next build",
59    "start": "next start",
60    "lint": "next lint"
61  },
62  "dependencies": {
63    "next": "11.1.2",
64    "react": "17.0.2",
65    "react-dom": "17.0.2"
66  },
67  "devDependencies": {
68    "eslint": "7.32.0",
69    "eslint-config-next": "11.1.2"
70  }
71}
72"scripts": {
73   "start": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts start",
74   "build": "SET NODE_OPTIONS=--openssl-legacy-provider && react-scripts build"
75 },
76

Edit

In my case, I'm using Nodejs 17.0.1 version and causing this error.

Firstly I'm using this command export NODE_OPTIONS=--openssl-legacy-provider before any command in GitBash Windows to fix this issue.

But, I think it's not an efficient way, so what I do is :

  1. Uninstall Nodejs 17.0.1
  2. Install it again Nodejs 16.13.0 version
  3. I'm facing error another error when I start the server using "yarn serve" (another of my exiting Vuejs project), I don't remember what is this, but after I run "yarn" and "yarn serve", everything works now as I accept

Source https://stackoverflow.com/questions/69719601

QUESTION

Vue 3 passing array warning: Extraneous non-props attributes were passed to component but could not be automatically inherited

Asked 2022-Feb-26 at 21:48

please, I'm learning a VueJS 3 and I have probably begineer problem. I have warn in browser developer console like this one:

enter image description here

The Message is:

1[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
2

I'm passing array of objects to the child Component. In my parent views/Home.vue compoment I have this implemenation:

1[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
2<template>
3  <div class="wrapper">
4    <section v-for="(item, index) in items" :key="index" class="box">
5      <ItemProperties class="infobox-item-properties" :info="item.properties" />
6    </section>
7  </div>
8</template>
9<script>
10import { ref } from 'vue'
11import { data } from '@/data.js'
12import ItemProperties from '@/components/ItemProperties.vue'
13
14export default {
15  components: {
16    ItemDescription,
17  },
18  setup() {
19    const items = ref(data)
20
21    return {
22      items,
23    }
24  },
25</script>
26

In child compoment components/ItemProperties.vue I have this code:

1[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
2<template>
3  <div class="wrapper">
4    <section v-for="(item, index) in items" :key="index" class="box">
5      <ItemProperties class="infobox-item-properties" :info="item.properties" />
6    </section>
7  </div>
8</template>
9<script>
10import { ref } from 'vue'
11import { data } from '@/data.js'
12import ItemProperties from '@/components/ItemProperties.vue'
13
14export default {
15  components: {
16    ItemDescription,
17  },
18  setup() {
19    const items = ref(data)
20
21    return {
22      items,
23    }
24  },
25</script>
26<template>
27  <div class="infobox-item-property" v-for="(object, index) in info" :key="index">
28    <span class="infobox-item-title">{{ object.name }}:</span>
29    <span v-if="object.type === 'rating'">
30      <span v-for="(v, k) in object.value" :key="k">{{ object.icon }}</span>
31    </span>
32    <span v-else>
33      <span>{{ object.value }}</span>
34    </span>
35  </div>
36</template>
37
38<script>
39export default {
40  props: {
41    info: {
42      type: Array,
43      required: false,
44      default: () => [
45        {
46          name: '',
47          value: '',
48          type: 'string',
49          icon: '',
50        },
51      ],
52    },
53  },
54}
55</script>
56

It doesn't matter if I have default() function or not. Also doesn't matter if I have v-if condition or not. If I have cycle in the Array, I got this warning

Data are in data.js file. The part of file is here:

1[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
2<template>
3  <div class="wrapper">
4    <section v-for="(item, index) in items" :key="index" class="box">
5      <ItemProperties class="infobox-item-properties" :info="item.properties" />
6    </section>
7  </div>
8</template>
9<script>
10import { ref } from 'vue'
11import { data } from '@/data.js'
12import ItemProperties from '@/components/ItemProperties.vue'
13
14export default {
15  components: {
16    ItemDescription,
17  },
18  setup() {
19    const items = ref(data)
20
21    return {
22      items,
23    }
24  },
25</script>
26<template>
27  <div class="infobox-item-property" v-for="(object, index) in info" :key="index">
28    <span class="infobox-item-title">{{ object.name }}:</span>
29    <span v-if="object.type === 'rating'">
30      <span v-for="(v, k) in object.value" :key="k">{{ object.icon }}</span>
31    </span>
32    <span v-else>
33      <span>{{ object.value }}</span>
34    </span>
35  </div>
36</template>
37
38<script>
39export default {
40  props: {
41    info: {
42      type: Array,
43      required: false,
44      default: () => [
45        {
46          name: '',
47          value: '',
48          type: 'string',
49          icon: '',
50        },
51      ],
52    },
53  },
54}
55</script>
56export const data = [
57  {
58    title: 'White shirt',
59    properties: [
60      { name: 'Material', value: 'Cotton', type: 'string', icon: '' },
61      { name: 'Size', value: 'M', type: 'string', icon: '' },
62      { name: 'Count', value: 4, type: 'number', icon: '' },
63      { name: 'Absorption', value: 4, type: 'rating', icon: '💧' },
64      { name: 'Rating', value: 2, type: 'rating', icon: '⭐️' },
65      { name: 'Confort', value: 2, type: 'rating', icon: '🛏' },
66      { name: 'Sleeves', value: 'Short', type: 'string', icon: '' },
67      { name: 'Color', value: 'White', type: 'string', icon: '' },
68    ],
69  },
70]
71

PS: Application works but I'm afraid about that warning. What can I do please like right way?

I will be glad for any advice. Thank you very much.

ANSWER

Answered 2021-Aug-16 at 13:32

The ItemProperties component has multiple root nodes because it renders a list in the root with v-for.

Based on the class name (infobox-item-properties), I think you want the class to be applied to a container element, so a simple solution is to just add that element (e.g., a div) in your component at the root:

1[Vue warn]: Extraneous non-props attributes (class) were passed to component but could not be automatically inherited because component renders fragment or text root nodes.
2<template>
3  <div class="wrapper">
4    <section v-for="(item, index) in items" :key="index" class="box">
5      <ItemProperties class="infobox-item-properties" :info="item.properties" />
6    </section>
7  </div>
8</template>
9<script>
10import { ref } from 'vue'
11import { data } from '@/data.js'
12import ItemProperties from '@/components/ItemProperties.vue'
13
14export default {
15  components: {
16    ItemDescription,
17  },
18  setup() {
19    const items = ref(data)
20
21    return {
22      items,
23    }
24  },
25</script>
26<template>
27  <div class="infobox-item-property" v-for="(object, index) in info" :key="index">
28    <span class="infobox-item-title">{{ object.name }}:</span>
29    <span v-if="object.type === 'rating'">
30      <span v-for="(v, k) in object.value" :key="k">{{ object.icon }}</span>
31    </span>
32    <span v-else>
33      <span>{{ object.value }}</span>
34    </span>
35  </div>
36</template>
37
38<script>
39export default {
40  props: {
41    info: {
42      type: Array,
43      required: false,
44      default: () => [
45        {
46          name: '',
47          value: '',
48          type: 'string',
49          icon: '',
50        },
51      ],
52    },
53  },
54}
55</script>
56export const data = [
57  {
58    title: 'White shirt',
59    properties: [
60      { name: 'Material', value: 'Cotton', type: 'string', icon: '' },
61      { name: 'Size', value: 'M', type: 'string', icon: '' },
62      { name: 'Count', value: 4, type: 'number', icon: '' },
63      { name: 'Absorption', value: 4, type: 'rating', icon: '💧' },
64      { name: 'Rating', value: 2, type: 'rating', icon: '⭐️' },
65      { name: 'Confort', value: 2, type: 'rating', icon: '🛏' },
66      { name: 'Sleeves', value: 'Short', type: 'string', icon: '' },
67      { name: 'Color', value: 'White', type: 'string', icon: '' },
68    ],
69  },
70]
71// ItemProperties.vue
72<template>
73  <div>
74    <section v-for="(item, index) in items" :key="index" class="box">
75    ...
76    </section>
77  </div>
78</template>
79

Source https://stackoverflow.com/questions/68803137

QUESTION

TypeError: match.loader.options.plugins is not a function

Asked 2022-Feb-24 at 05:03

I am trying to use tailwindCSS in a ReactJS app

These are the scripts commands in package.json file

1  "scripts": {
2    "start": "craco start",
3    "build": "craco build",
4    "test": "craco test",
5    "eject": "react-scripts eject"
6  }
7

This is my craco.config.js

1  "scripts": {
2    "start": "craco start",
3    "build": "craco build",
4    "test": "craco test",
5    "eject": "react-scripts eject"
6  }
7module.exports = {
8    style: {
9        postcss: {
10            plugins: [
11                require('tailwindcss'),
12                require('autoprefixer'),
13            ],
14        },
15    },
16}
17

When I am used npm run start command, I am facing this error

1  "scripts": {
2    "start": "craco start",
3    "build": "craco build",
4    "test": "craco test",
5    "eject": "react-scripts eject"
6  }
7module.exports = {
8    style: {
9        postcss: {
10            plugins: [
11                require('tailwindcss'),
12                require('autoprefixer'),
13            ],
14        },
15    },
16}
17TypeError: match.loader.options.plugins is not a function
18    at extendsPostcss (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:54:51)
19    at overrideLoader (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:97:9)
20    at C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:118:13
21    at Array.forEach (<anonymous>)
22    at overridePostcss (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:117:17)
23    at overrideStyle (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\style.js:9:25)
24    at mergeWebpackConfig (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\merge-webpack-config.js:77:30)
25    at overrideWebpackDev (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\override.js:11:36)
26    at C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\scripts\start.js:27:5
27

Things that I have tried :

  1. Reinstall node_modules

Got this error, when I tried to do that

1  "scripts": {
2    "start": "craco start",
3    "build": "craco build",
4    "test": "craco test",
5    "eject": "react-scripts eject"
6  }
7module.exports = {
8    style: {
9        postcss: {
10            plugins: [
11                require('tailwindcss'),
12                require('autoprefixer'),
13            ],
14        },
15    },
16}
17TypeError: match.loader.options.plugins is not a function
18    at extendsPostcss (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:54:51)
19    at overrideLoader (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:97:9)
20    at C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:118:13
21    at Array.forEach (<anonymous>)
22    at overridePostcss (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\postcss.js:117:17)
23    at overrideStyle (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\style\style.js:9:25)
24    at mergeWebpackConfig (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\merge-webpack-config.js:77:30)
25    at overrideWebpackDev (C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\lib\features\webpack\override.js:11:36)
26    at C:\Development\Open Source\Learning Hub\react\node_modules\@craco\craco\scripts\start.js:27:5
27$ npm i @craco/craco
28npm ERR! code ERESOLVE
29npm ERR! ERESOLVE unable to resolve dependency tree
30npm ERR!
31npm ERR! While resolving: first-react-app@0.1.0
32npm ERR! Found: react-scripts@5.0.0
33npm ERR! node_modules/react-scripts
34npm ERR!   react-scripts@"5.0.0" from the root project
35npm ERR!
36npm ERR! Could not resolve dependency:
37npm ERR! peer react-scripts@"^4.0.0" from @craco/craco@6.4.3
38npm ERR! node_modules/@craco/craco
39npm ERR!   @craco/craco@"*" from the root project
40npm ERR!
41npm ERR! Fix the upstream dependency conflict, or retry
42npm ERR! this command with --force, or --legacy-peer-deps
43npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
44

ANSWER

Answered 2021-Dec-18 at 22:00

It looks like the Tailwind configuration from CRACO is not needed anymore.

https://github.com/facebook/create-react-app/issues/11771#issuecomment-997217680

Look at Tailwind 3.0 install steps: https://tailwindcss.com/docs/guides/create-react-app

Source https://stackoverflow.com/questions/70403417

QUESTION

Group and create three new columns by condition [Low, Hit, High]

Asked 2022-Feb-10 at 16:22

I have a large dataset (~5 Mio rows) with results from a Machine Learning training. Now I want to check to see if the results hit the "target range" or not. Lets say this range contains all values between -0.25 and +0.25. If it's inside this range, it's a Hit, if it's below Low and on the other side High.

I now would create this three columns Hit, Low, High and calculate for each row which condition applies and put a 1 into this col, the other two would become 0. After that I would group the values and sum them up. But I suspect there must be a better and faster way, such as calculate it directly while grouping. I'm happy for any idea.


Data
1import pandas as pd
2
3df = pd.DataFrame({"Type":["RF", "RF", "RF", "MLP", "MLP", "MLP"], "Value":[-1.5,-0.1,1.7,0.2,-0.7,-0.6]})
4
5+----+--------+---------+
6|    | Type   |   Value |
7|----+--------+---------|
8|  0 | RF     |    -1.5 | <- Low
9|  1 | RF     |    -0.1 | <- Hit
10|  2 | RF     |     1.7 | <- High
11|  3 | MLP    |     0.2 | <- Hit
12|  4 | MLP    |    -0.7 | <- Low
13|  5 | MLP    |    -0.6 | <- Low
14+----+--------+---------+
15

Expected Output
1import pandas as pd
2
3df = pd.DataFrame({"Type":["RF", "RF", "RF", "MLP", "MLP", "MLP"], "Value":[-1.5,-0.1,1.7,0.2,-0.7,-0.6]})
4
5+----+--------+---------+
6|    | Type   |   Value |
7|----+--------+---------|
8|  0 | RF     |    -1.5 | <- Low
9|  1 | RF     |    -0.1 | <- Hit
10|  2 | RF     |     1.7 | <- High
11|  3 | MLP    |     0.2 | <- Hit
12|  4 | MLP    |    -0.7 | <- Low
13|  5 | MLP    |    -0.6 | <- Low
14+----+--------+---------+
15pd.DataFrame({"Type":["RF", "MLP"], "Low":[1,2], "Hit":[1,1], "High":[1,0]})
16
17+----+--------+-------+-------+--------+
18|    | Type   |   Low |   Hit |   High |
19|----+--------+-------+-------+--------|
20|  0 | RF     |     1 |     1 |      1 |
21|  1 | MLP    |     2 |     1 |      0 |
22+----+--------+-------+-------+--------+
23

ANSWER

Answered 2022-Feb-10 at 16:13

You could use cut to define the groups and pivot_table to reshape:

1import pandas as pd
2
3df = pd.DataFrame({"Type":["RF", "RF", "RF", "MLP", "MLP", "MLP"], "Value":[-1.5,-0.1,1.7,0.2,-0.7,-0.6]})
4
5+----+--------+---------+
6|    | Type   |   Value |
7|----+--------+---------|
8|  0 | RF     |    -1.5 | <- Low
9|  1 | RF     |    -0.1 | <- Hit
10|  2 | RF     |     1.7 | <- High
11|  3 | MLP    |     0.2 | <- Hit
12|  4 | MLP    |    -0.7 | <- Low
13|  5 | MLP    |    -0.6 | <- Low
14+----+--------+---------+
15pd.DataFrame({"Type":["RF", "MLP"], "Low":[1,2], "Hit":[1,1], "High":[1,0]})
16
17+----+--------+-------+-------+--------+
18|    | Type   |   Low |   Hit |   High |
19|----+--------+-------+-------+--------|
20|  0 | RF     |     1 |     1 |      1 |
21|  1 | MLP    |     2 |     1 |      0 |
22+----+--------+-------+-------+--------+
23(df.assign(group=pd.cut(df['Value'],
24                        [float('-inf'), -0.25, 0.25, float('inf')],
25                        labels=['Low', 'Hit', 'High']))
26   .pivot_table(index='Type', columns='group', values='Value', aggfunc='count')
27   .reset_index()
28   .rename_axis(None, axis=1)
29)
30

Or crosstab:

1import pandas as pd
2
3df = pd.DataFrame({"Type":["RF", "RF", "RF", "MLP", "MLP", "MLP"], "Value":[-1.5,-0.1,1.7,0.2,-0.7,-0.6]})
4
5+----+--------+---------+
6|    | Type   |   Value |
7|----+--------+---------|
8|  0 | RF     |    -1.5 | <- Low
9|  1 | RF     |    -0.1 | <- Hit
10|  2 | RF     |     1.7 | <- High
11|  3 | MLP    |     0.2 | <- Hit
12|  4 | MLP    |    -0.7 | <- Low
13|  5 | MLP    |    -0.6 | <- Low
14+----+--------+---------+
15pd.DataFrame({"Type":["RF", "MLP"], "Low":[1,2], "Hit":[1,1], "High":[1,0]})
16
17+----+--------+-------+-------+--------+
18|    | Type   |   Low |   Hit |   High |
19|----+--------+-------+-------+--------|
20|  0 | RF     |     1 |     1 |      1 |
21|  1 | MLP    |     2 |     1 |      0 |
22+----+--------+-------+-------+--------+
23(df.assign(group=pd.cut(df['Value'],
24                        [float('-inf'), -0.25, 0.25, float('inf')],
25                        labels=['Low', 'Hit', 'High']))
26   .pivot_table(index='Type', columns='group', values='Value', aggfunc='count')
27   .reset_index()
28   .rename_axis(None, axis=1)
29)
30(pd.crosstab(df['Type'],
31             pd.cut(df['Value'],
32                    [float('-inf'), -0.25, 0.25, float('inf')],
33                    labels=['Low', 'Hit', 'High'])
34             )
35   .reset_index().rename_axis(None, axis=1)
36 )
37

output:

1import pandas as pd
2
3df = pd.DataFrame({"Type":["RF", "RF", "RF", "MLP", "MLP", "MLP"], "Value":[-1.5,-0.1,1.7,0.2,-0.7,-0.6]})
4
5+----+--------+---------+
6|    | Type   |   Value |
7|----+--------+---------|
8|  0 | RF     |    -1.5 | <- Low
9|  1 | RF     |    -0.1 | <- Hit
10|  2 | RF     |     1.7 | <- High
11|  3 | MLP    |     0.2 | <- Hit
12|  4 | MLP    |    -0.7 | <- Low
13|  5 | MLP    |    -0.6 | <- Low
14+----+--------+---------+
15pd.DataFrame({"Type":["RF", "MLP"], "Low":[1,2], "Hit":[1,1], "High":[1,0]})
16
17+----+--------+-------+-------+--------+
18|    | Type   |   Low |   Hit |   High |
19|----+--------+-------+-------+--------|
20|  0 | RF     |     1 |     1 |      1 |
21|  1 | MLP    |     2 |     1 |      0 |
22+----+--------+-------+-------+--------+
23(df.assign(group=pd.cut(df['Value'],
24                        [float('-inf'), -0.25, 0.25, float('inf')],
25                        labels=['Low', 'Hit', 'High']))
26   .pivot_table(index='Type', columns='group', values='Value', aggfunc='count')
27   .reset_index()
28   .rename_axis(None, axis=1)
29)
30(pd.crosstab(df['Type'],
31             pd.cut(df['Value'],
32                    [float('-inf'), -0.25, 0.25, float('inf')],
33                    labels=['Low', 'Hit', 'High'])
34             )
35   .reset_index().rename_axis(None, axis=1)
36 )
37  Type  Low  Hit  High
380  MLP    2    1     0
391   RF    1    1     1
40

Source https://stackoverflow.com/questions/71068392

QUESTION

What should the result be when assigning a variable to a reference to itself, in-between modified and then returned by a function call?

Asked 2022-Feb-02 at 00:42
1#include <iostream>
2
3int& addOne(int& x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout << x << ' ' << addOne(x);
14}
15

I'm currently in the middle of learning about lvalues and rvalues and was experimenting a bit, and made this which seems to be getting conflicting results. https://godbolt.org/z/KqsGz3Toe produces an out put of "5 6", as does Clion and Visual Studio, however https://www.onlinegdb.com/49mUC7x8U produces a result of "6 7"

I would think that because addOne is calling x as a reference, it would explicitly change the value of x to 6 despite being called as an lvalue. What should the correct result be?

ANSWER

Answered 2022-Feb-02 at 00:42

Since C++17 the order of evaluation is specified such that the operands of = are evaluated right-to-left and those of << are evaluated left-to-right, matching the associativity of these operators. (But this doesn't apply to all operators, e.g. + and other arithmetic operators.)

So in

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16

first the value of the right-hand side is evaluated, yielding 5. Then the function addOne is called and it doesn't matter what it does with x since it returns a reference to it, to which the right-hand value 5 is assigned.

Formally, evaluating the right-hand side first means that we replace the lvalue x by the (pr)value it holds (lvalue-to-rvalue conversion). Then we call addOne(x) to modify the object that the lvalue x refers to.

So, imagining temporary variables to hold the results of the individual evaluations, the line is equivalent to (except for extra copies introduced by the new variables, which don't matter in the case of int):

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19

Then in the line

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20

we first evaluate and output x, resulting in 5, and then call addOne, resulting in 6.

So the line is equivalent to (simplified, knowing that operator<< will return std::cout again):

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20int t1 = x;
21std::cout &lt;&lt; t1 &lt;&lt; ' ';
22int t2 = addOne(x);
23std::cout &lt;&lt; t2;
24

The output 5 6 is the only correct one since C++17.


Before C++17, the evaluation order of the two sides of the assignment operator was unsequenced.

Having a scalar modification unsequenced with a value computation on the same scalar (on the right-hand side of your assignment) causes undefined behavior normally.

But since you put the increment of x into a function, an additional rule saying that the execution of a function body is merely indeterminately sequenced with other evaluations in the calling context saves this. It means that the line wont have undefined behavior anymore, but the order in which the evaluations of the two sides of the assignment happen could be either left-first or right-first.

This means we won't know whether x is evaluated first and then addOne(x) or the other way around.

Therefore after the line, x may be 5 or 6.

6 would be obtained if the evaluation happened equivalently to

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20int t1 = x;
21std::cout &lt;&lt; t1 &lt;&lt; ' ';
22int t2 = addOne(x);
23std::cout &lt;&lt; t2;
24int&amp; y = addOne(x);
25int t = x;
26y = t;
27

Then in the line

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20int t1 = x;
21std::cout &lt;&lt; t1 &lt;&lt; ' ';
22int t2 = addOne(x);
23std::cout &lt;&lt; t2;
24int&amp; y = addOne(x);
25int t = x;
26y = t;
27std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
28

pre-C++17 the same issue applied. The evaluations of the arguments to << were indeterminately sequenced, rather than left-to-right and so addOne(x) could be evaluated before the left-hand x, i.e. in addition to the previous order, the evaluation could also be equivalent to

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20int t1 = x;
21std::cout &lt;&lt; t1 &lt;&lt; ' ';
22int t2 = addOne(x);
23std::cout &lt;&lt; t2;
24int&amp; y = addOne(x);
25int t = x;
26y = t;
27std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
28int t2 = addOne(x);
29int t1 = x;
30std::cout &lt;&lt; t1 &lt;&lt; ' ' &lt;&lt; t2;
31

In this case x is first incremented and then its new value is printed twice.

Therefore possible program output could be either of the following:

1#include &lt;iostream&gt;
2
3int&amp; addOne(int&amp; x)
4{
5    x += 1;
6    return x;
7}
8
9int main()
10{
11    int x {5};
12    addOne(x) = x;
13    std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
14}
15addOne(x) = x;
16int t = x;
17int&amp; y = addOne(x);
18y = t; // same as x = t, because y will refer to x
19std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
20int t1 = x;
21std::cout &lt;&lt; t1 &lt;&lt; ' ';
22int t2 = addOne(x);
23std::cout &lt;&lt; t2;
24int&amp; y = addOne(x);
25int t = x;
26y = t;
27std::cout &lt;&lt; x &lt;&lt; ' ' &lt;&lt; addOne(x);
28int t2 = addOne(x);
29int t1 = x;
30std::cout &lt;&lt; t1 &lt;&lt; ' ' &lt;&lt; t2;
315 6
326 6
336 7
347 7
35

(Technically the int t2 = addOne(x) are two evaluations: One call to addOne returning a reference and then the lvalue-to-rvalue conversion. These could happen interleaved with the other evaluations, but this doesn't give any new program outputs.)


You can specify to use C++17 (or newer versions like C++20) with the -std=c++17 flag to the compiler if you are using GCC or Clang and /std:c++17 if you are using MSVC. Which standard version is chosen by-default depends on the compiler and compiler version.

Source https://stackoverflow.com/questions/70909321

QUESTION

Flutter (2.5) - A splash screen was provided to Flutter, but this is deprecated

Asked 2022-Jan-19 at 05:24

I am new to flutter and recently tried to develop a test app for learning sake with latest version Flutter 2.5. By looking at some tutorial online, I have added flutter_native_splash: ^1.2.3 package for splash screen. And works fine.

However, when I launch app for the first time, it shows following debug message

W/FlutterActivityAndFragmentDelegate(18569): A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

After visiting the above link, I am not able to understand much what is supposed to be done.

Code in pubspec.yaml

1flutter_native_splash:
2  color: &quot;#FFFFFF&quot;
3  color_dark: &quot;#000000&quot;
4  image: assets/images/splash_720.png
5  android: true
6  ios: true
7  android12: true
8

Also, compileSdkVersion and targetSdkVersion is set to 31 in build.gradle

Please help. Thanks in advance.

ANSWER

Answered 2022-Jan-19 at 05:24
To avoid that warning you just need to remove that API usage from your project. Remove these lines of code from the AndroidManifest.xml file.

Remove these lines of code

Previously, Android Flutter apps would either set io.flutter.embedding.android.SplashScreenDrawable in their application manifest, or implement provideSplashScreen within their Flutter Activity. This would be shown momentarily in between the time after the Android launch screen is shown and when Flutter has drawn the first frame. This is no longer needed and is deprecated – Flutter now automatically keeps the Android launch screen displayed until Flutter has drawn the first frame. Developers should instead remove the usage of these APIs. - source



UPDATE (FLUTTER 2.8.0)

As per the flutter 2.8.0 update, The newly created project doesn't have this warning.

They removed unused API from Androidmanifest.yml but still have belove mentioned code.

They still have these lines of code

Source https://stackoverflow.com/questions/69232006

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in Learning

Tutorials and Learning Resources are not available at this moment for Learning

Share this Page

share link

Get latest updates on Learning