D3 .extent() rejecting array of Dates in typescript

I’m struggling to utilize d3’s .extent() function in typescript.

I’ve got some code here that creates Date objects out of dates

 const dates:(Date | null)[] = data.map(row => d3.timeParse("%Y-%m-%d")(row.Date))

When I console log the dates variable, it looks something like this

[Sat Jun 24 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Sat Jun 24 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), Fri Jun 23 2023 00:00:00 GMT-0700 (Pacific Daylight Time), ...]

Therefore, I know my dates variable is full of Date objects, like expected…

However, when I try and use the d3.extent() function to find the highest and lowest dates

const xScale = d3
      .scaleTime()
      .domain(d3.extent(dates))
Argument of type '[undefined, undefined] | [string, string]' is not assignable to parameter of type 'Iterable<Date | NumberValue>'.

I’m confused as to why this might be, though, as my dates variable is in fact exclusively dates, and not, as is expressed in the error, ‘[undefined, undefined] | [string, string]’.

What is wrong about what I am passing in? How should I be passing in dates to the extent() function in typescript?

Convert UTC string to local time string moment js

I’ve a utc time string lets say 05:01 I want to convert this into localtime string.
Something like this 08:33.

I’ve tried this but its giving blank output.

var str = "05:03";
var d = moment(str, 'HH:mm').format('HH:mm').local();

I want to make it work using momemt js.

When the button is pressed twice by the same user, it crashes the bot. Discordjs

I wanted to make a fight command. So basically,

1, the player would type /fight

2, embed and button will be displayed

3, when the player presses the punch button, it will decrease the enemy’s health. Which worked. But when the same player presses the punch button again, it will log ‘Interaction is already acknowledged.’ crashing the whole bot.

Here is the code where it went wrong, this is to prevent the ‘Interaction failed’ error that appears in discord:

 const collector = lastReply.createMessageComponentCollector({
                    componentType: ComponentType.Button,
                    time: 15000,
                  });
                
                    collector.on("collect", async (interaction) => {
                        await interaction.deferUpdate()
                        
                        console.log('yes.')
                        return;
                    })
                

I got a seperate part to check if player had punched and decrease health

const confirmation = await lastReply.awaitMessageComponent({ time: 60_000 });
if (confirmation.customId === 'punch') {
 //the part where i decrease the enemy's health
}

I tried removing await interaction.deferUpdate() in the collector.on but it says ‘Interaction failed’.
I only wanted to allow the player to press the button twice without ‘Interaction failed’ error.

Typescript compiler not emitting errors in browser environment

I was making a code editor for typescript that runs within browser. For transpilation, i decided to use the typescript compiler (https://cdnjs.cloudflare.com/ajax/libs/typescript/5.1.6/typescript.min.js)

I transpiles to javascript, but is not emitting errors such as type errors, etc. The compiler I am using runs in a browser environment.

This is the typescript code before compiling
Raw typescript code

This is the code after compiling to javascript
Compiled typescript code

It should have raised some errors.

How do i enable the errors? Do i need to toggle some compiler options or do I need to use a different compiler?

For the code editor, you can find it at devnuts.surge.sh (for more clarity on what i am trying to make)

Thanks

I’ve done some research on it but the most i could find was errors in nodejs environment.
I tried toggling the compiler options for emitting errors but didn’t help.

Which laptop is recommended for a front-end programmer

Could you kindly assist me by recommending a laptop suitable for a front-end programmer? I’m currently a beginner in JavaScript but proficient in HTML and CSS. I’d appreciate it if you could specify a particular laptop and provide reasons. It’s important for me to avoid switching laptops due to work commitments in the near future, so I’m seeking a reliable option that can support my coding endeavors without interruption.

This is the laptop I have in mind “HP Folio 1040 G3”.

why can’t I get JSESSIONID from browser cookies in production using javascript?

i want to retrieve JSESSIONID from browser cookies. when I do in local environment i can get it. but when it’s in production I can’t get it. In below I will give you the difference between my cookies on local and production. And also I have attached the source code that I use.

I want to ask, why did this happen? How can I get JSESSIONID correctly?

Production

enter image description here

Local

enter image description here

sessionId () {
  const cookies = document.cookie.split(';')
  const cookiesObj = Object.fromEntries(document.cookie.split('; ').map(c => c.split('=')))
  const jSessionId = cookiesObj.JSESSIONID
  console.log('All cookies:', cookies) // Log all cookies
  console.log('cookiesObj: ', cookiesObj)
  console.log('JSESSION from object: ', jSessionId)

  for (let i = 0; i < cookies.length; i++) {
    console.log(cookies)
    const cookie = cookies[i]
    console.log('Current cookie:', cookie) // Log current cookie
    console.log('| jSessionId | ' + jSessionId + ' | JSESSIONID | ' + cookie.startsWith('JSESSIONID=') + ' | (spasi)JSESSIONID | ' + cookie.startsWith(' JSESSIONID='))

    if (jSessionId || cookie.startsWith('JSESSIONID=') || cookie.startsWith(' JSESSIONID=')) {
      const sessionId = jSessionId || cookie.substring('JSESSIONID='.length, cookie.length) || cookie.substring(' JSESSIONID='.length, cookie.length)
      console.log('Extracted session ID:', sessionId) // Log extracted session ID
      return sessionId
    }
  }

  return null
},

This is the result from this line > console.log(‘All cookies:’, cookies)

I try to get all cookies, but JSESSIONID. But JSESSIONID cannot be found and is not in the array

['_ga=GA1.1.65081268.1674548249', ' __zlcmid=1E5lY8RBkVpH3HE', ' _fbp=fb.2.1676598513649.1894969411', ' _gcl_au=1.1.1175302720.1682471982', ' SERVERUSED=nuxtserver1', ' _ga_SQ0WWF9CV8=GS1.1.1689055593.182.0.1689055593.60.0.0', ' DRM_STORE=%7B%22user%22%3A%7B%22userData%22%3A%7B…ser_id%22%3A%2217%22%2C%22wa%22%3A%22%22%7D%7D%7D', ' _ga_SP8DGHSHWB=GS1.1.1689059746.69.1.1689059927.0.0.0']

Monogo db no longer supports callback

export const addNewPlayer = (req, res) => {
    let newPlayer = new Player(req.body);

    newPlayer.save((err,Player) => {
        if(err){
            res.send(err);
        }
        res.json(Player);
});

i am new to this i am getting “No longer accepts a callback” error, how can i solve this without downgrading the current MongoDB version.

i tried testing POST in postman to save new player details. but getting mentioned error”No longer supports a callback”

Select specific javascript parts of the bootstrap.min.js of Bootstrap to reduce its size

I am building a site with Bootstrap, but I would like to reduce the size of the Javascript botstrap.min.js file. I would like to use only those few JS parts that I use and are currently only offcanvas.js and dropdown.js. I tried several ways sought on the web, but I did not succeed. As the last way I simply tried this (but it doesn’t work even):

<script src="js/offcanvas.js"></script>
<script src="js/dropdown.js"></script>

The solutions found on the web are these two of the Bootstrap website: Lean JavaScript or Webpack e bundler, but I don’t know how to apply them because I didn’t understand much about the explanation.

I have already reduced the size of the CSS file with Sass and Scss and with Purgecss, but I have no idea how I can do the same for bootstrap.min.js. As for the reduced CSS, I would like to have only one file to import (for example my-bootstrap.js) in which Impbiesto aganvas.js and dropdown.js in it

Someone can show me a practical example of how I can reduce the bootstrap.min.js file and select only the specific parts I use?

What is Schema Markup and what is its use for SEO?

Recently, I built a website sharecy.net and prepared to do Google seo by myself, so I found a lot of related information about google seo on the Internet; I accidentally found a very useful seo plug-in seoquake.
I tested my website through seoquake, and it gave several optimization suggestions after analysis, one of which said that my website did not mark Schema Markup. But I don’t know what this means, what should I do?
Then I tried to generate the Schema Markup structure according to the online tutorial, on this page, https://www.sharecy.net/?id=40
I hope that some professional friends can help me to see if there is any problem, thank you!

I hope that a professional friend can help me to see if there is any problem with the Schema Markup structure, thank you!

How can I let the `range.values` fill in as an array even if I only select one cell in excel?

So I have this code about getting a distance using Google API and JavaScript to an Excel file:[enter image description here][1]

    Office.onReady((info) => {
  if (info.host === Office.HostType.Excel) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;
  }
});

// Get directionsData.distance.text from taskpane.html
var jarak = localStorage.getItem("distanceValue");

// "Type in excel" code
export async function run() {
try {
  await Excel.run(async (context) => {
  /**
   * Insert your Excel code here
   */
  const range = context.workbook.getSelectedRange();

  // Read the range address
  range.load("address");

  // Fill in the value
  range.values = jarak;

  await context.sync();
  console.log(`The range address was ${range.address}.`);
});
} catch (error) {
console.error(error);
}
}

What I’d like to ask is if I change the range.values = jarak; to range.values = [[jarak], [latitude], [longitude]]; (The additional parameters will be defined later).

I want the code to let me only select one cell from excel and it fills the next 2 cells (using the new range.values I defined here will add it to the next column). The problem is that I have to select the 3 cells in order to let the excel fills the new range.values which is an array if I recall the name correctly.

How can I let the range.values fills in as an array even if I only select one cell in excel?

The excel interface I made is like this: https://i.stack.imgur.com/Nh3YG.png

Is it wrong to place the tag after the tag? [duplicate]

I was reading this book. In one of the codes in chapter 5 of the book, I saw the code below:

<!-- index.html file -->
<html>
<head>
  <meta charset="utf-8" />
  <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<div id="app"></div>
</body>

<script type="module">

  import GlobalApp from "./global-app.js";

  var app = Vue.createApp({
    components : {
      GlobalApp:GlobalApp
    },
    template : "<GlobalApp />"
  });

  var vm = app.mount("div#app");

</script>
</html>

That code is for a main html file that runs a vue app (not in SFC format). If you notice the code, it put script type="module" tag after </body> tag. I know that there are some similar questions like this one in this problem. But I could not found anything about script type="module" in none of them. I want to know that is this usage wrong or non-valid that we put script type="module" after </body>?

Application won’t work after disconnecting from RDP

The problem is that my Java Script runs perfectly fine when I have a connection with RDP to my Windows Server but when I disconnect (Clicking X) as title says my Script wont work as expected.

It is recieving the requests from my website but can’t do the tasks properly such as FFMpeg.

Error adding banner to the video: Error: ffmpeg exited with code 1:
at ChildProcess. (C:Usersdurieun02Desktopservernode_modulesfluent-ffmpeglibprocessor.js:182:22)
at ChildProcess.emit (node:events:513:28)
at ChildProcess._handle.onexit (node:internal/child_process:291:12)

This is just an explanation error, in reality my process is not even working.

And such more errors like this when I am disconnected, The whole point of me opening a VM was to keep my actual PC offline while server would run for me in the background.

I have also tried running my Script as a background process but it didn’t worked either. It still somehow didn’t have the permissions or something, not really sure why.

I also edited gpedit.msc and Edited necessary things such as “Session Time Limits” but its not revelant at all since my session is not turning off but rather function don’t work properly when RDP is not connected.

I have also trying running it as a scheduled task and windows service, the problem is still same, the script runs but its not working as expected, my website esentiially returns the errors.

Thanks for the helps, I hope we can find a solution for all.

Pixel Streaming Matchmaking issue: ‘WARNING: No empty Cirrus Servers are available’

I’ve been working on issue for some days, but I can’t figure out any solutions…

I’m testing this in Local computer.

  • I’m using default Pixel Streaming Matchmaker from github ‘EpicGames/PixelStreamingInfrastructure’.

  • I’m also using default Start_SignallingWebServer.ps1 from same repository.

  • I’ve Opened Port in my Windows Firewall Advanced Settings.

  • I found similar question asked here, but there were answers on.

  1. When I Open Matchmaker by open ‘run.bat’ from ‘PixelStreamingInfrastructureMatchmakerplatform_scriptscmd’, it works well.

Matchmaker run.bat

  1. After Open Matchmaker, I Open Start_SignallingWebServer with PowerShell,
    and it connects to Matchmaker without issue.

SignallingWebServer connect to Matchmaker

  1. Then I Open Unreal Instances(Application that I built from Unreal Project with Pixel Streaming Plugin)
    it Connects to SignallingWebServer without issue.

Unreal Instance connected to SignallingWebServer

  1. When I checked matchmaker.js from ‘PixelStreamingInfrastructureMatchmaker’, I found in function ‘getAvailableCirrusServer()’, when cirrusServer’s numConnectedClients is 0, and ready is true, it returns cirrusServer itself.

Matchmaker getAvailableCirrusServer()

  1. So, in the ‘ping’ message from matchmaker, I added console.log which is

Matchmaker Ping Message Log

console.log(Number of Clients in ${cirrusServer.address}:${cirrusServer.port}: ${cirrusServer.numConnectedClients}, ${cirrusServer.ready});

When I check this log in Matchmaker’s run.bat file running, it shows log

Matchmaker console log
’11:17:59.646 Number of Clients in MyIPAddress: 0, true’

This means that getAvailableCirrusServer() have to return cirrusServer, as there is no clients connected to signallingwebserver that I opened, and also instance is connected to signallingwebserver, so Matchmaker should be able to redirect any clients connected to itself to signallingwebserver.

But it doesn’t work as I imagined. When I open Chrome browser and enter to Matchmaker’s IP Address and Port,

Matchmaker not working

it shows message like this – ‘WARNING: No empty Cirrus servers are available’.

This log should be printed when getAvailableCirrusServer() failed to find any cirrusServer (which is SignallingWebServer).

But as you see in the picture (Matchmaker getAvailableCirrusServer), I’ve added some console.log to check whether the function enters if branch, and it actually enters, as you see in the picture above.

However, at the same time, it also shows log outside the loop, which is very awkward to me… because when the function already enters if statement, it has to return cirrusServer and get out from the function, but it is not working like that right now.

I want to know why the logs that shouldn’t be printed at same time is actually printing at same time, and ultimately solve this Matchmaking server issue (No empty Cirrus Servers)…

Would be grateful if someone provide me any ideas!

Next.JS 13 Firebase Storage: No default bucket found

Using Next.JS 13 and Firebase V9.

I have been able to make requests to Cloud Firestore successfully without issue. I believe my firebase app is configured correctly. I cannot identify the issue with my Cloud Storage setup though. Every time I try to get a ref and download a Cloud Storage file, I am met with No default bucket found. I made sure to initialize the storage bucket with files in the Firebase Console before I attempted this. I have tried numerous variations of implementation from Bard, Stackoverflow, and elsewhere, and I am certain it’s probably just a minor thing I’ve overlooked, but I can’t seem to narrow down the issue for the life of me.

Here is my Firebase.js file in my main project directory.

// Import the functions you need from the SDKs you need
import { initializeApp, getApp, getApps} from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getStorage} from "firebase/storage";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: process.env.FIREBASE_APIKEY,
  authDomain: process.env.FIREBASE_AUTHDOMAIN,
  projectId: process.env.FIREBASE_PROJECTID,
  storageBucket: process.env.FIREBASE_STORAGEBUCKET,
  messagingSenderId: process.env.FIREBASE_MESSAGEID,
  appId: process.env.FIREBASE_APPID,
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  measurementId: process.env.FIREBASE_MEASUREMENTID
};

// Initialize Firebase
const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();
const db = getFirestore(app);
const storage = getStorage(app);

//Export relevant modules
export { app, db, storage };

and here is the FileService file I’ve been trying to call when clicking a button on the website, which results in the no storage bucket found error.

import { storage } from "@/firebase"
import { ref, getDownloadURL } from "firebase/storage";

const downloadFile = async (fileName: string) => {
    const storageRef = await ref(storage);
    const file = await ref(storageRef, fileName);

    // Download the file to the specified location.
    await fetch(await getDownloadURL(file), {
        method: "GET",
        mode: "cors",
        headers: {
        "Content-Type": "application/pdf",
        },
    });
};

export default downloadFile;

I’ve also attempted to get a storageRef inside the Firebase.js file just to see if that would work but it throws the error there as well. I appreciate any guidance, I spent a long time trying to figure this one out and I wouldn’t be surprised if I’m doing overlooking something small and stupid but I need a third party to point me in the right direction here.

Recoil: Triggering a function on atom change

I’m trying to store a user object inside an atom and have it be cached inside localStorage each time it changes because the app might crash and I do not want the user to have to sign in every time:

localStorage.setItem('user', JSON.stringify(user))

Previously when I used useContext this was achieved through a useEffect in the parent component (App.js) that monitored the user object for changes. It’s no longer possible for me to do this after migrating from useContext to Recoil due to my NextJS project structure (RecoilRoot wraps around the children component, so the parent App.js itself does not have access to useRecoil methods). And so, I’m wondering if there’s a way to implement this kind of listener or callback using a built-in Recoil method

Desired process:

  1. Declare the state: const [user, setUser] = useRecoilState(userAtom)
  2. Trigger a change setUser({...})
  3. Trigger a callback on state change localStorage.setItem('user', JSON.stringify(user))