Can I run javascript code at command prompt just like any other python code? [closed]

I am trying to run .js code just like any other python command.

This code returns 10 as expected.

const add = (a, b) => {
    return a + b
}
console.log(add(4,6))

I saved the above code as myfile.js and then typed this command at the command prompt:

node myfile.js

I am trying to create a similar file for this code that I found here…

https://github.com/indic-transliteration/sanscript.js/

I should be able to pass 3 parameters at the command prompt like this…

node myfile.js aham itrans devanagari

I cloned the repo and tried the script found in test folder. But it did not work.

css animation using keyframes within a vue application

Here we have an in-out animation using css inside of a vue3 application.

If we look at this outside of our vue application in a plain html + css + js instance we can see that this is easily achievable when using requestAnimationFrame()

document.getElementById('toggleButton').addEventListener('click', function() {
        var rectangle = document.getElementById('myRectangle');
        if (rectangle.classList.contains('animation-in')) {
            rectangle.classList.remove('animation-in');
            requestAnimationFrame(() => {rectangle.classList.add('animation-out');})
            
        } else {
            rectangle.classList.remove('animation-out');
            requestAnimationFrame(() => {rectangle.classList.add('animation-in');})
        }
    });
#myRectangle {
            width: 100px;
            height: 150px;
            background-color: green;
            margin: 20px;
            transform: scale(0);
        }

.animation-out {
  animation-duration: 4s;
  animation-timing-function: ease;
  animation-direction: normal;
  animation-fill-mode: forwards;
  animation-name: scale-easeInOutBounce;
}

.animation-in {
  animation-duration: 4s;
  animation-timing-function: ease;
  animation-direction: reverse;
  animation-fill-mode: forwards;
  animation-name: scale-easeInOutBounce;
}

@keyframes scale-easeInOutBounce {
  0% { transform: scale(1); }
  2% { transform: scale(0.99); }
  4% { transform: scale(1); }
  10% { transform: scale(0.97); }
  14% { transform: scale(0.99); }
  22% { transform: scale(0.88); }
  32% { transform: scale(0.99); }
  42% { transform: scale(0.6); }
  50% { transform: scale(0.5); }
  58% { transform: scale(0.4); }
  68% { transform: scale(0.01); }
  78% { transform: scale(0.12); }
  86% { transform: scale(0.01); }
  90% { transform: scale(0.03); }
  96% { transform: scale(0); }
  98% { transform: scale(0.01); }
  100% { transform: scale(0); }
}
<!DOCTYPE html>
<html>
<head>
    <title>Rectangle Animation</title>
</head>
<body>

<div id="myRectangle"></div>
<button id="toggleButton">Toggle Animation</button>
</body>
</html>

The area where I would appreciate help and guidance, is applying a working solution within vue. The challenge is to integrate it within Vue’s reactivity and lifecycle hooks.

As we may know, requestAnimationFrame() is a JavaScript function that tells the browser to perform an animation and requests that the browser calls a specified function to update an animation before the next repaint. The method takes a callback function as an argument, which is called before the next repaint. This callback is where you’d typically update your animation logic. It’s more efficient and smoother for animations than setTimeout or setInterval, especially for web animations.

Here is a vue instance of the project that I need some help with:

https://jsfiddle.net/midnightstudios/fmz172wr/

<!DOCTYPE html>
<html>
<head>
    <script src="https://unpkg.com/vue@next"></script>
  <style>
    
    .element {
            width: 100px;
            height: 150px;
            background-color: green;
            margin: 20px;
            transform: scale(0);
        }

    .animation-out {
            animation-duration: 4s;
            animation-timing-function: ease; /*linear*/
            animation-delay: 0s;
            animation-iteration-count: 1;
            animation-direction: normal;
            animation-fill-mode: forwards;
            animation-play-state: running;
            animation-name: scale-easeInOutBounce;
            animation-timeline: auto;
            animation-range-start: normal;
            animation-range-end: normal;
        }

        .animation-in {
            animation-duration: 4s;
            animation-timing-function: ease;
            animation-delay: 0s;
            animation-iteration-count: 1;
            animation-direction: reverse;
            animation-fill-mode: forwards;
            animation-play-state: running;
            animation-name: scale-easeInOutBounce;
            animation-timeline: auto;
            animation-range-start: normal;
            animation-range-end: normal;
        }

        
        @keyframes scale-easeInOutBounce {
            0% { transform: scale(1); }
            2% { transform: scale(0.99); }
            4% { transform: scale(1); }
            10% { transform: scale(0.97); }
            14% { transform: scale(0.99); }
            22% { transform: scale(0.88); }
            32% { transform: scale(0.99); }
            42% { transform: scale(0.6); }
            50% { transform: scale(0.5); }
            58% { transform: scale(0.4); }
            68% { transform: scale(0.01); }
            78% { transform: scale(0.12); }
            86% { transform: scale(0.01); }
            90% { transform: scale(0.03); }
            96% { transform: scale(0); }
            98% { transform: scale(0.01); }
            100% { transform: scale(0); }
        }
  </style>

<script src="https://unpkg.com/vue@next"></script>
<script>
    
      const { createApp, ref, reactive, computed, watch } = Vue;

      </script>
</head>
<body>
    <div id="app"></div>
    <template id="app-template">
           
        <div :class="classes">

        </div>

        <button @click="trigger()" style="padding:5px;margin:10px;width:200px;height:30px; position: absolute; bottom: 10px; left: 50px;">{{triggerLabel}}</button>

    </template>
<script>
    const App = {
        template: '#app-template',
        components: {
        },
        setup() {

            const props = {

                // Define some reactive data
                active: ref(false),
            };

            return {...props};
        },
        created(){
            
        },
        mounted() {
        
        },
        watch: {

        },
        computed: {
            classes(){

                const animationClass = [];

                // Always add base classes
                animationClass.push('element');

                // Add classes for active and inactive states
                if (this.active) {
                        // Generate the class name
                        effectClass = `animation-in scale-easeInOutBounce`;

                        animationClass.push(effectClass);
                } else {
                        // Generate the class name
                        effectClass = `animation-out scale-easeInOutBounce`;
                        
                        animationClass.push(effectClass);
                }

                //requestAnimationFrame(() => { /* some fance function */ });

                return animationClass;
            },

            triggerLabel(){
        
                return !this.active ? 'Start Animation In' : 'Start Animation Out';

            },
        },
        methods: {
            trigger(){
                this.active =!this.active
            },
        }
    };

   const app = createApp(App).mount('#app');    
  </script>
</body>
</html>

How to render in real-time the django model’s field using django channels?

I already set up the connection between the server side which are the asgi.py, consumers, and routing, that is already listening to client side using javascript. But I don’t know how to render out, in real time, the field in that one model to my javascript that’ll will be shown in HTML.

This is the JavaScript:

var socket = new WebSocket(`ws://${window.location.host}/orders/`);

  socket.onmessage = function (e) {
    var data = JSON.parse(e.data);
    document.getElementById("testingMessage").innerText = data.message;
  };

This is the consumers.py so far:

class OrderConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        await self.accept()
        await self.send(json.dumps({'message':"testing"}))

    async def disconnect(self, close_code):
        await self.disconnect()

And this is the routing.py:

from . import consumers
from django.urls import path

websocket_urlpatterns = [
    path('time/', consumers.OrderConsumer.as_asgi())
]

This is the models.py model:

class BillingAddress(models.Model):

    isComplete = (
        ('NO', 'NO'),
        ('YES', 'YES'),
    )

    user = models.ForeignKey(User, on_delete=models.CASCADE)

    full_name = models.CharField(default='', null=True, max_length=1000)
    contact_number = models.CharField(default='', null=True, max_length=1000)
    full_address = models.CharField(default='', null=True, max_length=1000)
    message = models.CharField(default='', null=True, max_length=1000)

    total_price = models.CharField(default='', null=True, max_length=1000)

    is_complete = models.CharField(choices=isComplete, null=True, default='')

    def __str__(self):
        return self.full_name

    def save(self, *args, **kwargs):
        if self.full_name:
            self.slug = slugify(self.full_name)
        super(BillingAddress, self).save(*args, **kwargs)

All I want to achieve is to render that one field from the model (full_name) through the HTML in real time. Whenever there’s a new user registered, I want it to be rendered in real-time through the html.

Iphone IOS Crash issues

I’m facing an issue where my site continuously refreshes itself or crashes. This is occurring exclusively on iPhones, posibly mac and ipad. I don’t have access to a Mac or iPad to confirm, but I’m certain this problem doesn’t occur on PCs or Android devices.

I’ve tested it across different iphones all with iOS 16 or higher. I also tried 7 different browsers on the iPhone – Safari, Chrome, Firefox, Opera, Instagram, Edge, and DuckDuckgo, and the issue is on all of them.

My site is a wp site, and when browsing the post pages on my site, it triggers site reloads or crashes. The reload usually leads back to the same page, briefly displaying the error ‘This webpage was reloaded because an error occurred.‘ Sometimes, instead of reloading, it crashes with the error message ‘A problem repeatedly occurred.’

I’m unsure about the cause of this error or how to resolve it. I suspect it might be a memory issue because disabling my ads and plugins seems to reduce the rate of refreshes/crashes, though it doesn’t completely resolve the problem. If anyone has experienced this and knows a solution, please let me know.

React navigation bug

I am doing an app using react native, node.js and mySql. Unfortunately I am with a problem when it’s necessary to use react navigation in a small part of my code. I don’t know if the bug it’s caused for some problem with react navigation or my code. The erro happened when I use the arrow function executed by the onPress on the TouchableOpacity

Code:

import React from "react";
import { View , Text , TouchableOpacity } from "react-native";
import { css } from "../../assets/css/css";
import Icon from 'react-native-vector-icons/FontAwesome';

export default function Profile(props){

    return(
        <View style={css.areaMenu} >

            <TouchableOpacity style={css.buttonHome2}** onPress={()=>props.navigation.navigate('Home')}** >
                <Icon name="home" size={25} color={'white'} />
            </TouchableOpacity>

            <View style={css.areaTitle} >
                <Text style={css.textTitle} >Profile</Text>
            </View>

            <TouchableOpacity style={css.buttonLogout} **onPress={()=>props.navigation.navigate('Login')}** >
                <Icon name="sign-out" size={25} color={'white'} />
            </TouchableOpacity>
        </View>
    )
}

error:
TypeError: _reactNative.Keyboard.removeListener is not a function (it is undefined)

This error is located at:
in BottomNavigation
in ThemedComponent (created by withTheme(BottomNavigation))
in withTheme(BottomNavigation) (created by MaterialBottomTabViewInner)
in MaterialBottomTabViewInner (created by MaterialBottomTabView)
in RCTView (created by View)
in View (created by SafeAreaInsetsContext)
in SafeAreaProviderCompat (created by MaterialBottomTabView)
in MaterialBottomTabView (created by MaterialBottomTabNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by MaterialBottomTabNavigator)
in MaterialBottomTabNavigator (created by AreaRestrita)
in RNCSafeAreaView
in Unknown (created by AreaRestrita)
in AreaRestrita (created by SceneView)
in StaticContainer
in EnsureSingleNavigator (created by SceneView)
in SceneView (created by SceneView)
in RCTView (created by View)
in View (created by DebugContainer)
in DebugContainer (created by MaybeNestedStack)
in MaybeNestedStack (created by SceneView)
in RCTView (created by View)
in View (created by SceneView)
in RNSScreen
in Unknown (created by InnerScreen)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by InnerScreen)
in InnerScreen (created by Screen)
in Screen (created by SceneView)
in SceneView (created by NativeStackViewInner)
in Suspender (created by Freeze)
in Suspense (created by Freeze)
in Freeze (created by DelayedFreeze)
in DelayedFreeze (created by ScreenStack)
in RNSScreenStack (created by ScreenStack)
in ScreenStack (created by NativeStackViewInner)
in NativeStackViewInner (created by NativeStackView)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by SafeAreaInsetsContext)
in SafeAreaProviderCompat (created by NativeStackView)
in NativeStackView (created by NativeStackNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by NativeStackNavigator)
in NativeStackNavigator (created by App)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by App)
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes

Thanks your attention…

I tried create new functions to fix the bug, also tried ask for some Ia like chat gpt and bing.ai, but I still with this problem. (I am a beginner with react native).
Thanks.

How do I secure API keys and requests on my Express server?

So basically, I have a sign in with Google Button in my html, and I need the following code:

`

data-client_id=TOKEN HERE"

data-callback="processResponse"

data-context="continue-with"

data-ux_mode="popup"

data-auto_select="true">

</div>`

I have looked all over the internet, and I cannot find a good way to secure my client_id token. This is a general question that also applies to many other aspects of my website. For example, my front end html makes requests to add, change, and delete entries in a database, but anyone could send these requests and manipulate the database. How do I secure this?

I thought about process.env, but then anyone could open up the inspect element and type in console.log(process.env.TOKEN) to get it.

I also thought about requesting the backend server for the key, but I can’t find a good way to authenticate the request because then anyone could send a fetch request to my backend for this key. I thought about putting some sort of “password” that is required to authenticate the request, but then this password would have to be contained in the html making it essentially useless.

How to fix the error incompatible angular ivy in angular 11

enter image description here
enter image description here
How to fix the error in module.ts here’s my dependencies.

"dependencies": {
    "@angular/animations": "^11.2.14",
    "@angular/common": "^11.2.14",
    "@angular/compiler": "^11.2.14",
    "@angular/core": "^11.2.14",
    "@angular/forms": "^11.2.14",
    "@angular/localize": "^11.2.14",
    "@angular/platform-browser": "^11.2.14",
    "@angular/platform-browser-dynamic": "^11.2.14",
    "@angular/platform-server": "^11.2.14",
    "@angular/router": "^11.2.14",
    "rxjs": "^6.6.0",
    "tslib": "^2.0.0",
    "@fortawesome/angular-fontawesome": "^0.8.2",
    "@fortawesome/fontawesome-svg-core": "^1.2.27",
    "@fortawesome/free-solid-svg-icons": "^5.15.4",
    "ng-zorro-antd": "^11.4.2",}
"devDependencies": {
    "@angular-devkit/build-angular": "~0.1102.19",
    "@angular/cli": "^11.2.14",
    "@angular/compiler-cli": "^11.2.14",
    "@angular/language-service": "^11.2.14",
    "@angularclass/hmr": "^2.1.3",
    "@biesbjerg/ngx-translate-extract": "^4.2.0",
    "@ngx-rocket/scripts": "^5.2.3",
    "@ngxs/devtools-plugin": "^3.7.1",
    "tslint": "~6.1.0",
    "typescript": "~4.0.8",
    "webpack-cli": "^3.3.12"}

already update the angular/cli to 11.2.14. also the imports already update and restart the vscode and reinstall the node_module. still getting the error.

Timeout issue with Excel JavaScript WebQuery to NetSuite report

I have an issue with an Excel WebQuery to a NetSuite report timing out, it times out at about 90,000 records and there are 100,002 records in the report.

This is my working query that times out:

let
    Source =
    ()=> Web.Page(Web.Contents("https://{redacted_account_num}.app.netsuite.com/app/reporting/webquery.nl?compid={redacted_compid}&entity=139057&email={redacted_email}&role=1189&cr=1030&hash={redacted_hash}")),
    Delay = Function.InvokeAfter(Source, #duration(0,0,3,0)),
    Data0 = Delay{0}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Data0, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Document Number", type text}, {"Police QID", type text}, {"Police Role", type text}, {"Police Rank", type text}, {"Date Created", type date}, {"BAS SLA Info", type text}, {"Qty Shipped", type text}, {"BAS Category", type text}, {"Cooneen Size", type text}, {"Gender/Size/Length", type text}, {"Item", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","=","",Replacer.ReplaceText,{"Qty Shipped"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"Qty Shipped", Int64.Type}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Changed Type1",{"Document Number", "Police QID", "Police Role", "Police Rank", "Date Created", "BAS SLA Info", "BAS Category", "Cooneen Size", "Gender/Size/Length", "Item", "Qty Shipped"})
in
    #"Reordered Columns"

This is my crude attempt at paginating through the results to attempt to extract smaller amounts of data at a time to avoid the time-out, my paginated code simply times out and returns nothing.

let
    // Function to fetch a single page
    FetchPage = (offset as number, limit as number) as table =>
        let
            Url = "https://{redacted_account_num}.app.netsuite.com/app/reporting/webquery.nl?compid={redacted_compid}&entity=139057&email={redacted_email}&role=1189&cr=1030&hash={redacted_hash}&limit=" & Text.From(limit) & "&offset=" & Text.From(offset),
            Source = ()=> Web.Page(Web.Contents(Url)),
            Delay = Function.InvokeAfter(Source, #duration(0,0,3,0)),
            Data0 = Delay{0}[Data],
            PromotedHeaders = Table.PromoteHeaders(Data0, [PromoteAllScalars=true]),
            ChangedType = Table.TransformColumnTypes(PromotedHeaders,{{"Document Number", type text}, {"Police QID", type text}, {"Police Role", type text}, {"Police Rank", type text}, {"Date Created", type date}, {"BAS SLA Info", type text}, {"Qty Shipped", type text}, {"BAS Category", type text}, {"Cooneen Size", type text}, {"Gender/Size/Length", type text}, {"Item", type text}}),
            ReplacedValue = Table.ReplaceValue(ChangedType,"=","",Replacer.ReplaceText,{"Qty Shipped"}),
            ChangedType1 = Table.TransformColumnTypes(ReplacedValue,{{"Qty Shipped", Int64.Type}})
        in
            ChangedType1,

    // Pagination parameters
    PAGE_SIZE = 1000, // Define the number of records per page
    OFFSET_START = 0, // Starting offset
    maxPages = 101, // Define the maximum number of pages to fetch

    // Initialize the first page fetch
    FinalTable = Table.Buffer(FetchPage(OFFSET_START, PAGE_SIZE)),

    // Loop to fetch each page
    Output = List.Generate(
        ()=> [Offset = OFFSET_START, Table = FinalTable],
        each [Offset] < PAGE_SIZE * maxPages,
        each [Offset = [Offset] + PAGE_SIZE, Table = Table.Combine({[Table], FetchPage([Offset], PAGE_SIZE) })]
    ),

    // Get the final combined table
    CombinedTable = Table.Combine(List.Transform(Output, each [Table])),
    
    // Reorder columns in the combined table
    ReorderedColumns = Table.ReorderColumns(CombinedTable, {"Document Number", "Police QID", "Police Role", "Police Rank", "Date Created", "BAS SLA Info", "BAS Category", "Cooneen Size", "Gender/Size/Length", "Item", "Qty Shipped"})
in
    ReorderedColumns

How to stop video slider autoplay, when video playing?

I used swiper.js slider for video slide.
I want set autoplay , when video playing, swiper autoplay stop.

                          var storySwiper = new Swiper(vcat_id + ' .swiper-container',  {
                            slidesPerView: 1,
                            slidesPerGroup: 1,
                            loop: true,
                            autoHeight: false,
                            speed:3000,
                            autoplay: {
                                delay: 3000,
                                disableOnInteraction: false,
                                // waitForTransition: true,
                                // sliderFirstMove:true,
                                pauseOnMouseEnter: true,
                            },
                            navigation: {
                                nextEl: vcat_id + ' .swiper-button-next',
                                prevEl: vcat_id + ' .swiper-button-prev',
                            },
                            breakpoints: {  
                                768: {  
                                        slidesPerView:3,
                                        // spaceBetween: 30,
                                        // autoplay: false,
                                        freemode: false,
                                    }
                            },
                            on: {
                                slideChange: function (ell) {
                                  $('.swiper-slide').each(function () {
                                      var youtubePlayera = $(this).find('iframe').get(0);
                                      if (youtubePlayera) {
                                        youtubePlayera.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
                                      }
                                  });
                                },
                            }

Vite and RTLCSS

I’m using vite and vue 3 for compile my less file and using my less in index.html file like blow:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="/favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/src/assets/less/default.less">
    <title>Vite App</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>

i want to my less file also compile to RTLCSS so when i change the default.less to default-rtl.less, vite use my rtl.less file (in dev mode) and when i build my project it render two separated file like *.css and *-rtl.css
i have no ide how can i do it!

How to add an event at mutiple elements in vue.js

i am trying to add an double click event at multiple elements in vue3.

If it was a pure HTML and JS, i would code like

const actionElements = document.getElementsByClassName('none-dbclk');
Array.from(actionElements).forEach(function(element){
  element.addEventListener('dblclick',function(e) {...})
}

But in vue.js i only found to add @dblclick=”” at every elements in vue template.
additionally I’ve also heard that DOM multipulation is not generally recommanded in vue.js

what else i can try for this case?

Quokka not running in VSCode, showing long string of Javascript

I am taking a React class on Udemy and one of the sections is a refresher on Javascript. This module uses Quokka to run the code. When I attempt to run Quokka by using Start on Current File, it doesn’t run and in the output window that shows up, it displays a long string of Javascript. I didn’t find anything online and nobody on Udemy has seen this before. I am using a 2021 MBP.

I am using Node.js v21.4.0,

Here is what it looks like.

Quokka in VSCode

I did add the path to Node.js in the config file, even though it is in my path, and it made no difference. I tried uninstalling and reinstalling Quokka multiple times. I tried a bunch of older versions of Quokka.

How can I create a clustered column chart as a drilldown in highcharts?

I am looking to build a column chart that has a drilldown into a grouped column chart.

The following fiddle shows the rough plan of what I’m intending, except it is producing the same series regardless of which drilldown I click on.

https://jsfiddle.net/h5xm9dov/

I’m very novice at JS, but the plan is to use this structure as a base to then pass data onto it in R using the highcharter package.

If a div exists override top position css of another div

I am a beginner in Javascript, and I want to figure out how to change the top position of a div class if another div is visible on the web page.
For example, when a user is connected, the adminbar is visible on top of a website, and I want to override the top position of another div class inside the website.

The HTML :

<!-- A if The div is visible -->
<div id="wpadminbar" class="nojq"></div>
<!-- B The Other Element will change css top position if the Adminbar A is visible -->
<div onmouseover="mouseOverToggle()" onmouseout="mouseOutToggle()" id="new" class="child new wrapperInscription"></div>

What I tried in javascript:

<script>
  var adminbar = document.getElementById("wpadminbar");
  var coquillage = document.getElementsByClassName("wrapperInscription");
    if (adminbar.style.position === "fixed") {
        document.getElementsByClassName("wrapperInscription").style.top="86px";
    } else {
        document.getElementsByClassName("wrapperInscription").style.top="55px";
    }
  // if ( $('#wpadminbar').length > 0)
  //   $('.wrapperInscription').css('top','86px');
</script>

It doesn’t work for me, how can I manage to make it work please ? Is my syntax correct ?