asha91

New Members
  • Content count

    16
  • Joined

  • Last visited

Community Reputation

0 Spren

1 Follower

About asha91

  1. I'm working on a JavaScript project where I need to make multiple asynchronous calls using Promises, and I want to ensure that all promises are resolved before proceeding. What's the best way to handle multiple concurrent promises in JavaScript? For example, I'm making several API requests, and I want to process the data only when all the requests are complete. How can I achieve this using Promises, and are there any best practices or patterns to follow? I'd appreciate a code example or guidance on structuring and managing multiple concurrent promises effectively in JavaScript. Thank you!
  2. I'm facing a problem while trying to establish a connection between PHP and MySQL to retrieve data from a database. I'm using the mysqli extension for PHP, but I'm not able to fetch the expected results. Here's a simplified version of my code: <?php $servername = "localhost"; $username = "root"; $password = ""; $database = "mydatabase"; // Create connection $conn = new mysqli($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Attempt to fetch data $query = "SELECT * FROM mytable"; $result = $conn->query($query); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>"; } } else { echo "No data found."; } $conn->close(); ?> When I run this script, I get the "No data found." message even though I have data in the mytable table. I've confirmed my database credentials and table name, but I can't figure out what's causing this issue. Could someone please review my code and provide insights into what might be causing this problem? Is there a common mistake I might be overlooking or any debugging steps I should take to diagnose the issue? Any help would be greatly appreciated. Thank you!
  3. I've run into a problem with missing values in my DataFrame while working on a data science project utilizing Python's Pandas package. I sought assistance from the Scalers Data Science Project, but the problem has not yet been resolved. Numerous columns make up my dataset, and some of them have missing values that are denoted as NaN. Here's a snippet of my DataFrame: import pandas as pd # Sample DataFrame with missing values data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'], 'Age': [25, 28, None, 32, 22], 'Score': [85, None, 78, 92, None], 'Salary': [50000, 60000, 55000, None, 48000] } df = pd.DataFrame(data) I want to handle these missing values effectively before proceeding with my analysis. I'm considering a few options like removing rows with NaN, imputing the missing values with the mean, or using interpolation. Could someone please guide me on the best approach to handle missing values in my DataFrame? Additionally, I'd greatly appreciate some code examples to demonstrate the implementation of the chosen method. Thank you in advance for your help!
  4. When we do a natural join, do we join on attributes with the same names? Outcomes o1 Battles b1 natural join The only thing these two have in common is the battle name. However, in (Battles b1 naturally join Outcomes o1), natural join (Battles b2 natural join Outcomes o2) Tables: Ships (shipName, shipType, launchDate) Battles (battleName, battleDate) Outcomes (shipName, battleName, result) Create a SQL query that returns the names of ships that were damaged in naval combat and then took part in another. Answer: select o1.shipName from (Battles b1 natural join Outcomes o1) natural join (Battles b2 natural join Outcomes o2) where o1.result = ’damaged’ and b2.battleDate > b1.battleDate; All of the characteristics are shared. What is the current state of natural join? I've tried reading this article to get through it but I couldn't understand the example they give. Can you explain why this solution works?
  5. I know the principles of programming languages (at least Java, JavaScript, C + +, Python, Ruby, HTML, and CSS). I made a few simple Java (Android Studio) and Python applications ( Kivy ). I'd like to become a professional developer and start creating amazing multifaceted web programmes and applications; I've read this blog, but I'm not sure which tool is ideal for these objectives. If necessary, I am willing to learn a new programming language. In addition, I acquired my diploma in electrical and electronic engineering last year, and aside from studying Java (at school and in my first year of college), I learned the rest on the job. As a result, I lack sufficient knowledge about how to become a software engineer. Please! Could you pls help me?
  6. This function accepts the number of terms in the Fibonacci sequence in the child process, creates an array, and redirects the output to the parent via pipe. Parent must wait till the child develops the Fibonacci series. The received text always displays -1, although the transmitted text displays the number of entered numbers *4, which is acceptable. #include<stdio.h> #include<unistd.h> #include<sys/types.h> #include<string.h> int* fibo(int n) { int* a=(int*)malloc(n*sizeof(int)); *(a+0)=0; *(a+1)=1; int i; for(i=0;i<n-2;i++) { *(a+i+2)=*(a+i)+(*(a+i+1)); } return a; } int main() { int* fib; int fd[2]; pid_t childpid; int n,nb; int k=pipe(fd); if(k==-1) { printf("Pipe failed"); return 0; } childpid=fork(); if(childpid == 0) { printf("Enter no. of fibonacci numbers"); scanf("%d",&n); fib=fibo(n); close(fd[0]); nb=(fd[1],fib,n*sizeof(int)); printf("Sent string: %d \n",nb); exit(0); } else { wait(); close(fd[1]); nb= read(fd[0],fib,n*sizeof(int)); printf("Received string: %d ",nb); } return 0; }
  7. Well that's a good question and pretty good explanation. learned some knowledge here thanks
  8. I discovered the following function: def sub_kpi1_rule(sub_comp_appr_date, date_report_run, greater_of_date_sub_sub_ll): if pd.isnull(sub_comp_appr_date) and not alive_for_six_days(date_report_run, greater_of_date_sub_sub_ll): return "NA" elif (sub_comp_appr_date - greater_of_date_sub_sub_ll).ceil("1d").days <= 6: return "PASS" else: return "FAIL" Because all of the parameters are date types, I'm assuming (sub_comp_appr_date - greater_of_date_sub_sub_ll) ..returns a timedelta instance. I am confused about this ceil(syntax) elif (sub_comp_appr_date - greater_of_date_sub_sub_ll).ceil("1d").days <= 6: because when I try to subtract two dates using this method, I get the following error: from datetime import date a = date(2022, 10,1) b = date(2022, 10,15) (b-a).ceil("1d") --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In [36], line 4 2 a = date(2022, 10,1) 3 b = date(2022, 10,15) ----> 4 (b-a).ceil("1d") AttributeError: 'datetime.timedelta' object has no attribute 'ceil' On a data frame, the function is called: df["Sub KPI1"] = df.apply(lambda x: sub_kpi1_rule(x["SUBM_LATE_DESTINATION_COMPLIANCE_APPROVAL_DATE"], date_report_run, x["Greater of Date Submitted and Submission LL Created"]), axis=1) Because date report run is expressly transformed to one, I believe the types are pd.Timestamp: date_report_run = date(year_report_run, month_report_run, day_report_run) date_report_run = pd.Timestamp(date_report_run) I'm assuming I'll receive a pandas. libs.tslibs.timedeltas. Instead of a standard timedelta, use a timedelta back.
  9. I'm attempting to describe train routes as a data structure, but I'm having trouble expressing turnouts. This appears to be a graph problem, however, there is a distinction between it and conventional graphs. A railway turnout is a vertex that connects three other vertices. The letters A, B, and C In a railway system, however, the graph is traversed with a direction for that I looked over the internet and found this article about graph transversal but didn't understand it. So you may take the paths B -> turnout -> A and C -> turnout -> A, but not the path B -> turnout -> C. Is there a data structure (graph) that allows for the representation of pathways with directions? This data format would serve as the foundation for a software system to automate a small model railroad.
  10. I'm building a scripting language on top of the Java Virtual Machine. I can dynamically build Java auxiliary objects, access their properties, and activate their methods via reflection. However, I have now hard-coded particular event processing. For example, JScrollBar addAdjustmentListener() makes use of the Adjustable interface, JFrame windowClosing() makes use of the WindowAdapter interface, and JButton addActionListener makes use of the ActionListener interface. An anonymous function is called with the event data on the event receiving end of the scripting language, with 0-1 or 2 arguments of any kinds. My issue is, is there a (reflective) method to handle arbitrary events in Java? Handling all JComponent subclass events in general would also be a good place to start.
  11. Actually, I am using it for some personal projects. Thanks for the clarification, it really helped me in choosing the best alternative.
  12. In Java, if I try to do.equals() on a null string, a null pointer error is issued. I'm wondering whether I can perform the following if I'm attempting to compare if a string is equal to a constant string: MY CONSTANT STRING.equals(aStringVariable) I'm sure it'll work, but is this simply extremely bad code? This is a common Java idiom known colloquially as a Yoda condition. Personally, I prefer to handle the null situation directly, but the Yoda method is widely used, and any competent Java programmer should quickly grasp what is going on. How should I proceed?
  13. A linear data structure gradually traverses the data elements, with just one data element immediately accessible. Examples include arrays and linked lists. However, This article(https://www.scaler.com/topics/non-linear-data-structure/) on the internet suggested that in a doubly linked list, there is no contiguous memory structure. All the elements of a LinkedList are spread across the memory in a Non-Linear fashion. We may access two data pieces by utilizing the previous and next pointers. So, is the doubly linked list a nonlinear data structure?
  14. I'm working on a software with two threads. one iteration of a circular linked list Because the linked list is circular, there is always a following member. another thread is changing the list However, I receive a concurrentModificationException. What am I supposed to do with it? Thanks