Can Python functions be used in JavaScript?

I know that Python is great for AI, data analysis, and generally much simpler than JavaScript. In that sense, I would like to know if it’s possible to call Python functions from JavaScript?

What would happen if it were possible, would it really be useful?

I want to ask about code of program language [closed]

today I want to discuss about the problem which is solve the solution that related to a lot of problem. Example: I want to use loop in program language. I need to have the messagein orfer to a good program

Actually. I am student at University. so, I do not have the project. So, I want to join group to help me that known more knowledge. In order to become a good software engineer to have people who can use application or website better.

using Jquery load assets in android studio

I have been trying to use jQuery’s Load in a webView through Android Studio. I have an HTML page that, when I click a button, would load the new HTML and replace the content of a DIV with the new HTML. However, looking at the documentation, I realized that the LOAD function only worked on servers. I would like to know if it is possible to use Java to read the text in HTML code and replace it in the respective DIV that I need.
I thought about using JAVASCRIPT to access JAVA in Android Studio and having JAVA read the HTML and return the response via JAVASCRIPT. Then, I would use JQUERY’s HTML function, $(‘.divcont’).html(‘Content here’).

Is this possible? Is there a better solution for this?

Handling clipboard data copy and paste and clearing the data

I have the following code where I’m copying and then pasting some stuff like the following in the text area. I have it setup this way because when I paste the following three lines, the cursor stays right after the last line HIJ123 and not below HIJ123.

ABC123
DEF123
HIJ123

A couple of things I’m trying to achieve:

  1. After pasting the above three lines in the text area, if I want to paste the same thing (ideally it’s going to be different lines of text similar to above)again in the text area, let’s say after pressing enter after ABC123, the next three lines get pasted after HIJ123 as shown in the image below,even though the cursor was after ABC123 after pressing enter after ABC123. Is it possible to get it paster where I am looking for – after ABC123 in above scenario?

  2. Is there a way I could clear the clipboard data after pasting the contents? I was trying to achieve something using Clear Data! button but it doesn’t seem to be working.

enter image description here

let element = document.getElementById("post-text");

element.addEventListener('paste',(e) => { 
  e.preventDefault();
  console.log(event.clipboardData);
  element.value += (event.clipboardData || window.clipboardData).getData("text").trim()
} );

document.getElementById('post-button').addEventListener('click', function () {
 
var lines = $('#post-text').val().split('n');//gives all lines
 
 ///var lines = element.split('n');//gives all lines
 
 //To paste
 /*
ABC123
DEF123
HIJ123
 */

for(i=0 ; i < lines.length; i++){
$("#phrase").append("<div>"+lines[i]+"</div>")
}
});

document.getElementById('clear-button').addEventListener('click', function () {
console.log("What is element here?");
console.log(element);
element.value.clearData();


});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<textarea id="post-text" class="form-control" rows="8" placeholder="What's up?" required></textarea><br>
<input type="button" id="post-button" value="Post!">
<input type="button" id="clear-button" value="Clear Data!">
<div id="phrase"></div>

How do I add keywords to Deepgram implementation in JS?

This is the section of my code where I think the keywords should go.

class TranscriptionService extends EventEmitter {
  constructor() {
    super();
    const deepgram = createClient(process.env.DEEPGRAM_API_KEY);
    this.dgConnection = deepgram.listen.live({
      encoding: 'mulaw',
      sample_rate: '8000',
      smart_format: true,
      model: 'nova-3',
      punctuate: true,
      interim_results: true,
      endpointing: 200,
      vad_events: true,
      language: "en-US",
      utterance_end_ms: 1000,
      querystring: {
        replace: 'mail:male'  // Add find and replace query parameter
      }
    });

I went through the Docs and haven’t seen an example of code that looks like mine where I can as they all look something like “keywords=KEYWORD:INTENSIFIER”

My app is an AI that can talk over the phone but mistakes “male” for “mail” so I’m trying to use keyword boosting (maybe supression if possible) to fix this. Maybe my question is a bit stupid but any help would be appreciated.

I’ve tried adding another field for boosting but that didn’t work as the word was still mistaked. I’ve found that it works a bit as I used the weird words “Systrom” and “Krieger” and it interperted both of them correctly whereas without it would have failed to but it simply wont work in my case. I thought if it will always replace mail with male I can at least use the “replace” function so it will search through and change it but it doesn’t do anything.
Example:
Interaction 0: TTS -> TWILIO: Hello, this is [blank]. Can we begin?
Interaction 0 – STT -> GPT: Mail. Mail.

(Ignore the interaction, it’s just the fact that it hears mail every time.)

Is there a way to dynamically copy all local and global variables along with their values to the clipboard or a JSON file in VS Code?

I’m working on a project in Visual Studio Code and need to debug or log the state of my application. I’m trying to find out if there’s a way to dynamically copy all local and global variables along with their current values at once. Copying them individually is time-consuming and error-prone.

Is there a built-in feature, extension, or workaround that allows me to export or copy all variables and their values dynamically to my clipboard or into a JSON file? This would be incredibly helpful for debugging or sharing the state of my program with colleagues.

I’m currently using JavaScript, but I’m also curious if this is possible in other languages like Python or C#. Any guidance or recommendations would be appreciated.

Javascript Canvas Download Clashing

I’m working on a way to download two different sized versions of the picture using a canvas to repeat an image in it’s background.

It works when i tested just a single download option, but it doesn’t allow me to use more than one despite unique identifiers. Can you help me out? Below is the JavaScript code & notes.

Notes:

  • The canvas and download buttons are hidden within a toggle (div display:
    block/none). It worked for the first test, but not after adding
    different versions.

  • The body tag uses onload=”loadMe1();loadMe2()”; since they’re
    temporarily hidden by a Div

  • The JavaScript is within the body of the HTML5 code

    function loadMe1(){
    const canvas1 = document.getElementById(‘largePicPreview1’);
    const ctx1 = canvas1.getContext(‘2d’);
    const img1 = document.getElementById(‘lamp’);
    const pat1 = ctx1.createPattern(img1, ‘repeat’);
    ctx1.rect(0, 0, 50, 50);
    ctx1.fillStyle = pat1;
    ctx1.fill();
    return canvas1;
    }
    function convertCanvasToImage1(canvas1) {
    var image1 = new Image();
    image1.src = canvas1.toDataURL(‘image/png’);
    return image1;
    }
    // a button uses “onclick=”dwn1()”
    function dwn1(){
    var image1 = convertCanvasToImage1(document.getElementById(‘largePicPreview1’));
    var anchor1 = document.createElement(‘a1’);
    console.log(anchor1);
    anchor1.setAttribute(‘href’, image1.src);
    anchor1.setAttribute(‘download’, ‘image1.png’);
    anchor1.click();
    }

    function loadMe2(){
    const canvas2 = document.getElementById(‘largePicPreview2’);
    const ctx2 = canvas2.getContext(‘2d’);
    const img2 = document.getElementById(‘lamp’);
    const pat2 = ctx2.createPattern(img2, ‘repeat’);
    ctx2.rect(0, 0, 150, 150);
    ctx2.fillStyle = pat2;
    ctx2.fill();
    return canvas2;
    }
    function convertCanvasToImage2(canvas2) {
    var image2 = new Image();
    image2.src = canvas2.toDataURL(‘image/png’);
    return image2;
    }
    // a button uses “onclick=”dwn2()”
    function dwn2(){
    var image2 = convertCanvasToImage2(document.getElementById(‘largePicPreview2’));
    var anchor2 = document.createElement(‘a2’);
    console.log(anchor2);
    anchor2.setAttribute(‘href’, image2.src);
    anchor2.setAttribute(‘download’, ‘image2.png’);
    anchor2.click();
    }

How to select multiple buttons of the same class and assign a mouse event [closed]

I can access a single button by id, but nothing happens when I try setting a ‘click’ event for multiple buttons of the same class.
I have tried hundreds of different combinations of different ideas, but nothing works.
I have also spent over 12 hours trying to change the color of the button clicked.

The latest incarnation is here:
Those items selected by id work.
`

`
<!DOCTYPE HTML>

<html>

<head>
    <title>Learning</title>
</head>

<body>
    <h1>Learning to select multiple buttons based on class</h1>

    <h3>Click on the buttons</h3>

    <button onclick="colourChange()">BG</button>

    <button class "a" id="X1">A</button>
    <button class "b" id="X2">B</button>
    <button class "c">C</button>
    <button class "c">D</button>
    <button class "c">E</button>
    <button class "c">F</button>
    <button class "c">G</button>
    <button class "c">H</button>
    <button class "c">I</button>
    <button class "c">J</button>

    <h2 id="CC">Header 2</h2>

    <script>
        let a = document.getElementById('X1');
        a.addEventListener('click', event => {
            a.style.backgroundColor = 'green';
            alert("Hello World!");});

        let b = document.getElementById('X2');
        b.addEventListener('click', event => {
            b.style.backgroundColor = 'blue';});

        document.addEventListener('DOMContentLoaded', event => {
            let c = document.getElementsByClassName('.c');
            for (let i = 0; i < c.length; ++i) {
                c[i].addEventListener('click', event => {
                    c[i].innerHTML = 'Z';
                    alert("Event for c");}, false);};});

        let header2 = document.getElementById("CC");

        function colourChange() {document.body.style.background = 'orange'; header2.innerHTML = "Background changes ok";}
    </script>
</body>

</html>

`

`

I’ve tried with and without the test of DOM being loaded.
I’ve tried using query Selector All instead of get Elements By Class Name.
I’ve tried having a single button of class c.
I’ve tried umpteen pieces of code from various websites, include Stack Overflow, and read many web pages.
How can this be made to work?

Deciding on Database Indexes to Use

I’m creating an RDBMS that will use either MySQL or Microsoft SQL Server. I’m creating text files of data names and attributes that I will use. These text files are helping me decide what tables to create which leads to decisions about indexes.

I don’t know what to choose for indexes for the various tables. The database will contain people’s names and information about them. Using names for indexes means putting names in all the tables defeats one of the reasons for using an RDBMS.

The database will backend my webpage about family history. The webpage will be open to registered users who will be able to add and change information. I don’t know how to create indexes that they will know and be able to supply. The only solution I’ve thought of is to create a NAMES table that includes a unique index value for each name, like the LDS-ID used by the LDS Church ancestry data system. I could generate an index as each name is added based on birthdate and other variables and display that in the NAMES table search screen. I think this would work but don’t know if it’s a good idea.

I’ve searched and not found helpful articles discussing good practices for choosing and using indexes. I’d be grateful for suggestions on the subject and for links to articles.

How to select multiple buttons of the same class and assign a mouse event

I can access a single button by id, but nothing happens when I try setting a ‘click’ event for multiple buttons of the same class.
I have tried hundreds of different combinations of different ideas, but nothing works.
I have also spent over 12 hours trying to change the color of the button clicked.

The latest incarnation is here:
Those items selected by id work.
`

`
<!DOCTYPE HTML>

<html>

<head>
    <title>Learning</title>
</head>

<body>
    <h1>Learning to select multiple buttons based on class</h1>

    <h3>Click on the buttons</h3>

    <button onclick="colourChange()">BG</button>

    <button class "a" id="X1">A</button>
    <button class "b" id="X2">B</button>
    <button class "c">C</button>
    <button class "c">D</button>
    <button class "c">E</button>
    <button class "c">F</button>
    <button class "c">G</button>
    <button class "c">H</button>
    <button class "c">I</button>
    <button class "c">J</button>

    <h2 id="CC">Header 2</h2>

    <script>
        let a = document.getElementById('X1');
        a.addEventListener('click', event => {
            a.style.backgroundColor = 'green';
            alert("Hello World!");});

        let b = document.getElementById('X2');
        b.addEventListener('click', event => {
            b.style.backgroundColor = 'blue';});

        document.addEventListener('DOMContentLoaded', event => {
            let c = document.getElementsByClassName('.c');
            for (let i = 0; i < c.length; ++i) {
                c[i].addEventListener('click', event => {
                    c[i].innerHTML = 'Z';
                    alert("Event for c");}, false);};});

        let header2 = document.getElementById("CC");

        function colourChange() {document.body.style.background = 'orange'; header2.innerHTML = "Background changes ok";}
    </script>
</body>

</html>

`

`

I’ve tried with and without the test of DOM being loaded.
I’ve tried using query Selector All instead of get Elements By Class Name.
I’ve tried having a single button of class c.
I’ve tried umpteen pieces of code from various websites, include Stack Overflow, and read many web pages.
How can this be made to work?

Creating a hierarchical array of objects with many sub-levels

I have an array of objects (possible thousands) that may or not be nested (possible tens of nests). A subset of the data looks like this:

let data = [
   {"id":"m1", "name":"M1"},
   {"id":"m2", "name":"M2"},
   {"parent_id":"m2", "id":"s1", "name":"S1"},
   {"parent_id":"m2", "id":"s2", "name":"S2"},
   {"parent_id":"m2", "id":"s3", "name":"S3"},
   {"parent_id":"s3", "id":"b1", "name":"B1"}
 ];

This list looks pretty ordered but in real life, the objects can appear anywhere in the array ie. not ordered. Also note that the objects at the top layer do not have a parent_id. I’d like the array to be converted into:

newData = [ 
{ id: 'm1', name: 'M1'}, 
{ id: 'm2', name: 'M2', children:
   [ { parent_id: 'm2', id: 's1', name: 'S1'},
        { parent_id: 'm2', id: 's2', name: 'S2'},
        { parent_id: 'm2', id: 's3', name: 'S3', children:
            { parent_id: 's3', id: 'b11', name: 'B1'}
      } ] 
}
]

I have looked for various ideas and figured this answer came close so here is where I started:

const createDataTree = dataset => {
    let hashTable = Object.create(null)
    dataset.forEach( aData => hashTable[aData.id] = { ...aData, children : [] } )
    let dataTree = []
    dataset.forEach( aData => {
        if( aData.parent_id ) hashTable[aData.parent_id].children.push(hashTable[aData.id])
        else dataTree.push(hashTable[aData.id])
    } )
    return dataTree
};
console.log(createDataTree(data));

Two initial issues were evident- I don’t want objects without children to have an empty property- children:[] and this code only works with a single child level, not multiples.

For the first issue, I tried:

const createDataTree = dataset => {
    let hashTable = Object.create(null)
    let dataTree = []
    dataset.forEach( aData => {
        if( !aData.parent_id ) hashTable[aData.id] = { ...aData, children : [] }
        if( aData.parent_id ) hashTable[aData.parent_id].children.push(hashTable[aData.id])
        else dataTree.push(hashTable[aData.id])
    } )
    return dataTree
};
console.log(createDataTree(data))

This didn’t work (all objects still had a children:[]) and also I don’t understand how hashTable references dataTree such that dataTree is auto-magic-ally updated when a hashTable push occurs.

I like this approach because of its performance with large arrays- what changes are needed for children:[] and multiple levels, or is there a faster solution?

Run a JavaScript script directly from GitHub without installation, like with npx

I am trying to run a JavaScript script directly from GitHub without having to install it locally.

The idea is to do something similar to what npx nameProject does, where you can run a command without having to install the package.

I was wondering if there was a way to run a JS script that is on GitHub without having to clone or install it manually.

In other words, I would like to invoke the script directly from the repository, perhaps using a command like npx, but pointing to a JS file on GitHub.

And just a JS file, inside it I use the following dependencies:

const fs = require('fs').promises;
const path = require('path');
const { execSync } = require('child_process');

package.json:

{
  "name": "directory-inspector",
  "version": "0.0.0",
  "description": "A script to analyze and manage the directory in Node.js.",
  "main": "main.js",
  "exports": "main.js",
  "scripts": {
    "start": "node main.js"
  },
  "author": "",
  "license": "MIT",
  "dependencies": {},
  "devDependencies": {}
}

I tried using:

npx https://raw.githubusercontent.com/NAMEUSER/PROJECT/main/main.js

I get the following error:

npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_BAD_ARCHIVE: Unrecognized archive format
npm ERR! code TAR_BAD_ARCHIVE
npm ERR! TAR_BAD_ARCHIVE: Unrecognized archive format

Is there a solution to do this?

Socket.Io non consistent Data Stream

I am having trouble using socketio together with flask to display ‘live’ data.
I receive data on my webapp, but it is very inconsistent. It is not predictable when Data will arrive.

I am trying to display a simple sin curve for testing and it is turning out unrecognizable. Here I have logged some data that arrived as an example:

Live data received: Object { 1 time: 194.79929999929748, value: 0.021253876945582027}
Live data received: Object { 1 time: 240.1999998299949, value: 0.9913219514756684}
Live data received: Object { 1 time: 285.79999999999284, value: 0.02482940667349397}
Live data received: Object { 1 time: 331.19939999398926, value: -0.9718055527309507}
Live data received: Object { 1 time: 331.39998899998925, value: -0.9892221305516083}
Live date received: Object { 1 time: 376.79992999928018, value: -0.1899270803974535}
Live data received: Object { 1 time: 422.99999999998454, value: 0.8979144124613327}
Live data received: Object { 1 time: 468.3839999232813, value: -0.7849990633617221}
Live data received: Object { 1 time: 514.2293939999801, value: -0.4638514751873342}
Live date received: Object { 1 time: 514.9999999999861, value: 0.21939584858396854}
Live date received: Object { 1 time: 561.1999999999966, value: 0.9167452046090582}
Live data received: Object { 1 time: 561.3999999999907, value: 0.8105467146602126}

The code printed by the python code drirectly in the console seems to be pretty consistent spitting out a new value every 100ms.

My backend python code producing the sin wave looks like this:

app = Flask(__name__)
socketio = SocketIO(app)

def generate_live_data():
    t = 0
    while True:
        time.sleep(0.1)  
        t += 0.1
        value = math.sin(t)
        socketio.emit("live_data", {"time": t, "value": value})
        print(f"Live data received:", data)

thread = Thread(target=generate_live_data, daemon=True)
thread.start()

if __name__ == "__main__":
    socketio.run(app, host="0.0.0.0", port=5000, debug=True)

And my Frontent java-script framework looks like this:

socket.on("live_data", data => {
  if (liveChart) {
    liveChart.data.labels.push(data.time.toFixed(1));
    liveChart.data.datasets[0].data.push(data.value.toFixed(2));
    if (liveChart.data.labels.length > 50) {
      liveChart.data.labels.shift();
      liveChart.data.datasets[0].data.shift();
    }
    liveChart.update();
  }
});

Is there anything wrong with my code, that might impact this slow and irregular updating of the chart?

Error downloading node 14.21.3/14.20.0 with NVM. The system cannot find the file specified

I want to install version 14 for an old project that uses that version. I use nvm and all installations from 16 onwards work perfectly.

But, in version 14.20.0 and 14.21.3, it fails and gives me this error:

Usuario@DESKTOP-VMRUVSP MINGW64 ~
$ nvm install 14.21.3
Downloading node.js version 14.21.3 (64-bit)...
Complete
Downloading npm...
Creating C:UsersUsuarioAppDataLocalTempnvm-install-11959995temp

Downloading npm version 6.14.18... Complete
Installing npm v6.14.18...
error installing 14.21.3: open C:UsersUsuarioAppDataLocalTempnvm-npm-2920922696npm-v6.14.18.zip: The system cannot find the file specified.

Delete the temporary folders that start with nvm-install and nvm-npm and nothing, it keeps giving the error. So, I don’t know what to do.

What do you recommend I do? Thank you

How to install Node version 14

Creating a client that will carry onto the next page [closed]

I am working on a website where the scenario is on the first page you click on the client (list of buttons with their names) and after clicking it leads you to the next page where you can input their specifications ( their mood on a scale of 1-10, their speech, etc). When I click on the name, I want it to also then display the name that was chosen on the input page. Every name’s input page would be the same, so how could I code something where on the input pages it displays the name you selected? thank you

I haven’t tried it out yet, because I don’t know how to start and cant find something that depicts what I’m looking for.