node.js : function.prototype.method multiple exports inside one file

Noob in JS here.

Let’s say I have a js file where the contents are like

function a(){}
a.prototype.method1 = function() { ... };
a.prototype.method2 = function() { ... };

function b(){}
b.prototype.method3 = function() { ... };
b.prototype.method4 = function() { ... };

module.exports = new a();
module.exports = new b();

In this file, I’ve function definition.
In the next file, I’m trying to access the methods below

var x = require('./file.js');

x.a.method1();   //Not working
x.method1();     //Not working

But both types of accessing result in error for me. Can you please help me with steps on how to access the methods correctly?

And I can access those functions if I try to have only 1 export in one file. But I want it to be like this. 2 exports in a same file.

Cannot create a document inside the firebase collection

I am trying to create a simple to-do app using firebase as my CMS. But I am facing an error while trying to create my document on the firewall. My code is,

const addToDo = (e) => {
e.preventDefault();

addDoc(collection(db, "todos"), {
  inprogress: true,
  timestamp: firebase.firestore.FieldValue.serverTimestamp(),
  todo: todoInput,
})
setTodoInput("");

}

So I try to call this function once I click the button on the form,

    <form>
      <TextField
        id="standard-basic"
        label="Write a Todo"
        variant="standard"
        className="textField"
        value={todoInput}
        onChange={(e) => {
          setTodoInput(e.target.value);
        }} />
      <Button 
        type="submit" 
        variant="contained" 
        onClick={addToDo} 
        className="buttonDisplay">
        Display
        </Button>
    </form>

When I click the button I get an error on the console saying that “Uncaught TypeError: Cannot read properties of undefined (reading ‘FieldValue’).”

Here I have also attached the import for my App.js,

import './App.css';
import { TextField, Button } from '@material-ui/core';
import { useState } from 'react';
import {db} from './firebase_cofig';
import firebase from 'firebase/compat/app';
import { collection, addDoc } from "firebase/firestore";

And this is my firebase_config.js file,

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";

const firebaseConfig = {
  apiKey: "AIzaSyAVa9YdtqQAYuZ0u5stifRRhp5RULHLnRc",
  authDomain: "to-do-app-fd528.firebaseapp.com",
  projectId: "to-do-app-fd528",
  storageBucket: "to-do-app-fd528.appspot.com",
  messagingSenderId: "646758689416",
  appId: "1:646758689416:web:0c91670c0caa3d08b34d3d"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);

// const db = firebase.firestore();
const db = getFirestore(app);

export { db };

can someone help me on this issue?

React Native Expo + Firestore – How to avoid fetching from cache if no internet connection?

By default (at least if you are using Expo) it seems that if you try to .get() something from Firestore with no internet connection, the data will be returned from cache, even if the local persistence is not implemented in the browser.

You can see this behavior on Expo, with the original firebase sdk, if you run this method without connection:

async function performSomeQuery(query, limit) {
  const querySnapshot = await query.limit(limit).get();

  if (querySnapshot.metadata.fromCache) {
    throw new Error("It is from cache!");
  }

  if (querySnapshot.empty) {
    return [];
  }

  const result = querySnapshot.docs.map(parseDoc);

  return result;
}

For me, this behavior is a little confusing… because if you try to enable the Firestore local persistence in your Expo app, you will get the error code: unimplemented

firebase.firestore().enablePersistence()
  .catch((err) => {
      console.log(err.code); // unimplemented for Expo
  });

How can I receive exceptions instead of “cached” data when the internet is not connected??

Removing urls from a data-frame column with targetblank tag

I want to remove url’s from a column in a data-frame. The column I am interested in is called comment, and example entry in comment is:

|comment                                 |
|:--------------------------------------:|
| """Drone Strikes Up 432 Percent Under. |
|Donald Trump"" by Joe Wolverton, II,    |
|J.D.                                    |
|<a                                      |
|href=""https://www.thenewamerican.com/  |
|usne                                    |
|ws/foreign-policy/item/25604-drone-     |
|strikes-up-432-percent-under-donald-    |
|trump""                                 |
|title=""https://www.thenewamerican.com/ |
|usn                                     |
|ews/foreign-policy/item/25604-drone-    |
|strikes-up-432-percent-under-donald-    |
|trump""                                 |
|target=""_blank"">https://www.thenewamer|
|c                                       |
|an.com/usnews/foreign-policy/item/25604-|
|drone-st...</a><br/>""Trump is weighing |
| major escalation in Yemen's devastating| 
|war<br/>The war has already killed at   |
|least 10,000, displaced 3 million, and. | 
|left millions more at risk of famine."" |
|<br/>"                                  |

This above entry shows the issue I am trying to solve. I want to completely remove:

<a href=""https://www.thenewamerican.com/usnews/foreign-policy/item/25604-drone-strikes-up-432-percent-under-donald-trump"" title=""https://www.thenewamerican.com/usnews/foreign-policy/item/25604-drone-strikes-up-432-percent-under-donald-trump"" target=""_blank"">https://www.thenewamerican.com/usnews/foreign-policy/item/25604-drone-st...</a>

I’ve tried:

df['comment'] = df['comment_body'].replace(r'httpsS+', ' ', regex=True).replace(r'wwwS+', ' ', regex=True).replace(r'httpS+', ' ', regex=True)

However this likes with me in

href title targetblank com

How to use liquid template tags in external javascript in jekyllrb?

I’m trying to remove all the inline scripts from our jekyllrb project. The inline scripts pull some values from jekyll data eg. {{site.homepage_title}}, which throws an error when moved to an external/standalone javascript file.

I try renaming the javascript file for example search.js to search.js.liquid but it doesn’t work.

Any ideas or workaround would be much appreciated. Thanks!

JavaScript: How to fire the keyboard button “Tab”

If I press the “Tab” key in my ui the cursor jumps to next input field. I also want to achieve this behavior with the Enter key. Is it possible to press the Tab key via Javascript?

    public void Enter(KeyboardEventArgs e)
    {
        if (e.Code == "Enter" || e.Code == "NumpadEnter")
        {
            //press tab 
        }
    }

How to format date visible in DateRangePicker

The default format is ‘DD/MM/YYYY’ but I want ‘DD MMM YYYY’, how do I do this with mui/v5 DateRangePicker.

Does this get applied to DateRangePicker or the TextField? there are startProps and endProps but no documented description of their contents or overrides.

I tried mask=”__ ___ ____” but the mask doesnt even seem to be applied!

Address CSS general sibling selector and input:checked

I’ve tried to address styles defined like this:

header input[type=checkbox] ~ div#example {max-height:0px;}
header input[type=checkbox]:checked ~ div#example {max-height:100px;}

I would like to do something like

document.getElementById('example').style.maxHeight='10px';

but it should only change

input[type=checkbox]:checked

not the unchecked Version.

Maybe there is a way with nextElementSibling? Thanx for your help!

TypeError: Cannot read properties of undefined (reading ‘id’) (javascript)

when i run this code it gives me error Cannot read properties of undefined (reading ‘id’) what’s the problem in my code?

tasklist=[{"id": 58,"taskName": "task-1","lists": []}]

const createItem = () => {
    const itemName = document.getElementById("itemName").value;
    const taskId = document.getElementById("task-id").value;
    let itemObj;
    tasklist.filter((object) => {
        if (object.id === taskId) {
            console.log("true");
            itemObj = {
                id: Math.floor(Math.random() * 100),
                itemName: itemName,
                done: false,
            };
            object.lists.push(itemObj);
        }
        return object;
    });
    displayItem(taskId, itemObj.id);
};

Create connection to SQL SERVER use Javascript in HTML ( ASP.NET MVC )

I’m a newbie. I’ve watched this video https://www.youtube.com/watch?v=Rr9RE05rw4E and followed this. But I don’t have a response in my comment. I have a problem with “Error creating connection”. I don’t know why I can’t access the database. My syntax is the same as this video so I don’t know what is going wrong. My skill and my English are bad. I’m sorry.
Here is my code
`

<script type="text/javascript">
        var conn = new ActiveXObject("ADODB.Connection")
        var conn_str = ""
        var db_Host = ""
        var db_User = ""
        var db_Password = ""
        var db_Provider = ""
        var db_Default = ""
    function Show_Data() {
        db_Host = "LAPTOP-I8T1TTH1HUYEN";
        db_User = "sa";
        db_Password = "password";
        db_Provider = "SQLOLEDB";
        db_Default = "DEMO";
        conn_str = "Provider="+db_Provider+";Data Source="+db_Host+";User ID="+db_User+"; password="+db_Password+ "; Initial Catalog="+db_Default;
        show_data_from_database();
    }
    function show_data_from_database() {
        try {
            conn.Open(conn_str)// open the connection
            //alert
            var reader = new ActiveXObject("ADODB.Recordset");
            var strQuery = "SELECT * FROM user";
            reader.Open(strQuery, conn);//fetch the data
            reader.MoveFirst();//move to the first row
            while (!reader.EOF)//read until the last row of data
            {
                document.write(reader.fields(0) + "&nbsb;&nbsb;&nbsb");// print to the screen
                document.write(reader.fields(1) + "&nbsb;&nbsb;&nbsb");
                document.write(reader.fields(2) + "&nbsb;&nbsb;&nbsb");
                document.write(reader.fields(3) + "<br/>");
                //alert(rs.fiels(0));
                reader.movenext(); // move to the next row
            }
        }
        catch (e) {
            alert("Error creating connection")
        }
    }
</script>`

keeping div in the same position along with window resize

This content moves along with the window resize and I’m trying to make it stay in place. Is there any way to stop the content from moving or should I move the section along with window resize so that it appears in the same position?

Pictures of the content in [@media only screen and (min-width: 992px) and (max-width: 1199px)]

width: 1198 px
width: 992 px

The partial code

#hero {
    height: 100%;
    position: relative;
    float: left;
    padding: 18% 10% 35% 6%;
    margin: 0 5% 0% 5%;
    width: 90%;

}

.IntroText {
    margin-left: auto;
    margin-right: auto;
    color:black;
    padding-bottom: 1.5%;
    font-size: 20px;
    transform: translateX(-20px);
    transition: transform 1s, opacity 1s;
    transition-delay: 0.5s;
}

.MyName {
    color:#fad25a;
}

.knowMore {
    left: 0.4%;
    font-weight: bold;
    font-size: 20px;
    transform: translateX(-20px);
    transition: transform 1s, opacity 1s;
    transition-delay: 1s;
}

button, .talkButton {
    color: #d4af37;
    padding: 5px 25px;
    border: 2px solid #d4af37;
    position: relative;
    margin: auto;
    z-index: 1;
    overflow: hidden;
    transition: 0.3s;
}

button:after, .talkButton:after {
    content: '';
    background-color: #252526;
    position: absolute;
    z-index: -2;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

button:before, .talkButton:before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0%;
    height: 100%;
    background-color: #d4af37;
    transition: 0.3s;
    z-index: -1;
}
button:hover, .talkButton:hover {
    cursor: pointer;
    color: #252526;
}
button:hover:before, .talkButton:hover:before {
    width: 100%;
}

button:focus, .talkButton:focus {
    outline: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="hero" class="jumbotron">
            <div class="container">
            <h1 class="IntroText animated">
                Lorem Ipsum dolor <span class="MyName">sit amet</span> and<br> consecteuer
            </h1>
            <button type="button" id="knowbutton" class="knowMore animated" onclick="toAbout()">Know more</button>
        </div>
    </section>

document.elementFromPoint returning different elements for same input

I am using document.elementFromPoint to figure out what svg shape is at a certain point. I was experimenting with elementFromPoint on this image when I noticed that I was getting different outputs for the same input.Image of chrome devtools console where document.elementFromPoint is called with the arguments 0.25 and 50 in 2 different places, returning different svg elements

Here is exactly what I did for reproducibility.

  1. I cut and pasted the svg tag from the linked svg and inserted it into the body of an html file. The html file was set up using the single ! emmet shortcut in vscode. Nothing else was in the body. The only css was body{margin:0;}.
  2. In chrome I went around calling elementFromPoint. Mostly at .25,50 but sometimes just a little to the right or a little to the left. Sometimes calling with the same arguments over and over again to see if it would change.
  3. There was no scrolling done during this time. There wasn’t even an option as there was no scroll bar present.

My question is why does this happen? Is there a pattern to it? Is there a way to prevent it?
Thanks.

In safari browser, refused to display in a frame because it set “X-Frame-Options” to “Deny”

Actually, I tried to download a file inside iFrame using location.url='download file link'. it works well in all browsers except safari.

In safari browser, I am facing following issue.

Refused to display 'mydownlaod url' in a frame because it set "X-Frame-Options" to "Deny".

Could you please provide your suggestion to download a file inside iframe? Do we have any option to fix this in client side itself?

How can I create a function which will take a date and return schedules based on time condition

This is my database structure:

[
    {
        "schedule_time": "2021-05-17 12:39:29",
        "slot": "L",
        "item_date": "2021-05-18"
    },
    {
        "schedule_time": "2021-05-17 12:47:53",
        "slot": "D",
        "item_date": "2021-05-18"
    },
    {
        "schedule_time": "2021-05-18 13:55:22",
        "slot": "D",
        "item_date": "2021-05-19"
    },
    {
        "schedule_time": "2021-05-19 16:09:15",
        "slot": "L",
        "item_date": "2021-05-20"
    },
    {
        "schedule_time": "2021-05-19 16:11:55",
        "slot": "L",
        "item_date": "2021-05-20"
    },

I want to create a function that will take item_date and it will show how many schedules are between 9am to 12am. 12am to 3pm, 3pm to 6pm, 6pm to 9pm on previous days. if you look at the database the item_date and schedule_date are not the same. That’s why I want the previous day’s schedules listed in an array.

I have created a function it’s only returning 9am to 12am data. I want the schedules together in an array.

  function schedulesList (date){
        let dbItemDate = date;
        let otherDayArray = schedules.filter(num => num.item_date !== dbItemDate); // not equal because I want other dates schedules not the exact date
        let times = otherDayArray?.filter(num => num.schedule_time.split(' ')[1] >= '12:00:00' && num.schedule_time.split(' ')[1] <= '14:00:00');
        console.log('9am to 12pm', times.length, 'schedules') //
    }

How to set a Default Filter

When enter the page, I want to filter a default value before searching, i tried with onload , but i not sure how to work with onload and keyup together. Currently , the keyup filter function is works but i want to add a onload to let first times the page load with a default value filter.

HTML

<label>Search:<input type="search" id="searching" value="default-value"></label>

Script

<script>

$(document).ready(function(){
$("#searching").on("keyup", function() {
  var value = $(this).val().toLowerCase();
  $("#Table1body tr").filter(function() {
    $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
  });
});
});
</script>