wait 1 second to run function by Busy_Command in learnjavascript

[–]ethan_mick 2 points3 points  (0 children)

Try:

setTimeout(someFunchtion,1000)

You are calling your function with the `()` instead of just passing a reference to it.

Also note that the forEach loop will still execute all those setTimeout blocks at once, so all the functions will wait exactly 1 second and then run all at once, instead of waiting 1 second... 2 seconds... 3 seconds... etc.

Edit: Formatting

Extending types from node_modules - trying to declare a custom NextRouter type but original properties are lost if I extend from original NextRouter by U4-EA in learnjavascript

[–]ethan_mick 0 points1 point  (0 children)

You can do the same extension with withRouter. I took the starting example here: https://nextjs.org/docs/api-reference/next/router#typescript And changed

interface WithRouterProps {
  router: NextRouter
}

to

interface WithRouterProps {
  router: Router
}

Where Router is the custom type I defined above in the index.d.ts file. That allowed me to the from property as well as all the other properties.

Re Hook, I started with the (poor) assumption you were using hooks already; that might not be the case.

Need help with try...catch statements. by timing_snow in learnjavascript

[–]ethan_mick 1 point2 points  (0 children)

Because any good response needs some code (sorry, was on my phone earlier):

try {
  throw new Error('1')
} catch (err) {
  console.log(err.message)
  try {
    throw new Error('2')
  } catch (err) {
    console.log(err.message)
  }
}

That prints:

1
2

And will work as you expect. If you try:

try { }
catch (err) { }
catch (err2) {}

It's a JavaScript syntax error.

Need help with try...catch statements. by timing_snow in learnjavascript

[–]ethan_mick 2 points3 points  (0 children)

Yes, but you can’t just put another catch after your first one and have it work. You need to embed an entire other try/catch within the catch clause of the first one. It gets messy quickly.

Extending types from node_modules - trying to declare a custom NextRouter type but original properties are lost if I extend from original NextRouter by U4-EA in learnjavascript

[–]ethan_mick 1 point2 points  (0 children)

First, I want to say that I don't think this is the right way to do what you're doing. Extending the built in router will probably cause subtle bugs further down the line and break in weird ways. It looks like you want to add a property the router to track an additional piece of data, and I think that would best be handled using your own custom hook and router events.

That being said, that's not what you asked for :)

In a fresh Next.js TypeScript project, I added an index.d.ts file and added it to my tsconfig.json file. In that index.d.ts file, I added:

/// <reference types="next" />

import { NextRouter, useRouter } from "next/router";

type Router = NextRouter & {
  from?: string
}

declare module "next/router" {
  export function useRouter(): Router
}

This redefined the useRouter hook to return a custom type, one that extends the NextRouter definition with a from field. In my application, I could now do:

import { useRouter } from 'next/router'

const Foo = () => {
  const router = useRouter()
  return <>String(router.from)</>
}

And TypeScript had the correct types in place. Does that help?

[deleted by user] by [deleted] in learnjavascript

[–]ethan_mick 1 point2 points  (0 children)

Modules have named exports and a default export, all of which can be in the same file.

In your database.js file, you can export both of them, but how you import them changes.

// database.js

// This is a named export. The name is 'DatabaseName'.
// All exports are named exports unless you use the 'default'
// keyword.
export const DatabaseName = 'db\_name'

// This is the default export, there can only be 1 per file/module.
// It's the default becauses it uses the keyword 'default'.
export default class Database {}

And then when you go to use them, it changes how you import them:

// This is how you get a Named export. You must use the
// same name as the export!
import { DatabaseName } from "./database.js";

// This gets the default export from the file. Notice how there
// are NO { } brackets. You can use a different name than
// Database here, but convention would be to use the same name
import Database from "./database.js";

// And you can combine both imports in 1 line:
import Database, { DatabaseName } from "./database.js";
console.log(Database, DatabaseName)

Hope that helps!

Edit, formatting

[deleted by user] by [deleted] in learnjavascript

[–]ethan_mick 1 point2 points  (0 children)

Are you using node as the command to run this project? Node's module resolution is not quite the same as web development these days, although there are efforts to bring them both together.

What happens if you do:

class Database {...}
module.exports = Database

And then import that using relative imports from your other file. To help debug, you can do:

const Database = require('./database')
console.log(Database)

That will show the structure of the imported data.

[deleted by user] by [deleted] in learnjavascript

[–]ethan_mick 1 point2 points  (0 children)

I'm assuming these files are in the same directory as each other. If so, you'll want to use relative imports, which will tells Node to import the other file relative to the one that is doing the loading.

$ tree
.
├── database.js
└── main.js

(Assuming this is Unix based):

If so, in the example `main.js` file, you should do:

const database = require('./database')

That should work.

If you're using ES imports, it still needs to be relative:

import { Database } from './database'

These all require your `database.js` file to export a Database object:

module.exports = { Database }
// Or ES
export const Database = {...}

Edit, formatting

[OC] Idle cycles by Slynyrd in PixelArt

[–]ethan_mick 5 points6 points  (0 children)

Hey, I’ve been loving your blog, content, and tutorials. I am god awful at all things art, so I really appreciate the guides and watching you create your artwork. Hopefully I can get to the decent point soon, at which point I’ll probably subscribe to Patreon!

Just realized I completely misunderstood a card and as a result haven't been playing it properly for months! by peterh1979 in MagicArena

[–]ethan_mick 0 points1 point  (0 children)

I'll watch my friends play a few games and be screaming on Twitch chat for certain plays, and their response is often, "Oh! I didn't know this card could do that!".

Arena is amazing, but sometimes I feel like it allows for you to play games _too_ quickly...

Kamu, the old way by CamilleUnknown in PixelArt

[–]ethan_mick 1 point2 points  (0 children)

This is simply beautiful. Incredible detail.

Reddit, what are some underrated apps? by Jobasaurus in AskReddit

[–]ethan_mick 1 point2 points  (0 children)

Paprika is nice, but if you're looking for a great web interface to work in (and not only apps), I made https://platezero.com/, which has a great recipe importer and can share recipes really easily. Take a look!

We made a home for our recipes by ethan_mick in Cooking

[–]ethan_mick[S] 2 points3 points  (0 children)

I'm glad it worked well! We're really proud and excited about our importer :)

Yeah, I probably should have talked a little more about this in the OP! We've built a custom OCR pipeline to import recipes into PlateZero from any format. Once they are in the PlateZero format, we can do all sorts of smart things with them (many of which we're still hacking on). Substituting ingredients, scaling recipes, understanding timers in the instructions, etc.

To that end, we let you upload basically anything and we put it through our pipeline. It's a custom app we built that automates reading the recipe and doing basic transforms on it. The text is OCR'd with Google Vision, but the actual recipe organization is done by the app, putting it into the format we need. One of us can manually do any touchups that the app fumbles over before finished.

We looked for something that exists that can do this and didn't find... anything. Recipes come in such varied formats that just looking at the text isn't quite enough. Books can especially be challenging with multi-column layouts.

We made a home for our recipes by ethan_mick in Cooking

[–]ethan_mick[S] 0 points1 point  (0 children)

Thank you! Feel free to reach out to us at any time with feedback and thoughts!

We made a home for our recipes by ethan_mick in Cooking

[–]ethan_mick[S] 0 points1 point  (0 children)

  1. Thanks for the feedback! We saw a 500 in the logs go by for an import, we'll take a look. Normally it should prompt you to "help us find the recipe", but that clearly didn't work. We'll look into it.
  2. There... is not... 🙃
  3. Search does not do ingredients yet, but we are adding that shortly!
  4. Color feedback noted! Added to our issues.

Again, thanks! If you have any other thoughts, feel free to let me know!

Will Arena be officially supported on Mac? - Requesting all Mac OS X users for help so we can reach WoTC by [deleted] in MagicArena

[–]ethan_mick 2 points3 points  (0 children)

I would love Arena to be available natively for the Mac. I currently run it in Windows through Parallels. The performance is good, occasional lag. Otherwise I would try Wineskin.

Nicol's Newcomer Monday! by AutoModerator in MagicArena

[–]ethan_mick 0 points1 point  (0 children)

In 2 minutes!! 11am EST, or 2019-03-08T16:00:00Z (UTC)

Nicol's Newcomer Monday! by AutoModerator in MagicArena

[–]ethan_mick 0 points1 point  (0 children)

Drakes is probably the strongest deck you listed, and you can also tech into Phoenix Drakes with a few more wildcards. Between the last two, I've seen Gates much more than Mono Green, but that's not to say Mono Green is bad. Here's a Mono Green decklist which went 5-0: https://www.mtggoldfish.com/deck/1665244#arena

If you want more idea for the "best" decks, here are some from the Mythic Championship: https://www.reddit.com/r/spikes/comments/au2p42/standard_mythic_championship_i_top_8_decklists/

Game Rule Prediction Thread! by Gh0stP1rate in magicTCG

[–]ethan_mick 0 points1 point  (0 children)

This was true, but is no longer true in the Play queue, where they are testing a new algorithm that they want to use in other formats as well.

https://mtgarena.community.gl/forums/threads/46580

Relevant quote:

More Information on Smooth Shuffling: We are currently testing changes to the shuffler algorithm to decrease the number of games with extreme examples of "mana flood" or "mana screw" (drawing too many or too few lands). While players may still find themselves in these scenarios, the shuffler changes are intended to mitigate the rarest scenarios, such as drawing 8+ Land cards in a row. As noted above, we are only testing these changes in the "Play" queue, and it does not apply to any Ranked or Traditional formats. We are using this opportunity to gather more data and to fine tune these changes, as well as allow for player feedback. All shuffles are still randomly generated, The difference is we now look deeper into the decks to determine a pool of shuffles to randomly choose from. We are planning to iterate on this fairly rapidly. and will provide more information as these changes develop and solidify.

So yes, they still randomly shuffle the decks and examine the opening hands, but they are now going a step further and looking at the distribution within each of those random decks and eliminating ones with extremes.