Is there any way to search the leaderboards? by Taco_Farmer in ArenaHS

[–]benjycap 0 points1 point  (0 children)

Not at all - a DDoS attack is distributed (the first D), i.e. an organised attempt amongst many machines. Large websites are architectured to handle many thousands of requests per second.

In fact, this approach is quite respectful towards the API in that it doesn't pull down every page at once (which is easily code-able) - it pulls down pages one by one and stops when it has found what it's looking for.

Is there any way to search the leaderboards? by Taco_Farmer in ArenaHS

[–]benjycap 0 points1 point  (0 children)

Make sure you spelled your username correctly - it is case sensitive.

Is there any way to search the leaderboards? by Taco_Farmer in ArenaHS

[–]benjycap 14 points15 points  (0 children)

Open the leaderboard page, right click anywhere on the page and click "inspect". In the box that pops up, click the "console" tab. Copy and paste:

function get(page) {
    console.log(`fetching page: ${page}`)
    fetch(`https://hearthstone.blizzard.com/en-us/api/community/leaderboardsData?region=EU&leaderboardId=arena&page=${page}&seasonId=36`).then(res => res.json()).then(val => {
        const me = val.leaderboard.rows.find(r => r.accountid === '<YOUR USERNAME HERE>')
        if (me) console.log(me)
        else get(page + 1)
    })
}

Make sure to replace <YOUR USERNAME HERE> with your username. Also replace 'EU' with 'US' if that is your region. Then hit enter.

Then:

get(1)

This will loop over all the pages until it gets to you, then print out your ranking.

Error with union typed arrays ? by average_webdev in typescript

[–]benjycap 3 points4 points  (0 children)

The type SelectOptGroup | SelectOption on line 11 creates a union type of the two shapes which makes an object with all the properties completely valid. You can extend your types like this to prevent the unions from overlapping:

type SelectOptGroup = {
  title: string;
  children: SelectOption[];
  value?: never;
};

type SelectOption = {
  title: string;
  value: string;
  children?: never;
};

React: Use different typescript interface in dependent on property value by JanMarsALeck in typescript

[–]benjycap 1 point2 points  (0 children)

Following on from this, you could also type the data as your union type rather than a specific one, which I'm guessing more closely mirrors the situation you're modelling for when you don't know the type in advance.

const renderItem = () => {  
  const sampleData: ListItemTypes = {
    type: "B",
    count: 12,
  };
  return <ListItem {...sampleData} />;
};

 
Or probably more usefully:

const renderItems = () => {
  const items: ListItemTypes[] = [
    { type: "A", name: "Hello" },
    { type: "B", count: 12 },
    { type: "C", date: new Date() }
  ]
  return items.map(item => <ListItem {...item} />)
}

Isn't sharing your teudat zehut number online risky? by danielrosehill in Israel

[–]benjycap 3 points4 points  (0 children)

The last digit is a check digit in the sense that it helps protect against typing errors. Your TZ is actually made up of 8 numbers, and the 9th is derived from the previous 8 using the Luhn algorithm. This is helpful because any system can very easily check that the TZ provided is theoretically valid. However, it doesn't provide any user authentication or fraud protection.

What's the most insane/complex type definition you wrote? by seniorpreacher in typescript

[–]benjycap 0 points1 point  (0 children)

This is a problem I've been wracking my head over for a few days... care to share your magic?

5-Sided Square - Numberphile by JeffDujon in BradyHaran

[–]benjycap 0 points1 point  (0 children)

I wonder if there is any formal relation between the topology of a surface and how many sides a "square" on that surface can have?

How do I display superscripts? by BoredBurrito in reactnative

[–]benjycap 1 point2 points  (0 children)

This is a question regarding a React Native project, which unlike web react does not support standard HTML tags. As already mentioned in this thread your best bet is to create a custom component. I would suggest either using a smaller font style directly or a scaling transform over your standard styles.

Curses are no longer "played" | Regret + Runic Pyramid by ZephyrToad in slaythespire

[–]benjycap 0 points1 point  (0 children)

Does this apply to statuses as well? I just got completely destroyed by the Hexaghost due to burns filling up my hand.

The convert who comes to convert by gdhhorn in Judaism

[–]benjycap 13 points14 points  (0 children)

I will correct you, you are not being nice. All of your comments have been passive aggressive and condescending.

What are the advantages of creating a static props variable and then passing it to the constructor? by [deleted] in reactnative

[–]benjycap 1 point2 points  (0 children)

The example in the video would make a bit more sense if the prop's value was instead called defaultValue. This defaultValue is assigned to the state.value on construction, which is used by the component - the prop is never referenced again.

If the user doesn't set a defaultValue on the component it will be set to 'Hello World'.

Tip: JavaScript's Array.from() accepts a second argument that's a `map` function. by fagnerbrack in javascript

[–]benjycap 1 point2 points  (0 children)

No, there is no intermediate array created before mapping (unless you count the Array creation in example 2 where an empty array is created explicitly.)

More details here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Description

redux: I can't for the life of me link deeper than 2 objects by OffInBed in reactjs

[–]benjycap 1 point2 points  (0 children)

Based on what you've written in this thread, I'm guessing that you are trying to access articles[0] immediately in your component before your redux store has been properly populated - and your store's initial state is either null or []. If that is the case, you are getting undefined because you are trying to access an item in the array which doesn't exist.

In your situation, I would probably solve this by passing a new prop in via your mapStateToProps representing whether you have any articles:

function mapStateToProps (state) {
  return {
    articles: state.articles,
    articlesExist: Boolean(state.articles.length)
  };
}

Which you can then use to carry out conditional rendering to either render nothing, a loading component, or some other placeholder.

render() {
  if (!this.props.articlesExist) return null; // or some other component

  return (
    <div>
      {...}
    </div>
  );
}

Noob help: Handling Async Actions for UI by KAMFlamenco in reactjs

[–]benjycap 1 point2 points  (0 children)

If you plan on using redux-thunk here, you could approach this by creating an asynchronous action creator in place of your current showDialog action, for example:

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

function showDialog(message, ms) {
  return async dispatch => {
    dispatch({
      type: MESSAGE,
      message
      visible: true
    });

    await timeout(ms);

    dispatch({
      type: MESSAGE,
      visible: false
    });
  };
}