How to convert Node crypto.generateKeyPairSync to Deno?

I want to convert the following code from a Node (v18.1) program to Deno (v1.22), where a key pair is generated during SSH key exchange:

// generate.mjs
import { generateKeyPairSync } from "crypto";

const keys = generateKeyPairSync("x25519");

The code above is part of a larger SSH client, which mostly works in Deno when run in Node compatibility mode (--compat). However, generateKeyPairSync is not yet implemented, so I want to change it to a Deno equivalent:

deno run --compat --unstable --allow-env ./generate.mjs

error: Uncaught Error: Not implemented: crypto.generateKeyPairSync
  throw new Error(message);
        ^
    at notImplemented (https://deno.land/[email protected]/node/_utils.ts:22:9)
    at generateKeyPairSync (https://deno.land/[email protected]/node/internal/crypto/keygen.ts:662:3)
    at file:///C:/Users/gjzwiers/repos/nodeno_ssh/generate.mjs:3:14

I have looked at generateKey in the WebCrypto API, but it seems that it does not support x25519? Is there an alternative for x25519 in the WebCrypto API , or is there another way to get this working in Deno?

Puppeteer type on prompt

Hello I am trying to login into something like this;

The input fields can be translated into username and password and buttons are login and cancel.

I am trying to type on these fields and press on login button (blue one)

I have tried await page.authenticate({ username: ... , password: ... })
Also I have tried page.on('dialog', async (dialog) => .......) but both of them are not working, it just stays like that.

Or how can I select those fields, i dont know if its even possible since its javascript based function.

enter image description here

and here is my code;

import express from 'express';
import puppeteer from 'puppeteer'; 
import userAgent from 'user-agents'; 

const app = express();
 

const screenshot = 'github3.png';

app.get('/', async (req, res) => {
  const browser = await puppeteer.launch({
    headless: false,
    executablePath: `C:/Program Files (x86)/Google/Chrome/Application/chrome.exe`,
    defaultViewport: null,
    args: ['--start-maximized'],
  });
  const page = await browser.newPage();
  await page.setUserAgent(userAgent.toString());
  page.setDefaultNavigationTimeout(0);
  await page.goto('myUrl...', {
    waitUntil: 'load',
    timeout: 0,
  });
  await page.click('#krbSubmit');

// AFTER THIS CLICK THE PROMPT OPENS ON THE NEXT PAGE

  //   await browser.close();
  res.send('hi');
});

app.listen('5000', console.log('server listening'));

JavaScript check if string equals an other one

I want to check if the value of metadata.data.symbol is equal to DBH. I can’t use string.includes because I have some values that are equals to DBHB and that’s not the ones I want to catch.

I then tried :

 if(metadata.data.symbol.includes("DBH")){
       console.log(metadata.data.symbol)
       console.log(metadata.data.symbol === "DBH")
 }

But I don’t understand why it isn’t working, I even printed the typeof metadata.data.symbol and it returned string :
enter image description here

Here is a small example where it’s working :

let x = "DBH"
console.log(x === "DBH")

javascript sorting by value, if the values are equal, sorting between equal items by a different value

I have an object data, I sort this data according to their points, but if the points are the same, I want the last updated item to be on top. but I could not create the algorithm here. Can you help me ?

My JSON Data

[
  {
    "name": "Item 1",
    "point": 3,
    "updatedAt": "10/06/2022 9:39"
  },
  {
    "name": "Item 2",
    "point": 4,
    "updatedAt": "10/06/2022 9:45"
  },
  {
    "name": "Item 3",
    "point": 2,
    "updatedAt": "10/06/2022 9:39"
  },
  {
    "name": "Item 4",
    "point": 1,
    "updatedAt": "10/06/2022 9:39"
  },
  {
    "name": "Item 5",
    "point": 5,
    "updatedAt": "10/06/2022 9:39"
  },
  {
    "name": "Item 6",
    "point": 2,
    "updatedAt": "11/06/2022 3:05"
  }
]

For example, the points of Item 3 and Item 6 are the equal here, but Item 3 displays at the top. Because I added Item 6 later. So how do I get Item 6 to be above Item 3 if their points are equal?

I was planning to do this so that the last updated is at the top.

I tried several methods but it didn’t work, for now this is my starting code.

if (sortBy === "lowtohigh") {
      computedData = data.sort((a, b) => {
        return a.point - b.point
      });
}
if (sortBy === "hightolow") {
      computedData = data.sort((a, b) => {
        return b.point - a.point
      });
}

Thank you for your answers in advance.

Mongoose statics not found

Created a statics in a userModel.js such as userSchema.statics.login, and trying to refer to it in other file, but WebStorm is saying that is Unresolved function or method login(), pls help).

userSchema.statics.login = async function (email, password)  {
const user = await this.findOne({ email });
if(user){
    const auth = await bcrypt.compare(password, user.password);
    if(auth){
        return user;
    }
    throw Error('Incorrect password');
}
throw Error('Email doesn`t exist');
}
const User = mongoose.model('user', userSchema);
module.exports = User;

File in which i trying to refer:

const User = require("../models/userModel");
module.exports.login_post = async function (req, res) {
  const { email, password } = req.body;

  try {
      const UserLogin = await User.login(email,password);
    res.status(200).json({user: UserLogin._id});
  } catch (err) {
    res.status(400).json({})
  }

}

Z-Index not working in Tailwind CSS React Js

How can make the calendar pop up? I am using tailwind CSS, it wont work. I tried to follow the documentation about the z-index.

this is my main homepage. And it’s arranged completely.

  const Homepage = () => {
  return (
    <div>
      <Navbar />
      <Header />
      <UnderHeader />
      <div className="mt-14 flex flex-col items-center gap-8">
        <Featured />
      </div>
    </div>
  )
}

this is UnderHeader.jsx where the content of search box , date etc..

 return (
    <div className="w-screen h-80 max-h-7xl drop-shadow-lg  ">
      <div
        className="w-full h-full mt-5 bg-no-repeat bg-cover bg-center opacity-100 bg-neutral-800  bg-blend-overlay flex items-center justify-center "
        style={{ backgroundImage: `url(${BackgroundIsland})` }}
      >
        <div className="flex items-center justify-evenly p-4 w-3/4 h-16 text-lg border-2 border-white/[.2] bg-white/[.08] rounded-full">
          <div className="flex gap-3 items-center  justify-center text-white">
            <FaBed size={36} className="" />
            <input
              type="text"
              placeholder="Location..."
              className="px-3 border-b-2 py-1 text-dark focus:outline-none w-72 bg-transparent cursor-pointer"
            />
          </div>
          <div className="flex gap-3 cursor-pointer text-white items-center relative z-50 justify-center">
            <FcCalendar size={36} className="text-white" />
            <p onClick={() => setOpenDate(!openDate)}>
              {`${format(date[0].startDate, 'MM/dd/yyyy')}`}
              <span className="mx-2 font-thin">to</span>
              {`${format(date[0].endDate, 'MM/dd/yyyy')}`}
            </p>
            {openDate && (
              <DateRange
                editableDateInputs={true}
                onChange={(item) => setDate([item.selection])}
                moveRangeOnFirstSelection={false}
                ranges={date}
                className="absolute top-[50px]"
              />
            )}
          </div>
          <div className="flex gap-3 text-white items-center justify-center relative">
            <HiUserGroup size={36} className="" />
            <p
              className="cursor-pointer"
              onClick={() => setOpenOptions(!openOptions)}
            >{`${options.adult} adult • ${options.children} children • ${options.room} room`}</p>
            {openOptions && (
              <div className="absolute top-[50px] bg-white text-gray-800 rounded-sm px-3 py-4 drop-shadow-2xl">
                {/* This is person choose */}
                <ButtonHeader
                  title="Adult"
                  buttonName="adult"
                  quantity={options.adult}
                  handleOption={handleOption}
                />
                <ButtonHeader
                  disabled={options.children <= 1}
                  title="Children"
                  buttonName="children"
                  quantity={options.children}
                  handleOption={handleOption}
                />
                <ButtonHeader
                  disabled={options.room <= 1}
                  title="Room"
                  buttonName="room"
                  quantity={options.room}
                  handleOption={handleOption}
                />
              </div>
            )}
          </div>
          <div className="flex gap-1 cursor-pointer bg-blue-200 hover:bg-blue-300 duration-300 rounded-full px-4 py-3 items-center justify-center">
            <FcSearch size={24} className="" />
            <p className="text-lg font-bold">Search</p>
          </div>
        </div>
      </div>
    </div>
  )

This is featured.jsx that contains the image, which and it is under the header.jsx

const Featured = () => {
  return (
    <div className="w-full max-w-5xl flex justify-between gap-4 ">
      <div className="w-full object-cover relative">
        <img
          src="https://images.unsplash.com/photo-1472213984618-c79aaec7fef0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=855&q=80"
          alt=""
          className="w-full object-fit  z-[1]"
        />
        <div className="text-white rounded-lg h-64 absolute bottom-4">
          <p className="text-5xl absolute">Dublin</p>
          <p className="text-5xl absolute">123 Properties</p>
        </div>
      </div>
    </div>
  )
}

export default Featured

enter image description here

Tinymce upload image url in react doesn’t work

I am trying to insert image url in my texteditor made in Reactjs and tineymce. But it gives error as:

Uncaught TypeError: Cannot read properties of undefined (reading 'nodeName')

This is my code for editor.

export default function DraftEditor() {
  const editorRef = useRef(null);
 
  const example_image_upload_handler = (blobInfo, progress) =>
    new Promise((resolve, reject) => {
      const xhr = new XMLHttpRequest();
      xhr.withCredentials = false;
      xhr.open(
        "POST",
        "image_upload_url",
        true
      );

      xhr.upload.onprogress = (e) => {
        progress((e.loaded / e.total) * 100);
      };

      xhr.onload = () => {
        if (xhr.status === 403) {
          reject({ message: "HTTP Error: " + xhr.status, remove: true });
          return;
        }

        if (xhr.status < 200 || xhr.status >= 300) {
          reject("HTTP Error: " + xhr.status);
          return;
        }

        const json = JSON.parse(xhr.responseText);

        if (!json || typeof json.data != "string") {
          reject("Invalid JSON: " + xhr.responseText);
          return;
        }

        resolve(json.data);
      };


      const formData = new FormData();
      formData.append("image", blobInfo.blob(), blobInfo.filename());

      xhr.send(formData);
    });
  return (
    <>
      <Editor
        apiKey={process.env.REACT_APP_TINY}
        onInit={(evt, editor) => (editorRef.current = editor)}
        initialValue={``}
        init={{
          images_upload_handler: example_image_upload_handler,
          plugins: [
            "image",
          ],
          image_title: true,
          file_picker_types: "image",
          automatic_uploads: true,
          content_style:
            "body { font-family:Helvetica,Arial,sans-serif; font-size:14px }",
          images_file_types: "jpg,svg,png",
          toolbar: "codesample code",
          content_style:
            "body { font-family: 'Courier New', Courier, monospace; font-size: 0.9em }",
        }}
      />
    </>
  );
}

This image upload code is from it’s documentation. I am uploading local image to my server and trying to insert the returned link in the editor.

This is my error ss.
enter image description here

How to use an if or condition statement to hide/not display href link and text from .json file using javascript

I’m working on a site which pulls information from a .json file when a location on a map is selected to populate information in a content template, one of these fields contains URLs to real estate virtual walkthroughs, though not all of the properties in the .json file have Virtual Walkthrough URLs in their respective fields.

Currently the site uses:

HTML:

<li><span style="color: #0000ff;"><a href={VirtualLink} target="_blank" rel=”noopener noreferrer” style="color: #0000ff;">Real Estate Walkthrough</a></span></li>

This works fine for the properties that have a URL listed in the .json file against the property ID, however if the field is empty the link text still displays, and the link won’t work as there is no URL in the .json field for the specific property.

I want to be able to use javascript in a similar manner to the Excel IF(condition, value_if_true, value_if_false), to display the text “Real Estate Walkthrough” and href link if the .json field contains a URL for the property ID selected and if the .json field is empty then to display nothing.

How can I change the direction of the head when the key (37,38,39,40) are pressed?

I have tried to use if statements, I also tried for loop and I think that the solution is to do a if statement, stating that if you click the down key then rotate head by 90 degrees, so that it points downwards. I tried that but it isn’t working.

The code i added i have put it in // // because it isn’t working

(function() {
  /////////////////////////////////////////////////////////////

  // Canvas & Context
  var canvas;
  var ctx;

  // Snake
  var snake;
  var snake_dir;
  var snake_next_dir;
  var snake_speed;
  var img;

  // Food
  var food = {
    x: 0,
    y: 0
  };

  // Score
  var score;

  // Wall
  var wall;

  // HTML Elements
  var screen_snake;
  var screen_menu;
  var screen_setting;
  var screen_gameover;
  var button_newgame_menu;
  var button_newgame_setting;
  var button_newgame_gameover;
  var button_setting_menu;
  var button_setting_gameover;
  var ele_score;
  var speed_setting;
  var wall_setting;

  /////////////////////////////////////////////////////////////

  var activeDot = function(x, y) {
    ctx.fillStyle = "#FFFFFF";
    ctx.fillRect(x * 10, y * 10, 10, 10);
  }


  /////////////////////////////////////////////////////////////

  var changeDir = function(key) {

    if (key == 38 && snake_dir != 2) {
      snake_next_dir = 0;
    } else {

      if (key == 39 && snake_dir != 3) {
        snake_next_dir = 1;
      } else {

        if (key == 40 && snake_dir != 0) {
          snake_next_dir = 2;
        } else {

          if (key == 37 && snake_dir != 1) {
            snake_next_dir = 3;
          }
        }
      }
    }

  }

  /////////////////////////////////////////////////////////////

  var addFood = function() {
    food.x = Math.floor(Math.random() * ((canvas.width / 10) - 1));
    food.y = Math.floor(Math.random() * ((canvas.height / 10) - 1));
    for (var i = 0; i < snake.length; i++) {
      if (checkBlock(food.x, food.y, snake[i].x, snake[i].y)) {
        addFood();
      }
    }
  }

  /////////////////////////////////////////////////////////////

  var checkBlock = function(x, y, _x, _y) {
    return (x == _x && y == _y) ? true : false;
  }

  /////////////////////////////////////////////////////////////

  var altScore = function(score_val) {
    ele_score.innerHTML = String(score_val);
  }

  /////////////////////////////////////////////////////////////

  var mainLoop = function() {

    var _x = snake[0].x;
    var _y = snake[0].y;
    snake_dir = snake_next_dir;

    // 0 - Up, 1 - Right, 2 - Down, 3 - Left
    switch (snake_dir) {
      case 0:
        _y--;
        break;
      case 1:
        _x++;
        break;
      case 2:
        _y++;
        break;
      case 3:
        _x--;
        break;
    }

    snake.pop();
    snake.unshift({
      x: _x,
      y: _y
    });


    // --------------------

    // Wall

    if (wall == 1) {
      // On
      if (snake[0].x < 0 || snake[0].x == canvas.width / 10 || snake[0].y < 0 || snake[0].y == canvas.height / 10) {
        showScreen(3);
        return;
      }
    } else {
      // Off
      for (var i = 0, x = snake.length; i < x; i++) {
        if (snake[i].x < 0) {
          snake[i].x = snake[i].x + (canvas.width / 10);
        }
        if (snake[i].x == canvas.width / 10) {
          snake[i].x = snake[i].x - (canvas.width / 10);
        }
        if (snake[i].y < 0) {
          snake[i].y = snake[i].y + (canvas.height / 10);
        }
        if (snake[i].y == canvas.height / 10) {
          snake[i].y = snake[i].y - (canvas.height / 10);
        }
      }
    }

    // --------------------

    // Autophagy death
    for (var i = 1; i < snake.length; i++) {
      if (snake[0].x == snake[i].x && snake[0].y == snake[i].y) {
        showScreen(3);
        return;
      }
    }

    // --------------------

    // Eat Food
    if (checkBlock(snake[0].x, snake[0].y, food.x, food.y)) {
      snake[snake.length] = {
        x: snake[0].x,
        y: snake[0].y
      };
      score += 1;
      altScore(score);
      addFood();
      activeDot(food.x, food.y);
    }

    // --------------------

    ctx.beginPath();
    ctx.fillStyle = "#000000";
    ctx.fillRect(0, 0, canvas.width, canvas.height);

    // --------------------

   var img = new Image();  //right
    img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAI9JREFUKFOFkEsOwyAMRIf778o3t2CLANMzBbIEqqSJojS09dJ64/EMI6IupYS1FrVWfBvWe+/zPCMSYTIa3ge01m78Bh7bUjJCJBi9CvxFcAEPQc4ZkSK00gjh7TAET4eyCQTnv8FlKaD0hOCPMVjKeokwKQW3//oRZgeMgnODMGc95pb2+JelRF2I/4W/AE+DiZ3bAvWPAAAAAElFTkSuQmCC";
    for (var i = 0; i < snake.length; i++) {
                     if (!i) {
                    ctx.drawImage(img, snake[i].x * 10, snake[i].y * 10);
                } else {
                  activeDot(snake[i].x, snake[i].y);
                }
                }
  // 
  // var img = new Image();  //right
    //img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAI9JREFUKFOFkEsOwyAMRIf778o3t2CLANMzBbIEqqSJojS09dJ64/EMI6IupYS1FrVWfBvWe+/zPCMSYTIa3ge01m78Bh7bUjJCJBi9CvxFcAEPQc4ZkSK00gjh7TAET4eyCQTnv8FlKaD0hOCPMVjKeokwKQW3//oRZgeMgnODMGc95pb2+JelRF2I/4W/AE+DiZ3bAvWPAAAAAElFTkSuQmCC";
    
    //var img2 = new Image(); //left
   // img2.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAJBJREFUKFN9kEkOwyAQBBs42vCmBAb7yi/Mmv/fHIFELLyEc00X3QzAjocnhIBzDjknsDuQcw5rLTbvYbSGUmoEK7CuFYgNmOf552qJDagJ8Qp0ki2L3XP5QL9fmKYj4fxtRmT2XAqMNoPqAnY1ESHE0A6klJcdhta9rQ8BZGqZ4+DPPITNV8PNPGdfHzylhC9RviZfCk+uKwAAAABJRU5ErkJggg==";
    
   // var img3 = new Image(); //up
   // img3.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAMBJREFUKFNtzkEORDAYhuGvtcWdZESXmJYDOJgLaDGzkZrEOJNYM1EhnRnf8u+TNyUAVlgLwxsopej7l30GseEG6qYGpQ6SOMayLCf+glEUQSkFQoCMC3Ra/8OtpmqFJE7M4+P5xD1Nz+pZZIyhqip4nmfgPM/Ic4Gu26sG7rXa/MueXTWQsQhSSrjuXju2VYUQ0FqDOI6zVlIiTfa//a5pW2RCgHDO17Is4fv+JZymCUVRgAzDsAZBcImO4zi+8QEHM08/DnuEBQAAAABJRU5ErkJggg==";
    
   // var img4 = new Image(); //down
   // img4.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAAXNSR0IArs4c6QAAAMFJREFUKFN9j0EOgjAQRT+wJZwJF9KwQWXKBTgYB9AqZVmi9k7A1tYUIqaGOMs/b17+BFo/bZru8G+01giIyDZNgyRJNtlhGFDXNYIoiuxFCJyOx02wlRIV5wgAWMYYhBCI49iDp2kE5xxK9QsYhiFubYtDUXig7DpQWcIYs4Bum+cM5/PXOo4jqqqCUmo+XsFfq+wkqKTZ5oGzlTFcrgLWAkSEvu/XKqvRJc7qehnzQnlaun3GA12YZfsZuN8f3mNvE4RXPXElQSQAAAAASUVORK5CYII=";



//switch (event.key) {
   // case "ArrowLeft":
      //  for (var i = 0; i < snake.length; i++) {
                    // if (!i) {
                //  ctx.drawImage(img2, snake[i].x * 10, snake[i].y * 10);
            //  } else {
            //    activeDot(snake[i].x, snake[i].y);
            //  }
                //}
       // break;
 //   case "ArrowRight":
    //   for (var i = 0; i < snake.length; i++) {
                    // if (!i) {
            //      ctx.drawImage(img, snake[i].x * 10, snake[i].y * 10);
            //  } else {
            //    activeDot(snake[i].x, snake[i].y);
        //      }
            //  }
    //    break;
   // case "ArrowUp":
     //   for (var i = 0; i < snake.length; i++) {
            //   if (!i) {
            //      ctx.drawImage(img3, snake[i].x * 10, snake[i].y * 10);
                //} else {
                //  activeDot(snake[i].x, snake[i].y);
            //  }
            //  }
   //     break;
 //   case "ArrowDown":
    //    for (var i = 0; i < snake.length; i++) {
                //   if (!i) {
        //          ctx.drawImage(img4, snake[i].x * 10, snake[i].y * 10);
        ///     } else {
        //        activeDot(snake[i].x, snake[i].y);
        //      }
            //  }
      //  break;

      
    // --------------------

    activeDot(food.x, food.y);

    // Debug
    //document.getElementById("debug").innerHTML = snake_dir + " " + snake_next_dir + " " + snake[0].x + " " + snake[0].y;    

    setTimeout(mainLoop, snake_speed);
  }

  /////////////////////////////////////////////////////////////

  var newGame = function() {

    showScreen(0);
    screen_snake.focus();

    snake = [];
    for (var i = 4; i >= 0; i--) {
      snake.push({
        x: i,
        y: 15
      });
    }

    snake_next_dir = 1;

    score = 0;
    altScore(score);

    addFood();

    canvas.onkeydown = function(evt) {
      evt = evt || window.event;
      changeDir(evt.keyCode);
    }
    mainLoop();

  }

  /////////////////////////////////////////////////////////////

  // Change the snake speed...
  // 150 = slow
  // 100 = normal
  // 50 = fast
  var setSnakeSpeed = function(speed_value) {
    snake_speed = speed_value;
  }

  /////////////////////////////////////////////////////////////
  var setWall = function(wall_value) {
    wall = wall_value;
    if (wall == 0) {
      screen_snake.style.borderColor = "#606060";
    }
    if (wall == 1) {
      screen_snake.style.borderColor = "#FFFFFF";
    }
  }

  /////////////////////////////////////////////////////////////

  // 0 for the game
  // 1 for the main menu
  // 2 for the settings screen
  // 3 for the game over screen
  var showScreen = function(screen_opt) {
    switch (screen_opt) {

      case 0:
        screen_snake.style.display = "block";
        screen_menu.style.display = "none";
        screen_setting.style.display = "none";
        screen_gameover.style.display = "none";
        break;

      case 1:
        screen_snake.style.display = "none";
        screen_menu.style.display = "block";
        screen_setting.style.display = "none";
        screen_gameover.style.display = "none";
        break;

      case 2:
        screen_snake.style.display = "none";
        screen_menu.style.display = "none";
        screen_setting.style.display = "block";
        screen_gameover.style.display = "none";
        break;

      case 3:
        screen_snake.style.display = "none";
        screen_menu.style.display = "none";
        screen_setting.style.display = "none";
        screen_gameover.style.display = "block";
        break;
    }
  }

  /////////////////////////////////////////////////////////////

  window.onload = function() {

    canvas = document.getElementById("snake");
    ctx = canvas.getContext("2d");

    // Screens
    screen_snake = document.getElementById("snake");
    screen_menu = document.getElementById("menu");
    screen_gameover = document.getElementById("gameover");
    screen_setting = document.getElementById("setting");

    // Buttons
    button_newgame_menu = document.getElementById("newgame_menu");
    button_newgame_setting = document.getElementById("newgame_setting");
    button_newgame_gameover = document.getElementById("newgame_gameover");
    button_setting_menu = document.getElementById("setting_menu");
    button_setting_gameover = document.getElementById("setting_gameover");

    // etc
    ele_score = document.getElementById("score_value");
    speed_setting = document.getElementsByName("speed");
    wall_setting = document.getElementsByName("wall");

    // --------------------

    button_newgame_menu.onclick = function() {
      newGame();
    };
    button_newgame_gameover.onclick = function() {
      newGame();
    };
    button_newgame_setting.onclick = function() {
      newGame();
    };
    button_setting_menu.onclick = function() {
      showScreen(2);
    };
    button_setting_gameover.onclick = function() {
      showScreen(2)
    };

    setSnakeSpeed(150);
    setWall(1);

    showScreen("menu");

    // --------------------
    // Settings

    // speed
    for (var i = 0; i < speed_setting.length; i++) {
      speed_setting[i].addEventListener("click", function() {
        for (var i = 0; i < speed_setting.length; i++) {
          if (speed_setting[i].checked) {
            setSnakeSpeed(speed_setting[i].value);
          }
        }
      });
    }

    // wall
    for (var i = 0; i < wall_setting.length; i++) {
      wall_setting[i].addEventListener("click", function() {
        for (var i = 0; i < wall_setting.length; i++) {
          if (wall_setting[i].checked) {
            setWall(wall_setting[i].value);
          }
        }
      });
    }

    document.onkeydown = function(evt) {
      if (screen_gameover.style.display == "block") {
        evt = evt || window.event;
        if (evt.keyCode == 32) {
          newGame();
        }
      }
    }
  }

})();
::selection {
  color: #FFFFFF;
  background: transparent;
}

 ::-moz-selection {
  color: #FFFFFF;
  background: transparent;
}

* {
  margin: 0;
  padding: 0;
  font-family: "VT323";
}

body {
  background-color: #000000;
}

.wrap {
  margin-left: auto;
  margin-right: auto;
}

header {
  width: 340px;
  font-size: 0;
}

canvas {
  display: none;
  border-style: solid;
  border-width: 10px;
  border-color: #FFFFFF;
}

canvas:focus {
  outline: none;
}


/* Top Styles */

h1 {
  display: inline-block;
  width: 100px;
  font-size: 32px;
  color: #FFFFFF;
}

.score {
  display: inline-block;
  width: 240px;
  font-size: 20px;
  color: #FFFFFF;
  text-align: right;
}

.score_value {
  font-size: inherit;
}


/* All screens style */

#gameover a,
#setting a,
#menu a {
  display: block;
}

#gameover a,
#setting a:hover,
#menu a:hover {
  cursor: pointer;
}

#gameover a:hover::before,
#setting a:hover::before,
#menu a:hover::before {
  content: ">";
  margin-right: 10px;
}


/* Menu Screen Style */

#menu {
  display: block;
  width: 340px;
  padding-top: 95px;
  padding-bottom: 95px;
  font-size: 40px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  color: #FFF;
}

#menu h2 {
  -webkit-animation: logo-ani 1000ms linear infinite;
  animation: logo-ani 1000ms linear infinite;
  margin-bottom: 30px;
}

#menu a {
  font-size: 30px;
}

@-webkit-keyframes logo-ani {
  50% {
    -webkit-transform: scale(1.3, 1.3);
  }
  100% {
    -webkit-transform: scale(1.0, 1.0);
  }
}

@keyframes logo-ani {
  50% {
    transform: scale(1.3, 1.3);
  }
  100% {
    transform: scale(1.0, 1.0);
  }
}


/* Game Over Screen Style */

#gameover {
  display: none;
  width: 340px;
  padding-top: 95px;
  padding-bottom: 95px;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  font-size: 30px;
  color: #FFF;
}

#gameover p {
  margin-top: 25px;
  font-size: 20px;
}


/* Settings Screen Style */

#setting {
  display: none;
  width: 340px;
  margin-left: auto;
  margin-right: auto;
  padding-top: 85px;
  padding-bottom: 85px;
  font-size: 30px;
  color: #FFF;
  text-align: center;
}

#setting h2 {
  margin-bottom: 15px;
}

#setting p {
  margin-top: 10px;
}

#setting input {
  display: none;
}

#setting label {
  cursor: pointer;
}

#setting input:checked+label {
  background-color: #FFF;
  color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">

<header class="wrap">
  <h1>Snake</h1>
  <p class="score">Score: <span id="score_value">0</span></p>
</header>

<canvas class="wrap" id="snake" width="320" height="320" tabindex="1"></canvas>

<!-- Game Over Screen -->
<div id="gameover">
  <h2>Game Over</h2>
  <p>press <span style="background-color: #FFFFFF; color: #000000">space</span> to begin a</p>
  <a id="newgame_gameover">new game</a>
  <a id="setting_gameover">settings</a>
  
</div>

<!-- Setting screen -->
<div id="setting">
  <h2>Settings</h2>

  <a id="newgame_setting">new game</a>

  <p>Speed:
    <input id="speed1" type="radio" name="speed" value="120" checked/>
    <label for="speed1">Slow</label>
    <input id="speed2" type="radio" name="speed" value="75" />
    <label for="speed2">Normal</label>
    <input id="speed3" type="radio" name="speed" value="35" />
    <label for="speed3">Fast</label>
  </p>

  <p>Wall:
    <input id="wallon" type="radio" name="wall" value="1" checked/>
    <label for="wallon">On</label>
    <input id="walloff" type="radio" name="wall" value="0" />
    <label for="walloff">Off</label>
  </p>

</div>
 <!-- Main Menu Screen -->
<div id="menu">
  <h2>Snake</h2>

  <a id="newgame_menu">new game</a>
  <a id="setting_menu">settings</a>
</div>

jsPDF ISSUE – image rendering

I am using jsPDF library to generate a MRI report with 4 images. Every time a request submitted to a server, these images are saved to a specified directory and they are changing with each request.

when rendering them from the directory to the report, the images from the first request is rendered not the new ones.
Is there a type of caching in jsPDF ?

generateMRIReport(patientNumber){
    window.jsPDF = window.jspdf.jsPDF;
    const MRI_REPORT = new jsPDF();
     MRI_REPORT.addImage(`WEB-INF/media/testing_mods_${patientNumber}.png`, 'PNG', 5, 80, 196, 70);
     MRI_REPORT.addImage(`WEB-INF/media/testing_preds.png_${patientNumber}.png`, 'PNG', 5, 160, 196, 70);
     MRI_REPORT.save(`NEUROPH_${patientNumber}_MRI_REPORT.pdf`);
}

How to set circle-color using filters in mapbox data-expression?

Want to show different colored circles on the map using mapbox-gl-js.

Currently it is possible to show different colors using:

  'circle-color': [
      "case",
      [">=", ["get", 'count'], 12],
      "#000000",
      "#ffffff"
   ]

, but need to perform multiple filter to be performed for single color.

need something like:

[">=", ["get", 'count'], 120], && ["<=", ["get", 'count'], 200],

and if above results to true show red color circle.