Why does the script increase the entered time by 33 minutes?

There is a script that, when entering time in column A or B, should substitute the current date for the entered time.

function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  var range = e.range;
    if (range.getColumn() === 1 || range.getColumn() === 2) {
    var time = range.getValue();
    if (typeof time === 'object') {
      var hours = time.getHours();
      var minutes = time.getMinutes();
      var date = new Date();
      date.setHours(hours);
      date.setMinutes(minutes);
      date.setSeconds(0); // Обнуляем секунды
      var formattedDate = Utilities.formatDate(date, Session.getScriptTimeZone(), 'dd.M HH:mm');
      sheet.getRange(range.getRow(), range.getColumn()).setValue(formattedDate);    
}  
}
}

But, after entering, for example, 14:00 in a cell, the value first changes to 11.25.2023 14:00, and then immediately to 11.25.2023 14:33.
With what it can be connected?

When replacing date.setMinutes(minutes); on date.setMinutes(minutes – 33); The cell displays the actual entered time -33 minutes (11.25.2023 13:27).

Change HTML DOM while page loads

I want to edit some node’s content in DOM on the page, but if i do it using window.onload it’s done only after the full page loaded and it is visible that the content of node changes.

So, is there a way to edit some node’s content while page loading but before it’s shown to user?

Third-Party Vue Packages with Nuxt.js: Will They Work Together?

I’m diving into using third-party Vue packages/plugins with Nuxt.js and wondering if they play nice together without much hassle. Do all Vue packages just smoothly fit into Nuxt, or do they often need some tweaking or special handling?

My main worry is that a package built for regular Vue might not work as expected within Nuxt. Take, for instance, an OpenStreetMap plugin – what if it works perfectly fine with Vue but runs into issues within a Nuxt project because it doesn’t account for server-side rendering and assumes it’s only in a browser environment?

I’m trying to get a clearer picture of any challenges or limitations when using third-party Vue stuff in Nuxt.js. Can someone help clarify if there are things I need to watch out for or adapt to make everything work together seamlessly?

Email queue keeps sending out duplicate emails

I’m trying to implement an email queue, but it’s not quite working as expected. The idea is to respond from an endpoint as quickly as possible and then just have the queue manager attempt to process the queue in the background, in this case send out an email.

One of the problems is that the interval keeps executing when this.running is set to true. Another problem is that an email sometimes sends out multiple times, when it should only be sent out once.

I’ve also tried using redis for this because I recognise the closure issue with initialize and also saw bull as a potential solution, but I’m trying to avoid as many unneccessary libraries as possible. Ideally, I’d like to make some sort of base class that I can reuse for different queues, for examples an SMS queue, not just an email queue. But for now, I guess I’m just trying to get this email queue to work.

What am I doing wrong here? Here’s my code:

import emailClient from 'services/emailClient';
import randomUuid from 'services/randomUuid'

export interface EmailClientConfig {
    to: string;
}

const MAX_ATTEMPTS_FOR_EMAILS = 5;
class EmailQueueManager {
    private running = false;
    private emailQueue = new Map();

    private handleRemoveSentEmailsFromQueue(sentEmailUuids: string[]) {
        // delete each sent out email from queue
        sentEmailUuids.forEach((sentEmailUuid) => {
            this.emailQueue.delete(sentEmailUuid);
        });

        // set state to "ready to process"
        this.running = false;
    }

    private async handleProcessEmailQueue() {
        // determines if queue is currently being executed
        this.running = true;
        const processedEmails: Record<string, boolean> = {};
        // list of successfully sent emails
        const sentEmailUuids: string[] = [];

        // do nothing if currently being executed, so as
        // to not send out duplicate emails
        if (!this.emailQueue.size) {
            this.running = false;
            return;
        }

        const emails = [...this.emailQueue];

        for (let i = 0; i < emails.length; i++) {
            const [emailUuid, { attempts, emailLogEvent, ...emailConfig }] = emails[i];

            emailClient(emailConfig)
                .then((result) => {
                    sentEmailUuids.push(emailUuid);

                    // maybe do something else
                })
                .catch((err) => {
                    if (attempts > MAX_ATTEMPTS_FOR_EMAILS) {
                        // remove from queue permanently if
                        // attempt count exceeds what is allowed
                        this.emailQueue.delete(emailUuid);
                    } else {
                        // send back to queue and attempt to send email out again
                        this.emailQueue.set(emailUuid, {
                            attempts: attempts + 1,
                            emailLogEvent,
                            ...emailConfig,
                        });
                    }
                })
                .finally(() => {
                    // flag email as "processed", regardless of whether
                    // or not is was successfully sent
                    processedEmails[emailUuid] = true;
                });
        }

        // check every 250ms if all emails in queue
        // were processed (not necessarily successfully sent out)
        const checkProcessedEmailsInterval = setInterval(() => {
            if (Object.values(processedEmails).every(Boolean)) {
                this.handleRemoveSentEmailsFromQueue(sentEmailUuids);
                clearInterval(checkProcessedEmailsInterval);
            }
        }, 250);
    }
    public addEmailToQueue({
        emailConfig,
        emailLogEvent,
    }: {
        emailConfig: EmailClientConfig;
        emailLogEvent: string;
    }) {
        // add email to queue
        this.emailQueue.set(randomUuid(), { attempts: 0, emailLogEvent, ...emailConfig });
        // and immediately process the queue
        this.handleProcessEmailQueue();
    }

    public initialize() {
        // check every minute if there are
        // emails in queue that need to be processed
        setInterval(() => {
            if (!this.running) {
                this.handleProcessEmailQueue();
            }
        }, 1000 * 60);
    }
}

const emailQueueManager = new EmailQueueManager();

// instantiate the interval
emailQueueManager.initialize();

export default emailQueueManager;

And I use this like so:

import emailQueueManager from 'src/managers/queues/emailQueue';

. . .
async function someEndpoint(req, res) {
    // do stuff
    emailQueueManager.addEmailToQueue({
        emailConfig: {
            to: '[email protected]',
        },
        emailLogEvent: 'sent_email',
    });
    // do more stuff

    res.end()
}
. . .

getServerSideProps doesn’t show in inspect element

I’m using getServerSideProps function to render my components and scripts.

for example:

import Head from "next/head";

 <Head>
  return (
<Schema url={"/faq"}/>
)
 </Head>

Schema component is a script file for seo.
content of schema shows inside view page source but it doesn’t show in inspect element.

Find value from json in js

I am trying to get a value from json by using the JSON.parse function. My JSON is below:

var ralList = `{ 
    "RAL 1000": "205-186-136",
    "RAL 1001": "208-176-132",
    "RAL 1002": "210-170-109",
    "RAL 1003": "249-169-0",
    "RAL 1004": "228-158-0",
    "RAL 1005": "203-143-0",
    "RAL 1006": "225-144-0",
    "RAL 1007": "232-140-0",
    "RAL 1011": "175-128-80",
    "RAL 1012": "221-175-40",
    "RAL 1013": "227-217-199",
    "RAL 1014": "221-196-155",
    "RAL 1015": "230-210-181"
}`;

const data = JSON.parse(ralList);

How do I find the RGB value according to RAL xxxx in data object?

Thanks for help.

Order of execution for class in javascript

class Department{   
 constructor(){     
  console.log('parent class')   
 } 
} 
class Employee extends Department{  
  constructor(){    
   super()     
   console.log('child constructor method')   
  }     
  findName(){       
   console.log('Vimal');   
  } 
} 
let E1 = new Employee(); console.log(E1.findName())

Now in the above code it gives me the logs as “parent class” “child constructor method” “User Name” undefined Now where is this undefined coming from can anyone help me understand this

How to highlight custom keywords in Ace Editor in Angular?

I’m trying to highlight a couple of keywords that are present in this.$rules . However I’m not able to get the final output . Can you please tell me what I’m missing here?

This is what I have tried inside an Angular component

` export class AceBuildsEditorComponent implements OnInit, AfterViewInit {
@ViewChild(“editor”) private editor: ElementRef;

ngAfterViewInit(): void {
    ace.config.set("fontSize", "14px");
    const editor = ace.edit(this.editor.nativeElement);
    const oop = ace.require('ace/lib/oop');
    const TextMode = ace.require('ace/mode/text').Mode;
    const TextHighlightRules = 
    ace.require('ace/mode/text_highlight_rules').TextHighlightRules;
    const customHighlightRules = function() {
    this.$rules = {
         start: [
            {
              regex: /b(sometext|othertext)b/,
              token: 'keyword',
            },
         ],
    };
  };

  oop.inherits(customHighlightRules, TextHighlightRules);
  const Mode = function() {
    this.HighlightRules = customHighlightRules;
  };
  oop.inherits(Mode,TextMode);

  (function() {
      this.$id = "ace/mode/custom";
   }).call(Mode.prototype);
 }

}
`

Fix multiple console logs useEffect?

I have this problem where my code console logs 3 times at page load and also increments it’s index. I have no clue as to why this is happening. I’ve tried moving some stuff in and out of a useEffect but this didn’t help. I am using the typewriter-effect module together with NextJS. I’ve setup a minimal reproduce example here: https://codesandbox.io/p/sandbox/sleepy-shadow-ccvg97

When viewing the console log throughout the app you will notice that the index will be one too high. I know I could probably just set the index -1 after the page is done loading or something like that but I don’t think that that would be a ‘clean’ way of solving this issue.

In case you’d like to look at the code through Stack Overflow:

const words = ['innovative<br/>thinker', 'creative<br/>mind', 'web<br/>designer'];

const determineArticle = () => {
        const word = words[currentWordIndex];
        console.log(word);
        const vowels = ['a', 'e', 'i', 'o', 'u'];
        const firstLetter = word.toLowerCase()[0];
        console.log(vowels.includes(firstLetter) ? 'an' : 'a');
    }

    const [currentWordIndex, setCurrentWordIndex] = useState(0);

    useEffect(() => {
        if (Number.isInteger(currentWordIndex)) determineArticle();
    }, [currentWordIndex]);

    const typeWord = async (typewriter) => {
        for (let i = 0, len = words.length; i < len; i++) {
            await new Promise((resolve) => {
                typewriter
                    .callFunction(() => {
                        if (currentWordIndex == 15) setCurrentWordIndex(0);
                        setCurrentWordIndex((prevIndex) => prevIndex + 0.5);
                        resolve();
                    })
                    .typeString(words[i])
                    .pauseFor(2500)
                    .deleteAll()
                    .start();
            });
        }
    };

And here is the html:

<TypeWriter
    options={{
    autoStart: true,
    loop: true,
}}
    onInit={(typewriter) => {
          typeWord(typewriter);
    }}
/>

Also a screenshot for a visual example:
Image

How to avoid memory leak in useState

I have two react projects (Main UI and Widget UI), the first one renders the landing page and the other one gets triggered when the edit button is clicked on the Main UI App.

The widget application is installed as a dependency in Main UI and we pass our main UI props to the widget using useState.

The application works as expected but i see an error in console stating useState memory leak.

How can I get rid of the issue?

Note: Having two seperate projects are business requirements

I’m thinking about moving the application to redux, but I’m unsure how two different applications will share the store and update it

Videos not autoplaying on mobile

I’m using reactjs and for some reason, videos are not autoplaying on mobile.
I’m using iOS 17, Safari
Here is my code:

<div className="video" ref={videoRef} dangerouslySetInnerHTML={{
                    __html: `
                <video 
                loop 
                muted 
                autoplay 
                playsinline 
                muted 
                defaultMuted 
                loop
                >
                 <source src=${video} type="video/mp4" />
                  </video>
        `}}>

On mobile, there is just a play button.

I also tried to play the video using javascript:

const videoRef = useRef(null)
    useEffect(() => {
        if (videoRef.current) {
            const videoElement = videoRef.current.children[0];
            videoElement.play();
        }
    })

However, I get the error: `The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission =.“`

I can’t run TypeScript inside “node:bookworm” docker image

When I tried to run TypeScript server inside a container from “node:21.1.0-bookworm” it didn’t work and gave me this error :

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /app/src/index.ts

I tried to install it manually by running “npm install -g typescript” in Dockerfile and by “docker logs” it didn’t work!

Dockerfile:

FROM node:21.1.0-bookworm as test-node-image
WORKDIR /app
COPY package.json .
ARG NODE_ENV
RUN npm install -g typescript
RUN npm install
COPY ./ /app
ENV PORT 3000
EXPOSE $PORT
CMD [ "npm","run","start" ]

package.json file:

{
  "devDependencies": {
    "ts-node": "^10.9.1",
    "tsx": "^4.4.0",
    "typescript": "^5.3.2"
  },
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "start": "tsx watch src/index.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": ""
}

tsconfig.json file:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "baseUrl": "src",
    "sourceMap": false,
    "outDir": "./dist",
    "noEmitOnError": true,
    "esModuleInterop": true,
    "allowJs": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "skipLibCheck": true
  },

  "include": ["src/**/*"],
  "ts-node": {
    "esm": true,
    "experimentalSpecifierResolution": "node"
  },
  "watchOptions": {
    "watchFile": "dynamicPriorityPolling",
    "watchDirectory": "dynamicPriorityPolling",
    "excludeDirectories": ["**/node_modules", "dist"]
  }
}

Note: The same project works on “node:18” without any problems!