javascript – POST request ERROR: ‘Access denied: Invalid token, wrong code’

I am trying to make a POST request using NODE but is throwing error. Here what I am trying to do is to generate TOTP with Headers and SHA512 hashed Token in NODE. In the header, we have to pass my private GITHUB GIST URL and my EMAIL_ID, that’s why I couldn’t share it here. Can you plz help! Here is my node code:

const axios = require('axios');
const base64 = require('base-64');
const utf8 = require('utf8');

const { totp } = require('otplib');


const reqJSON = 
{
    github_url: GITHUB_URL,
    contact_email: MY_EMAIL
}
const stringData = JSON.stringify(reqJSON);

const URL = 'https://api.challenge.hennge.com/challenges/003';
const sharedSecret = reqJSON.contact_email + "HENNGECHALLENGE003";

totp.options = { digits: 10, algorithm: "sha512",  epoch: 0 }

const myTotp = totp.generate(sharedSecret);
const isValid = totp.check(myTotp, sharedSecret);

console.log("Token Info:", {myTotp, isValid});

const authStringUTF = reqJSON.contact_email + ":" + myTotp;
const bytes = utf8.encode(authStringUTF);
const encoded = base64.encode(bytes);
const createReq = async () =>
{

    try 
    {

        // set the headers
        const config = {
            headers: {
                'Content-Type': 'application/json',
                "Authorization": "Basic " + encoded
            }
        };

        console.log("Making req", {URL, reqJSON, config});

        const res = await axios.post(URL, stringData, config);
        console.log(res.data);
    }
    catch (err)
    {
        console.error(err.response.data);
    }
};
createReq();

Basically, what I have to do is to submit my code which is in my private gist github profile. But when I run node myfile.js command to run, it gave me the error:

Token Info: { myTotp: '1980479983', isValid: true }
Making req {
  URL: 'https://api.challenge.hennge.com/challenges/003',
  reqJSON: {
    github_url: 'https://gist.github.com/sthakur369/233ab97e2d4c4a67630bf6c61f629fe1',
    contact_email: 'sthakur369@gmail.com'
  },
  config: {
    headers: {
      'Content-Type': 'application/json',
      Authorization: 'Basic c3RoYWt1cjM2OUBnbWFpbC5jb206MTk4MDQ3OTk4Mw=='
    }
  }
}
{ message: 'Access denied: Invalid token, wrong code' }

Here is my Stakoverflow link of this question.

javascript – Code Missing Expression or Not Working

I have another post out there, but I am missing something in this code and it’s not working. Need a PRO to look at my mickey-mouse script and help me execute it.

Site can be located at https://wbtfoundation.org – top bar has city geolocation (e.g. Rockwall, Texas | United States (this is the storeID)

Based on div storeID (geolocation populated)

CSS

.ACTIVE-CodeClass {display:none} //active banner
.DEFAULT-CodeClass {display:none} //default banner



HTML

<div class="ACTIVE-CodeClass" id="ACTIVE-CodeClass">
   <a href="http://magento.stackexchange.com/store-find/" title="">
      <picture class="" id="">       
        <!--(if IE 9)><video style="display: none;"><!(endif)-->
        <source srcset="http://magento.stackexchange.com/2020/UAT/ACTIVE-BANNER-D.jpg?$staticlink$" media="(min-width: 768px)">
        <!--(if IE 9)></video><!(endif)-->
        <img src="https://magento.stackexchange.com/2020/UAT/ACTIVE-BANNER-D.jpg?$staticlink$"     alt="">
      </picture>
    </a>
</div>

<div class="DEFAULT-CodeClass" id="DEFAULT-CodeClass">
   <a href="http://magento.stackexchange.com/store-find/" title="">
      <picture class="" id="">       
        <!--(if IE 9)><video style="display: none;"><!(endif)-->
        <source srcset="2020/UAT/DEFAULT-BANNER-D.jpg?$staticlink$" media="(min-width: 768px)">
        <!--(if IE 9)></video><!(endif)-->
        <img src="2020/UAT/DEFAULT-BANNER-D.jpg?$staticlink$"     alt="">
      </picture>
    </a>
</div>


JS

$( document ).ready(function() {
let storeID = itemStore (); 

// find region
var itemStore=('Rockwall', 'Dallas', 'Travis', 'Hunt', 'Tarrant', 'Houston', 'Gainsville');
$(itemStore).each(function(){
  if ($('#storeID').text().indexOf(this) != -1) {

// execute active region banner 
var customerStore = itemStore;  // Test Store
var storeOcapiUrl = '/s/athome-sfra/dw/shop/v20_4/stores/' + customerStore;

$.ajax({
   url: storeOcapiUrl,
   data: {
     client_id: 'a9392000-57a9-46a4-bd86-78c5ff617795'
   },
   success: function(storeData){
   console.log(storeData);
   if ( storeData.c_enablePickup && storeData.c_enableDelivery ) {
     // show active storeBanner
     $('.ACTIVE-CodeClass').show();
   } else if (storeStatus && storeData == null) {
     // show a default storeBanner
     $('.DEFAULT-CodeClass').show();
   }
} 
});

clean code – Preferred architecture for tree stuctured data (Angular/Typescript)

After reading some of “Clean Architecture” I got the idea that perhaps I should reconsider the way I have architected a chart of accounts/accounts object in an accounting program.

I have accounts which live in a tree structure like this:

Budget account (root) 
   Sections (0..n)
     Accounts (0..n)
       Subaccounts (0.n)
          LineItems(0..n)`

Only line items have an actual concrete ‘total’ value, which is entered by a user and stored as a number field. Each level of the hierarchy derives the total from the sum of its children’s total, so the Budget Account total is ultimately equal to the sum of all the line items.

My question is this — Should the ‘total’ property above ‘lineitem’ of each account be implemented as a function equal to something like

get total() :number {
  return (sumOf(children.total())
} 

, or should it be designed as a number field on each account which is updated in response to user lineitem changes by responding to an observable which announces changes in the values of any of accounts children?

In the former case, accuracy and maintainability, simplicity, concurrence are all probably increased if there is only one set of actual data to be maintained at the line item level, but it just seems like a heck of a lot of processing that has to happen each time a page with accounts has to show its total. For example if a page header {{budgetAccount.total}} that in turn would provke a process where every single account is recursed through a loop to calculate the total — on every page referesh! And if you print the entire chart of accounts, the same numbers are added over and over and over each time an account.total is requested. However, with the speed of and capacity of todays machines and browser and I don’t have akeen sense if the burden of all this processing is actually meaningful or not and worth persisting some of these imemdiate totals within the accoutn object, so they don’t need recalculation everytime some uses the getter.

For context, might be 20K-30K lineitems in my actual budget, split over maybe 1,000 accounts at various levels. But of course, an exceptionally large budget may come along with as many as 100,000 or 500,000 line items. In my application, the entire budget structure is kept in memory once retrieved from the back end..

What the factors that should be considered in this decision?

console – C# Better structure in my code & any other critiques

Any advice on how to make this code; cleaner, more effective, just overall better!

Program creates a ‘post’ in the console. The post has a:

  1. message
  2. create on date
  3. score for ‘upvotes’ and ‘downvotes’

Users are able to upvote or downvote the post using upvote or downvote with a simple trim and to lower applied to the string.

Any feedback is good feedback. I am currently a working programmer but being self-taught the confidence is not always there..

Want to see it in action? https://repl.it/repls/RoughGhostwhiteApplet

Thanks in advance

namespace StackOverflowPost
{
    class Program
    {
        static void Main(string() args)
        {
            Console.WriteLine("Write a post!");
            string post = Console.ReadLine();
            Post newPost = new Post();
            newPost.AddPostMessage(post);
            
            bool val = true;
            while (val)
            {
                newPost.ShowPost();
                Console.WriteLine("What would you like to do now? n You can 'UpVote', 'DownVote'");
                string inputData = Console.ReadLine();
                string cleanData = inputData.Trim().ToLower();

                if (cleanData == "upvote")
                {
                    newPost.Upvote();
                }
                else if (cleanData == "downvote")
                {
                    newPost.DownVote();
                }
                else
                {
                    val = false;
                }
            }
        }

        class Post
        {
            int voteScore;
            string postMessage;
            DateTime postDate;


            public Post()
            {
                this.postDate = DateTime.Now;
            }

            public void AddPostMessage(string post)
            {
                postMessage = post;
            }

            public void Upvote()
            {
                voteScore++;
            }
            public void DownVote()
            {
                voteScore--;
            }

            public void ShowPost()
            {
                Console.WriteLine("------------------------------------");
                Console.WriteLine($"Original Post Date {postDate}");
                Console.WriteLine($"User wrote: {postMessage}");
                Console.WriteLine($"Votes: {voteScore}");
                Console.WriteLine("------------------------------------");
            }
            
        }
    }
}

windows forms – Need Word Falling into lava game C#, Some Incomplete code is given, Please help me someone

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void MainButton1_Click(object sender, EventArgs e)
        {

        }

        private void MainTimer_Tick(object sender, EventArgs e)
        {
            
            MainLabel1.Location = new Point(MainLabel1.Location.X, MainLabel1.Location.Y+10);


        }

        private void MainLabel1_Click(object sender, EventArgs e)
        {
            
            MainLabel1.Location = new Point(MainLabel1.Location.X, MainLabel1.Location.Y + 10);
            if (MainLabel1.Location.X <= 0 || MainLabel1.Location.X + MainLabel1.Location.Y >= 743)
            {
                MainLabel1.Location = new Point(MainLabel1.Location.X-10, MainLabel1.Location.Y );
            }
            if (MainLabel1.Location.Y <= 0)
            {
                MainLabel1.Location = new Point(MainLabel1.Location.X, MainLabel1.Location.Y - 10);
            }
        }

        private void MainLabel2_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            MainLabel2.Location = new Point(MainLabel2.Location.X, MainLabel2.Location.Y + 10);
        }
    }
}

AnyDice — efficiency of code calculating rolls hitting a target with mixed pools; hitting the 5 second barrier

I have some code that is hitting the 5 second barrier;

function: target N:n of A:s B:s C:s {
    result: (count {1..N, 1..(N/2)} in (sort {A, B, C}))
}
output (target 7 of 4d12 0d20 0d8)
output (target 7 of 4d12 2d20 0d8)
output (target 7 of 4d12 4d20 0d8)

Even if I remove the final output line, it still fails.

I believe the code does what I want it to – calculate the number of dice rolling at or under the target from mixed pools (it runs when using other pools: d20s seem to be a problem).

Is there anyway I can improve it so that at least the first two of these output lines will run (or better yet, all three of them)?

N.b. from my perspective these were some of the simplest pools I wanted to look at.

development process – Inspection code reviews, is it outdated today?

I’m a big proponent of peer reviews on every change, like with pull requests etc, however I’m questioning if this type of review alone is enough.

For one, I have trouble with reviewers ‘missing the forest for the trees’ so to speak. Their focus is on the changeset and often fail to consider future or past integration, the overall feature being developed or even the overall component. e.g. for a single web service feature, we’ve broken it down to two major tasks, front & backend. backend is complete and reviewed, frontend is complete and reviwed, both are individually logically sound, but no one has picked up that the backend is exposing more data than the frontend is actually consuming. Or commonly, the first task/review assumed that a certain check will be implemented in a later task, but it never does. I believe a final review after a feature or module is complete could help.

Secondly, pull requests are meant to be fast and thus not thorough. But with security issues and other critical functions, a thorough inspection and even a checklist of questions or items to consider is needed. Again, a separate inspection process apart from pull requests is needed.

However, i don’t see any support for this at all. Popular wisdom seems to be formal inspection reviews are outdated and a hindrance from the past. It’s all lightweight change-based code reviews. Even the tools aren’t supportive of it, like with git pull requests being conflated as a review system.

So I’m here, to seek validation for my views, or condemnation that I’m stuck in a past world. And also to seek advise, if i’m doing something wrong with my code reviews or how else I can deal with them better.

tic tac toe code in c++ with two players

My main problems are making draw case and any player can choose a place which is chosen by another player here is the code :

#include <iostream>
using namespace std;

char board(3)(3) = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};
static int turnnumber = 1 ;
bool winner = false, flag = false ;
bool win(){
     if(board(0)(0)==board(1)(1)&&board(1)(1)==board(2)(2))
    winner = true ;
    if(board(0)(2)==board(1)(1)&&board(1)(1)==board(2)(0))
    winner = true ;
if(board(1)(0)==board(1)(1)&&board(1)(1)==board(1)(2))
    winner = true ;
if(board(0)(0)==board(0)(1)&&board(0)(1)==board(0)(2))
    winner = true ;
if(board(2)(0)==board(2)(1)&&board(2)(1)==board(2)(2))
    winner = true ;    
if(board(0)(0)==board(1)(0)&&board(1)(0)==board(2)(0))
    winner = true ;
if(board(0)(1)==board(1)(1)&&board(1)(1)==board(2)(1))
    winner = true ;
if(board(0)(2)==board(1)(2)&&board(1)(2)==board(2)(2))
    winner = true ;
            
    if(winner==true&&turnnumber==1)
       cout << "player2 won nn" ;
    if(winner==true&&turnnumber==2)
       cout << "player1 won nn" ;
 
    return winner;
}

void view()
{
    for (int i = 0; i < 3; i++)
    {
        for (int x = 0; x < 3; x++)
        {
            cout << "(" << board(i)(x) << ")  ";
        }
        cout << endl
             << "-------------" << endl;
    }
}
    
void players()
{
    
    char player1 = 'X', player2 = 'O';
    int number;
    cout << "nplayer " << turnnumber << " it's your turn ";
    if(turnnumber==1)
       turnnumber++;
    else if(turnnumber==2)
       turnnumber--;
    char player;
    if(turnnumber==1)
       player=player2;
    if(turnnumber==2)
       player=player1;
    cin >> number ;
    
    switch(number){
        
    case 1:
        board(0)(0) = player;
        break;
    case 2:
        board(0)(1) = player;
        break;
    case 3:
        board(0)(2) = player;
        break;
    case 4:
        board(1)(0) = player;
        break;
    case 5:
        board(1)(1) = player;
        break;
    case 6:
        board(1)(2) = player;
        break;
    case 7:
        board(2)(0) = player;
        break;
    case 8:
        board(2)(1) = player;
        break;
    case 9:
        board(2)(2) = player;
        break;
    default:
        cout << "nwrong numbern";
        players();
         
    }
    system("cls");
    view();
 
    if(!win())
        players();
}

int main()
{
    view();
    players();
}

git – Gitflow, use code from another feature branch in feature branch

me and a friend are working on a project, and we are both doing seperate things (he does UI, I do some data structure), and his code relies on my code. Right now we have a master, a develop and 2 feature branches (one for UI and one for data structure). How can he test his UI with my commits, without making one huge mess out of the commit history and without committing to develop (since both features are not done yet)?

Sorry if it’s a beginner question, quite new to git!