ascii art using letter in javascript [duplicate]

Create a program that translates the input (any combination of X, Y, or Z) to their low-resolution
ascii art-like representation (use letter ‘O’ as the character to draw the letters).

Input Parameters:

  • letters – any combination of the letters X, Y, and Z (example: XYZ, ZXY, ZZXXXYYYYY)
  • size – block size of each letter; odd numbers, greater than or equal to 3 (example: 3, 5, 7, 9… etc)
  • direction – horizontal or vertical

more for a beginner coding and i could not find any refence other reference ive found is make image into ascii art and it would be helpful if it could be explained every part.thank you

Playwright headless tests are slower than headful tests

Playwright headless tests are supposed to be faster than the headful tests. My headful tests are taking ~17sec and headless ones are taking ~1min.

Looking into the problem, I saw that in headless mode, the chrome might be running without gpu acceleration and I should force enable gpu acceleration through flags like

--use-gl="swiftshader"
--enable-unsafe-webgpu
--ignore-gpu-blacklist

I tried all of them, none of them seems to work. Do someone know the solution? Am I on the right track?

Implementing JS code to change CSS elements

This is a code excerpt from my program, and I would like to know how o change this in order to adjust the top and left values by using JS variables in the tag which is above it in order to randomize its position in a 9×9 grid. I am making a game out of this.

<style>
            #backgroundColor {
                background-color: rgba(211, 233, 254, 0.779);
                margin-top: 5%;
            }

            #content {
                text-align: center;
                width: 100%;
            }
/* I want to change the top and left values to correspond with JS variables. */
            h1 {
                position: absolute;
                top: 1.75%;
                /* Alter values in a grid by 10.75. Make a varible in <script>, go from 1.75-87.75 */
                left: 27.25%;
                /* Alter values in a grid by 5.5. Make a variable in <script>, go from 27.25-71.25 */
                color: rgb(47, 0, 0)
            }

            div {
                position: relative;
                text-align: center;
            }

            image {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
            }
            
            .center {
                display: block;
                margin-left: auto;
                margin-right: auto;
                width: 50%;
            }

            .numbers {
                font-family: monospace;
                font-size: xx-large;
                font-weight: normal;
                font: Menlo;
            }

            .title {
                font-family: monospace;
                font-style: italic;
                font-weight: lighter;
                font-size: xx-large;
            }

            .subtitle {
                font-family: monospace;
                font: Courier;
                font-size: large;
                font-weight: lighter;
            }
        </style>

I tried using the following JS Code:

<script type="text/javascript">
    "use strict";
            function getNumCoords(ifX, ifY) {
                const numGridMax = 8;
                var yPos = Math.floor(Math.random()*numGridMax);
                var xPos = Math.floor(Math.random()*numGridMax);
                if (ifX === 1) {
                    return (xPos*5.5)+27.25;
                }
                if (ifX === 1) {
                    return (yPos*10.75)+1.75;
                }
            }
            var outputX = getNumCoords(1, 0) + "%";
            var outputY = getNumCoords(0, 1) + "%";
            var number = document.getElementById("random");
    </script>

In order to change the CSS Elements.

Three.js smooth rotation in character control

Code :

I’ve written a code that adds character movement to an Object3D in Three.js
WASD respectively sets the move forward , left , backward , right variables

  • constants :
walkinbgSpeed = 5;
rotationSpeed = Math.PI ;
  • updateRAF : passed deltatime in seconds , updates movement position then calls rotate
 updateRAF(dts) {
        if (this.moveForward) {
            this.model.position.z += this.walkinbgSpeed * dts;
            this.rotate(dts, 0)
        }
        if (this.moveBackward) {
            this.model.position.z -= this.walkinbgSpeed * dts;
            this.rotate(dts, Math.PI)
        }
        if (this.moveLeft) {
            this.model.position.x += this.walkinbgSpeed * dts;
            this.rotate(dts, Math.PI/2)
        }
        if (this.moveRight) {
            this.model.position.x -= this.walkinbgSpeed * dts;
            this.rotate(dts, -Math.PI/2)
        }

    }
  • rotate : smoothly rotates an Object3D by gradually increments the interpolation factor t + using the quaternion slep function directly on the model’s quaternion
 rotate(dts, angle) {
        let t = 0;

        const animateRotation = () => {
            t += this.rotationSpeed * dts;

            if (t >= 1) {
                t = 1; // Clamp t to ensure it doesn't exceed 1
            }

            const qb = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), angle);

            this.model.quaternion.slerp(qb, t);

            if (t < 1) {
                requestAnimationFrame(animateRotation); // Continue animation if not finished
            }
        };

        requestAnimationFrame(animateRotation);
    }

Problem :

  • Pressing one direction at a time rotates the model smoothly as intended

  • Combining two direction buttons starts with a smooth rotation , ends up insta-rotating the model in the last held button direction with no smoothness applied

Note :

  • If needed full code can be provided

  • Any help is greatly appreciated

Is it possible to use WFS.writeTransaction on the server side of a node application

I have a node application that traces a route on a road network and is returned in a JSON format.
I have created on OpenLayers feature from the JSON object and I want to save this feature into an OpenLayers v9 layer using WFS-T.
This processing is all occurring on the server side. There is no map interface.
When I call the WFS.writeTransaction() function I get TypeError: Cannot read properties of undefined (reading ‘createElementNS’)

I have done this successfully previously, but It has always been on the client side and with a map interface.

The code below is from the ol/xml.js file and seems to indicate there should be a document available

export function createElementNS(namespaceURI, qualifiedName) {
   return getDocument().createElementNS(namespaceURI, qualifiedName);
}

My question is is it possible to create a document on the server side so this writeTransaction method will succeed?

Getting dropped file path in Electron

In electron, there’s a feature where you can drag out an element and drop it on your desktop as seen in this example. I’ve searched all over the place for a possible example or GitHub issue I can refrence but the closest I got to a working solution was to simply drag out a filler file which then the system searches for and provides me with a valid path.

I’ve noticed this question which seems to have gone unanswered unfortunately (and the Electron team also seems unintrested in adding onto the startDrag function anytime soon)

As mentioned earlier, I’ve tried saving this temporary dummy file which then gets searched for and the respective path is given. Not very ideal for large systems just for a simple feature addition on the Electron teams end which is kind of disappointing. I’d also like to refrence this GitHub issue which I feel was closed down by the Electron team in an effort to effectively ditch their community.

Anyway, I apologize for the unesscary blabber and any efforts you will put into helping solve this issue would be highly appreciated.

Thanks.

Formulas not working until clicking “Enable Editing”

I’m using exceljs for my project to manipulate an excel file in my React app. It works as expected but when users download the file, the formulas in the file does not calculate until users click on “Enable Editing”. This is a problem because our users will mostly use ipad, and when they download from the ipad, it doesn’t even show the option to “Enable Editing”. Is there a way to recalculate the worksheet before downloading?
Here is the code:

const ExcelJS = require("exceljs");

const handlePrintExcel = async () => {
        try {
            const response = await fetch("/test.xlsx");
            if (!response.ok) {
                console.log("Network response error");
            }
            const blob = await response.blob();
            // Read the Blob using ExcelJS
            const workbook = new ExcelJS.Workbook();
            workbook.xlsx
                .load(blob)
                .then(async (wb) => {
                    const worksheet = workbook.getWorksheet("Sheet1");

                    const cell_f8 = worksheet.getCell("A1");
                    cell_f8.value = 123;
                    const cell_a2 = worksheet.getCell("A2");
                    cell_a2.value = 123;                    

                    workbook.properties.readOnlyRecommended = false;
                    workbook.properties.date1904 = false;

                    workbook.security = {
                        lockWindows: false,
                        lockStructure: false,
                        workbookPassword: null,
                        workbookAlgorithmName: null,
                        workbookHashValue: null,
                    };

                    workbook.calcProperties.fullCalcOnLoad = true;

                    // Write the changes to a buffer
                    const buffer = await workbook.xlsx.writeBuffer();
                    return buffer;
                })
                .then((data) => {
                    // Create a new Blob with the updated data
                    const updatedBlob = new Blob([data], {
                        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    });
                    // Create a URL for the Blob
                    const url = window.URL.createObjectURL(updatedBlob);
                    // Create an anchor element to trigger the download
                    const anchor = document.createElement("a");
                    anchor.href = url;
                    anchor.download = `Test.xlsx`;
                    // Trigger the download
                    anchor.click();
                    // Revoke the URL to release resources
                    window.URL.revokeObjectURL(url);
                })
                .catch((error) => {
                    console.error("Error processing Excel file: ", error);
                });
        } catch (error) {
            console.error("Error converting Excel file into Blob:", error);
        }
    };

Can’t execute ./gradlew clean

I’m currently working on my react native project and wanted to build apk to send my friend. I did everything according to this instruction https://reactnative.dev/docs/signed-apk-android and some video on youtube.

Everything worked fine till the moment when I tried to execute ./gradlew clean and then another command starting with ./gradlew. It just starts downloading it from https://services.gradle.org/distributions/gradle-8.3-all.zip and then fails.

I tried downloading it manually and everything seemed good, gradle -v command works fine from any console, but ./gradlew command still do the same.

I would be really grateful if someone could help me

chrome.downloads.download on MS Edge: windows update this week added a bug. Work-around?

I’m working on an extension for MS Edge (Version 122.0.2365.80) running on Win10 pro. The extension has been working properly, but not any more.
I’m using chrome.downloads.download in javascript and what it used to do is invoke the SaveAs dialog box pointing to the last saved-to folder. Now it points to the browser’s default directory.
Is anyone else seeing this?
Is there an option in chrome.downloads.download to point the SaveAs in the right direction?
Here’s the code for the background.js:

chrome.runtime.onInstalled.addListener(function() {
  console.log('Extension installed / updated');
});

chrome.runtime.onMessage.addListener(function (request, sender) {
  if (request.type === 'popupMessage') {
    // Access parameters from the content script
  var receivedParams = request.data;

  // Do something with the parameters
    console.log(receivedParams);
chrome.downloads.download({
       url: receivedParams,
       filename: 'desired_filename.ext',
       saveAs: true
    }, function(downloadId) {
       console.log('Download initiated with ID:', downloadId);
    });
   }
 });

Thanks in advance for any pointers you can provide.

When I call the background.js, I expect it to bring up the SaveAs dialog box pointing at the last-saved-to-directory.
Instead, the code (unchanged) now brings up the SaveAs dialog box pointing to the browser’s default directory.

browser still in loading state after adding a lib for my components nx monorepo

Current Behavior

browser still in loading state after adding a lib for my components im using nx monorepo with react and vite

Expected Behavior

the app to be loaded and shown the ui in browser

Steps to Reproduce

  • create nx monorepo
  • add workspace for react
  • add react and typescript in also vite in package.json
  • import your ui in apps/yourApp
  • nx serve yourApp
  • success compilation
  • open the url
  • the app will still in loading state

Nx Report

Node   : 21.5.0
OS     : linux-x64
pnpm   : 8.15.3

nx (global)        : 18.0.0
nx                 : 18.0.6
@nx/js             : 18.0.6
@nx/linter         : 18.0.6
@nx/eslint         : 18.0.6
@nx/workspace      : 18.0.6
@nx/devkit         : 18.0.6
@nx/eslint-plugin  : 18.0.6
@nx/react          : 18.0.6
@nrwl/tao          : 18.0.6
@nx/vite           : 18.0.6
@nx/web            : 18.0.6
typescript         : 5.3.3

Failure Logs

when i try to build:


The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.
vite v5.1.4 building for production...

/src/styles.scss doesn't exist at build time, it will remain unchanged to be resolved at runtime
x Build failed in 9.31s
error during build:
Error: Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:
(vite:esbuild) transform "/home/oem/ppppppp/paletta monorepo/react-monorepo/Libs/Assets/src/lib/icons/StatistiqueIcon.tsx"
(vite:esbuild) transform "/home/oem/ppppppp/paletta monorepo/react-monorepo/Libs/Assets/src/lib/icons/ExpandRightIcon.tsx"
(vite:esbuild) transform "/home/oem/ppppppp/paletta monorepo/react-monorepo/Libs/Assets/src/lib/icons/HomeIcon.tsx"
(vite:esbuild) transform "/home/oem/ppppppp/paletta monorepo/react-monorepo/Libs/Assets/src/lib/icons/ParcCheckIcon.tsx"
    at process.handleBeforeExit (file:///home/oem/ppppppp/paletta%20monorepo/react-monorepo/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:19915:28)
    at Object.onceWrapper (node:events:634:26)
    at process.emit (node:events:519:28)
Warning: command "vite build" exited with non-zero status code

when i try to serve: (it seems working)

 nx run admin:serve

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

  VITE v5.1.4  ready in 402 ms

  ➜  Local:   http://localhost:4200/
  ➜  press h + enter to show help

[TypeScript] Found 0 errors. Watching for file changes.
h

  Shortcuts
  press r + enter to restart the server
  press u + enter to show server url
  press o + enter to open in browser
  press c + enter to clear console
  press q + enter to quit

Package Manager Version

pnpm 8.15.3

Operating System

Linux

Additional Information
enter image description here

Open Angular page with parameters

There is an old jsp +javascript application, I need to redirect to the page of a new application written in Angular and send data
Is it possible to transfer, for example, a token to the angular?

I tried to make a redirect to – http://localhost:4200/token/hrl4lhlhga – hrl4lhlhga <== token

const routes: Routes = [
  {
    path: 'token/:value',
    component: TestComponent,
  }
];
export class TestComponent {
  @Input() value?: string;
}
bootstrapApplication(AppComponent, {
  providers: [
    provideRouter(appRoutes, withComponentInputBinding()),

But ‘value’ always undefined

How to properly connect to Guacamole through guacamole-common-js

I have a Google Cloud Virtual Machine instance which has Guacamole installed on it via Docker. I can access via my browser correctly via http://[virtualmachineip]:8080/guacamole/#/ and control it.

I’m building a Svelte app that would let me control the virtual machine through this Client, however I keep receiving the error: ERROR o.a.g.w.GuacamoleWebSocketTunnelEndpoint - Creation of WebSocket tunnel to guacd failed: Parameter "GUAC_ID" is required. on my guacamole docker logs.

Here is how my javascript code is looking:

  function initializeGuacamoleClient() {

    var tunnel = new Guacamole.WebSocketTunnel(
      "ws://[virtualmachineaddress]:8080/guacamole/websocket-tunnel"
    );

    guacClient = new Guacamole.Client(tunnel);

 
    if (displayContainer) {
      displayContainer.appendChild(guacClient.getDisplay().getElement());
      displayContainer.style.display = "block";
      guacClient.connect("username=guacadmin&password=guacadmin");
    }
  }

I would appreciate any inputs because I have not found any rellevant information on the documentation.

Here is my docker-compose.yml just in case it may have something to do.

version: '3'

services:
  guacd:
    image: guacamole/guacd
    container_name: guacd
    restart: always
    ports:
      - "4822:4822"

  mysql:
    image: mysql:5.7
    container_name: guac_mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: (my password)
      MYSQL_DATABASE: guacamole_db
      MYSQL_USER: guacamole_user
      MYSQL_PASSWORD: (my password)
    volumes:
      - guacamole_db:/var/lib/mysql

  guacamole:
    image: guacamole/guacamole
    container_name: guacamole
    restart: always
    depends_on:
      - guacd
      - mysql
    environment:
      GUACD_HOSTNAME: guacd
      MYSQL_HOSTNAME: mysql
      MYSQL_DATABASE: guacamole_db
      MYSQL_USER: guacamole_user
      MYSQL_PASSWORD: (my password)
      GUACAMOLE_CORS_ENABLED: 'true'
      GUACAMOLE_CORS_ALLOWED_ORIGINS: '*'
      GUACAMOLE_CORS_ALLOWED_METHODS: 'GET, POST, PUT, DELETE, OPTIONS'
    ports:
      - "8080:8080"
    links:
      - guacd
      - mysql

volumes:
  guacamole_db:

I’m using this library https://www.npmjs.com/package/guacamole-common-js
Thank you so much.

useNavigate not redirecting to a new page

So after entering data to a form, it should redirect to the /VisitorConfirmationPage with the data of the user stored in the object “formData”,but instead it refreshes the form page( the data has been sent to the server and database). The alert(‘added’) doesn’t always show up. Why is this happening?

    const navigate = useNavigate();

const addData=async()=>{

        var name = document.getElementById("inputName").value;
        var email = document.getElementById("inputEmail").value;
        var phoneNo = document.getElementById("inputPhoneNumber").value;
        var employee = document.getElementById("employee").value;
        // var image = p_image;
        const imageSrc = webcamRef.current.getScreenshot();
        setImageSrc(imageSrc);
        
        const response = await fetch(imageSrc);
        const blob = await response.blob();

        let formData = new FormData();
        formData.append("name", name)
        formData.append("email", email)
        formData.append("phoneNo", phoneNo)
        formData.append("employee", employee)

       
        formData.append("p_image",blob, "captured-image.jpg");

        

        axios.post("http://localhost:4000/api/registerVisitor",formData,{headers:{"Content-Type":"multipart/form-data"}}).then(response =>{
            alert('added');
            navigate('/VisitorConfirmationPage',{state:formData})
        }).catch(error => {
            console.error(error);
            alert("error!")
        });        
    }

I tried to move the navigate function outside the axios function. That didn’t work. I also tried this code inside the response of the axios response case and it didn’t work.

               <Link to={{
                pathname: "/VisitorConfirmationPage",
                state:formData
            }} />
            window.location = "/VisitorConfirmationPage";;

I found a strange behavior in JS. How to stop this behavior [duplicate]

let’s start with two files index.html and script.js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>click me</button>
    <div></div>
    <script src="script.js"></script>
</body>
</html>
const buttonUser = document.querySelector("button");
const divUser = document.querySelector("div");

buttonUser.addEventListener("click", () => {
    divUser.innerHTML = `
        <h1> welcome to the page </h1> 
        <button onclick="welcomeMassage()"> click me 2 <button>
    `
})

function welcomeMassage() {
    console.log("Hello World!");
}

if i clicked in the first button the addEventListener work and adding h1 and second button two divUser adn if i click on the second one it’s also work and console.log(“Hello world”) but :::::::

if change the javascript file two script.mjs and index.js

    <script type="module" src="script.mjs"></script>

When I click on the first button, the addEventListener works, but when I click on the second button, it does not work and shows up in the console. The welcomeMassage function is not defined, and I can’t access it from the console. So why has this happened, and how can I prevent this behavior?

i want when use scritp.mjs file and i click in the button not show in console functionNamve not defined and perform the function