How to use Can Google Cloud be linked to APP?

Can Google Cloud be linked to APP?
Yes, Google Cloud can be linked to an app in various ways, depending on the services you want to use. Google Cloud offers a wide range of services and tools that can be integrated with your app to improve its functionality, scalability, and performance. Here are some common ways Google Cloud can be linked to an app:

  1. Cloud Storage
    If your app requires file storage (images, videos, documents, etc.), Google Cloud Storage provides a scalable and secure way to store and retrieve data. You can integrate this with your app to upload, store, and access files.

  2. Cloud SQL and Firestore
    For apps that need databases, you can use Cloud SQL (for relational databases like MySQL or PostgreSQL) or Firestore (a NoSQL database). These can be easily linked to your app to store and manage structured or semi-structured data.

  3. Google Compute Engine or Kubernetes Engine
    If your app requires a backend server, you can deploy it on Google Compute Engine (for virtual machines) or use Google Kubernetes Engine for containerized apps. These platforms allow your app to scale and handle increased traffic efficiently.

How to Link Google Cloud to Your App:
SDKs and APIs: Google Cloud provides client SDKs and APIs for most of its services, which can be integrated directly into your app’s code.
Authentication: Use Google Identity services like OAuth or Firebase Authentication to manage user logins.
Deployment Tools: Use Google Cloud’s command-line tools or CI/CD pipelines for deploying your app and linking it to various Google Cloud services.

Use a mapping function to map one property to another object

I have an array of objects as per below.

songs = [
  { 
    track_name: "name of track" , 
    track_genres: ["chamber pop","indie pop"] },
  { 
    track_name: "name of track 2" , 
    track_genres: ["dutch r&b","indie soul", "indie pop"] },
  { 
    track_name: "name of track 3" , 
    track_genres: ["indie pop","chamber pop","indie soul"] }
]

I have another mapping object that looks like this

genres = [
  {
    name: "Pop",
    children: [{name:"chamber pop"},{name:"indie pop"}]
  },
  {
    name: "R&B",
    children: [{name:"dutch r&b"}]
  },
  {
    name: "Soul",
    children: [{name:"indie soul"}]
  }
]

What I want to do is for each track, go through the track genres, and use the “genres” variable to assign the parent genres for each track. Parent genre ideally shouldn’t be repeated.

Expected Output:

const songs = [ 
{ 
  track_name: "name of track", 
  track_genres: ["chamber pop", "indie pop"], 
  parent_genres: ["Pop"] }, 
{ 
  track_name: "name of track 2", 
  track_genres: ["dutch r&b", "indie soul", "indie pop"], 
  parent_genres: ["R&B","Soul","Pop"] }, 
{ 
  track_name: "name of track 3", 
  track_genres: ["indie pop", "chamber pop", "indie soul"], 
  parent_genres: ["Pop", "Soul"] }
];

React useEffect goes in infinite loop while fetching data

I am trying to fetch some data inside my component using useEffect hook and it is going in infinite loop. I am using this react tutorial page and this race conditions page for reference. Here is my code.

function AppNew () {
  const [matchData, setMatchData] = useState(null)
  const [matchesLoaded, setMatchesLoaded] = useState(false)

  useEffect(() => {
    let active = true;
    
    const responseMatches = axiosInstance.get("api/matches/")
        .then(responseMatches => {
            if (active) {
                setMatchData(responseMatches.data);
                setMatchesLoaded(true);
            }
        })
        .catch (error => {
            throw error;
        })

    return () => {
        active = false
    }
  });
  
  console.log("match data: ");
  console.log(matchData);

} 

The API returns valid data in about 10ms. console.log statements for matchData keep writing the data to the console infinitely.

When the path of lib contains @, the type of the submodule cannot be obtained in monaco-editor, how to solve this problem?

  1. open this monaco-editor playground
  2. hover Typography and click to peek definition, and then you can’t see OriginTypography type.

Image

If rename @scope/myLib to myLib, then it can get type when peek definition, so I think there must be some problems when use addExtraLib to add some lib that its path has @, most of lib may have scope, so @ can’t be avoided.

Image

javascript number based for loop skipping iterations 1-5

I have this function and I cannot at all figure out why its doing this, there doesn’t seem to be solutions online that apply to this, I have this loop:

for (i = 0; i<components.length; i++){
        console.log(i);
        if (components[i] != null){
            components[i].draw();
        }
    }

in the console log it goes 0, 6, 7, 8, etc.. I have debugged and checked that the components array has items at 1-5. draw is called for the first component fine but it skips the second iteration all together

I can’t figure out any possible reason why this is happening, even if components was modified, ‘i’ should still continue going up by 1

How to get the value from select tag in alpine.js

I have an xml file where i am iterating the object as dropdownData

<select x-model="areaData" class="form-input w-full cursor-pointer" x-show="dropdownType==='Area'" x-on:change="selectArea($event.target.value)">
                    <template x-for="(item, index) in dropdownData" :key="index">
                        <option :value="item.dataid" x-text="item.displayname" class="workspace-data flex hover:bg-accent focus:bg-accent cursor-pointer gap-4 items-center  border-t first:border-t-0">
                        </option>
                    </template>
                </select>

 selectArea(areaItem) {
      console.log(areaItem, " <>? "); //item.dataid
 }

When i am trying to print the selected option in my selectArea method of .js file i am getting string item.dataid

How to Delete an Annotation Using Wagtail Review and Annotator.js on Button Click?

I am working with both Wagtail Review and Annotator.js in my project. I want to add a delete button (an “X” inside a red circle) to annotations, and when clicked, it should delete the corresponding annotation. I have added the delete button inside the annotation’s controls, but I am struggling to properly trigger the deletion.

What I have so far:

  • I am using Annotator.js to create and manage annotations. The annotations appear on hover over the parent element (annotator-outer annotator-viewer).
  • The delete button is injected dynamically inside the .annotator-controls span when the annotation becomes visible.
  • I am trying to use the click event to trigger the annotation deletion, but I am not sure how to properly call the Annotator.js delete function or if I am handling the interaction correctly within Wagtail Review.

Here’s the current approach I have:

  1. When the annotation parent (.annotator-outer.annotator-viewer) is hovered, I dynamically add the “X” delete button inside .annotator-controls.
  2. I attach a click event listener to the delete button.
  3. I expect the click to trigger the annotation deletion using Annotator.js.

Code snippet:

document.addEventListener('DOMContentLoaded', (event) => {
    function deleteAnnotation() {
        console.log('Delete function triggered!');
        // Assuming annotator.js method is accessible to delete the annotation
        if (window.annotator && window.annotator.deleteSelected) {
            window.annotator.deleteSelected();
            console.log('Annotation deleted');
        } else {
            console.log('annotator.js method not found.');
        }
    }

    function injectTextAndAddEvent(span) {
        span.textContent = '×'; // Add delete button content
        span.addEventListener('click', deleteAnnotation); // Attach click event
    }

    document.querySelectorAll('.annotator-outer.annotator-viewer').forEach(parentDiv => {
        parentDiv.addEventListener('mouseenter', function() {
            const span = parentDiv.querySelector('.annotator-controls');
            if (span) {
                injectTextAndAddEvent(span);
            }
        });
    });
});

Problem:

  • The button appears as expected, but clicking it does not delete the annotation.
  • I’m not sure if I’m using the correct Annotator.js method or if there’s a better way to interact with the annotations inside the Wagtail Review framework.

What I need help with:

  • How can I properly trigger the deletion of an annotation using Annotator.js when clicking the delete button?
  • Is there a specific method in Annotator.js or Wagtail Review that I should use for deleting annotations?

I would appreciate any insights from someone familiar with both Annotator.js and Wagtail Review.

How to save files to a directory using FileSystemDirectoryHandle?

I’m trying to look for some documentation on FileSystemDirectoryHandle and if it is possible to save files to the opened directory. I’ve been searching for a couple hours now, any help will be appreciated.
-Alex

I tried searching on google but I’ve only found base overviews of the api. And I’ve tried looking at the returned object itself

After changing the length of a page, why do I have to pause for a split-second before auto-scrolling?

In response to user input, I clear the nodes in a container, then copy some other nodes in. This changes the length of the page.

I wanted to scroll back to the top right after this, so added this:

window.scrollTo({ top: 0, behavior: 'smooth' });

But it wasn’t working. It never scrolled back to the top. Sometimes it scrolled partially, sometimes it didn’t do anything. It was inconsistent.

I got to wondering if it was a timing thing, so I added this, after copying the nodes in.

await new Promise(r => setTimeout(r, 10));
window.scrollTo({ top: 0, behavior: 'smooth' });

Sure enough, waiting 1/100th of a second before scrolling makes if work perfectly, every time. I’ve tried every combination of async/await, and nothing works other than pausing for a split-second before scrolling.

I’m assuming the page is calculating its height, or the required amount of scroll, in the moment before the nodes are copied in? How realistic is that assumption?

Is there some more elegant way to handle this, other than my (ugly) pause?

Is there a way to create the package.json based on the code?

I just start to study javascript and vue and trying to build the example project todo-vue. But it seems that the modules in package.json are too old and always fail during the “npm install”.

Is there a way that the package.json file can be updated with the latest version or regenerated from the project code? Or is there a way to make the project work?

Not sure it is a valid question. But I did try some example projects and all failed due to the mdoule version.

sweetalert2 call new popup when a popup still on page, prevent run codes after await in function

With sweetalert2 we move form a popup to other popup… without closing with any standard method before switching… just fire a new one that we need.

now I test script and see when call fire for new popup, code lines after await Swal.fire();... first function not run!

In this case we need run some code when a Swal popup is dismissed with firing new one…(dismiss without reason based on documentation)

If a popup is dismissed by Swal.close() or another popup, the Promise will be resolved with an object { isDismissed: true } (dismiss will be undefined).

if rejected and not resolved should be throw exception.isn’t it?
I test this function for example, call two time(with waiting):

async function x() {
    console.log(1111);
    await Swal.fire();
    console.log(2222);
}

I think should write log 2222 after second call but just log 1111 for second call, after acting to confirm second popup write log 2222! without error!
await Swal test result

+note: I test a promise instead of Swal. with promise correctly worked, but Swal has problem!
await Promise test result

Why did something happen?
Regardless of the version we are using, can anyone tell why this is happening?

React native new architecture VS flutter

Which framework ( react native with the new architecture / Flutter ) is more suitable for mobile applications development

A generale comparison between the two frameworks ( proformance , speed … )
Or even a review of the new react native architecture

Calculate point coords relative to a rotated DIV

I have a rotated DIV within a non-rotated DIV and I’m trying to work out the cursor position on the outer DIV in relation to the rotated DIV. I guess I need the position as though the coordinate system has been rotated to match the angle of the rotated div.

Following is an example of what I need:

rotated DIV within a DIV

I know or can easily get:

  • w1, the width of the outer DIV
  • h1, the height of the outer DIV
  • w2, the width of the inner/rotated DIV
  • h2, the height of the inner/rotated DIV
  • a, the angle of the rotated DIV
  • x1, the x coord of a point P
  • y1, the y coord of a point P

I don’t know how to get, but need, x2 and y2.

I’m trying to use a for loop to increment through multiple button elements so I can assign different actions to them

I cannot figure this out, Here is the code,
I am very much new to javascript and I’ve read through MDN docs and haven’t come up with anything.

let numberOfbuttons = document.querySelectorAll(".numbers");

for (i = 0; i < numberOfbuttons; i++) {
  document.querySelectorAll(".numbers")[i].addEventListener("click", function() {
    document.querySelector(".result").innerHTML = "1"
  })
};
body {
  background-color: blanchedalmond;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.Calc {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
  grid-area: 2/2;
}

button[value="0"] {
  grid-area: 5/2/5/2;
}

button {
  background-color: aliceblue;
  color: black;
}

button[value="AC"] {
  grid-area: 5/1;
}

button[value="+"] {
  grid-area: 3/4;
}

button[value="-"] {
  grid-area: 2/4;
}

.result {
  grid-area: 1/1/1/5;
  background-color: #CBD2A4;
  text-align: center;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8" />
  <title>Calculator</title>
  <link rel="stylesheet" href="styles.css" />
  <link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet" />
</head>

<body>
  <div class="Calc">
    <div class="result">
      <p>Type in your "numbers"</p>
    </div>

    <button class="numbers">1</button>
    <button class="numbers">2</button>
    <button class="numbers">3</button>
    <button class="numbers">4</button>
    <button class="numbers">5</button>
    <button class="numbers">6</button>
    <button class="numbers">7</button>
    <button class="numbers">8</button>
    <button class="numbers">9</button>
    <button class="numbers">0</button>
    <button value="AC">AC</button>
    <button value="+">+</button>
    <button value="-">-</button>
    <button value="*">x</button>
    <button value="/">/</button>
    <button value="=">=</button>
  </div>
  <script src="index.js" charset="utf-8"></script>
</body>

</html>

How to avoid gaps in the lifecycle of a react component

I’m currently learning how to use function components in react and got a bit of a timing problem. As it seems, the event that should trigger a rerender is called between the rendering of the component and the call to the useEffect hook. Is there any delay between those two that would allow an async event to be executed? And how would I prevent this “gap”? (I do not remember about every having such a problem with class components and the componentDidMount function for registering my eventListener back then).

Given this component (with very simplified types and logic):

export default function CounterDisplay(): React.JSX.Element {
    const [lastEventInstance] = useEvent('counter_changed_event');

    const counter = lastEventInstance ? lastEventInstance.counter : 0;

    console.log('Start rendering CounterDisplay: ', counter);
    return (
        <div>{counter}</div>
    );
}

with this custom event hook:

export function useEvent(eventName: string) {
    const [lastEventInstance, setEventInstance] = useState<undefined | {counter: number}>(undefined);

    useEffect(() => {
        function handleEvent(event: EventDefinition) {
            console.log('Pushing new event into the state');
            setEventInstance(event);
        }

        console.log('Listening to event ' + eventName);
        EventManager.addEventListener(eventName, handleEvent);
        return () => {
            console.log('Stop listening to event');
            EventManager.removeEventListener(handleEvent);
        };
    }, [lastEventInstance]);
    return [lastEventInstance];
}

I get this output in the console:

> Start rendering CounterDisplay: 0
> EventManager notifies event "counter_changed_event" with data {counter: 1}
> Listening to event counter_changed_event

while the html output keeps showing the value 0.
And to be clear: Yes, the {counter: 1} object is an entirely new object that is definetely even shallowly different from the previous.

I hope someone can help me with this, as this is at the moment a nasty race condition.