React native Camera Kit continuously scan Qr code with mutltiple callbacks onReadCode

I need to integrate the QR code scanner for my project with react native, I’m using the plugin react-native-camera-kit, this plugin supports QR and Bar code scan but when i scan the code it continuously scan the code and call back the function onReadCode={()=>} the continuously. I need to remove the camera from QR code to stop it.

is that any way to scan the QR code only once.

<Camera
 showFrame={true}
 laserColor={Colors.green}
 frameColor="white"
 onReadCode={(event: any) => {
 console.log("event=>", event?.nativeEvent.codeStringValue)
 }}
 scanBarcode={true}
 style={{flex: 1}}
 />

Node.Js WebPack Error when Using Dependency Array

I’m having difficulty trying to figure out why the dependOn WebPack property is failing when using multiple dependencies.

If I have an entry point as :

./src/EntryA.js

let LibraryA = require("./library/LibraryA.js");
let LibraryB = require("./library/LibraryB.js");

class EntryA {
    constructor() {
        console.log("EntryA");
        let libraryA = new LibraryA();
        let libraryB = new LibraryB();
    }
}

module.exports = EntryA;

With it’s two dependencies as :

./src/library/LibraryA.js

class LibraryA {
    constructor() { console.log("LibraryA"); }
}

module.exports = LibraryA;

./src/library/LibraryB.js

class LibraryB {
    constructor() { console.log("LibraryB"); }
}

module.exports = LibraryB;

Then WebPack seems to have no problem creating the bundle with this config :

module.exports = {
  mode: "production",
  entry: {
    EntryA: {
        import: "./src/EntryA.js"
    }
  },
  output: {
    filename: "[name].min.js",
    path: path.resolve(__dirname, "bundle"),
    libraryTarget: "var",
    library: "[name]",
  },
  target: "web",
  module: {
    rules: [
      {
        test: /.(js)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: { presets: ["@babel/preset-env"] }
        }
      }
    ]
  }
};

This is fine but when the single bundle becomes too big and I want to split out the dependencies I run into problems, like with this updated config :

module.exports = {
  mode: "production",
  entry: {
    EntryA: {
        import: "./src/EntryA.js",
        dependOn: ["LibraryA", "LibraryB"]
    },
    LibraryA: "./src/library/LibraryA.js",
    LibraryB: "./src/library/LibraryB.js"
  },
  output: {
    filename: "[name].min.js",
    path: path.resolve(__dirname, "bundle"),
    libraryTarget: "var",
    library: "[name]",
  },
  target: "web",
  module: {
    rules: [
      {
        test: /.(js)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: { presets: ["@babel/preset-env"] }
        }
      }
    ]
  }
};

It looks like it’s working because I still get the three bundles I am expecting

./bundle/LibraryA.min.js
./bundle/LibraryB.min.js
./bundle/EntryA.min.js

But trying to run them in the HTML file no longer works (without splitting the dependencies it did work) :

<html>
  <head>
    <script src="./bundle/LibraryA.min.js"></script>
    <script src="./bundle/LibraryB.min.js"></script>
    <script src="./bundle/EntryA.min.js"></script>
  </head>
  <body>
    <script>
      window.onload = () => { const entryA = new EntryA(); }
    </script>
  </body>
</html>

With the errors :

Uncaught TypeError: o[r] is not a function
Uncaught TypeError: EntryA is not a constructor

I’m looking to code a random button selector in my HTML, JS, CSS app

Just to preface. I have little experience in css/html/js.

I’m building an application loosely based on wordle but instead of a word. You’re guessing a sportsman.

The info of the player is given through different stat categories which are revealed on the press of a button.

The button will be chosen at random; which leads to the problem i’m facing.

I have 5 buttons inside of a container div.

I’m looking to have these buttons light up consecutively (one-by-one) for a random amount of time until the animation slows down and lands on a particular button (similar to some animations i’ve seen on gambling sites like online roulettes or slot machines).

The button that gets chosen will reveal a list of particular stats pertaining to the player based on the category that its titled as:

button display

After some bits of research I can kind of grasp how variables and functions work in js, and have coded some ‘onclick’ events into my web page but am unsure as to how I code what i’m trying to achieve.

Any help would be greatly appreciated.

How do I detect that a Telegram web app for bots was closed?

I’ve set up a Telegram bot that launches a web app, in any way: inline button, keyboard, link… Once the tasks in the web app are completed, the user may close the web app using the “close” button and not through any button in my web app that I can log.

I’d like my bot to do some operations in the database when this happens.

How can I detect when the web app closes?

answerWebAppQuery cannot be used for this purpose, unload, beforeunload, pagehide and blur and similar events are not detected, and the web_app_close event is fired from the app to the bot and as such cannot be intercepted. How can I know when the web app was closed? There is a possible workaround but it relies on the user finishing the interaction the way I want them to do and not to use the “close” button, which is unrealistic.

footer-html not loading JavaScript in Laravel-Snappy

I used Laravel-Snappy for generate Pdf with large data.
I want to add page count and many more things in Footer-html. I used below code from https://wkhtmltopdf.org/usage/wkhtmltopdf.txt .

  <!DOCTYPE html>
  <html><head><script>
  function subst() {
      var vars = {};
      var query_strings_from_url = document.location.search.substring(1).split('&');
      for (var query_string in query_strings_from_url) {
          if (query_strings_from_url.hasOwnProperty(query_string)) {
              var temp_var = query_strings_from_url[query_string].split('=', 2);
              vars[temp_var[0]] = decodeURI(temp_var[1]);
          }
      }
      var css_selector_classes = ['page', 'frompage', 'topage', 'webpage', 'section', 'subsection', 'date', 'isodate', 'time', 'title', 'doctitle', 'sitepage', 'sitepages'];
      for (var css_class in css_selector_classes) {
          if (css_selector_classes.hasOwnProperty(css_class)) {
              var element = document.getElementsByClassName(css_selector_classes[css_class]);
              for (var j = 0; j < element.length; ++j) {
                  element[j].textContent = vars[css_selector_classes[css_class]];
              }
          }
      }
  }
  </script></head><body style="border:0; margin: 0;" onload="subst()">
  <table style="border-bottom: 1px solid black; width: 100%">
    <tr>
      <td class="section"></td>
      <td style="text-align:right">
        Page <span class="page"></span> of <span class="topage"></span>
      </td>
    </tr>
  </table>
  </body></html>

I got error —

The exit status code ‘-1073741819’ says something went wrong: stderr: “Loading pages (1/6) [> ] 0% [======> ] 10% [==============================> ] 50% [============================================================] 100% Counting pages (2/6) [============================================================] Object 1 of 1 Resolving links (4/6) [============================================================] Object 1 of 1 Loading headers and footers (5/6) [> ] 1% [=> ] 3% [===> ] 5% [===> ] 6% [====> ] 8% [======> ] 10% [=======> ] 12% ” stdout: “” command: “C:Program Fileswkhtmltopdfbinwkhtmltopdf” –lowquality –margin-bottom “30mm” –margin-top “40mm” –page-size “a4” –encoding “UTF-8” –enable-javascript –javascript-delay “13500” –enable-local-file-access –enable-smart-shrinking –no-stop-slow-scripts –footer-html “C:UsersRAGINE1AppDataLocalTempknp_snappy64b90da61bd510.93606603.html” –header-html “C:UsersRAGINE1AppDataLocalTempknp_snappy64b90da61bf1d8.66548341.html” “C:UsersRAGINE1AppDataLocalTempknp_snappy64b90da61baf51.08168467.html” “C:UsersRAGINE1AppDataLocalTempknp_snappy64b90da61bcec9.78969162.pdf”.

I tried :

 $pdf = PDF::loadView('report.pdf.Report', $data=['Products'=>$Products])
           ->setOption('margin-top', '40mm')
           ->setOption('margin-bottom', '30mm')  
           ->setOption('enable-javascript', true)
           ->setOption('javascript-delay', 13500)
           ->setOption('enable-smart-shrinking', true)
           ->setOption('no-stop-slow-scripts', true)
           ->setOption('header-html', $headerHtml)
           ->setOption('footer-html', $footerHtml)
           ->setPaper('a4');
         
        return $pdf->inline();

Also tried in snappy.php

'pdf' => [
        'enabled' => true,
        'binary' => '"C:Program Fileswkhtmltopdfbinwkhtmltopdf"',
        'timeout' => 3600,
        'options' => [
            'enable-local-file-access' => true,
            'encoding'      => 'UTF-8'
        ],
        'env'     => [],
    ],

Still, I am not able to find solution.
Sorry for my bad English. Any help would be appreciable.

How to calculate the score of the quiz? [closed]

i am making a buzzfeed style quiz project where after answering 5 questions you can find out which planet of the solar system are you. but instead of linking one planet to eight different choices i have each choice linked to 2 planets. However, when i try to calculate the score i dont get an answer because i dont have a highest number score. i either got 2 even answers, or multiple same answers so my quiz can’t give the result of the answers.

i tried setting the answer score required to match with planet from greater than 5 to less than 4 four in hopes of getting an answer but i got 2 same answers with a score of 4.

How can I make the last element don’t render alone using the Tiny Slider 2 Library?

I have been using Tiny Slider 2 in my company for months and I had no problems until I was asked to create a slider with this behavior
expected behavior

But by default tiny slider ends the slide pagination like this
default behavior

I tried adjusting the css margin based on the current index of the element slide but the transition did not have a good user experience.

Problem printing text that has just been written

Im making a simple html webpage with some JavaScript. I take information from a JSON file, and with help of JavaScript, I format the text and prepare it to export to a CSV file.

The problema comes when I write the text on the page, and after try to read it. It gives me an EMPTY string, so I cant export it.

For testing, im just wiriting the OutPut with console.log, but im not getting the response i would like

JavaScript

document.addEventListener('DOMContentLoaded', function () {
    convertData();
});

function convertData() {
    fetch('info.json')
    .then(response => response.json())
    .then(data => showData(data))
    .then(print())
    .catch(error => console.error('Error:', error));
}

function showData(data) {
    const container = document.getElementById("container");

    for (var i = 0; i < data["data"].length; i++) {
        var obj = data["data"][i];

        container.innerHTML += "<br>" + obj["field1"] + "; " + obj["field2"] + "; "
    }
}

function print() {
    const container = document.getElementById("container");
    const data = container.innerHTML;
    console.log(data);   
}

HTML

<!DOCTYPE html>
<html>

<body>
    <div id="container"></div>
</body>
</html>

When I use container.innerHTML += "....." it shows me content correctly, but when i print it, it doesnt.

Build responsive UI in React Native using metrics directly from the design

I’m trying to get the perfect safe area outside of the top and bottom areas of a mobile device, like below. 

My goal is to put the designer’s value into a function and quickly have a screen that will look exactly the same on both Android and iOS. There are packages, but unfortunately, they do not work perfectly. There are always differences between Android and iOS or between Android models. To fix this situation, I did something like this:

  1. For example, suppose the designer has placed two buttons with 426 and 420 sizes on a green screen with default dimensions of 393×852. So a green area of 6 units will appear at the bottom of the screen.

  1. In such a case, I prepared a function like the one below to take the number directly from the design and transfer it directly to the code. The general logic is this: On phones and tablets with a notch, the value of “Dimensions.get(“window”).height includes the safe area as well as the height in its upper (status bar) and lower fields. Therefore, we subtract these two fields. On handset phones without a notch, only the top field is included in the “Dimensions.get(“window”).height” value. Therefore, we only remove the upper part. I may have misdiagnosed this situation. I came to this conclusion based on the devices I tried. Please correct me if I am wrong.
import React from "react";
import { View, Dimensions } from "react-native";
import { SafeAreaView, initialWindowMetrics } from "react-native-safe-area-context";
import DeviceInfo from 'react-native-device-info'

const MainScreen = () => {

    const defaultValues = {
        height: 852,
        width: 393
    }

    const units = {
        width: Dimensions.get("window").width,
        height: Dimensions.get("window").height - initialWindowMetrics.insets.top - (DeviceInfo.hasNotch() || DeviceInfo.getDeviceType() == "Tablet" ? initialWindowMetrics.insets.bottom : 0)
    }

    const getRH = (number) => {
        return (number * units.height) / defaultValues.height
    }

    return (
        <SafeAreaView style={{ flex: 1, backgroundColor: 'red' }}  >
            <View style={{ flex: 1, backgroundColor: "green" }} >
                <View style={{ height: getRH(426), backgroundColor: "#D9D9D9" }} />
                <View style={{ height: getRH(420), backgroundColor: "#835050" }} />
            </View>
        </SafeAreaView>

    );
};

export default MainScreen;
  1. As a result, everything works fine on the emulators shown in the screenshot below as well as on the physical devices: Sony Xperia XZ1 (no notch handset), Samsung Galaxy A7 2018 (no notch handset) and iPhone 8 (no notch handset).

Problem: When I try this procedure on the Reeder P13 Blue Max L 2022 device, a problem occurs. Because “Dimensions.get(“window”).height” directly returns the safe area (not including the top and bottom areas) as a value. As a result, the green part looks much more in the function I prepared.

Question: How can I resolve these different behaviors? As I mentioned above, my goal is to quickly prepare a UI that gives the same result on all devices by putting the value given by the designer into a function. How can I reach this conclusion?

REACT-NEXT app – global CSS changes are not reflecting after deployed in server via Jenkins

I’m an Angular guy, but I just started recently with REACT-NEXT. Currently, I am using the company’s internal REACT custom libraries in my application. It’s a scratch project.

I’m trying to override custom component CSS. I could see some random class .cQ9mf in the browser, so I added my CSS rule like this:

.cQ9mf{
     padding: 3rem;
     margin: 2rem! important // my CSS rule
}

Issue

The above rule only works in http://localhost:3000/, but I don’t see those changes after I deployed them to the server via Jenkins.

When I expend the source explorer in the browser, I still see .cQ9mf in globals.css, but on the CSS debugger, cQ9mf is converted into another random class like xJpLd.

I’m doing something wrong, or is this a configuration issue?

Could someone help me on this?

Thanks

webpack compile each scss and js files separately

I want to bundle multiple scss and js entries into multiple output files using webpack.
I have tried different solutions for it, but non of them did what I needed.

This is how the directory structure looks like:

assets
   package.json
   webpack.config.js
   css
      dist
      src
         lib
         pages
         fonts.scss
         main.scss
   js
      dist
      lib
      src
         components
         pages
         App.js
         

I want to end up having the main.scss & all the scss files from the “css/src/pages” directory compiled to “css/dist/main.css” and “css/dist/pages/page-name.css”.

My webpack.config.js file looks like this:

const path = require('path');
const fs = require('fs');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");



let config = {
    mode: "production",
    watch: true,
    module: {
        rules: [
            {
                test: /.scss$/i,
                include: [
                    path.resolve(__dirname, 'css/src'),
                    path.resolve(__dirname, 'css/src/pages')
                ],
                // use: [MiniCssExtractPlugin.loader, "css-loader", 'sass-loader']
                // use: ['file-loader', 'sass-loader', 'css-loader']
                use: [
                    {
                        loader : 'file-loader',
                        options: { outputPath: '/', name: '[name].css'}
                    },
                    'sass-loader'
                ]
            }
        ]
    },
    // plugins: [new MiniCssExtractPlugin()],
    // optimization: {
    //     minimize: true,
    //     minimizer: [new CssMinimizerPlugin()]
    // }
};

const main = Object.assign({}, config, {
    name: 'main',
    entry: './js/src/App.js',
    output: {
      filename: 'app.min.js',
      path: path.resolve(__dirname, 'js/dist'),
    }
});


const exp  = [main];
const jsDir = __dirname + "\js\src\pages";
const jsFiles = fs.readdirSync(jsDir);

jsFiles.forEach(fileName => {
    const nameOnly = fileName.replace(".js", "");
    const current = Object.assign({}, config, {
        name: nameOnly,
        entry: './js/src/pages/'+fileName,
        output: {
          filename: fileName,
          path: path.resolve(__dirname, 'js/dist/pages'),
        }
      });
      exp.push(current);
});



// const cssMain = Object.assign({}, config, {
//     name: 'mainCss',
//     entry: './css/src/main.scss',
//     output: {
//       filename: 'main.css',
//       path: path.resolve(__dirname, 'css/dist'),
//     }
// });

// exp.push(cssMain);

const cssDir = __dirname + "\css\src\pages";
const cssFiles = fs.readdirSync(cssDir);

cssFiles.forEach(fileName => {


    const nameOnly = fileName.replace(".scss", "");
    const current = Object.assign({}, config, {
        name: nameOnly + "Css",
        entry: './css/src/pages/'+fileName,
        output: {
          filename: nameOnly + ".css",
          path: path.resolve(__dirname, 'css/dist/pages'),
        }
    });

    exp.push(current);

});



module.exports = exp;

As you can see there are few lines that are commented out, those are part of the things I’ve tried, but non of it worked, unfortunately.

The scss files from the “css/src/pages” directory always print javascript inside like in the attached screenshot and the main.scss file is compiled well into css but not into the right directory (it goes to “css/dist/pages” too).

enter image description here

FYI – the javascript compilation works as expected.

Any help will be highly appreciated! Thank you in advance 🙂

Blazor Server: Read image saved as blob as base 64 string

I am creating application in Blazor Server Net 6

I was able to save the image as a blob on the local browser by going through the documentation

https://learn.microsoft.com/en-us/aspnet/core/blazor/images?view=aspnetcore-7.0#stream-image-data

The images are rendering perfectly in the browser
Image being rendered after being converted into a blob

The Blob URL looks something like this

blob:https://localhost:7066/94065f17-5b19-47e4-9256-59f3e237a662

Now, I need to read the blob as a base 64 string. I tried to use IHTTPClient as mentioned below

var result=await httpClient.GetStreamAsync(_card.LogoImageDetails.ActualImage);

But, it throws an exception given below
enter image description here

Waiting for an efficent solution to solve this issue

Regards
Saad

encode url in java and javascript yielding different results

fdf

JAVA CODE
@Test
    public void testUrl() {
        String s = "tata, abcd & xyz - 1/2kg ()";
        String encode = URLEncoder.encode(s, StandardCharsets.UTF_8);
        System.out.println(encode);
    }
RESULT: tata%2C+abcd+%26+xyz+-+1%2F2kg+%28%29

=====
JS CODE
encodeURIComponent("tata, abcd & xyz - 1/2kg ()");
RESULT: tata%2C%20abcd%20%26%20xyz%20-%201%2F2kg%20()

Can you please help me yield same result for both.
I am more in favor of ‘+’ sign instead of %20