dimanche 28 mars 2021

Iam getting a error while rendering a component in the main component using react js

The error is: Objects are not valid as a React child (found: object with keys {code, message, a}). If you meant to render a collection of children, use an array instead.

I will show my code where Iam trying to render the component:

document.querySelector(".App").innerHTML = "";
const errorElement = <ShowErr message={err} />;
ReactDOM.render(errorElement, document.querySelector(".App"));

My component:

import Button from "@material-ui/core/Button";

const reload = () => {
  window.reload();
};

const ShowErr = (props) => {
  const imgStyle = {
    display: "block",
    margin: "auto",
    marginTop: "100px",
    marginBottom: "50px",
    borderRadius: "50%",
  };
  const msgStyle = {
    textAlign: "center",
    marginTop: "30px",
    fontFamily: "Ubuntu",
    color: "red",
  };
  const btnStyle = {
    display: "block",
    margin: "auto",
    marginTop: "50px",
  };

  return (
    <div className="err">
      <link rel="preconnect" href="https://fonts.gstatic.com" />
      <link
        href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@300&display=swap"
        rel="stylesheet"
      ></link>

      <img
        src="https://img.icons8.com/emoji/48/000000/cross-mark-button-emoji.png"
        style={imgStyle}
      />
      <h3 className="error-msg" style={msgStyle}>
        {props.message}
      </h3>
      <Button color="secondary" style={btnStyle} onClick={reload}>
        Reload and Try Again
      </Button>
    </div>
  );
};

export default ShowErr;

Please tell if any solution




Dot Net Core Web API Return Response From Endpoint

I'm busy trying to create a very simple Dot Net Core Web API (Dot Net 5) and I've run into a strange issue where I cannot get the endpoint to return a response.

I've tried to use

await context.Response.WriteAsync("Hello World!");

as per the documentation but I'm getting the error

'HttpResponse' does not contain a definition for 'WriteAsync'

This is the full Startup.cs code

public class Startup {

    public Startup(IConfiguration configuration) {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services) { }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {

        app.UseRouting();

        app.UseEndpoints(endpoints => {
            endpoints.MapGet("/test", async context => {
                //Console.WriteLine("Exec Test");
                await context.Response.WriteAsync("Hello World!");
            });
        });

    }

}

I'm sure there's something I'm missing




how to design a blog. using html css javascript and backend services

I have started web development, I have used WordPress but I want to code my own blog, but I don't know where to start, Can someone guide me as to which technologies I should use, what things I should learn, and what steps to follow. please do mentions how I can build good UI, and what are the things that require backend services. Can I make my blog totally on the frontend? I just want to have articles in it. furthermore, I am also learning to make an app from flutter so I am wanting to make a blog app for the website too (like connecting them). What is the use of backend in such blogs, and how much to do?. Is an API needed. I hope you can suggest to me some ideas.

please be simple and clear as possible.




I found this problem when use firebase authication and cloude_firebase in my flutter web app

Running with sound null safety TypeError: Cannot read property 'app' of undefined at Object.app$ [as app] (http://localhost:49841/packages/firebase_core_web/src/interop/core.dart.lib.js:42:101) at new cloud_firestore_web.FirebaseFirestoreWeb.new (http://localhost:49841/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:988:64) at Function.registerWith (http://localhost:49841/packages/cloud_firestore_web/src/write_batch_web.dart.lib.js:842:73) at Object.registerPlugins (http://localhost:49841/packages/nse7a/generated_plugin_registrant.dart.lib.js:33:46) at main (http://localhost:49841/web_entrypoint.dart.lib.js:41:35) at main.next () at runBody (http://localhost:49841/dart_sdk.js:37229:34) at Object._async [as async] (http://localhost:49841/dart_sdk.js:37260:7) at main$ (http://localhost:49841/web_entrypoint.dart.lib.js:40:18) at http://localhost:49841/main_module.bootstrap.js:19:10 at Array.forEach () at window.$dartRunMain (http://localhost:49841/main_module.bootstrap.js:18:32) at :1:8 at Object.runMain (http://localhost:49841/dwds/src/injected/client.js:8656:21) at http://localhost:49841/dwds/src/injected/client.js:22068:19 at _wrapJsFunctionForAsync_closure.$protected (http://localhost:49841/dwds/src/injected/client.js:3830:15) at _wrapJsFunctionForAsync_closure.call$2 (http://localhost:49841/dwds/src/injected/client.js:10905:12) at Object._asyncStartSync (http://localhost:49841/dwds/src/injected/client.js:3794:20) at main__closure1.$call$body$main__closure (http://localhost:49841/dwds/src/injected/client.js:22080:16) at main__closure1.call$1 (http://localhost:49841/dwds/src/injected/client.js:22007:19) at StaticClosure._rootRunUnary [as call$2$5] (http://localhost:49841/dwds/src/injected/client.js:4153:16) at _CustomZone.runUnary$2$2 (http://localhost:49841/dwds/src/injected/client.js:12136:39) at _CustomZone.runUnaryGuarded$1$2 (http://localhost:49841/dwds/src/injected/client.js:12068:14) at _ControllerSubscription._sendData$1 (http://localhost:49841/dwds/src/injected/client.js:11697:19) at _DelayedData.perform$1 (http://localhost:49841/dwds/src/injected/client.js:11849:59) at _PendingEvents_schedule_closure.call$0 (http://localhost:49841/dwds/src/injected/client.js:11898:14) at Object._microtaskLoop (http://localhost:49841/dwds/src/injected/client.js:3990:24) at StaticClosure._startMicrotaskLoop (http://localhost:49841/dwds/src/injected/client.js:3996:11) at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (http://localhost:49841/dwds/src/injected/client.js:10774:9) at invokeClosure (http://localhost:49841/dwds/src/injected/client.js:1250:26) at MutationObserver. (http://localhost:49841/dwds/src/injected/client.js:1269:18) ERROR - 2021-03-28 17:45:59.793377 GET /web_entrypoint.dart.lib.js:40:18 Error thrown by handler. FormatException: Illegal scheme character (at character 4) web_entrypoint.dart.lib.js:40:18 ^

dart:core _Uri.resolve package:flutter_tools/src/isolated/devfs_web.dart 503:57 WebAssetServer._resolveDartFile package:flutter_tools/src/isolated/devfs_web.dart 395:17 WebAssetServer.handleRequest package:dwds/src/handlers/injector.dart 110:32 DwdsInjector.middleware..




Problems parsing POST request with GO webserver

I am very new to GO and I am trying to set up a very basic GO webserver and so far I have had no issues handling GET requests without any parameters, however now I am trying a POST request with some parameters and I am having two different issues depending on how I send the request.

Here's the code that handles the route

func SubmitData(w http.ResponseWriter, r *http.Request) {
    reqBody, _ := ioutil.ReadAll(r.Body)

    var userInfo SubmittedUserInfo
    fmt.Println(string(reqBody))

    unmarshalErr := json.Unmarshal(reqBody, &userInfo)
    if unmarshalErr != nil {
        fmt.Println("Error Unmarshalling JSON:", unmarshalErr)
    }

    _ = json.NewEncoder(w).Encode(userInfo)

    if unmarshalErr != nil {
        log.Printf("error decoding response: %v", unmarshalErr)
        if e, ok := unmarshalErr.(*json.SyntaxError); ok {
            log.Printf("syntax error at byte offset %d", e.Offset)
        }
        log.Printf("request body: %q", reqBody)
    }

}

Here's the SubmittedUserInfo structure that I am trying to create with the JSON data.

type SubmittedUserInfo struct {
    Number int16 `json:"Number"` // is always a number between 0 and 10
    Age int16 `json:"Age"`
    Nationality string `json:"Nationality"`
    Gender string `json:"Gender"`
    DominantHand string `json:"DominantHand"`
}

Here is the function that handles the requests

func handleRequests(port string) {
    muxRouter := mux.NewRouter().StrictSlash(true)
    muxRouter.HandleFunc("/", Home)
    muxRouter.HandleFunc("/health", HealthCheck)
    muxRouter.HandleFunc("/submit_data", SubmitData).Methods("POST")
    log.Fatal(http.ListenAndServe(port, muxRouter))
}

Here are the actual errors I am getting. If I send the following request with Python 3.8 I get the corresponding error

import requests

url = "http://localhost:5050/submit_data"

args = {
    "number": 0,
    "age": 25,
    "nationality": "russian",
    "gender": "male",
    "dominantHand": "right"
}
response = requests.post(url, args)

Error:

Error Unmarshalling JSON: invalid character 'N' looking for beginning of value
2021/03/28 11:23:27 error decoding response: invalid character 'N' looking for beginning of value
2021/03/28 11:23:27 syntax error at byte offset 1
2021/03/28 11:23:27 request body: "Number=0&Age=25&Nationality=russian&Gender=male&DominantHand=right"

Now if I send a request with Postman specifying the exact same parameters I get the error

Error Unmarshalling JSON: unexpected end of JSON input
2021/03/28 11:24:38 error decoding response: unexpected end of JSON input
2021/03/28 11:24:38 syntax error at byte offset 0
2021/03/28 11:24:38 request body: ""

What am I doing wrong? I am very used to doing this in Python and I won't be surprised if there's some additional work I need to do in GO to ensure everything is formatted properly, but I have no idea what that might be, so any help or advice would be greatly appreciated!




Boolean logic interpretation in google chrome console

I'm having difficulties figuring out why the code below doesn't work as expected:

const userInput = prompt("Enter something");

if (userInput) {
    console.log("TRUTHY");
} else {
    console.log("FALSY");
}

I keep getting "TRUTHY" no matter what I do. I understand the logic of this code and even when running the source file from the class I'm not getting the expected output.

I should get "FALSY" whenever the input is: 0, null, undefined, an empty string or NaN.

What am I doing wrong? Thank you.




Web scraping 40+ websites in search of opportunities in python

I have been tasked to automate the task of searching for opportunities (tenders) in 40+ websites for a company. The opportunities are usually displayed in table format. They have a title, date published, and a clickable link that takes you to a detailed description of what the opportunity is. One website example is: http://www.eib.org/en/about/procurement/index.htm

The goal would be to retrieve the new opportunities that are posted everyday and that fit specific criteria. So I need to look at specific keywords within the opportunities' title. These keywords are the fields and regions in which the company had previous experience.

My question is: After I extract these tables, with the tenders' titles, in a dataframe format, how do I search for the right opportunities and sort them by relevance (given a list of keywords)? Do I use NLP in this case and turn the words in the titles into binary code (0s and 1s)? Or are there other simpler methods I should be looking at?

Thanks in advance!