Generating public private keys from openpgp

I have the following code and I’m trying to generate public-private key:

const openpgp = require("openpgp")
const generateKeyPair = async () => {
const { publicKeyArmored } = await openpgp.generateKey({
    userIds: [
        {
            name: 'Jon Smith', email: '[email protected]',
            comment: 'This key is for public sharing'
        }
    ],
    curve: 'ed25519',
    passphrase: 'super long and hard to guess secret',
});

console.log(publicKeyArmored);
}

But I’m getting this error. Any idea how to solve it:

(node:17380) UnhandledPromiseRejectionWarning: Error: Unknown option: userIds

How to authentication vs authorization for google drive?

Hello I want to create a music stream website (mp3) by using google drive as a database . I embed mp3 from google drive and It’s work OK. but I want to make auto play when 1st song is complete 2nd song is auto start. first two song is ok one complete and then another one start but there is an error when 2nd song is complete and 3rd song not start which is shown (failed to reload source:403 Forbidden error) how can i solve it? I am just beginner level in web-development and i only know front-end. you can show my code in here.

https://jerrym2channel.infinityfreeapp.com/min.html

var song_westlife = {
    "01": {
        title: "အဆင်ပြေဖို့ခက်တယ်",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:32",
        track: "http://docs.google.com/uc?export=open&id=1C37RidYgEeuPG2EJKwCuWffjN_XTAunB"
        
    },
    "02": {
        title: "ခွင့်လွှတ်ပေးပါ",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:00",
        track: "http://docs.google.com/uc?export=open&id=1Bb8CEl-lu4ufKEYXeYdxElrbG6fti3U7"
    },
    "03": {
        title: "ရှိပါစေတော့",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:17",
        track: "http://docs.google.com/uc?export=open&id=10IJYpMyrrI_nQMH5fMdhClNbZ0ra-T7R",
    },
    "04": {
        title: "ပြန်ဆုံခွင့်လေး",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:29",
        track: "http://docs.google.com/uc?export=open&id=1twJbIPnYwz3cWJvzvGPVTVJBwOzQ99DF",
    },
    "05": {
        title: "နင်ပျော်နေပါစေ",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "4:28",
        track: "http://docs.google.com/uc?export=open&id=1MKyyZoyafrNCZuJjOumpDJJYJpm8KtgG",
    },
    "06": {
        title: "ပြန်လိုချင်တယ်",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:03",
        track: "http://docs.google.com/uc?export=open&id=16Ow-wqkr1i1X9TqhHtu5VLG8YiSPUSxG",
    },
    "07": {
        title: "နင့်ဘေးနားအရိပ်လိုငါ",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "5:17",
        track: "http://docs.google.com/uc?export=open&id=1C0ziMtRrP_3KG7P48iQQ-tX8S6Sh-hD_",
    },
    "08": {
        title: "မခေါ်ရက်ဘူး",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:38",
        track: "http://docs.google.com/uc?export=open&id=1OZ1sw5snOXSUvEnmbTYGWV9ApCGql9fd",
    },
    "09": {
        title: "တန်ဖိုးထားပြီးချစ်မှာ",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "2:52",
        track: "http://docs.google.com/uc?export=open&id=1dJkIeHFvuGYs7lTkiGH8owGguRubkknR",
    },
    "010": {
        title: "နင်ထွက်သွားခဲ့ဟိုးအဝေး",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:54",
        track: "http://docs.google.com/uc?export=open&id=1hNlZuMUnhaea5g5IcXd6-KsJjwBlv0XF",
    },
    "011": {
        title: "for you",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "3:18",
        track: "http://docs.google.com/uc?export=open&id=143I45iZ4nBAGdSnmf6D5mg43oDpjIgHH",
    },
    "012": {
        title: "အချစ်တွေအပြည့်ရှိတယ်",
        artist: "Min Khant",
        genre: "Myanmar songs",
        duration: "4:05",
        track: "http://docs.google.com/uc?export=open&id=15rMTg8IuO2COyEez-0RX5RNE4Tps7K8m",
    },
    "013": {
        title: "ပြန်ချစ်ကြမယ်",
        artist: "Min Khant & Ko Htet",
        genre: "Myanmar songs",
        duration: "3:32",
        track: "http://docs.google.com/uc?export=open&id=1XHQYW1UGRqYYscjgo1aKmpMjTxpFV-gw",
    },
    "014": {
        title: "မင်းစိတ်ကြိုက် ",
        artist: "Min Khant & Ko Htet",
        genre: "Myanmar songs",
        duration: "3:57",
        track: "http://docs.google.com/uc?export=open&id=1JlSAPzZQpJ0I7CMcvVv1maBjQQB2uvCA",
    }
}
<!DOCTYPE html>
<html>
<head>
    <title>Westlife</title>
    <link href="img/M2.png" rel="icon" type="image/png" >
    <link href="css/westlife.css" rel="stylesheet" type="text/css" >
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
   <meta charset="utf-8">

</head>
<body>
        <nav class="navbar navbar-expand-lg navbar-dark " id="navbar">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">JerryM2</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"  aria-expanded="false" >
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mx-auto ">
        <li class="nav-item">
          <a class="nav-link" href="index.html#home">Home</a>
        </li>

        <li class="nav-item">
          <a class="nav-link"  href="index.html#about">About</a>
        </li>

        <li class="nav-item">
          <a class="nav-link"  href="index.html#songs">songs</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="index.html#contact">Contact</a>
        </li>
        </ul>
      
      <button class="btn p-2 my-lg-0  my-2">Sign in</button>
    
  </div>
</nav>

                    <div class="body_content">
                        <div class="title">
                            <span></span>
                            <span>TiTle</span>
                            <span>Artists</span>
                            <span>Genre</span>
                            <span>Duration</span>
                            <span>
                                <li class="autoplay_btn">

                                <label>
                                    <h5>AutoPlay</h5>
                                    <!-- <input type="checkbox" > -->
                                     <input type="checkbox" name="changemode" id="toggle" class="form-check-input"/>
                                    <span style="width: 65px;"></span>
                                </label>

                            </li>
                            </span>
                            <span></span>
                        </div>
                        <div class="list">
                            
                        </div>

                        
                        
                    </div>

            </div>
        </div>

        <!-- jQuery CDN link -->
        <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js"></script> -->
      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" ></script>
      <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" ></script>
      <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" ></script>

        <script src="js/minkhant.js" type="text/javascript"></script>

        <script>
            $(document).ready(function(){
            
            var list = $(".list");
            var list_block;

            for (var key in song_westlife){
                list_block = $('<div class="list_block"></div>');
                list.append(list_block);


                list_block.append('<span class="play_btn"><img src="img/play.svg" class="play_icon"><img src="img/pause.svg" class="pause_icon"></span>');

                list_block.append('<span class="song_title">'+ song_westlife[key].title+'</span>');
                list_block.append('<span class="song_artist">'+ song_westlife[key].artist+'</span>');
                list_block.append('<span class="song_genre">'+ song_westlife[key].genre+'</span>');
                list_block.append('<span class="song_duration">'+ song_westlife[key].duration+'</span>');
                list_block.append('<span class="beat_animation"><ul><li></li><li></li><li></li><li></li><li></li></ul></span>');
                list_block.append('<span class="track"><audio id="audio" controls><source src="'+song_westlife[key].track+'" type="audio/mp3"></audio></span>');
                list_block.append('<span class="download_btn"><a target="_blank" href="'+song_westlife[key].track+'"><img src="img/download.svg"></a></span>');


                }

                

            // Play functionalily

                $(".list_block .play_btn .play_icon").on('click',function(current){

                    $(this).parent().find(".play_icon").css("display","none");
                    $(this).parent().find(".pause_icon").css("display","inline-block");
                    $(".play_icon").not(this).parent().find(".pause_icon").css("display","none");
                    $(".play_icon").not(this).parent().find(".play_icon").css("display","inline-block");

                    // ADD/Remove class

                    $(this).parent().parent().addClass("isPlaying");
                    $(".play_icon").not(this).parent().parent().removeClass("isPlaying");

                    // Beat animation Play

                    $(this).parent().parent().find(".beat_animation li").css("animation-play-state","running").css("opacity","1");
                    $(".play_icon").not(this).parent().parent().find(".beat_animation li").css("animation-play-state","paused")
                    .css("opacity",".1");


                    // pause current audio track when play next/prev audio tack 

                    $("audio").each(function(e){
                        if(e !== current.currentTarget){
                            $(this)[0].pause();
                        }

                    });

                    // play current audio track

                    $(this).parent().parent().find(".track audio")[0].play();

                });

                // pause functionalily

                $(".list_block .play_btn .pause_icon").on('click',function(){

                    // hide pause icon 
                    $(this).parent().find(".pause_icon").css("display","none");
                    // show play icon
                    $(this).parent().find(".play_icon").css("display","inline-block");

                    // beat animation pause
                    $(this).parent().parent().find(".beat_animation li").css("animation-play-state","paused");

                    // pause currnt audio track 
                    $(this).parent().parent().find(".track audio")[0].pause();

                });

                // auto play functionalily

                $(".autoplay_btn label input").on('change',function(){

                    if ($(this).is(":checked")){
                        $("audio").on('ended',function(){

                            $(this).parent().parent().next().find("audio")[0].play();

                            $(".list_block").removeClass("isPlaying");
                            $(this).parent().parent().next().addClass("isPlaying");
                            $(this).parent().parent().next().find(".beat_animation li").css("animation-play-state","running").css("opacity","1");

                            $(this).parent().parent().next().find(".pause_icon").css("display","none");
                    
                            $(this).parent().parent().next().find(".play_icon").css("display","inline-block");


                        });
                    } else {

                        $("audio").on('ended',function(){

                            $(".beat_animation li").css("animation-play-state","paused").css("opacity",".1");
                            $(".pause_icon").css("display","none");
                            $(".play_icon").css("display","inline-block");


                        });
                    }

                }).change();

            });
        </script>       

                
</body>
</html>

How to limit the size of each read from a ReadableStream

Im Accessing a file from my device storage using HTML file input then I read that file as a stream.

  • Is there any built-in way to limit the length of each read to specific number of bytes.
const stream = myFile.stream() 
const reader = stream.getReader();

//actually I use this each time I want to read more data from the stream
reader.read().then(function({ done, value }) { 
  
    const bufferSizeInBytes = value.length //  I want to limit this to 1000 bytes as max value
   
    })

Another question that’s confusing me, why do we get different size of the buffer on each read, does it depend on the available memory or cpu or how does it actually work? if it depends on the memory we would be able to read the whole stream in one single read since the file is around 100 mb and my available memory is around 6GB , but actually it took many reads what made me think that the memory is not the only factor behind this operation.

any help would be much appreciated.

Save a variable and use it in later stage in Ramda compose

I am very new to Ramda and have got stuck in a problem. I need to get response from an api and pass it to next function but that same response needs to be used again at a later stage in the same compose. How can I save its value in that ramda func scope so it can be re-used again?

const getData = (req, ctx) => R.compose
        (
          R.andThen(... do some action using response from callSomeApi_2 and prop2)
        , R.andThen(callSomeApi_2(req, ctx))
        , R.andThen(R.map(R.prop('prop1'))) // response has prop1 and prop2 where prop2 is needed after getting response from callSomeApi_2
        , callSomeApi_1(req, ctx)
        );

How can this be achieved?

Why can not access parameter of parent ajax call into child ajax call

I retrieve data from data from database using ajax call. In my code can not access parameter of parent ajax call request to child ajax request call. I can see error in compiler. I can try to put asyc: false in child request but using async i can access parameter but child ajax call only work one time.

Here down is my code

$.ajax({
        type: "GET",
        url: "/meetzen/comments",
        data: {  acId: accountId, pstId: postId },
        success: function(res) {
            // res.lenth = 2
            for (var i = 0; i < res.length; i++) {
                $.ajax({
                    type: "GET",
                    url: "/meetzen/getlikeornotimgzoom",
                    data: {commentId: res[i].comment_id},
                    success: function(likeornot){
                        
                        if(likeornot == 0)
                        {
                            $("#btnlikeornot").append("<button type = 'submit' onclick ='btncommentunlike("+res[i].comment_id+")' id='commentunlikebtn"+res[i].comment_id+"' data-id='"+res[i].u_id+" ' class='comment-like-button-style'>" +
                                                "<img src='https://img.icons8.com/material-outlined/24/000000/like--v1.png'/>" +
                                            "</button>");
                        }
                        else
                        {
                            $("#btnlikeornot").append("<button type = 'submit' onclick ='btncommentlike("+res[i].comment_id+")' id='commentlikebtn"+res[i].comment_id+"' data-id='"+res[i].u_id+" ' class='comment-like-button-style'>" +
                                                "<img src='https://img.icons8.com/material-rounded/24/fa314a/like.png' />" +
                                            "</button>");
                        }
                    }
                });
            }
       }
});

Error

imagezoom.js:68 Uncaught TypeError: Cannot read properties of undefined (reading 'comment_id')
    at Object.success (imagezoom.js:68)
    at i (jquery.min.js:2)
    at Object.fireWith [as resolveWith] (jquery.min.js:2)
    at A (jquery.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery.min.js:4)

How to prevent anchor with query string from reloading page

How do I prevent anchor to reload page when there are query strings included in URL.
Below is link which reloads page before redirecting to section directly.

<a href="https://iamhoste.com/experiences/?in-home-chef-experiences/#explore">Explore Experiences</a>

Clicking on this link reloads page and then redirect to section (#explore). Is there anyway I can prevent reloading.

In ReactJS application Using Format.js library how can I convert date to date and time

I am new to React & Format.js. I need to do a small task which I am not able to do so. Please help me to convert date to date and time in my react js app format.js they used as a component it is written like this.

I also followed this article but not able to understand

 <FormattedDate value={new Date(data.situDate)} year="numeric" month="short" day="2-digit" />

and inside the data it is like this response

"situDate":"2021-12-07T15:56:47.661+00:00"

I needed to show like in this format

27 oct. 2020 16:24:22

How renew greenlock-express certificates forcefully at any time?

I have CA certificates files in “greenlock.d/live/URL_PATH/”. It’s expiration date is Aug 2022.

But I want to renew them right now to check whether they are renewing or not. Please suggest me how can I renew them at any time?

What I have done:

I have tried number of solutions like:

  • Tried Some commands
  • Changing renewal time (“renewAt”) in “greenlock.d/config.json”

Code:

app.js

'use strict';

var app = function(req, res) {
    res.end('Hello, Encrypted World!');
};

module.exports = app;

server.js

'use strict';

var beapp = require('./app.js');

require('greenlock-express')
    .init({
        packageRoot: __dirname,
        maintainerEmail: "EMAIL_ID",
        configDir: './greenlock.d',
        cluster: true
    })
    // .serve(beapp);
    .ready(httpsWorker);
function httpsWorker(glx) {
    var httpsServer = glx.httpsServer(null, beapp);
    httpsServer.listen(443, "0.0.0.0", function () {
        console.info("Listening on ", httpsServer.address());
    });
}

greenlock.d/config.json

{
  "defaults": {
    "store": {
      "basePath": "./greenlock.d",
      "module": "greenlock-store-fs"
    },
    "challenges": {
      "http-01": {
        "module": "acme-http-01-standalone"
      }
    },
    "renewOffset": "-45d",
    "renewStagger": "3d",
    "accountKeyType": "EC-P256",
    "serverKeyType": "RSA-2048",
    "subscriberEmail": "EMAIL_ID"
  },
  "sites": [
    {
      "subject": "URL_PATH",
      "altnames": [
        "URL_PATH"
      ],
      "renewAt": 1
    }
  ]
}

Angular change PUT request to PATCH

I am calling an API for updating Project name, description and using ID. I have a PUT request that updates all the data. But I want to update only Project name and description. I am not able to perform the PATCH call provider. Can someone tell me how to call the PATCH request
thanks.

This is my PUT request. And I want PATCH request

put(apiUrl, data) {
const apiURL = environment.endPointUrl + apiUrl;
const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/json',
    AuthenticationKey: `${CryptoJS.AES.decrypt(
      localStorage.getItem('UAuthToken') == null
        ? ''
        : localStorage.getItem('UAuthToken'),
      environment.EncryptionKey
    ).toString(CryptoJS.enc.Utf8)}`,
  }),
};
return this.http.put(apiURL, data, httpOptions);

}

This is my Service.ts

UpdateProject(data){
const apiURL = 'http://192.168.1.22:8080/TestExpress/projects/updateProject/projectDescription/projectId/projectName';
return this.callProvider.put(apiURL, data);

}

Custom Validator function with Button on Client Click – Javascript

I have a textbox to which I have assigned a CustomValidator which has a ClientValidationFunction=”txtcheck”

ASPX:

<asp:TextBox ID="txt1"  MaxLength="10" CssClass="class1" Width="90%" runat="server"></asp:TextBox>
<asp:CustomValidator runat="server" ID="valtxt1" ControlToValidate="txt1" ValidateEmptyText="true" ValidationGroup="Save" Display="Dynamic"
                        ClientValidationFunction="txtcheck" Font-Italic="True"></asp:CustomValidator>
<asp:Button ID="btnSave" Text="Save" CausesValidation="True" runat="server" ValidationGroup="Save" OnClientClick="show()" UseSubmitBehavior="false" />

Javascript :

The alert messge is mandatory as it is required.

function txtcheck(source, args) {
Alert('incorrect value');
args.IsValid = false;
}

function show(){
var validated = Page_ClientValidate('valSave');
    if (validated) {
-- show some data.
      }
}

On click of Save Button I do a Page_ClientValidate to check other controls.

The issue is, on click of Save; txtcheck() is getting called twice.
Once via the CustomValidator & other when I do the Page_ClientValidate. Due to this the Alert message is also shown twice.

Pls guide as to how to call the txtcheck() only once & show alert once.

Any help is greatly appreciated.

complex object manipulation

I have an array:

const arr = [
    {
        countries : {countryCode :"US", value: true},
        vendors:  [{vendorName: 'TES', value: true}, {vendorName: 'HPEFS', value: true}]
    },
    {
        countries : {countryCode :"CA", value: true},
        vendors:  [{vendorName: 'TES', value: true}, {vendorName: 'HPEFS', value: false}]
    }
];

expected result:  [{vendor: "TES", countries: [US, CA]}, {vendor: "HPEFS", countries: [US]}]

Any idea is appreciated, Thanks in advance

angular asynchronous request from multiple methods

From ngOnchanges I called the method _generateLocationFormForApproval and it has an output which is this.absoluteUri. After calling _generateLocationFormForApproval the next call is _pageEventDealsForApprovalList. Now I want to access the result from _generateLocationFormForApproval whic is this.absoluteUri inside _pageEventDealsForApprovalList after its result but it is giving me undefined although this.absoluteUri has a value.

Any idea ? with the asynchronous call ? Thansk.

#code

  ngOnChanges(changes: SimpleChanges): void {
      if(this.dealId) {
        this._generateLocationFormForApproval();
        this._pageEventDealsForApprovalList();
      }
    }
    
    
    
    private  _generateLocationFormForApproval() {
      this.dealService.generateLocationSubmission(this.dealId)
      .subscribe({
        next: (res) => {
          if (res.isSuccess) {
            this.absoluteUri = res.data.absoluteUri;
          }
        },
        error: err => this.notificationService.showError(err),
        complete: noop,
      });
    }
    
private _pageEventDealsForApprovalList() {
  console.log("1")
  console.log("this.absoluteUrithis.absoluteUri" , this.absoluteUri)
  this.searchInput = '';
  const status = [DEAL.STATUS.FORAPPROVAL, DEAL.STATUS.APPROVED]
  this.dealType = [];
  this.isLoading = true;
  this.dealService
    .getAllDeals(
      status,
      this.accountId,
      this.transaction.id,
      this.table.pageIndex + 1,
      this.table.pageSize,
      this.searchInput,
      this.table.sortParams,
      this.table.sortDirs,
      this.dealType
    )
    .pipe(finalize(() => (this.isLoading = false)))
    .subscribe((res) => {
        if(res) {
          console.log("this.uri" , this.absoluteUri)
        }
    }, (err) => this.notificationService.showError(err)
  );
}

Handling form content with JavaScript and Perl

I have a music project in Perl which also requires some JavaScript but I seem to be stuck.
I need to execute a program (ffplay) as a command-line application so it runs without displaying a GUI window. The Perl handles the server end of things (sqlite database access). I need JavaScript because I display track names as a button, which when clicked is supposed to run ‘ffplay’ to play the track named in the button code. But the button click requires JavaScript.

When I click a track name button, it only displays the first track, no matter which one I
click.

The following code is in a ‘while’ loop extracting track names from the DB.

print<<EndHTML;
<script>
function process(form) {
    var form=document.Player
        alert ("Track: " + form.Player.Track.value)
}
</script>
EndHTML

print qq{<form name="Player">};
print qq{<input type="button" onClick="process(this.form)" class="alphaButton" name="Track" value="$Track"><br/>};
print qq{</form>};

Google Drive API doesn’t show files inline

I am trying to show a file from the Google Drive API inline so that the browser will display it. So far when I request the file it only downloads it. But when I add some code to make it show it in line I get the error “Failed to load PDF document”.

Here is my code:

const googleFile = new Request(`https://www.googleapis.com/drive/v3/files/${FileID}?alt=media`, {
      method: "GET",
      headers: {
        "Authorization": `Bearer ${googletoken}`,
      },
    });
const googleFileResponse = new Response(fetch(googleFile), {
      headers: {
        'Content-Disposition': 'inline',
      }
    });
    return googleFileResponse

Thanks for your help.