import class in typescript is throwing an error

Trying to import class in the file and it is throwing an error it might be quick fix i would appreciate the help.

class.ts

export class Cache {
    private cache: CCache;
    public async getCache(tokenId: string): Promise<any> {
        // add logic here 

        return memberInfo;

    }

}

otherFile.ts

    import { Cache } from "./class.ts";
        public before(args: any) {
        let specialtyCache: any;
        specialtyCache =  new Cache().getCache(args.token);
}

Error

Constructor of class 'Cache' is private and only accessible within the class declaration.ts

Javascript regex replace character if preceded AND followed by a letter

Basically I am working with a string that is a json string and I would like to turn it into a real json (by using the JSON.parse()) but there are some quotation marks in the middle of the sentences.

Example: ‘{“author”: “Jonah D”Almeida”, … }’
(I want to replace the one in between D and Almeida)

As it already has quotation marks around the whole sentence, javascript gives an error because it can’t create a json out of it and so, to solve that basically I want to replace the quotation mark in the middle of the sentence for a ‘ but only if it has letters preceeding and following the quotation mark.

My thought: myString.replace('letter before ... " ... letter after', "'")

Any idea how can I get this right?

React memo creates rerender in next.js app

I’m having an issue with react memo when using nextjs. In the _app e.g. I have a button imported:

Import { ChildComponent } from './ChildComponent';
        
const Button = ({ classN }: { classN?: string }) => {
      const [counter, setCounter] = useState(1);    

      return (
          <StyledButton
            onClick={() => setCounter(counter + 1)}
          >
            {counter}
            <ChildComponent>
          </StyledButton>
        );
      };

Child component:

import React from 'react';

export const TestComponent = React.memo(
  () => {
    React.useEffect(() => {
      // eslint-disable-next-line no-console
      console.log('rerender child component');
    }, []);

    return <p>Prevent rerender</p>;
  },
  () => false
);

Tested in Nextjs and React but the Codesandbox for Nextjs is not working, so unfortunately I can’t share it (as in the framework won’t start). So here is the working one:
https://codesandbox.io/s/objective-goldwasser-83vb4?file=/src/App.js

How to turn a Javascript Object into a CSS style sheet

I have an object that goes

'buttonProperties' {
    backgroundColor : 'green'
    fontSize : '10px'
}

How would I make the button use those properties using a method like:

Object.keys(buttonProperties).forEach((x) => {
    button.style[x] = buttonProperties[x];
})

const buttonProperties = {
        backgroundcolor: 'green', 
        textSize : '10px'
},

button = document.getElementById('button')

button.addEventListener('click', () => {
  Object.keys(buttonProperties).forEach((x,i) => {
      button.style[x] = buttonProperties[x]
  })
})
<button id = 'button'>Submit</button>

How to get the file chooser window to close using Puppeteer?

I’m using Puppeteer to upload a file from my desktop to a website. It does upload the file, but the file explorer window stays opened and so the automation stops working.

const [fileCHooser] = await Promise.all([
        page.waitForFileChooser(),
        page.click("upload button id"),
    ]);

    await fileCHooser.accept(["dektop/example.csv"]);

Is there a way I can force it to close?

Merge content of several pdf documents

I get lot’s of stamp-documents like this every day:

stamp-doc

There is lot’s of white space under every stamp. If I print them, that cost’s lots of paper, so I want to merge the content of several documents into one pdf-document. So that I can place like 8 stamps on into one document and just have to print one page instead of 8.

I want to solve this problem with javascript (or node.js) and I’ve already found some pdf-libraries, but these libraries just let me copy whole pages and don’t eliminate the white-space.

Are there any suggestions?

I also thought about converting the pdf to png or jpeg and cut the whitespace of the image, but I don’t if that’s possible.

I would really appreciate your help πŸ™‚

Javascript fire function from object

I would like to add a path on an svg, from an “object”.
myPath() for the attribute d works fine, but
I want to trigger my function from the object obj, and the obj.action() for d doesn’t work… Why ?

var obj = {
  action: function() {
    myPath();
  }
}

function myPath() {
  return "M 10 10 L 50 10 L 50 90 L 10 90 Z";
}

$("button").on('click', function() {
  // doesn't work... :-(
  $("svg").find("path").attr("d", obj.action());

  // ... but it's working with this :
  //$("svg").find("path").attr("d", myPath());
});
svg {
  width: 100px;
  height: 100px;
  background-color: #C0C0C0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>Click Me</button>
<svg><path /></svg>

What are some reasons Selenium wouldn’t find an Element?

I’m writing an automated test for a Web-based application that’s coded in JavaScript and uses the Dojo framework. I can find the elements I want the bot to find in Developer Tools using well-defined XPATHS, but the automated test fails to find the text the XPATH leads to.

My test code looks something like this:

if verified:
     verify_detail.set_pass()
else:
     raise AssertionError("Cannot verify detail. Text did not match expected value.")

And the text I’m looking for on the UI isn’t misspelled in the config file.

Anyone else have this problem? XPATH works in Developer Tools but fails when the test is run.

Use Javascript to parse a sub-array of a JSON [duplicate]

I’m working with some JSON objects about homes. The JSON looks like the below. How would I use Javascript parsing to pull out the “yearBuilt” value? It’s part of the building array, which is part of the parcel array.

I’ve explored looping based on other similar asked-questions, but can’t arrive at anything that seems to work. Thanks!

{
   "home_value":298900,
   "page_url":"https://www.example.com/",
   "parcel":{
      "address":{
         "full":"123 Main Street",
         "city":"Raleigh",
         "state":"NC",
         "house":"2856",
         "houseExt":null,
         "street":"Jameson",
         "streetPre":"W",
         "streetPost":null,
         "streetSuffix":"Rd",
         "unit":null,
         "unitType":null,
         "zip":"27604",
         "zip4":"3776"
      },
      "apn":"1725.14-22-9727 0145193",
      "areas":[
         {
            "type":"Heated Building Area",
            "areaSquareFeet":1574
         },
         {
            "type":"Calculated Finished Area",
            "areaSquareFeet":1574
         }
      ],
      "building":[
         {
            "noOfUnits":1,
            "class":null,
            "classDescription":null,
            "quality":null,
            "condition":null,
            "architecturalStyle":"Conventional",
            "yearBuilt":1986,
            "effectiveYearBuilt":1986,
            "totalStories":2,
            "totalRooms":null,
            "bedrooms":null,
            "kitchens":null,
            "fullBaths":2,
            "baths":2,
            "comments":null,
            "occupancyStatus":"Assumed Owner Occupancy",
            "heating":"Forced air",
            "airConditioning":"Yes",
            "foundation":null,
            "fireplace":null,
            "water":null,
            "sewer":null,
            "quarterBaths":null,
            "halfBaths":0,
            "threeQuarterBaths":null
         }
      ],
      "state":"NC",
      "zoningCode":null,
      "zoningDescription":"R-6",
      "zpid":"6487528",
      "county":"Wake County"
   }
}

Как ΠΏΡ€ΠΈ ΠΊΠ»ΠΈΠΊΠ΅ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡƒ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ Ρ‚Π°ΠΊ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠ΅ ΠΊΠ½ΠΎΠΏΠΊΠΈ ΠΎΡΡ‚Π°Π²Π°Π»ΠΈΡΡŒ Π°ΠΊΡ‚ΠΈΠ²Π½Ρ‹ΠΌΠΈ?

Π£ мСня Π΅ΡΡ‚ΡŒ список ΠΊΠ½ΠΎΠΏΠΎΠΊ, ΠΈ ΠΌΠ½Π΅ Π½ΡƒΠΆΠ½ΠΎ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€ΠΈ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΈ Π½Π° ΠΏΠΎΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠ΅ ΠΊΠ½ΠΎΠΏΠΊΠΈ, ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠ΅ ΠΎΡΡ‚Π°Π²Π°Π»ΠΈΡΡŒ Π°ΠΊΡ‚ΠΈΠ²Π½Ρ‹ΠΌΠΈ. ΠŸΠΎΠΌΠΎΠ³ΠΈΡ‚Π΅ это Ρ€Π΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Ρ‚ΡŒ

Is there a way to fix a batch size mismatch between output from final model layer and input?

What I’ve done: I have a complete dataset of 898 labels with a total of ~55,000 images. For purposes of speed, I took 10 of those labels and about ~600 images to test the code below. I’ve tried changing the batchSize, modifying the data function, but to no avail.

Problem: Error: Batch size mismatch: output dense_Dense1 has 10; expected 500 based on input conv2d_Conv2D1_input.

Goal: Either change the final output of dense_Dense1 to have 500, or change the expected input of conv2d_Conv2D1_input to only 10.

Complete Code:

var tf = require('@tensorflow/tfjs');
var tfnode = require('@tensorflow/tfjs-node');
var fs = require(`fs`)

const numberOfClasses = 10;

const imageWidth = 500;
const imageHeight = 800;
const imageChannels = 3;

const batchSize = 3;
const epochsValue = 5;

const createImage = async (fileName) => {
  const imageBuffer = await fs.readFileSync(fileName);
  const image = await tfnode.node.decodeImage(imageBuffer);
  return image;
}

const labelArray = indice => Array.from({length: numberOfClasses}, (_, k) => k === indice ? 1 : 0)

async function* data() {
  for (i = 1; i < numberOfClasses+1; i++) {
    for (x = 10; x < 40; x++) {
      const feature = await createImage(`./images/${i}/${i}-${x}.png`) ;
      const label = tf.tensor1d(labelArray(i))
      yield {xs: feature, ys: label};
    }
  }
}

function onBatchEnd(batch, logs) {
  console.log('Accuracy', logs.acc);
}

const main = async () => {
  const model = tf.sequential();

  model.add(tf.layers.conv2d({
    inputShape: [imageWidth, imageHeight, imageChannels],
    filters: 8,
    kernelSize: 5,
    padding: 'same',
    activation: 'relu'
  }));
  model.add(tf.layers.maxPooling2d({
    poolSize: 2,
    strides: 2
  }));

  model.add(tf.layers.conv2d({
    filters: 16,
    kernelSize: 5,
    padding: 'same',
    activation: 'relu'
  }));
  model.add(tf.layers.maxPooling2d({
    poolSize: 3,
    strides: 3
  }));
  
  model.add(tf.layers.flatten());

  model.add(tf.layers.dense({
    units: numberOfClasses,
    activation: 'softmax'
  }));

  model.compile({
    optimizer: 'sgd',
    loss: 'categoricalCrossentropy',
    metrics: ['accuracy']
  });

  model.summary()

  const ds = tf.data.generator(data);

  model.fitDataset(ds, {
    epochs: 5,
    batchSize: 10,
    callbacks: {onBatchEnd}
  }).then(info => {
    console.log('Final accuracy', info.history.acc);
  });

}
main()

Javascript eventListener inside while loop

I am trying to figure out whether it is possible in Javascript to implement an eventListener into a while loop which can pass a value to a variable inside the loop. I need this to cancel an infinite loop which continiously should send a data frame to a TCP-socket (watchdog). When the socket is closed the loop should end. I use a webworker for this purpose, but it does not work.
Here is the code:

// WebWorker with infinite loop

var check = "true";
let i=0;
let j=0;
var returnedEvent;

while(check){

self.postMessage(i);


onmessage = (event) => { 

    returnedEvent = event.data;
    console.log("worker: " + event.data);
    let check = returnedEvent;  
    }
    
    sleep(100);
    
}
console.log("loop completed");

function sleep(delay)
    {
    var start = new Date().getTime();
        while (new Date().getTime() < start + delay);
    }

in

Laravel not laoding vue js and css

i looked already in every question and couldn’t find a solution for my problem
I am looking forward to your help.
My Problem: i use Laravel 8 and tried to implement Laravel Chatter and now it’s working partly but the vue css and vue js is not loading…every normal css and js is loading Screenshot here please help me to fix this.. Heres is a screenshot from browser dev tools Screenshot from browser dev tools
Vue is already binded in app.js and everything is done
Thanks!
Greets LaviS

Link the entire box

i have the element “box” with some text and a link.

<div class="box bg-gray-300 w-48 flex-auto text-center p-10 group hover:bg-red-900 hover:cursor-pointer"><div class="group-hover:text-white">Text</div><div><a href="http://www.google.com" class="group-hover:text-white">LINK</a></div></div>

Here you can find the sample code: https://play.tailwindcss.com/uOHpX71hJq

How can i have the link AND the hover on the entire box? With Javascript i can trigger only the click, but not the hover? I found a working example on the tailwind website: enter link description here

enter image description here