How to run gunicorn from 1 folder above manage.py

My folder structure is completely messed up but I am trying to load my django project on to a docker image for the first time and its failing on my CMD step

My directories are as follows:

WORKDIR/appname/appname/wsgi.py

In my docker image I need to call the gunicorn command that runs the server. Typically when I am in the terminal I can cd into the right directory and run

gunicorn appname.wsgi:application --bind 0.0.0.0:8000

How can run this same command from 1 folder structure outside of where I normally am?

I have tried gunicorn ./appname/appname.wsgi:application ...

Thanks in advance

Best way to query for team id from team name and then query for all users with that team id in firestore?

I have a collections of users where each document ID is the uid and the documents have 2 fields: user_name and team_id.
I have another collection of teams where each document ID is randomly generated and the documents have 2 fields: team_name and team_id (the randomly generated id).

I am using react router and useParams to a team name to a component.
I would like to query the team collection to see which document in there has team_name equal to the team name that is passed. Then I would like to get the team_id from the document that has that team name and use it to query the user collection for which users have that team_id.

I know if I can get the team_id then I can do something like:

const queryRef = query(
  collection(db, 'users'),
  where('team_id', '==', team.id)
);
const [users] = useCollectionOnce(queryRef);

and then inside my return do something like:

{videos.docs.map((user) => {
  const data = user.data();
  const userName = data.user_name;
  return (
    // display userNames in some way
  );
})}

I was wondering what the best way to get the team_id value from the team_name value or if there are any other better ways to get the list of users.

Prototype variable in javascript class notation

What is the way of declaring a proper prototype-like variable as in functions but using class notation in Javascript?

Some background:

Currently we have two ways of declaring a “class” templates with ES6

  1. using function
function Something(v) {
  this.v = v;
}

Something.prototype.isSomething = true;

And then use it:

let sth = new Something(2);

As a result value contains instance variable sth.v = 2;
and prototype variable (shared among all instances) as sth.prototype.isSomething = true

The isSomething variable will become an instance variable when we change it, for a particular instance, like so:
sth.isValue = false. Then we have sth.v = 2 and sth.isSomething = false, and isSomething will ‘move’ from .prototype to instance in the structure of the object (it is possible to verify in the console). Such case is increasing memory only for the edited instance as for the rest of Something instances the isSomething property will still be pointing to the .prototype.

  1. using class
class Something {
  isSomething = true; // is this the correct usage?
  constructor(v) {
    this.v = v;
  }
}


And then use it:

let sth = new Something(2);

In this case
the sth.v = 2 as in previous example but sth.prototype.isSomething is not existing in chain (at least this is how it is shown in the browser console).

Instead, the isSomething variable is by default stored as an instance variable by default. This is not intended because, as per my understanding, each instance will now duplicate isSomething property, increasing the memory usage.

Does the class notation triggers some optimisation in JS engine under the hood to handle aforementioned drawbacks?

I am aware of availability of static Value.isValue option but this is not the same as class variables have different usage.

The consideration here is that very often the code is ‘refactored’ from javascript functions or IIFE’s to new ES6 classes but I wonder if brings described memory penalties. As far as I remember for high performance the .prototype props were used as much as possible in the past and made the difference (example being many graphics libs like Three.js).

Load .txt contents into javascript variable for use in javascript file itself

This should be a simple enough problem. But every solution I have found is related to use with HTML.

I am trying to take the contents of a text file, assign the contents to a variable in javascript, and use that javascript variable in the javascript file itself not in an html page or the like.

For example, I have a text file called ‘treeView.txt’ which contains the following: “{‘1’ : { ‘2’ : { ‘3’ : { ‘a’: {}, ‘b’ : {}, ‘c’ : {}}}}};”

I am trying to read this content into a javascript variable. And then later, use this variable in a javascript function. Unfortunately, every combination of filereader, etc, that I use doesn’t return the variable. For example:

fetch('/treeView.txt')
   .then(response => response.text())
   .then((data) => {
     const allFolders = data;
    });

cannot locate my text file and returns a 404 error. I want to use data as the content of my allFolders variable to be used later on in my javascript file in a javascript function.

Unable to access input sources for inline WebXR session

I would like to access input sources – in particular, the Quest touch controllers – during an inline WebXR session (not entering immersive VR mode; I am not using three.js or A-Frame) on the Quest browser. I request and store the session with the code:

let xrSession;

navigator.xr.requestSession("inline").then( function(session) {
    xrSession = session;
});

The variable xrSession does in fact store an XRSession type variable with an inputSources field, but inspecting inputSources via the Javascript console, it is always an empty array; I am unable to access any data.

How can I access input sources in WebXR, or the Quest controller data (such as button pressed states) in general, in the Quest browser without entering VR mode?

If condition is not getting validate

This is a function to check if input data only contains numeric values

<input type="text" class="form-control" placeholder="Search &amp; enter" id='dtablesearch' onkeyup="searchcollum()"/>

const searchcollum = () =>{
    let filter = document.getElementById('dtablesearch').value.toUpperCase();
    if (/^d+$/.test(filter)==true){
              let dtable = document.getElementById('zero_config');
              let tr = document.getElementsByTagName('tr');
              for (var i=0; i<tr.length; i++){
                let td = tr[i].getElementsByTagName('td')[2];
                if (td){
                  let txtvalue = td.textContent || td.innerHTML;
                  if (txtvalue.toUpperCase().indexOf(filter)>-1){
                    tr[i].style.display = "";
                  }else{
                    tr[i].style.display = "None";
                  }
                }
              }
           }
        }

Condition isn’t getting True as result even when I enter 16 in the input…

Any suggestions ??

How can I use the latest react version (react18)?

When using npx create-react-app my-app, I got this error:

( You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.1).
  We no longer support global installation of Create React App.
  Please remove any global installs with one of the following commands:
  - npm uninstall -g create-react-app
  - yarn global remove create-react-app

 The latest instructions for creating a new app can be found here:
 https://create-react-app.dev/docs/getting-started/ )

I used the command npm uninstall and also check out the [getting started with react][1]

[1]: https://create-react-app.dev/docs/getting-started/ ,but that links suggest the same process
of npx create-react-app my-app. I also used this command npm install react react-dom but this
only install a node modules and a package.json. It doesn’t create the usual react boilerplate
and all. Anyone have any idea, please help.

what is the value of results for the makeCounter()

What is the value of const result? my guess was (3, 1). This is confusing to me so any help would be appreciated.

    function makeCounter() {
      let count = 0;
      return function() {
        count += 1;
        return count;
      }
    }
    const counter1 = makeCounter();
    const counter2 = makeCounter();
    counter1();
    counter1();
    
    const c1 = counter1();
    const c2 = counter2();
    const result = [c1,c2];
    console.log(result)

jQuery count checkboxes and group count by data-attribute

I have a number of html checkboxes that I am trying to count like this…

    jQuery('.mycheckboxes').change(function() {
      var count = jQuery('.mycheckboxes:checked').length;
      console.log(count);
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="checkbox" class="mycheckboxes" data-section="1" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="1" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="1" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="1" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="2" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="2" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="2" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="2" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="3" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="3" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="3" name="mycheckboxes">
    <input type="checkbox" class="mycheckboxes" data-section="3" name="mycheckboxes">

This is working correctly, but I want to create something like an array which will group the count of clicked checkboxes by the data-section attribute, so my output would look something like…

{
    data-section-1 : 4,
    data-section-2 : 3,
    data-section-3 : 1,
};

What is my best approach, I am more used to using PHP so would be trying to create an array, but should I be using an object instead?

My database query function always return null

I maked query function for my project. But result always is null, how i can debug this code?

const queryDB = async (collection,filter) =>  {
  let result = null
  await MongoClient.connect(url, function(err, getDb) {
    if (err) throw err;
    const db = getDb.db("global"); 
    db.collection(collection).findOne(filter, function(err, result) {
      if (err) throw err;
      result = result
    })
  })
  return result
}

Cordova Save As

I’m looking for a “Save as…” feature with Ionic/Cordova.

I searched for it for a long time, but every solution use the Cordova’s File plugin.

I don’t want to arbitrarily define a file location before to save it, I want to let the user select his own location / directory, as in this screenshot.

The file-saver package can do that, but unfortunately doesn’t work with Cordova.

Any clue?

Parse script in string format to JSON

I am trying to parse a string that comes from a database into useable JSON

This is the string

"<script type="application/json">n[n    {n        "id": "test1_label",n        "variants": [n            {n                "name": "when-all",n                "values": [n                    {n                        "main": false,n                        "name": "test1_label",n                        "type": "swatch",n                        "property": "@background-color",n                        "value": "primary-dark",n                        "id": "34543"n                    }n                ]n            }n        ]n    }n]n</script>"

The data that is saved looks like this and I am trying to get it back to this original format once retrieved.

[
    {
        "id": "test1_label",
        "variants": [
            {
                "name": "when-all",
                "values": [
                    {
                        "main": false,
                        "name": "test1_label",
                        "type": "swatch",
                        "property": "@background-color",
                        "value": "primary-dark",
                        "id": "34543"
                    }
                ]
            }
        ]
    }
]

I’ve tried to use replace with regex to clean it up and then parse it but no luck.

Separate firestore queries in the same react function

In the fetchUserCart() function, I am trying to first get an array containing strings with the product unique name and then set my state array with the result from the second query (query based on first query’s result). While the first one works, the second one doesn’t and I dont understand why. When I try to map currentProducts to render a table, the array is empty.

export const CartPage = () => {


    const [user,  error] = useAuthState(auth);
  const [cartItems, setCartItems]=React.useState(0);
  const [currentProducts, setCurrentProducts]=React.useState([]);


  const fetchUserCartItems=async()=>{
  
    const q = query(collection(db, "users"), where("uid", "==", user?.uid));
    const doc = await getDocs(q);
    const data = doc.docs[0].data();
    let cartItemsClone=data.cartItems;
    setCartItems(cartItemsClone);  
    
} 

const fetchUserCart = async() =>{
    const q = query(collection(db, "users"), where("uid", "==", user?.uid));
      const doc = await getDocs(q);
      const data = doc.docs[0].data(); 
      let cart=data.cart; 
      console.log(cart);
      let products =[];
      cart.forEach(async(item)=>{
        const q = query(collection(db, "products"), where("uniqueName", "==", item));
        const doc = await getDocs(q);
        const data = doc.docs[0].data();  
        products.push(data);
        
      })
      setCurrentProducts(products);
  }

 
React.useEffect(() => {
  fetchUserCartItems();
  fetchUserCart();
}, [user], [currentProducts] );

The ban command doesn’t do what it’s supposed to do

When I try to run my command, instead of the errors I specified, I get the errors from the console and the result is: Failed to ban the user and the console says DiscordAPIError: Interaction has already been acknowledged. and/or missing permissions. But if I try to ban myself with an account that has no rights, I get banned myself. So if I do tryfyfu /ban user: @tryfyfu with my acc (the account without rights) I can still ban myself but the bot should actually say: “❌ | You can’t ban a user from the guild!” answer and so it is with the other functions like invalid memberor ❌ | You can't ban yourself and so on Here’s the code. Would be nice if someone could help me.

const {
    Client,
    CommandInteraction,
    Message,
    MessageEmbed,
    MessageActionRow,
    MessageButton
} = require('discord.js');

module.exports = {
    name: 'ban',
    description: 'Ban a user',
    options: [
        {
            name: "user",
            description: "Choose the user to ban.",
            type: "USER",
            required: true
        },
        {
            name: "reason",
            description: "reason for punishment",
            type: "STRING",
            required: false
        }
    ],
    run: async (client, interaction, options) => {
        const member = interaction.options.getMember("user")
        const reason = interaction.options.getString("reason") || "No reason given"


        if(!interaction.member.permissions.has("BAN_MEMBERS")) {
        const buttons = new MessageActionRow()
        .addComponents(new MessageButton()
        .setLabel("Permissions")
        .setEmoji("⚙️")
        .setStyle("LINK")
        .setURL("https://discord.com/developers/docs/topics/permissions"))

        const embed = new MessageEmbed()
        .setColor("RED")
        .setDescription("❌ | You can't ban a user from the guild!")

        interaction.reply({
            embeds: ,
            components: [buttons],
            ephemeral: true
        })
    }
     if(member === interaction.member) {
            const embed = new MessageEmbed()
            .setColor("RED")
            .setDescription("❌ | You can't ban yourself")

            interaction.reply({
                embeds: 
            })
        }
     if (!member) {
        
        const embed = new MessageEmbed()
        .setColor("RED")
        .setDescription("❌ | Invalid Member")

        interaction.reply({
            embeds: ,
            ephemeral: true
        })
        }
    
        try {
            await interaction.guild.bans.create(member, {
                reason
            })
            const embed = new MessageEmbed()
            .setColor("GREEN")
            .setDescription(`✅ | ${member.user.tag} was banned for: ${reason}`)
            
            return interaction.reply({
                embeds: 
            })
        }
        catch(err){
            if (err){
                console.error(err)
                const embed = new MessageEmbed()
                .setColor("RED")
                .setDescription(`❌ | Failed to ban ${member.user.tag}`)

                return interaction.reply({
                    embeds: 
                })
            }
        }
}
}