How can I sign a Solana transaction on the frontend with data coming from the backend?

    async function getTransaction(){
    $.ajax({
        url: 'http://localhost:8080/gettransaction',
        type: 'GET',
        dataType: 'json',
        success: async function(data) {
            console.log(data); // Log the data for debugging

            // Reconstruct the Transaction object
            var transaction = new solanaWeb3.Transaction();
            transaction.recentBlockhash = data.recentBlockhash;
            transaction.feePayer = new solanaWeb3.PublicKey(data.feePayer);

            // Assuming 'data.instructions' is an array of instruction objects
            for(let instructionData of data.instructions) {
                // Create each instruction and add it to the transaction
                const instruction = new solanaWeb3.TransactionInstruction({
                    keys: instructionData.keys.map(key => ({
                        pubkey: new solanaWeb3.PublicKey(key.pubkey),
                        isSigner: key.isSigner,
                        isWritable: key.isWritable
                    })),
                    programId: new solanaWeb3.PublicKey(instructionData.programId),
                    data: Buffer.from(instructionData.data) // Assuming 'data' is a Uint8Array or similar
                });
                transaction.add(instruction);
            }

            // Sign and send the transaction
            var provider = await getProvider();
            //here it breaks, i get a Buffer not defined error
            let signed = await provider.signTransaction(transaction);
            var connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('mainnet-beta'));
            let signature = await connection.sendRawTransaction(signed.serialize());
            await connection.confirmTransaction(signature);
            console.log("Transaction signature:", signature);
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.error('Error:', errorThrown); // Handle errors here
        }
    });
}
app.get('/gettransaction', async (req, res) => {
    try {
        const amountInSol = 0.01;   
        const publicKey = new solanaWeb3.PublicKey(publicKeyStr);
        var connection = new solanaWeb3.Connection(rpcNodeLink);
        var recieverWallet = new solanaWeb3.PublicKey(recieverWalletAddress);
        var transaction = new solanaWeb3.Transaction().add(
        solanaWeb3.SystemProgram.transfer({
            fromPubkey: publicKey,
            toPubkey: recieverWallet,
            lamports: solanaWeb3.LAMPORTS_PER_SOL * amountInSol //Investing 1 SOL. Remember 1 Lamport = 10^-9 SOL.
        }),
        );
        transaction.feePayer = publicKey;


        if(transaction) {
            console.log("Txn created successfully");
        }  
        res.status(200).json(transaction);
    } catch (error) {
        console.error(error);
        res.status(500).json({ error: 'Internal server error' });
    }
});

The first is the front end code

And the second is the backend code

When I try to sign the transaction, I get a Buffer not defined error, I was not expecting it, as I cant wrap my head around why signing the transaction using the phantom wallet provider would require the buffer from the backend in the frontend, and I can’t sign it in the backend because I dont have access to the provider, I also dont want to do it using a private Key.

I tried writing it all in the frontend and couldnt create the transaction, and had to use an api to make it in the backend and return it to the front end, but now I have issues when it comes to signing it, as i get a Buffer is not defined error, I tried using a CDN to get a Buffer into my front end, but all I got were more errors.

WebAuthn: Does navigator.credentials.create() work from localhost to another (sub)domain?

I am trying to develope the WebAuthn registration flow in Java.
For this reason I got access to the privacyIDEA server from my university.
Let’s assume, for example, that the origin domain from my university is called university-server.com. The privacyIDEA server has the subdomain webauthn.university-server.com.
For building the web application I am using Vaadin.

If I start the web application, Tomcat will be started as local web server.
The idea behind this web application is:

  • Users can log in with their username and password and create a WebAuthn token as their 2nd factor.
  • The registration process should be triggered when users press on a button.
  • If enrollment succeed, the WebAuthn token should be saved on webauthn.university-server.com.

From here, I encountered two problems:

Problem 1:

On the localhost site, I am prompted to use my security key, but the registration process is never completed. Apparently the data never arrives.

Problem 2:

If I set in the JavaScript function navigator.credentials.create() the parameter rp (Relying Party) to the subdomain webauthn.university-server.com and start the web application,
unlike the first problem, I will never be prompted to use my security key. Instead, the error “The operation is insecure” appears.

Can the WebAuth enrollment work at all with my test environment?
To be honest, I am not sure about this.

Error in Laravel with DataTables after adding Google Translator JS code

I am encountering an issue with a Laravel application i got online, after adding the Google Translator JS code to either the index.php or the resources/views folder, pages with tables are not loading properly. with this error message:

DataTables warning: table id=dataTable - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

the Google Translator JS code:


<div id="google_translate_element"></div>

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

I am looking to integrate Google Translate functionality into my Laravel application using a JavaScript translator script. The goal is to enable users to translate the website content into their preferred language.

npm install @react-navigation/native-stack

PS C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUser> npm install @react-navigation/native-stack

npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUsernode_modules@react-navigationnative-stack
npm ERR! dest C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUsernode_modules@react-navigation.native-stack.DELETE
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, rename ‘C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUsernode_modules@react-navigationnative-stack’ -> ‘C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUsernode_modules@react-navigation.native-stack.DELETE’
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:UsershpAppDataRoamingnpm-cache_logs2023-11-27T14_19_20_331Z-debug.log
PS C:UsershpDesktopFinal ProjectEthio-FoodEthio-foodUserEthioFoodUser> what is this problem and also how can it fix this please?

Two carousels sharing an image

So i have two modals, each with it’s own gallery and images. Whenever I open one and then the other modal, that second modal will display the last image selected from the previous gallery from other modal.

 // Product detail
$('.product-wap a').click(function(){
  var this_src = $(this).children('img').attr('src');
  $('.galerija').attr('src',this_src);
});
return false;

when I try to paste html it’s all scrambled up for some reason.

    <div class="row">
        <div class="col-lg-5 mt-5">
            <div style="margin-left: 1em" class="card mb-3"> 
                <img class="card-img img-fluid galerija" src="assets/img/posude/posuda1a.jpeg" alt="Card image cap"> <!-- slika artikla -->
            </div>
            <div class="row">
                <!--Start Controls-->
                <div class="col-1 align-self-center">
                    <a href="#multi-item-example001" role="button" data-bs-slide="prev">
                        <span class="sr-only">Previous</span>
                    </a>
                </div>
                <!--End Controls-->
                <!--Start Carousel Wrapper-->
                <div id="multi-item-example001" class="col-10 carousel slide carousel-multi-item" data-bs-ride="carousel">
                    <!--Start Slides-->
                    <div class="carousel-inner product-links-wap" role="listbox">

                        <!--First slide-->
                        <div style="margin-bottom: 1em" class="carousel-item active">
                            <div class="row">
                                <div class="col-4">
                                    <a href="#">
                                        <img class="card-img img-fluid" src="assets/img/posude/posuda1a.jpeg" alt="Product Image 1"><!-- slika artikla na dnu -->
                                    </a>
                                </div>
                                <div class="col-4">
                                    <a href="#">
                                        <img class="card-img img-fluid" src="assets/img/posude/posuda1b.jpg" alt="Product Image 1"><!-- slika artikla na dnu -->
                                    </a>
                                </div>
                                <div class="col-4">
                                    <a href="#">
                                        <img class="card-img img-fluid" src="assets/img/posude/posuda1c.jpeg" alt="Product Image 2"><!-- slika artikla na dnu #2 -->
                                    </a>
                                </div>
                                <div class="col-4">
                                    <a href="#">
                                        <img class="card-img img-fluid" src="assets/img/posude/posuda1d.jpeg" alt="Product Image 3"><!-- Slika artikla na dnu #3 -->
                                    </a>
                                </div>
                            </div>
                        </div>
                        <!--/.First slide-->
                    </div>
                    <!--End Slides-->
                </div>
                <!--End Carousel Wrapper-->
                <!--End Controls-->

How to Load 100 million rows csv into relational db MySql using node js within less than 10 minutes

I have one csv file it contains 100 million rows with 10 columns.
Currently it takes more than 1 hour to load 100 millions of rows.
To load CSV using Node JS into MySql, I used batch processing and node js stream features.

Hi
I want to load that 100 million rows into MySql db using node js within less than 10 minutes, because I have 70 CSV and each contains minimum 100 million row.
Please provide some guidance or reference links.
If you are suggesting any other relational db then it works for me.
Only requirement is it should load 100 millions rows CSV less than 10-15 minutes.

Hardware Configuration:-
Intel Xenon 8 core processor
RAM 16 GB

Issues in Lighthouse with Font Display

“I’m using Lighthouse to optimize my website with Next.js and TypeScript with Tailwind, and I’m facing an issue with font-display that is causing extended loading times. Lighthouse has identified that web fonts are causing a delay (350 ms in total for various variants of ‘TT Norms Pro’) before the text becomes visible. How can I solve this problem?”
specific problem

How do I fix this issue?

Nextjs app directory doesnt not have getStaticPats

I ran into an issue with the new nextjs app router

where i wanted to use SSG pages for stapi blog but was getting this error when building

app/blog/[slug]/page.tsx
Type error: Page "app/blog/[slug]/page.tsx" does not match the required types of a Next.js Page.
  "getStaticPaths" is not a valid Page export field.

for

import { BlogArticlePreview } from "@/components/landingPages/BlogArticles";
import { getBlog, getBlogs } from "@/services/strapi/modules/blog";
import { BlogPage } from "./BlogPage";

const fetchBlog = async (slug: string) => {
  try {
    return await getBlog(slug);
  } catch (error) {
    return null;
  }
};

export const getStaticPaths = async () => {
  const data = await getBlogs();

  const paths = (data as any).data.map((item: any) => {
    return {
      params: { slug: item.attributes.slug },
    };
  });

  return {
    paths,
    fallback: true,
  };
};

export default async function Page({ params }: any) {
  const blog = ((await fetchBlog(params.slug)) as any)
    ?.attributes as unknown as BlogArticlePreview;

  return <BlogPage {...blog} />;
}

enter image description here

How can I integrate useFont hook into my own theme.js file?

I’m currently making an iOS app with Expo React Native and I want to call fonts in my own theme.js file. Unfortunately, I’ve tried many many ways but no one worked.

Helps will much appreciated.

My useFont section

const [ fontsLoaded ] = useFonts({
    'thin': require('./assets/fonts/Montserrat-Thin.ttf'),
    'light': require('./assets/fonts/Montserrat-Light.ttf'),
    'extraLight': require('./assets/fonts/Montserrat-ExtraLight.ttf'),
    'regular': require('./assets/fonts/Montserrat-Regular.ttf'),
    'medium': require('./assets/fonts/Montserrat-Medium.ttf'),
    'semiBold': require('./assets/fonts/Montserrat-SemiBold.ttf'),
    'bold': require('./assets/fonts/Montserrat-Bold.ttf'),
    'extraBold': require('./assets/fonts/Montserrat-ExtraBold.ttf'),
    'black': require('./assets/fonts/Montserrat-Black.ttf'),
  });

  if (!fontsLoaded) { return null; }

and my theme.js


const colors = {
    primary: '#00FF66',
    background: '#181818',
    backgroundSecond: '#424242',
    black: '#000000',
    yellow: '#FFF500',
    white: '#FFFFFF',
    whiteSecond: '#F3F3F3',
    transparent: 'rgba(0,0,0,0)',
};

const sizes = {
    xxsmall: 8,
    xsmall: 10,
    small: 11,
    xxmedium: 12,
    xmedium: 14,
    medium: 16,
    large: 20,
    xlarge: 22,
    xxlarge: 24,
};

const bluramounts = {
    nav: 30,
    header: 50,
};

const safeArea = {
    left: 15,
    right: 15,
    contentSpace: 50,
    viewHeadingTop: 70,
    viewHeadingBottom: 25,
    headingBottom: 15,
};

export const theme = {
    colors,
    sizes,
    bluramounts,
    safeArea,
};  

Tried calling them in one function then returning in theme.js but not worked.

Safari iPhone sometimes difficult to scroll

I have a page with content styled like this:

.header {
  height: 100px;
}

.content {
  height: calc(100% - 100px);
  overflow-y: auto;
}

Sometimes I scroll content but the body moves instead of scrolling inside the content, only happens on iPhone safari.

I used javascript to replace safari’s scroll, it works fine but the animation is not as smooth as the default scroll.
How can I solve this problem without using javascript, or if I do, how do I optimize the animation, or is there any library? I have tried many libraries but haven’t found what I want.

link demo

plupload how to disable / enable Add files button?

I’ve been trying pluploader out to front end upload files to my Photo gallery webpage and it works well. Basically just followed the examples on the website. But I would like to disable the Add files button initially until user has selected an upload destination “album” which they do by pressing a button click handler I implemented (see album-select onclick below). I have managed to disable the Add button in the constructor as shown, but I’m having no luck re-enabling it when user presses the album button. Any ideas how to implement re-enabling the Add files button from my own button press? Thanks!

<script type="text/javascript">

    var uploader = $("#upl").plupload({
      // General settings
      url : g_homeUrl + "get-from-browser/",
    
      // Maximum file size
      max_file_size : '10mb',
    
      // Specify what files to browse for
      filters : [
          {title : "Image files", extensions : "jpg,jpeg,gif,png"}
      ],
    
      // Sort files

      sortable: true,
    
      // Enable ability to drag'n'drop files onto the widget (currently only HTML5 supports that)
      dragdrop: true,

       // To disable Add files button. 
       buttons: {
        browse: false
      },
    
      // Views to activate
      views: {
          list: true,
          thumbs: true, // Show thumbs
          active: 'thumbs'
      }
    
    });
    
    uploader.init();

    uploader.bind('complete', function(up, fl){
      console.log('Completed uploading ' + fl.files.length + " files"); 
    });

    uploader.bind('error', function(up, err) {
      document.getElementById('console').innerHTML += "nError #" + err.code + ": " + err.message;
    });

    document.getElementById('album-select').onclick = function(e) {
      albSet = e.target.dataset.album;
      var albTitle = e.target.dataset.title;
      var html = "Upload to album " + albTitle + "<br/>";
      html += "Click add files to select your images for upload";
      document.getElementById('console').innerHTML = html;
      // How to enable browse (Add files) button if disabled in constructor?
      //uploader.disableBrowse(false) says not a function??
    }
    
</script>

inserting OSM overpass API using Node.js to Postgresql

The other elements such as id, tags, and type of the object can sucessfully inserted to the database. However, the columns of lat and lon is giving null value. I tried the column type of (decimal, varchar, double, and float). and here is the javascript code of index.js

https://drive.google.com/drive/folders/1QAY4Ga-9Vcjn41ChInM4vhsS-e6jF2Op?usp=drive_link

enter image description here
null value in database

enter image description here log in console showing latitude and longitude

i am trying to use geoplugin in my nuxt 3 project but i couldn’t find any solution

server/api/geolocation.js
import { createError, send } from 'h3';

export default async (req, res) => {
    const ip = req.headers['x-forwarded-for']?.split(',').shift() || req.socket?.remoteAddress;
    try {
        const response = await fetch(`http://www.geoplugin.net/json.gp?ip=${ip}`);
        const data = await response.json();
        send(res, 200, data);
    } catch (error) {
        console.error("Error in geolocation API:", error);
        send(res, 500, createError({ statusCode: 500, statusMessage: 'Internal Server Error' }));
    }
};

this is my code where i am using the geolocation by middleware approach

my vue component where i want to use the geoplugin

<script setup>
import { onMounted, ref } from 'vue';

const geolocation = ref(null);

onMounted(async () => {
  try {
    const response = await fetch('/api/geolocation');
    geolocation.value = await response.json();
    console.log(geolocation.value); // Log the response
  } catch (error) {
    console.error('Error fetching geolocation data:', error);
  }
});

</script>

<span v-if="geolocation && geolocation.geoplugin_countryName === 'United Kingdom'"><img></span> but the image is not showing either its uk ip address or not