How can i execute my script with web3 just with javascript?

this is the begin of my script

const fs = require("fs");
const readline = require("readline");
const Web3 = require("web3");
const web3 = new Web3(Web3.givenProvider || "http://127.0.0.1:7545");

i tried to execute that like this

node ./Works/script.js’

but i am getting this error:

code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Works/script.js' ]

how can i execute that?

Can’t deploy project on Vercel due to name error

I want to deploy on project on vercel but i keep got an error that say me the projet is not valide like this message:

Error:The name of a Project can only contain up to 100 alphanumeric lowercase characters and hyphens. Learn More

but my name project is: ecommerce_sanity

or this error : The name contains invalid characters. Only letters, digits, and underscores are allowed. Furthermore, the name should start with a letter.

for this name project: headphones_ecommerce

I try different name but keep got this error do someone already face this?

Regex to match pattern with prefix ‘/front-cover’ [closed]

So I have an array of objects, and I want to return an array of objects that have the imageUrl of ‘/front-cover’ as the prefix. I know I have to use a combination of the find function and a regex to match that pattern, however I suck at regex.

This is the inital array of Objects

[
   {
      "id":"template001",
      "width":300,
      "height":600,
      "imageUrl":"/front-cover-portrait-1.jpg"
   },
   {
      "id":"template002",
      "width":300,
      "height":600,
      "imageUrl":""
   },
   {
      "id":"template003",
      "width":300,
      "height":600,
      "imageUrl":""
   },
   {
      "id":"template004",
      "width":300,
      "height":600,
      "imageUrl":"/back-cover-portrait.jpg"
   },
   {
      "id":"template005",
      "width":300,
      "height":600,
      "imageUrl":"/front-cover-portrait-2.jpg"
   },
   {
      "id":"template006",
      "width":600,
      "height":300,
      "imageUrl":"/front-cover-landscape.jpg"
   },
   {
      "id":"template007",
      "width":600,
      "height":300,
      "imageUrl":""
   },
   {
      "id":"template008",
      "width":600,
      "height":300,
      "imageUrl":"/back-cover-landscape.jpg"
   }
]

I want to return this as a result

[
   {
      "id":"template001",
      "width":300,
      "height":600,
      "imageUrl":"/front-cover-portrait-1.jpg"
   }
   {
      "id":"template005",
      "width":300,
      "height":600,
      "imageUrl":"/front-cover-portrait-2.jpg"
   },
   {
      "id":"template006",
      "width":600,
      "height":300,
      "imageUrl":"/front-cover-landscape.jpg"
   }
]


How to use an AngularJS module on Angular

Right now I need to apply one card carousel in my Angular 13 project. I was trying to find any simple carousel module that doesn’t need bootstrap (as I am using Bulma), jquery, or lots of dependencies and found this one ui-carousel. But the installation and usage guides of this module describes how to use it on AngularJS, but not specifically about Angular, if it is usable or how to do it.
If it isn’t applicable, or even if it isn’t the best, which other alternative module could I use?

i can’t make a button work, i’ve tried the eventListener and the onclick

please if someone would be so kind and help me, i would be very happy, clearing i’m a beginner so help if you can, please.

the html

<div>
        <h2>TO-DO LIST</h2>
        <input type="text" id="tasks"  class="List" placeholder="add">
        <input type="submit" id="subButton" onclick="action()">
        <!-- <button type="button" id='resetBut' onclick="deleteIl()">Reset</button>-->
        <div>

       <ul id="myUl" ></ul>

the js

function action() {

    let item = document.createElement('li');
    let inputValue = document.getElementById('tasks').value;
    var t = document.createTextNode(inputValue);
    item.appendChild(t);

        if(inputValue === ''){
            alert("you must write something!");
        }
        else{
            document.getElementById('myUl').appendChild(item);
        }
        document.getElementById('tasks').value= '';
        
        const tasksDelete = document.createElement ("button");
        tasksDelete.classList.add("delete");
        tasksDelete.innerHTML= 'X';
        item.appendChild(tasksDelete);
        document.getElementsByClassName("delete").onclick = log();
        //document.getElementsByClassName("delete").addEventListener("click", log());
        
            function log(){
                console.log("name")
            }
            //tasksDelete.document.getElementById('myUl');
             //tasksDelete.removeChild();
}

i’m trying to put a delete button on the elements ‘li’ (this works), and trying to use the removeChild() but i’m getting ‘Uncaught ReferenceError: removeChild is not defined’, so to see if it’s working i’ve change the removeChild() for the log function, and now the log function appears in the console when a press the subButton and not when i click on the delete button.

Why does React log to Chrome-Console “Content-script injection failed” (from allpages.js) when I never set up code to inject a script?

I am nearly done with my code for my new Website but am really bothered that the following gets somehow logged to my Chrome-Console:

enter image description here

For instance, it gets printed when I switch between pages of my Website (using react-router-dom). I am not consciously injecting any script (nor do I know how that would work or why I would do such a thing).
I don’t even know what “allpages.js” is, I never came across it so far.
If I click on it, to see the area that throws the error, I get the following (it is on line 83):

enter image description here

Happy to provide any further info or code and thanks everyone!

Getters vs functions for internal properties

Consider this code snippet

class A {
  constructor() {
   this._val = 5;
  }
  
  get val() {
    return this._val;
  }
  
  getVal() {
    return this._val;
  }
}

const a = new A();
console.log(`A.val: ${a.val}, A.getVal: ${a.getVal()}`);
  

Obtaining _val of object a works via both the accessor get val() as well as the regular method getVal(). Are there any differences between the two other than that the former exposes a property val on a whereas getVal() is function that is exposed as a property on a?

– Openlayers – Display popups on makers added from an object list

I’m currently learning how to use openlayers for a web application that includes a simple map. To add a popup to the map, I know that I have to create a container and a popup body in my html code then create an overlay in my script and finally add a click event on the map that displays the content of the popup.

But I am facing a problem concerning the function: my markers are not from a GeoJSON, but from a list of objects and in the majority of the examples available on the internet, we retrieve the coordinates of the different markers of the geojson and they are passed as parameters to the setPosition() method. In my case, I retrieve the coordinates using a for loop, but I get the error: “Cannot read properties of undefined (reading ‘coordinates’)” This is my code

var map = new ol.Map({
  target: 'map',
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  view: new ol.View({
    center: ol.proj.fromLonLat([2.347479, 48.860730]),  
    zoom: 12
  }),
  controls: ol.control.defaults().extend([
    new ol.control.FullScreen(),
    new ol.control.ScaleLine(),
    ])
});

class Marker {
    constructor (name, lon, lat) {
        this.name = name;
        this.lon = lon;
        this.lat = lat
    }

    getName () {
        return this.nom
    }
}


var marker1 = new Marker('Santa-Cruiz', 2.33581863894,   48.8609963623); 
var marker2 = new Site('New York', 2.28316017256, 48.8786328114);

var markers = [];
markers.push(marker1);
markers.push(marker2);


var iconStyle = new ol.style.Style({
    image: new ol.style.Icon ({
        anchor: [0.5, 1],
        src: "pin.png"
    })
});


var markerFeatures = [];
for (marker of markers) {
    var feature = new ol.Feature({
        geometry: new ol.geom.Point(ol.proj.fromLonLat([marker.lon, marker.lat])),
        name: marker.name

    });

    feature.setStyle(iconStyle);
    markerFeatures.push(feature);

}

let markersLayerSource = new ol.source.Vector({
    features: markerFeatures
});

let markersLayer = new ol.layer.Vector({
    source: markersLayerSource
});


var container = document.getElementById("popup-content");

var overlay = new ol.Overlay({
  element: container,
  autoPan: true,
  autoPanAnimation: {
    duration: 250
  }
});

map.on('click', function (event){
    closePopup();
    function popup(event) {
        for (var i = 0; i < markers.length; i++) {
        let marker = markers[i];
        var coordinates = [marker.lat, marker.lon];
        var coordinate = event.coordinates;

        content.innerHTML = getName();

        overlay.setPosition(coordinate);
    };

}

map.addLayer(markersLayer);
map.add(overlay);

Does someone have an idea on how to fix it ? Thank you !

Component double re-render caused by resize observer

I am trying to create a custom hook, to determine if width of certain element is “small”, “medium” or “large”. I do that by passing to custom hook a ref to which element resize observer is suppose to watch and by passing array which contain object with sizes and values:

const ComponentC = () => {

    const ref = useRef()

    const size = useResizeObserver(ref, [
        { small: 500 },
        { medium: 700 },
        { large: 1000 },
    ])

    console.log(size)
    
    return (
        <div ref={ref}>Hover over me</div>
    )
}

export default ComponentC;

My custom hook stores observer as ref and on starts observing ref inside of useEffect. I also have a “findBreakPoint” which determines where current width of element falls into, for instance if width of an element is 550 then its “medium” size.

export default function useResizeObserver(elRef, breakpoints) {
    const [breakSize, setBreakSize] = useState()

    const observer = useRef(
        new ResizeObserver(entries => {
            // Only care about the first element, we expect one element ot be watched
            const { width } = entries[0].contentRect
            const breakPoint = findBreakPoint(breakpoints, width)
            console.log(breakSize)
            setBreakSize(breakPoint)
        })
    )

    useEffect(() => {
        if (elRef.current) {
            observer.current.observe(elRef.current)
        }
        return () => {
            observer.current.unobserve()
        }
    }, [elRef, observer])

    return breakSize
}

function findBreakPoint(breakpoints, width) {
    const breakpointIndex = breakpoints
        .map(x => Object.values(x)[0])
        .findIndex(x => width < Math.round(x));

    // element is larger than every breakpoint so it must be the last breakpoint
    if (breakpointIndex === -1) {
        return Object.keys(breakpoints[breakpoints.length - 1])[0];
    }

    return Object.keys(breakpoints[breakpointIndex])[0];
}

Problem is that when size of element changes for example from “medium” to “large” then ComponentC renders twice for some reason, I don’t know why.

How to get an HTML table’s rows’ data whose last columns are filled in?

I’m trying to save these rows into an array, but nothing happens as I click on saveButton.
Would appreaciate any help in finding out why.

Here’s the function generating the table

function createTable(dataArray) {
if (dataArray && dataArray !== undefined && dataArray.length != 0) {
    var option = "<select name='D1'>" +
    "<option value='empty'></option>" +
    "<option value='approved'>Approved</option>" +
    "<option value='dicsuss'>Discuss</option>" +
    "<option value='cancelled'>Cancelled</option>" +
    "</select>";
    var result = "<table class='table table-sm table-striped' id='dtable' style='font-size:0.8em'>" +
    "<thead style='white-space: nowrap'>" +
    "<tr>" +                               //Change table headings to match witht he Google Sheet
    "<th scope='col'>Client</th>" +
    "<th scope='col'>Name</th>" +
    "<th scope='col'>Date</th>" +
    "<th scope='col'>Approval</th>" +
    "<td>" +
    "</td>" +
    "</tr>" +
    "</thead>";
    for (var i = 0; i < dataArray.length; i++) {
        result += "<tr>";
        for (var j = 0; j < dataArray[i].length; j++) {
            result += "<td>" + dataArray[i][j] + "</td>";
        }
        result += "<td>" + option + "</td>";
        result += "</tr>";
    }
    result += "</table>";
    var div = document.getElementById('search-results');
    div.innerHTML = result;
    } else {
    var div = document.getElementById('search-results');
    //div.empty()
    div.innerHTML = "Data not found!";
    }
}

…and this is to save it and pass the data on to be saved into a spreadsheet:

//MAKES PICKED OPTIONS AVAILABLE SO THAT SERVER - SIDE FUNCTIONS CAN WRITE THEM TO THE DESTINATION SHEETS
var saveButton = document.getElementById("saveButton"); 
saveButton.onclick = function(){
var tableData = []; 
var table = document.getElementById("dtable");

for (var i = 0; i < table.length; i++){
   let tableCells = table.rows.item(i).cells;
   let cellLength = tableCells.length;

for(let j = 0; j < cellLength;j++){
   let cellVal = tableCells.item(j).innerHTML;
   tableData.push(cellVal)
   }
}
console.log('Pushed Data: ' + JSON.stringify(tableData))
rows = JSON.stringify(tableData);  
google.script.run.formToSheets(tableData);
google.script.host.close();
}

Here’s a URL to the web app

Appreciate your help.

How to take different templates as an input based on condition using ngTemplateOutlet in angular

I have running Angular 12 application and I want to achieve a scenario where I want to display different html templates inside parent component using ngTemplateOutlet. All the different templates is a separate html files

parent.component.html

<ng-container [ngTemplateOutlet]="templatePath"> 

<ng-template #test1></ng-template> // displays the content of test1.html
<ng-template #test2></ng-template> //  displays the content of test2.html

templatePath is basically path of the html template which will come as an input property.

parent.component.ts

templatePath = './test1.html'; // not sure how to fetch the html template, so added this

test1.html

<h1>Hello</h1>

This is just a html template file. I don’t want to use component for this

test2.html

<h1>Welcome</h1>

This is just a html template file. I don’t want to use component for this

I am not sure whether ngTemplateOutlet is the right way to achieve the above scenario. Please suggest what can be used in Angular to achieve this scenario.

In Next.js is there a way to determine if if scrollRestoration was used, or even if the back button was used?

I am using the scrollRestoration feature of Next.js to restore the page position when a back button is pressed. The problem, is that it doesn’t restore the horizontal scroll position of the carousels on that page. So I have created my own session variables to track the position of each carousel and restore them on page load. The problem, is that I ONLY want to restore these scroll positions if the back/forward button was pressed. If there is an indicator that scrollRestoration was used on the page I could use that, otherwise, if there is an indication that the page was visited using the forward/back buttons that would also solve it.

Any ideas?

How to send IMAGE/MEDIA messages on WhatsApp Web?

I want to send media files or images with caption using Whatsapp URL like below:

https://web.whatsapp.com/send?phone=${PHONE_NUMBER}&text=${encodeURI(MSG)}

With the help of above URL, we can send custom messages to any PHONE_NUMBER (even if PHONE_NUMBER is not added as contact).

I want to send media files through this URL.

Disclaimer:

  1. I don’t want to use any Automation tool like Selenium, Puppeteer or any WhatsApp API.

How can I get a list of all the embed-links of many hundred videos I bookmarked in browser?

Hello dear Stackoverflow ppl,

I know HTML and so I want to code myself a little website with a collection of all of my favourite videos from youtube and other websites I have currently stored as simple bookmarks in my browser. To do this I need the embed link of all the videos you can get by clicking on “share” and “embed link” under a video (then you will get an iframe with thumbnail and so on). However I need to do this not just once, but for hundreds and thousands of videos, so I can’t copypaste all of them one by one. Kind of a batch process is required. I have absolutely no idea on how to do this. I want a html document with many thousands of iframes as an end result.

Thank you for any suggestions <3

How to increase the specificity of a class of props?

I have a component with a button. It has a default class and a class passed to its from the props. But sometimes the default class overwrites the class from the props. Is it possible to increase the specificity of the class from the props or lower the specificity of the default class?

  1. Do not suggest using !important
  2. Do not suggest to prescribe default styles for the button tag, I do not want to apply them to all buttons in the project
  3. Assigning an id for each button is also not an option
  4. In the props, it is the class name that needs to be passed, not the style
import React from 'react'
import styles from './Button.module.scss'
import classNames from 'classnames'

const Button = ({ children, className, ...props }) => {
  return (
    <button {...props} className={classNames(styles.btn, className)}>
      {children}
    </button>
  )
}