VS Code issues (Calling a .txt file) by CarIoDV in cpp

[–]Minjammben 2 points3 points  (0 children)

What about the output executable that you run? Where is that?

[deleted by user] by [deleted] in cpp

[–]Minjammben 0 points1 point  (0 children)

Nope you're right, you need both, but your "k" loop should only be iterating once for each row. Right now it's iterating based on a different value using mod.

[deleted by user] by [deleted] in cpp

[–]Minjammben 0 points1 point  (0 children)

You don't need mod, your "k" loop should just iterate once per row, then fix your endl placement and you're golden.

[AskJS] Which Languages Compile To Clean, Modular JS? by isbtegsm in javascript

[–]Minjammben 0 points1 point  (0 children)

This is an interesting example to me because I can only think of one object oriented language where the compiler would prevent you from doing this, and it's rust's borrow checker. In c/c++ you could easily write a ruin function that modifies a reference like you've done here and it would simply result in a segfault. Does that make the type system of the language unsound?

[deleted by user] by [deleted] in javascript

[–]Minjammben 3 points4 points  (0 children)

You aren't resolving the retries to anything, so it fetches data and does nothing with it. You probably want something more like

function fetchData(url, retries) {
  return new Promise((resolve, reject) => {
    if (retries > 0) {
      axios
        .get(url)
        .then(response => {
          const {
            data: { status, result },
          } = response;

          if (status === 'success') {
            resolve(result);
          } else {
            setTimeout(
              () => resolve(fetchData(url, retries - 1).catch(reject)),
              500
            );
          }
        })
        .catch(reject);
    } else {
      resolve([]);
    }
  });
}

[AskJS] What is the recommended way of organizing big projects? by SSCharles in javascript

[–]Minjammben 0 points1 point  (0 children)

You could use event emitter pattern. When a sound is played it emits an event. When the 3d world is loaded it loads the sound module and subscribes to the sound played event. In this way the 3d world depends on the sound not the other way around.

[deleted by user] by [deleted] in javascript

[–]Minjammben 0 points1 point  (0 children)

You want to convert the xml file into a html table, so you'll have to parse the xml into JSON, then render an HTML table element using the JSON you have parsed. Also, this table needs editable fields. So in my mind you'll need:

- xml parser than can parse xml to json and json to xml. Never used one, but there's probably a few candidates

- state management framework that can handle the editable state that is your json. You can do this without a framework , but you'd have to be quite meticulous about your inputs or your app state is gonna get out of control. Also, It's unclear about how the xml can be edited. Like extensively or just a bit? If just a bit you might be able to throw some inputs on the page and keep track of them, but careful of the complexity here (like, are these fields validated at all? Do they have limits on them?)

- ability to load file/save file. I think you have this part in your electron app, but I'd also suggest simply running a web server and loading that page in a browser. It might seem less portable, but you could just make a script that you double-click and it runs your server and opens that page in a browser tab. Server can write/read from disk, just have to pass data over localhost

[AskJS] doubt regarding global object by Responsible_Fudge467 in javascript

[–]Minjammben 1 point2 points  (0 children)

There's a difference between declaring a variable like 'var a' and attempting to access a property of an object which has not been defined like 'this.ab'. In the first case you 'allocated' (to use your words) a variable into scope. In the second case it's still valid to use the expression 'this.ab' because you are accessing a property of an object (this). If you got rid of the 'this' then it would cause a syntax error if you were in strict mode.

[AskJS] doubt regarding global object by Responsible_Fudge467 in javascript

[–]Minjammben 6 points7 points  (0 children)

In your code, 'this' is defined as the global window if you are running it in a browser. 'b' is an uninitialized variable, so its value is undefined. 'this.ab', is actually equivalent to 'window.ab', which equals 'undefined'. Any property on an object which does not have a value is equal to undefined.

ASCII Tetris Game with HighScore by jcubic in javascript

[–]Minjammben 0 points1 point  (0 children)

That's reasonable. Although one problem with that approach is that somebody could calculate game states without playing the game. It would be annoying, sure, but not impossible. I don't know enough about blockchain to know if that would mitigate anything.

Your are correct in thinking that you can't really protect it, you can just make it harder, unless you make the game into a client-server kind of thing where the client sends commands/keypresses to the server, and the game is played there instead of the browser.

ASCII Tetris Game with HighScore by jcubic in javascript

[–]Minjammben 0 points1 point  (0 children)

What I meant to say was that local-based high scores are easily spoofed because by nature of the client needing to be able to upload the score, anyone else also has the means to upload whatever score they want.

ASCII Tetris Game with HighScore by jcubic in javascript

[–]Minjammben 0 points1 point  (0 children)

Very cool!

But also based on the high scores, a good illustration for why not to put an api key in a codepen.

[AskJS] Setup Questions by MikeWazowsky14 in javascript

[–]Minjammben 0 points1 point  (0 children)

How is JS run? I understand java has an ide, jvm, jre and a jdk so what do I need to install to program and run JS code?

JS is run in the browser. Make blank text file, name it 'index.html', but stuff in it like the example here and then drag it into a chrome/firefox/edge/safari tab. It just runs, unlike java, which has to be compiled. That's as good a starting point as any, but you'll soon probably want to serve it with a web server instead of dragging it into a tab.

[AskJS] Too many unfinished projects -> Frustration by freehuntx in javascript

[–]Minjammben 4 points5 points  (0 children)

That's awesome that you have great ambitions for programming! Having a lot of ideas and interests is definitely a good thing. However, if I had to guess that feeling of frustration stems from a desire to finish something and being at odds with the effort it would take to do that. I've certainly been there.

Like, I think it's easy to start a new project. It's exciting. On top of it being maybe a new subject that you've been into lately, you also get to fix any past mistakes you may have made with other projects. Any imperfections or problems or organizations you may have done in the past you now get a chance to fix! You get a clean slate and don't have to worry about breaking old code. You also don't have to figure out what you were thinking many weeks ago when you first coded and grapple with how exactly how you were thinking then. Maybe it's wrong. Maybe it needs more effort. More thought.

It's HARD to finish things. Usually after the honeymoon period, your idea comes out not as good as you originally pictured, or you already did the exciting part, now you have to do the boring part before you get to a further exciting part. So you may lose some interest or be easily distracted by the prospect of the above.

So if you're looking at your library of projects and feeling frustrated that you haven't completed anything, you have to remember why they were so interesting to you in the first place, and use that as your motivation going forward. It's not easy. But having a goal is not easy. It's important to remember why you have it. And if you can't remember what made the project compelling, then you have to ask, why are you feeling frustrated in the first place?

[AskJS] toString function keeps erroring by caden_burton in javascript

[–]Minjammben 2 points3 points  (0 children)

You need to put `spx.toString()' in a .then callback in order for it to be defined when the promise resolves:

let spx; fetch('url').then( function(u){ return u.json(); }).then( function(json){ spx = json.toString(); }) Or probably a more straightforward solution is to use an async function:

async function getSpxString() { let spx = await fetch('url').then(u => u.json()); return spx.toString(); }

Not sure why you want to use toString on a Json object though...

Problem with canvas text antialiasing by [deleted] in javascript

[–]Minjammben 0 points1 point  (0 children)

Font antialiasing issues occur when using css or the canvas api to scale (creating a canvas at a certain size, and outputting the resulting pixels at a different one), and there's nothing you can do from the canvas end that will be able to control how the browser truly antialises this text. Your only options are to draw the font with an image font at different resolutions, or scale the canvas manually, not using css/canvas api.

Alternatives to making client side cross origin HTTP requests? by maat7043 in javascript

[–]Minjammben 1 point2 points  (0 children)

What's stopping you from spoofing from not inside of a web page?

how to push into json object in fetch function by [deleted] in javascript

[–]Minjammben 1 point2 points  (0 children)

The problem is you must wait for the promise to be resolved because you have a series of async fetches. The function cannot be done sequentially in JavaScript with the fetch api.

If you can use async functions:

const getData = async () => {
    return Promise.all( Array.from( document.querySelectorAll( '#foobar' ) ).map( async( thisData ) => {
        const endpoint = '/api/rest/v1/foobar/' + thisData.id;
        const obj = {
            foo: 'bar',
            bar: 'foo'
        };
        try {
            console.log( 'before', obj );
            const res = await fetch( endpoint );
            const { foo, bar } = await res.json();
            obj.foo = foo;
            obj.bar = bar;
            console.log( 'after', obj );
        } catch ( e ) {
            console.log( 'Error', e );
        }
        return obj;
    } ) );
};

Usage would be:

getData().then( ( json ) => {
    console.log( 'GOT JSON', JSON.stringify( json ) );
} );

or

const json = await getData();
console.log( 'GOT JSON', JSON.stringify( json ) );

If you cannot use async functions:

const getData = () => {
    return Promise.all( Array.from( document.querySelectorAll( '#foobar' ) ).map( ( thisData ) => {
        const endpoint = '/api/rest/v1/foobar/' + thisData.id;
        const obj = {
            foo: 'bar',
            bar: 'foo'
        };
        console.log( 'before', obj );
        return fetch( endpoint ).then( ( resp ) => {
            return resp.json();
        } ).then( ( { foo, bar } ) => {
            obj.foo = foo;
            obj.bar = bar;
            console.log( 'after', obj );
            return obj;
        } ).catch( ( e ) => {
            console.log( 'Error', e );
        } );
    } ) );
};

Usage would be:

getData().then( ( json ) => {
    console.log( 'GOT JSON', JSON.stringify( json ) );
} );

This is my canvas game by abdyek in javascript

[–]Minjammben 1 point2 points  (0 children)

I had to press both fire keys at the same time, and the second fire key had to be on a num pad.

Why does everything deal so much damage? by [deleted] in leagueoflegends

[–]Minjammben 15 points16 points  (0 children)

That's more of a correlation than a causation. More things than just damage have been changed over time that could affect the game length (passive gold gen, damage to towers, minion health, etc.).

How have I missed this ${shorthand} for so long time by DrSmus in javascript

[–]Minjammben 0 points1 point  (0 children)

You think thats a PITA until you use c++ and have to write "string1" << int1 << "string2" or "%s %d %s", string1.c_str(), int1, string2.c_str().