Flipping a Leaflet.js map

There is a Leaflet.js map that the user cannot move with the mouse (it is necessary that there be only one map that does not move to another)

var map = L.map('map', {
    dragging: false,
    touchZoom: false,
    scrollWheelZoom: false, 
    doubleClickZoom: false, 
    boxZoom: false,
    maxBounds: L.latLngBounds(L.latLng(40, -10), L.latLng(60, 10)),
    maxBoundsViscosity: 1.0
}).setView([51.505, -0.09], 2);

var osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
osm.addTo(map);

You need to make an input of type range so that you can scroll through the map without going beyond the borders. I tried it myself but it does not work correctly (it does not scroll).

I leave the code of what I did myself. It can be useful

<section class="map-section">
  <div class="map-container">
     <div id="map"></div>
     <input type="range" id="horizontal-pan-slider" min="-50" max="50" step="1" value="0">
  </div>
</section>
var horizontalPanSlider = document.getElementById('horizontal-pan-slider');


horizontalPanSlider.addEventListener('input', function() {
  var horizontalPanValue = parseInt(horizontalPanSlider.value);
  var mapBounds = map.getBounds();
  var horizontalOffset = (mapBounds.getEast() - mapBounds.getWest()) * horizontalPanValue / 100;
  map.panBy([horizontalOffset, 0], { animate: false });
});

how to insert multiple documents in mongodb

image of student model
i have a model student which have ref to model Profile,
i have array of object having data for student fields and Profile feilds both,
so if i use insertMany i can not create document for profile first then give its ref to student then create student
how can i do operation on that array of objects so that first profile document is created then student

is there any other method or can we do it with insertmany

React router cant find createBrowserHistory from @remix-run/router when am using react/components/router in plain html

I know how to make react applications using ‘create-react-app’ but in this particular use case i need to include all the dependencies from cdns the components need to be dynamically generated via php and are to be included as babel src script tags then babel Babel.transformScriptTags(); needs to be run to start the react application. This is the sctrict requirement in my situation that all of this needs to be generated dynamically via php then when all is loaded in browser i need to stert the react app on the client side.
For brevity to present here i have just included the code in script tags as static in the same html file.

When i am just only displaying the components the react app does start this problem arises when i am using react router as a js file;

The issue here is react router cant find the “createBrowserHistory” also the route does not render giving error

“React.createElement: type is invalid”

“index.tsx:341 Uncaught TypeError: Cannot read properties of undefined (reading ‘createBrowserHistory’)”

there is an import in the generate index.tsx as follows

import {
  createRouter,
  createBrowserHistory,
  createHashHistory,
  joinPaths,
  stripBasename,
  ErrorResponse,
  UNSAFE_invariant as invariant,
  UNSAFE_warning as warning,
} from "@remix-run/router";

will including this manually solve the problem ? or is there something else ? if it is possible to run router this way what is the mistake i am doing ?

<!DOCTYPE html>

<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
    <script crossorigin src="https://unpkg.com/[email protected]/umd/history.production.min.js"></script>
    <script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react-router/6.14.1/react-router.development.js"></script>
    <script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react-router-dom/6.14.0/react-router-dom.development.js"></script>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/style.css" />
</head>

<body>
    <div id="root"> ROOT </div>
    <script crossorigin type="text/babel" data-type="module" data-plugins="transform-modules-umd" defer src="./components/Demo.js"></script>
    <script crossorigin type="text/babel" data-type="module" data-plugins="transform-modules-umd" defer src="./App.js"></script>
    <script crossorigin type="text/babel" data-type="module" data-plugins="transform-modules-umd" defer src="./index.js"></script>
    <script type="text/javascript">
        //window.createBrowserHistory = HistoryLibrary.createBrowserHistory;
        window.onload = function () {
            new Promise(function (resolve, reject) {
                var script = document.createElement('script');
                script.setAttribute('type', 'application/javascript');
                script.onload = resolve;
                script.onerror = reject;
                script.src = 'https://unpkg.com/@babel/standalone/babel.min.js';
                document.getElementsByTagName('head')[0].appendChild(script);
            }).then(function () {
                console.log('running babel');
                Babel.transformScriptTags();
            });
        }

    </script>
    <script type="text/babel" data-type="module" data-plugins="transform-modules-umd">
    </script>
    <script type="text/babel" data-type="module">
    </script>
</body>

</html>
import React, { Component } from "React";

const Demo = (props) => {
    console.log('demo');
    return (
        <div>demo : {props.type}</div>
    )
}

export default Demo;
import React from "React";
import ReactDOM from 'ReactDOM';
import App from './App';

const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(<App />);
import React from "React";
//import ReactDOM from 'ReactDOM';
import { createBrowserHistory } from "HistoryLibrary";
import { BrowserRouter } from "ReactRouterDOM";
import AppRoutes from './AppRoutes';
import Demo from './components/Demo';

function App() {
    return (
        <BrowserRouter>
        <AppRoutes />
    </BrowserRouter>
    );
}
export default App;
import React, { Component } from "React";
import { createBrowserHistory } from "HistoryLibrary";
import { Routes, Route, Outlet, Link  } from "ReactRouterDOM";
import Demo from './components/Demo';

function AppRoutes() {
    return (
        <Routes>
            <Route path="/" element={<Demo type="main" />}>
                <Route index element={<Demo type="main" />} />
                <Route path="about" element={<Demo type="about" />} />
                <Route path="dashboard" element={<Demo type="dashboard" />} />
                <Route path="*" element={<Demo />} />
            </Route>
        </Routes>
    );
}

export default AppRoutes;

I have tried using the basic react components which works in the above method but now i am trying to use react router this way and it does not work. I know and have used react router in create-react-app and have made several projects also but never done as a html include so is this possible to do if so then how ?

Dragonbones displayed but wont animate in PixiJS game

I am having a hard time making my animation work…
My project is a game made with PixiJS and vanilla JavaScript, and I need to animate game character via Dragonbones files.
The thing is that Dragonbones character is visible on screen and positioned as it should, but it is not animating when I call the animation name.

My code is down below, the first part of the code is about importing and loading Dragonbones files and it is working properly, the second part of the code is about calling animation.
I have tried to add “ticker”, and update it via “clock”, “world clock”, and “FPS” but again and again nothing is happening, my character is visible on screen and not moving…
Any help is welcomed.


    const femaleVikingTextures = PIXI.Loader.shared;
    femaleVikingTextures
      .add("female_viking_ske", "dragonbones_assets/female_viking_ske.json")
      .add("female_viking_tex", "dragonbones_assets/female_viking_tex.json")
      .add(
        "female_viking_tex_image",
        "dragonbones_assets/female_viking_tex.png"
      )
      .load(femaleVikingSetup);

    function femaleVikingSetup() {
      dbfactory.parseDragonBonesData(
        femaleVikingTextures.resources["female_viking_ske"].data
      );
      dbfactory.parseTextureAtlasData(
        femaleVikingTextures.resources["female_viking_tex"].data,
        femaleVikingTextures.resources["female_viking_tex_image"].texture
      );

      self.armature = dbfactory.buildArmature("Armature");

      setTimeout(() => {
        self.armature.animation.play("animtion0");
        self.armature.display.anchor.set(0.45, 1);
        self.armature.display.position.set(-20, -380);
        self.armature.display.scale.x = 0.95;
        self.armature.display.scale.y = 0.95;

        self.femaleVikingContainer.addChild(self.armature.display);
      }, 1000);
    } ```

Removing Null Value from the Json

Hi I have below JSON Format, how to remove the values which contains blank value or null value.

dataJSON==
    {
      "Cli Info:Sub_Ind":""
      "Cli Info:Sub_Mat":"",
      "Cli Info:Sub_Ewwu":"",
      "Cli Info:Sub_kjlo":"",
      "Cli Info:Sub_uti":"",
      "S Funds:S_C_origin":"Afghanistan;Albania",
      "S We:Count_we":"Antigua & Barbuda;American Samoa;Austria",
      "Add Juri:Jurid_Coun":"Andorra;Angola"
     }

kindly anyone from community help me to remove the null value in above JSON with the help of Javascript.

i tried the approach but not working.


 function clean(obj) {
  for (var propName in obj) {
    if (obj[propName] === null || obj[propName] === undefined) {
      delete obj[propName];
    }
  }
  return obj
}

I am expecting to remove all the null,blank and undefined values from the JSON

Timer counter for auction products on the archive page

The auction product timer counter works fine on the single store page, I want to add it to the store archive page as well, but it only displays for the first product in the store archive and does not show the rest.

Based on Countdown timer until product sale ends on WooCommerce single product page answer code, here is my code attempt:

function sales_timer_countdown_product() {
    global $product;
    $sale_date = get_post_meta( $product->get_id(), '_sale_price_dates_to', true );
    if ( ! empty( $sale_date ) ) {
        ?>
        <script>
            // Set the date we're counting down to
            var countDownDate = <?php echo $sale_date; ?> * 1000;
            // Update the count down every 1 second
            var x = setInterval(function() {
                // Get today's date and time
                var now = new Date().getTime();
                // Find the distance between now and the count down date
                var distance = countDownDate - now;
                // Time calculations for days, hours, minutes and seconds
                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                // Output the result in an element with id="saleend"
                document.getElementById("saleend").innerHTML = days + "d " + hours + "h " + minutes + "m " + seconds + "s ";
                // If the count down is over, write some text
                if (distance < 0) {
                    clearInterval(x);
                    document.getElementById("saleend").innerHTML = "The sale for this product has EXPIRED";
                }
            }, 1000);
        </script>
        <!-- this is where the countdown is displayed -->
        <p id="saleend" style="color:red"></p>
        <?php
    }
} add_shortcode( 'sales_timer_countdown_product', 'sales_timer_countdown_product' );

What is the problem?

In Stripe How to Avoid a user making multiple callback with same session_id

I have a payment system using a stripes checkout session where a user pays and then is redirected to a success page where I make a call to my BE with the session Id and check the status & client_reference_id and then allot the credit. Now After this step, I want to avoid a scenario where the user uses the same session ID and gets more and more credits using the same session Id.

I thought expiring a session but it only works on open
status.

Is there any way to avoid this?

Can’t get a word out of random letters [closed]

Can’t get a word out of random letters?

var alphabet = "abcdefghijklmnopqwxyz";
var randomWord = alphabet[Math.floor(Math.random() * alphabet.length)];
var randomString = "";
let a = 2
let b = 1
while (randomString.length < 6) {
  randomString += randomWord
};
console.log(randomString);

Can’t get a word out of random letters

scrape data from tables using playwright

I’m new to playwright and node. Need to scrape some tables, so want to check whats the most efficient way of scraping the large data from tables:

  1. Is it by locating the table with locator and looping through all rows and columns?
  2. Or is it possible to get all the html content of table at once and then get the data from it? if yes, what would be the most efficient way?
  3. Or any other suggested approach?
    Note: some cells contain anchor tags so will need to get the href values as well.

TIA.

I am making an event listener where I need to put a function but I am having problems in doing so

I have made a function outside the event listener:
function nextSequence(){
Some something here
}
Then I had an event listener:

$(document).keydown(

after this I used to make a nameless function earlier but now I want to input a function that has been earlier made. So how do I do it

I tried
$(document).keydown(nextSequence ())
But nothing happened

Redirect to route onSubmit of React Hook Form

With React Hook Form, I want to redirect user to /Page2 on Submit.

However, for some reason, I am getting redirected to http://localhost:3000/#/
I have event.preventDefault(), but still not sure why the redirect is happening to / and not to Page2

const onSubmit = async (data, event) => {
    event.preventDefault();
    history.push("/Page2"); // history = useHistory()
    return false;
};


<form ref={formRef} onSubmit={handleSubmit(onSubmit, onError)}>
    <Input 
        {...register("name")} 
        inputProps={{maxLength: name.maxLength}}
    />
    <Button
        variant="cta"
        type="submit"
        disabled={!isValid}>
        Continue
    </Button>
</form>

in next.js 13.4 why useRouter dosen’t contain pathname or query?

I passed pathname and query but its not working in userRouter hook. when I console.log then it dosen’t show any pathname or uery parameters.

"use client";
import { useRouter } from "next/navigation";
import React, { useEffect, useState } from "react";

const ProductDetails = () => {
  const router = useRouter();
  const [product, setProduct] = useState({});
  const [isLoading, setLoading] = useState(false);

  useEffect(() => {
    setLoading(true);
    setProduct(router.query);
    setLoading(false);
  }, []);

  console.log(product);
  return (
    <div>
      <img src={product.image} alt='productImg' />
    </div>
  );
};

export default ProductDetails;

CSS transition buggy and stuttering in Safari but works perfectly in Chrome

This is my first post here so sorry if something isn’t formatted correctly.
CSS:

.para {
    position: absolute;
    pointer-events: none;
    transition: transform 0.45s cubic-bezier(.2,.49,.32,.99) 0s;
    -webkit-transition: transform 0.45s cubic-bezier(.2,.49,.32,.99) 0s;
}

JavaScript:

const para_el = document.querySelectorAll(".para");
let xVal = 0, yVal = 0;

window.addEventListener("mousemove", (e) => {
    xVal = e.clientX - window.innerWidth / 2;
    yVal = e.clientY - window.innerHeight / 2;

    para_el.forEach(el => {
        let speedx = el.dataset.speedx;
        let speedy = el.dataset.speedy;
        el.style.transform = `translateX(calc(-50% + ${-xVal * speedx}px)) translateY(calc(-50% + ${yVal * speedy}px))`;
    })
})

The above code is for a parallax effect. it works perfectly on Chrome but not on Safari. It works fine on both browsers up until I add the transition CSS but after that Safari refuses to correctly render it. It glitches and stutters about, almost as if Safari thinks the cursor is somewhere else for a fraction of a second, before snapping everything back to where it should be. I’ve spent over 2 hours trouble shooting this and I haven’t got anywhere with it, I don’t think it’s a webkit issue since as far as I know Chrome uses webkit too on MacOS (since -webkit-transition: 0s; disables the transition on both browsers). Is this a Safari bug or does Safari just for whatever reason treat my CSS different to every other browser? Thanks.

Jest error Cannot find module ‘@babel/preset-env’

I am having great trouble using Vue Jest Unit Test. This is the most complicated installation I have ever done, which was to install Jest Unit Test and get it running. So far, I have created done the following installation steps:

  1. npm install -g @vue/cli@latest
  2. npm install
  3. vue add unit-jest
  4. Added "test": "jest" to scripts in package.json
  5. Added jest: true to .eslintrc.js
  6. The installation auto-generated an example.spec.js file.
  7. I then ran npm test and now I am facing the failure error for my example.spec.js file.
Cannot find module '@babel/preset-env'

Make sure that all the Babel plugins and presets you are using
    are defined as dependencies or devDependencies in your package.json
    file. It's possible that the missing plugin is loaded by a preset
    you are using that forgot to add the plugin to its dependencies: you
    can workaround this problem by explicitly adding the missing package
    to your top-level package.json.


    Require stack:
      node_modules/@babel/core/lib/config/files/plugins.js
      node_modules/@babel/core/lib/config/files/index.js
      node_modules/@babel/core/lib/index.js
      node_modules/jest-snapshot/build/InlineSnapshots.js
      node_modules/jest-snapshot/build/State.js
      node_modules/jest-snapshot/build/index.js
      node_modules/jest-runtime/build/index.js
      node_modules/@jest/core/build/cli/index.js
      node_modules/@jest/core/build/jest.js
      node_modules/jest-cli/build/cli/index.js
      node_modules/jest-cli/build/index.js
      node_modules/jest-cli/bin/jest.js
      node_modules/jest/bin/jest.js

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.524 s

Please help me, I have been spending a few hours and the installation for Jest unit test is still incomplete. What do I need to do? I am using Vue.

example.spec.js

import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
  it('renders props.msg when passed', () => {
    const msg = 'new message'
    const wrapper = shallowMount(HelloWorld, {
      props: { msg }
    })
    expect(wrapper.text()).toMatch(msg)
  })
})