Using leaflet-vue-3 How do I open a specific existing popup from a button?

I have a whole bunch of markers on a leaflet-vue map

   <l-marker
        v-for="station in stations"
        :lat-lng="[station.lat, station.lon]"
        :options="{title: station.stationname}"
        autoPanOnFocus="true"
        keyboard="true"
        @click="closeAll()"
    >

 <l-icon :icon-size="[15,15]" :icon-url="'/img/bus.png'"/>
 <l-popup>
 .....
 </l-popup>
</l-marker>

How do I write a method which will identify open a specific popup programatically when a button is clicked?

JavaScript heap out of memory error on Angular[11] build

I’m facing a ‘JavaScript heap out of memory error’ error when I try to build the Angular App with a command

ng build –prod –output-hashing=all

Then, I’ve been finding a solution on the internet and found a lot of recommends from the Stackoverflow to use

node –max_old_space_size=5120 ./node_modules/@angular/cli/bin/ng

But it is not working for me.

When I use this command I can get rid of memory issue but I face with a ton of error instead which all about “not a known element” and “cannot bind to ‘ngModel'” issues

For example,

error NG8001: 'nz-page-header-extra' is not a known element:
1. If 'nz-page-header-extra' is an Angular component, then verify that it is part of 
 this module.
2. If 'nz-page-header-extra' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to 
  the '@NgModule.schemas' of this component to suppress this message.
3   <nz-page-header-extra style="padding-top: 0.5rem">

or

error NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'.

12         [(ngModel)]="searchValue"

Note, the ‘ng build –prod –output-hashing=all’ used to work before, but it is not working after the project has more features.

My Angular dependencies

"@angular/animations": "^11.2.14",
"@angular/cdk": "^12.1.4",
"@angular/common": "~11.2.9",
"@angular/compiler": "~11.2.9",
"@angular/core": "~11.2.9",
"@angular/forms": "~11.2.9",
"@angular/platform-browser": "~11.2.9",
"@angular/platform-browser-dynamic": "~11.2.9",
"@angular/router": "~11.2.9",

Node and Quokka Will Not Show Return Values

While watching tutorials I noticed that node and Quokka are able to show a function’s return values unless. However I am not able to get this to work unless I wrap the function in a console.log. I reinstalled node using nvm but nothing changed. It will print a console.log no problem. Below is an example.

function add(x, y) {
   return (x + y);
}

add(2, 5);

This will not show anything in the console when using Quokka or running the file through node. However, when wrapping it in a console.log like so.

function add(x, y) {
      return (x + y);
}

console.log(add(2, 5))

It will show 7 in the console. I feel liek I have a setting wrong somewhere because in this tutorial, https://www.youtube.com/watch?v=f_sEWa5hA0Q @4:44, his function works just fine and the return value shows up in the Quokka output. I tested with console.log('hello') and that also shows up just fine.

how to untoggle class on old card when new card is selected

Currently, when i click on a card, it changes the styling so that its border is white instead of grey, when i click on a new card, the previous card’s border still remains white, how can i get the previous card to toggle again when new card is selected?

i know i just need some logic that will listen for another event on screen and will then remove toggle but i feel like there would be an easier way to do it…

var numberOfCards = document.querySelectorAll(".card").length;

for (var i = 0; i < numberOfCards; i++) {

  document.querySelectorAll(".card")[i].addEventListener("click", function() {

    var currentCard = this.querySelector(".card .card-body .card-title").innerHTML;

    switch (currentCard) {
      case "Temperature":
        this.classList.toggle("card-clicked");
        break;

      case "pH":
        this.classList.toggle("card-clicked");
        break;

      case "Water Change":
        this.classList.toggle("card-clicked");
        break;

      case "Lighting":
        this.classList.toggle("card-clicked");
        break;

     default:
    }
  });
};

i tried to add in before the switch:

    switch (currentCard) {
      case "Temperature":
      case "pH":
      case "Water Change":
      case "Lightning":
        this.classList.remove("card-clicked");
        break;
    default:
    }

but i think it stops the second switch from running?

How to display an image using IPFS url?

It would like to know how to display an image from IPFS, I’m having a file that is sent to IPFS and the url is retrieved, so I have tried the below to display the image in a img tag using the url retrieved but it is not showing:

<img
  alt="Profile"
  className="rounded-full w-40 h-40"
  src={
   values.url
    ? values.url
    : '/static/img2.png'
  }
/>

So I tried with src={ values.url ? URL.createObjectURL(values.url) : '/static/img2.png'} , the image is displayed but after I send this url with other info through a metamask transaction, the next error is shown: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.

Given a set of x words, how would we place them in an n by n grid and then fill in the other spaces with random letters?

I have made it through the initial testing phase of pre-employment screening and I have my technical interview on Friday. They were nice enough to tell me what kinds of questions they will be asking. Most of what they mentioned I am not concerned about. However, there is one question that I feel will disqualify me from consideration. I have three days to figure out how to solve it and memorize the solution. Here is the question:

“We will talk about how we might implement a new feature for auto generating a word search. Given a set of x words, how would we place them in an n by n grid and then fill in the other spaces with random letters. Examples of word searches: https://thewordsearch.com/printable/

We will use jsfiddle to collaborate on the code”

Any help would be greatly appreciated. I really want this job and feel like it would be a huge missed opportunity if I don’t land it.

Use alternate value if a field is null in Elasticsearch

I have field A and B. While indexing, if value of A is null, I want to get value of B instead.

Header: "header", id: "id", accessor:
 // if A is present in Elastic search, use A else use B.

I am thinking store this value to C so that I can use C later in query as well, but I am not sure about how to achieve it. I did not come across such a use case anywhere. Is it possible to handle this case ? Any help is appreciated. Thank you.

how do I convert pokemon.types.forEach() in jquery?

so i’m refactoring some JS code and switching it to jquery, does anyone have suggestions in how you would go about coverting?

const pokeType = {fire: 'text-danger', grass: 'text-success', 
                    water: 'text-primary', electric: 'text-warning', 
                    flying: 'text-info', poison: 'text-secondary'};

// This is the code i want to change into jquery pokemon.types

  pokemon.types.forEach(t => modalTitle.classList.add(pokeType[t.type.name]));
  modalTitle.innerHTML = `<p><strong>${pokemon.name}</strong></p>`;

check if substring exsits in main string per word

I have a string I want to check if a substring is in the main string. The code I have below works partially. The problem is I want to check if the substring matches per word to the main string currently it checks per character. To Explain this better say my main string is the banana is yellow and if the substring I am looking for is banana is I want it to print true but if the substring is ana is it prints false. How can I achieve this? Thanks in advance.

const testString = 'the banana is yellow'
const checkString = 'ana is'

//should have printed false
if (testString.includes(checkString)) {
  console.log('true')
} else {
  console.log('false')
}

onChange event fires on wrong mapped file input element

I am stuck on this issue with onChange handler being fired on a wrong element after .map function. I have a component, which I use to display mapped values, which looks like this:

const Step: React.FC<StepProps> = ({ status, title, text, onClick, onChange }) => {
  return (
    <button disabled={status === CompletionStatus.Completed} className={Styles.item} onClick={onClick}>
      <mui.IconButton css={css.completionIcon} disabled={status === CompletionStatus.Completed}>
        {status === CompletionStatus.Completed ? <muiIcons.Check /> : <Plus />}
      </mui.IconButton>

      <div className={Styles.content}>
        <span className={status === CompletionStatus.Completed ? Styles.titleCompleted : Styles.title}>{title}</span>

        <span className={status === CompletionStatus.Completed ? Styles.textCompleted : Styles.text}>{text}</span>
      </div>

      {onChange && (
        <>
          <label htmlFor="file-button" className={Styles.inputLabel} />
          <input id="file-button" className={Styles.input} type={'file'} onChange={onChange} />
        </>
      )}
    </button>
  );
};

So, some of the mapped elements are being used with onClick, and two use onChange to gain photos from the user.

The issue is, that every time I trigger the onChange event on any of those inputs, only the first ones fires, e.g (I added this onChange function to test the name of the element that is being fired, and every time only the first one in the list is being console.logged)

onChange={(event: any)=> {
  console.log(event, step);
  event.target.value = null;
}}

Maximum Depth Exceeded in React-Redux JS when trying to access object value within state

I am currently working on a private route for checking if a user has the ‘vendor’ attribute set as true or false. When a user is logged in, the state changes so that there is a User object that has attribute vendor within it. The problem arises when I try to access the user object in the private route which returns an ‘update depth exceeded error’. When I try to use just the ‘isAuthenticated’ state, it works fine. Somehow the accessing of the object triggers a re-render and update/ setState which causes the loop. Is there a way to bypass this and access the state object?

Redux state image:
Redux state image

    const PrivateRoute_for_vendor = ({ children, auth, GetAPI }) => {

 
        if (auth.isloading) {
            return <h2>loading swirl</h2>
        }
        //accessing the auth.user.vendor makes it re-render?
        else if (auth.user.vendor && auth.isAuthenticated) {
            return children
        }
        //user is an object and isAuthenticated is not, isAuthenticated by itself works. 
        else {
    
            return <Navigate to='/login' />
        }
    }
const mapStatetoProps = state => ({
    auth: state.Auth, //Auth is the name of my reducer which processes the state
})

export default connect(mapStatetoProps, { GetAPI })(PrivateRoute_for_vendor)

within App.js render() part:
    <Route path="/posts" element={<PrivRoute_for_vendor><Posts /></PrivRoute_for_vendor>} />

How to downgrade the syntax of `chart.js 3.0` to `chart.js 2.0`

I’m absolute nood at JS. I’ve a requirement where I’ve to use 2 different chart.js versions for different plots.

`chart.js @3.8.0` for #plot1

`chart.js @2.8.0` for #plot2

My most of the code written with chart.js @2.8.0. Only one plot with chart.js @3.8.0

my chart.js @3.8.0 plot code

graph2() {

    const options = {
      type: 'line',
      data: {
        labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
        datasets: [{
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
          segment: {
            borderColor: (ctx) => (ctx.p0.parsed.y < ctx.p1.parsed.y ? 'green' : 'red')
          }
        }]
      },
      options: {}
    }

    const ctx = document.getElementById('mychart').getContext('2d');
    new Chart(ctx, options);
},

After digging some documentation I came to know that syntax migrated
https://www.chartjs.org/docs/master/getting-started/v3-migration.html …Is there is any way to modify my plot code so that I can use in my chartjs @2.8.0 version.

ReactJS add component to Javascript object

I’m using a Javascript object to hold the info for a side menu (e.g. name, path), then using a couple of nested maps to build the actual menu composed of MUI components. This works for info that is stored as JS primitive types, but I also want to include an icon as part of that object, which itself is a React component coming from MUI. Example:

  const menuItems = {
    Text: [
      { name: 'TTS', path: 'textTTS', icon: </InboxIcon>, enabled: true },
    ],
    Image: [...],
    Video: [...],
    Live: [...],
  }

However, I get an error because (I think) it’s trying to evaluate the actual component when I add it to the object:

Unexpected token (26:45)

  24 |   const menuItems = {
  25 |     Text: [
> 26 |       { name: 'TTS', path: 'textTTS', icon: </InboxIcon>, enabled: true },
     |                                              ^
  27 |     ],

What’s the correct way to reference a component, without actually adding the contents of the component to an object?

FYI here is how I’m building the actual side menu:

let menuComponents = Object.keys(menuItems).map((header, index) => {
    return (
      <List
        key={header}
        subheader={
          <ListSubheader component="div" id="nested-list-subheader">
            {header}
          </ListSubheader>
        }
      >
        {menuItems[header].map((item, index) => {
          return (
            <ListItem
              key={item.path}
              disablePadding
              sx={{ display: 'block' }}
              onClick={() => {
                navigate(item.path);
              }}
            >
              <ListItemButton disabled={item.enabled ? false : true}>
                <ListItemIcon>{item.icon}</ListItemIcon>
                <ListItemText primary={item.name} />
              </ListItemButton>
            </ListItem>
          );
        })}
      </List>
    );
  });

String in method returns undefined wherever the ‘this” keyword is used after storing it into a variable [duplicate]

I have two object literals. Inside the first object, there is a method in which I created a string in that will be logged to the console when it’s called. I am using the “this” keyword in the string to refer to the object’s name.

I store the method into a variable in the global environment and called it with two arguments, and while both arguments get successfully passed to the method, “undefined” gets returned for wherever I used the “this” keyword in the string. I know that I can use the “call” method to fix this, but I want to know why this happens in the first place.

I didn’t think this would happen since a method is a function and functions are objects, and objects are reference values. So, therefore, by saving the method into a variable, I thought doing that doesn’t create a copy of the method and that the “bookFunction” variable points to the same function that’s in the object in memory, which the “this” keyword in that method equates to “american1” (the first objects name).

Questions:

  1. After storing the method in a variable, and calling it, why is wherever the “this” keyword is used in the string, “undefined” gets returned?

  2. Is storing the method into a variable copying it?

const american1 = {
  airline: "American Airlines",
  iataCode: "AA",
  book: function (flightNum, name) {
    console.log(
      `${name} booked a flight on ${this.airline} flight ${this.iataCode}${flightNum}`
    );
  },
};

const delta1 = {
    airline: 'Delta Airlines',
    iataCode: 'DL',
}

const bookFunction = american1.book;

bookFunction(23, 'John Doe');

// bookFunction.call(delta1, 23, 'Average Joe');

Remove duplicates or distinction from array of objects by knockout.js

How to remove duplicates objects from an array by using Knockout.js

   var ticketgroups = [
      {TicketGroup: TicketGroup1, SortOrder: 1},
      {TicketGroup: TicketGroup1, SortOrder: 1},
      {TicketGroup: TicketGroup2, SortOrder: 2},
      {TicketGroup: TicketGroup2, SortOrder: 2},
      {TicketGroup: TicketGroup3, SortOrder: 3},
      {TicketGroup: TicketGroup3, SortOrder: 3},
    ];

Output should be

 var filltered = [
          {TicketGroup: TicketGroup1, SortOrder: 1},
          {TicketGroup: TicketGroup2, SortOrder: 2},
          {TicketGroup: TicketGroup3, SortOrder: 3},
        ];