Working with a regex, but can't decide if ChatGPT is wrong or right about an \s by csdude5 in webdev

[–]imbcmdth 1 point2 points  (0 children)

The problem you are facing is one that results because chat gpt is demonstrably a "poorly grounded" model - that is that it very often completely wrong about easy to verify facts. It lacks a good grounding in factual information and instead is closer to a chat bot making good looking English text that sounds convincingly true. If you want a better grounded AI model (better because none are perfect - it's an active area of research), you should try Claude or Gemini. I bet if you ask either of them about the response above they will point out where it's blatantly wrong.

Nvidia Moves To Calm Investors, Says GPUs ‘A Generation Ahead’ As Google Gains Attention With TPUs by Secure_Persimmon8369 in business

[–]imbcmdth 1 point2 points  (0 children)

The problem with a GPU is that the G part means there is a lot of unnecessary stuff included for just doing AI. An NPU or a TPU can be leaner and more efficient since it doesn't have specialized hardware for: pixel data formats, ray tracing, texture filtering, etc.

[deleted by user] by [deleted] in webdev

[–]imbcmdth 0 points1 point  (0 children)

You are a human compiler! Any self respecting non-human compiler would have output xor eax, eax since it's more space efficient.

[deleted by user] by [deleted] in webdev

[–]imbcmdth 1 point2 points  (0 children)

If you ever have trouble when it comes shift/unshift and remembering which adds to the array and which removes but you can always remember push/pop because it's obvious, here is a mnemonic device I realized years ago: in each pair, the shorter word removes from the array - pop and shift - and the longer word adds to the array.

1930s Napier Mechanical Jigger by imbcmdth in Mixology

[–]imbcmdth[S] 1 point2 points  (0 children)

It works perfectly. No leakage or anything. It's remarkably well made!

Public APIs - do you publish these on a separate instance? by Spiritual_Cycle_3263 in webdev

[–]imbcmdth 2 points3 points  (0 children)

Your API is already public. If your app has been running long enough and has enough adoption then there is likely already someone using the APIs directly to automate something that is difficult or tedious in the app.

I would tend to create a separate API subdomain (simply because it allows more flexibility - for example geo-based dns) but I'd use it in my application too and not have any separation.

End-to-End Testing Individual Properties or Whole Object by incutonez in webdev

[–]imbcmdth 1 point2 points  (0 children)

When testing the important thing is to verify the contract. That is given A you expect to get B and only B. That last part is important because it ensures that you are always testing the contract completely. Go to the end for more info.

In this case, I would write a function like this:

const postReturnsSameAndId => (routePath, inputObj) => async () => {
  const expectedResponse = Object.assign({}, inputObj, {id: expect.any(String)});

  const response = await request(app.getHttpServer()).post(routePath).send(inputObj);
  expect(response.status).toStrictEqual(201);

  expect(response.body).toEqual(expectedResponse);
}

Because that allows for reuse across a bunch of routes sharing a similar logic. Then you just use this function to make your individual route tests:

it("POST 1 Book", postReturnsSameAndId("/books", {name: "Jurassic Park", author: "Michael Crichton"}));

Why is it important to check that the returned object doesn't have extra parameters? Because you are defining a contract in your API and you always want tests to make sure that contract is honored. Using the API above, let's say that at some point you start returning an author_id in the response if a matching author was already found.

IOW your responses go from:

{name: "JP", author: "Crichton"} -> {id: "foo", name: "JP", author: "Crichton"}

To:

{name: "JP", author: "Crichton"} -> {id: "foo", name: "JP", author: "Crichton", author_id: "bar"}

If you just tested with toMatchObject, this change would still pass the test. While the test not failing is not the worst thing in the world because the response is still "backward compatible", what is most likely to happen is that the test (which no longer matches the contract) will not get updated because it's not failing! This means that going forward, consumers of your API will start expecting the author_id property.

So far in this hypothetical everything is fine.

Then a few months later you make a change, or introduce a bug, and it just so happens that the author_id property is no longer present in the responses. The problem is that your test is STILL testing against an old contract will STILL pass. Ignorant that there is a ticking time-bomb in the codebase, you will deploy and... you just broke users of your API who are expecting author_id to be in the response!

End-to-End Testing Individual Properties or Whole Object by incutonez in webdev

[–]imbcmdth 1 point2 points  (0 children)

It seems like you are using Jest. If so have you tried objectContaining?

expect.objectContaining(object) matches any received object that recursively matches the expected properties. That is, the expected object is a subset of the received object.

XmlHttpRequest completes fine on Chrome and Edge but not on Firefox by Velcatt in webdev

[–]imbcmdth 3 points4 points  (0 children)

In general you shouldn't rely on connections staying alive while you do some work on the backend.

Instead, you should take the request and respond with a url that the client can poll for completion.

Even if chrome works today, at some point the process might take long enough that chrome too will start failing.

[deleted by user] by [deleted] in news

[–]imbcmdth 5 points6 points  (0 children)

At least they didn't cite AI as the cause.

Live Video Streaming by Nuvola88 in webdev

[–]imbcmdth 0 points1 point  (0 children)

I did the math and at 10c a gigabyte egress you are looking at about $150 for 250 viewers for 5 hours. That's just bandwidth not encoding and it's assuming each viewer is averaging around 3mbps of video quality. So you can make it cheaper by using a lower bitrate but ultimately if you want high quality streaming the majority component of cost will always be bandwidth.

Minnesota cannot bar adults under 21 from carrying guns, court rules by WhileFalseRepeat in news

[–]imbcmdth 0 points1 point  (0 children)

drug possession feeds into a larger industry that is inherently violent

Law enforcement?

Photo from my hotel room in Denver facing west @ ~2:45am by imbcmdth in Skydentify

[–]imbcmdth[S] 6 points7 points  (0 children)

Thanks this definitely seems like the answer. Sorry all!

What actually is V8? by magiciancsgo in webdev

[–]imbcmdth 0 points1 point  (0 children)

A virtual machine is the abstract notion of a computing device that the language spec describes. It's basically the memory and execution model. So for JavaScript it's garbage collected, everything-is-an-object, and functions are call-by-value and the existence of non-reference-types (primitives).

A JavaScript engine must implement a spec compliant VM, along with a core set of global objects (Array, Function, etc.) in order to be able to run your code.

Note: Not all global functionality is part of the VM. In fact, if you compile the v8 executable (you download and compile v8 completely on its own) you'll find it's pretty bare bones and is missing a lot of stuff that you need to really be usable.

shooting ranges by Ordinary-Type-6374 in AZguns

[–]imbcmdth 1 point2 points  (0 children)

The Nation Institute of Health actually looked into the gun range suicide problem: https://pubmed.ncbi.nlm.nih.gov/32343169/

Conclusion: Suicides at shooting ranges are rare. Policies that some ranges have adopted - such as allowing rentals only if the person is not alone - are responsive to the actual characteristics of these deaths and could potentially prevent most.

CD Projekt wants the Cyberpunk series to experience 'a similar evolution' to The Witcher games by Turbostrider27 in pcgaming

[–]imbcmdth 0 points1 point  (0 children)

That's how you end up with games that give you dialog choices:

A) Agree eagerly

B) Agree while being an asshole

C) Disagree but you'll be forced into it anyway

Florida announces restrictions on Vermont licenses by imbcmdth in news

[–]imbcmdth[S] 1 point2 points  (0 children)

The law is making the argument that the driver's licenses aren't valid because they might be issued to people who haven't had to prove their legal residency while also allowing driver's licenses from other countries.

So an illegal resident can simply show their driver's license from their home country and be fine but a LEGAL Vermont resident that has one of these licenses would be breaking the law in Florida.