Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
smackfu
Jun 7, 2004

I’m not sure which would be easier, creating types for some of our bs internal packages or just rewriting them into typescript and getting the types for free.

Adbot
ADBOT LOVES YOU

M31
Jun 12, 2012
The framework I would like to find would be based on the standard APIs so it's usable on different runtimes. Also, there will be a lot of proxying and not a lot of routing, so being able to do something like
code:
import {serve} from 'somewhere';

serve({port: 8080}, async (request: Request) => {
  request.headers.set('x-request', 'bar');
  let response = await fetch("http://somewhere.else", request);
  response.headers.set('x-response', 'bar');
  return response;
});
in a couple of lines would be really great.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
You could try my framework, it does it's best to let you use just native req/res node thingys.

Lamech
Nov 20, 2001



Soiled Meat
hello thread I've never been in before

I'm trying to make a test using a textbook publisher's online testmaker website thing. There's thousands of questions in their test bank, and various filters to find specifically which questions you want to add. So you filter it down to specific chapters or type of questions or whatever, and there's still like 90 possible questions to add. Then, you have to click the Add Question button to add the question to your test. My problem is that the multimillion-dollar textbook publisher failed to make an ADD ALL button, and I don't want to hit the Add Question button 90 some times (per test). And after clicking Add Question, the next question down moves slightly, so it's really annoying.

I did some googling and found this https://medium.com/swlh/how-to-automate-clicks-using-javascript-4855f0f42b60, which helps.

So I'm at...

code:
for ( let i = 0; i < 1000; i++ ) {
document.getElementById("__input__button__addbutton__0").click();
}
...which works on the first button only since "__input__button__addbutton__0" is the name of the first button to click. My problem is that all the buttons are then named sequentially. "__input__button__addbutton__1", "__input__button__addbutton__2", etc.

How do I make a code to click all the goddamn buttons on this site that are named "__input__button__addbutton__X" where X is like 0 to maybe 200.

Thank you ahead of time.

Volguus
Mar 3, 2009
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

How to concatenate strings:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_operators#string_operators

N.Z.'s Champion
Jun 8, 2003

Yam Slacker
You could also use template strings which use the backtick ` char and ${ your variable or expression goes here } ... so something like,

code:
for ( let i = 0; i < 1000; i++ ) {
document.getElementById(`__input__button__addbutton__${i}`).click();
}

prom candy
Dec 16, 2005

Only I may dance
Speaking of backend frameworks this looks pretty good https://hono.dev/

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
I looked at this and don't understand the built-in authentication. It's a single fixed login?

prom candy
Dec 16, 2005

Only I may dance

Combat Pretzel posted:

I looked at this and don't understand the built-in authentication. It's a single fixed login?

I think it's just HTTP Basic Auth

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Yeah, but the examples just supply static login data. I'd expect a callback or something to look up things, e.g. in a database.

I just looked up the source code, at least you can supply an array of logins. The bearer auth just accepts a single token to check against.

So yeah, again... :thunk:

barkbell
Apr 14, 2006

woof
i just use fastify

prom candy
Dec 16, 2005

Only I may dance

Combat Pretzel posted:

Yeah, but the examples just supply static login data. I'd expect a callback or something to look up things, e.g. in a database.

I just looked up the source code, at least you can supply an array of logins. The bearer auth just accepts a single token to check against.

So yeah, again... :thunk:

I think it's just middleware and you BYO storage engine?

cruft
Oct 25, 2007

FML I'm doing JavaScript work again.

Okay so I have this fullCalendar thing inside a div that needs to be normally hidden, but when you click a button it becomes un-hidden. But fullCalendar apparently does something to detect width or height of its container, and I guess when it initializes, one of those is 0. There are up to 6 calendars on a page.

I think I have two options here:

  • Kludge something into the handler for "clicked the expand button" that somehow tracks down whether there's a fullCalendar inside, and asks it to resize (that's a function you can call)
  • When I create the calendar, set up a mutation observer that looks for when the visibility of any parent element changes, and trigger resize
  • Make the expand handler emit a synthetic event on the document called "somethingExpanded", and every time I make a calendar, set up an event handler to resize the thing when the event fires.

Am I missing anything? All of these suck. Maybe the last one isn't so bad.

cruft fucked around with this message at 23:43 on Jul 19, 2023

AlphaKeny1
Feb 17, 2006

I'm not sure I understand, you can add new fullCalendars and sometimes it initializes at 0 width/height? Can you fix that initialization? Is something happening that causes these dimensions to change after page load, where fullCalendar needs to fit into each individual div which may or may not be different?

When you add a calendar it expands something and changes other dimensions?

It kind of sounds like you might want to fix those things first if you can. Hide/unhide handlers should just do hide/unhide things without other complicated calculations imo. Needing to put in mutation observers seems unnecessary unless you're building on top of something you can't change in which case yeah you do have a few options but it depends on what exactly is happening.

edit: are the dimensions fixed? Like can you just use css?

AlphaKeny1 fucked around with this message at 08:56 on Jul 20, 2023

cruft
Oct 25, 2007

I just did the third option with .xpand events and moved on. FullCalendar must be doing some weirdness with displayed size or something, I don't know. But if it's initialized inside a hidden div and then the div becomes unhidden, the calendar is trash until you resize the window or trigger a redraw by switching dates. :shrug:

I left a lot of sassy comments though, no need to worry about that.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Lately I've been getting Typescript and React tutorials in my Youtube feed, and watching them, they multiply even more. Watching these, I'm always learning about new things, since I'm learning/making this poo poo up as I go at work.

I came across the unknown type. These tutorials all tell me, I should use them in data fetching scenarios. I have some database abstraction layer I could put them in. But then I get told about type guards. In all the examples, they show simple types to check. However, when I fetch data from a database, and I get a 20 columns wide and 2000 rows long table, I really can't be assed to check all these fields in a type guard, because that's a performance loss at some point.

How do you all do this? For instance just check the first row? Blindly cast to object or some (array of some) type?

prom candy
Dec 16, 2005

Only I may dance

Combat Pretzel posted:

Lately I've been getting Typescript and React tutorials in my Youtube feed, and watching them, they multiply even more. Watching these, I'm always learning about new things, since I'm learning/making this poo poo up as I go at work.

I came across the unknown type. These tutorials all tell me, I should use them in data fetching scenarios. I have some database abstraction layer I could put them in. But then I get told about type guards. In all the examples, they show simple types to check. However, when I fetch data from a database, and I get a 20 columns wide and 2000 rows long table, I really can't be assed to check all these fields in a type guard, because that's a performance loss at some point.

How do you all do this? For instance just check the first row? Blindly cast to object or some (array of some) type?

You basically have two options here:

1. Do runtime schema validation with something like Zod or the new kid on the block Valibot. This has a runtime cost but it gives you confirmation that your types are what you think they are.

2. Create a type or interface called like Item (or whatever is being represented in the database) and then cast your data as Array<Item>. This is basically telling the compiler "I know better than you, and I know that this data is an Array of Items." It has no runtime cost but also does no actual runtime validation.

If you know for sure that your database schema is being enforced elsewhere then option 2 is probably fine. If your database potentially has bad data in it and you want to fail early in those scenarios, option 1 is better. You can also just set up option 2 with a realistic representation of what will be in your database, i.e. mark fields as optional/nullable even if they're not "supposed" to be. That will move your type checking code downstream a little bit (i.e. having to check if "name" is present or not) but that might be better than just erroring out if you do runtime validation and the DB returns a lovely row. Depends entirely on how you want to manage receiving bad data in your app. Personally I would probably be very strict with user input but more lenient with data coming from the DB.

smackfu
Jun 7, 2004

I’m not sure what the benefit of unknown is vs passing a generic type of what you expect your API to return.

prom candy
Dec 16, 2005

Only I may dance
If you cast as unknown aren't you gonna just get type errors when you try to access anything?

lunar detritus
May 6, 2009


Yeah, unknown it's for cases when you honestly are not sure what's going to be and you don't want to use any or it's not worth it to type every possible case for a very generic function that will work for most things (like functions that process arrays and don't care about their contents, so unknown[] works).

necrotic
Aug 2, 2005
I owe my brother big time for this!
I wouldn’t use unknown for a data source I control. Use it for 3rd party apis and data sources, not your database layer that you control.

gbut
Mar 28, 2008

😤I put the UN🇺🇳 in 🎊FUN🎉


necrotic posted:

I wouldn’t use unknown

You can type even the 3rd party stuff by loosely defining only the stuff you use.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Sure, and if I don’t care about those parts I wouldn’t type them. I’m mostly saying using unknown for first party isn’t necessary, but may be beneficial for third party (or just plain old user input, like if you offer an API for others to call)

huhu
Feb 24, 2006
Curious if anyone knows why the implementation of sets in JavaScript feels so bad? Is this the result of having to move a proposal through W3C? Just one example is intersection:

Python Intersection
code:
z = x.intersection(y)
JavaScript Intersection
code:
let z = new Set([...x].filter(i => y.has(i)));

necrotic
Aug 2, 2005
I owe my brother big time for this!
There’s a TC-39 proposal to make set suck less https://github.com/tc39/proposal-set-methods

W3C isn’t involved in JavaScript, the ECMA group handles JavaScript. The current Set was added back in ES6, which was the first major update to JavaScript in _years_.

Why they added very a limited implementation I can't say (TC-39 wasn't around, and I'm not sure where to find any discussions prior to then).

edit: found it, not a lot of discussion and its on a now defunct site. Thanks, wayback machine!

https://web.archive.org/web/20170105121945/http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets

necrotic fucked around with this message at 19:35 on Aug 18, 2023

El Gar
Apr 12, 2007

Hey Trophy...

In all likelihood it just wasn't on the radar. Focus was on making it a very basic iterator like Map. All of the methods there are either specific to basic Set functionality (has, add, clear, delete) or came with it being an iterator (forEach, entries, keys, values)

Arrays in JS don't have intersection either so there wasn't any sort of parity to try to keep there.

Fwiw "[...x]" re-casts your entire set as an array in memory. Iterate through the Set itself and conditionally add to a new Set if this is something you're actually wanting to do in your code.

Combat Pretzel
Jun 23, 2004

No, seriously... what kurds?!
Speaking of TC39 things, the goddamn IETF needs to get off their asses to finalize their timezones poo poo, so that Temporal can be finished.

necrotic
Aug 2, 2005
I owe my brother big time for this!
Ban time zones and ship it. Easy

prom candy
Dec 16, 2005

Only I may dance

necrotic posted:

Ban time zones and ship it. Easy

I am willing to eat dinner at 11pm and go to bed at 5am if it means no more time zones. Hell that's what the Spanish do already.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

necrotic posted:

Ban time zones and ship it. Easy


prom candy posted:

I am willing to eat dinner at 11pm and go to bed at 5am if it means no more time zones. Hell that's what the Spanish do already.

:same:

VagueRant
May 24, 2012
On an AWS lambda with 10gb of memory, I'm hitting the NodeJS heap limit trying to stream a 7mb file and output a 3.5mb file.

Running some garbage collection logs on my unit tests, but can't see anything unusual to indicate a memory leak. Even removing the streams and just loading data (smaller local files) into memory seems to make little difference.

Any advice on how to find where this is going wrong?

necrotic
Aug 2, 2005
I owe my brother big time for this!
Have you configured the heap limit?

https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes

The crash report should mention how much was used when it shut down.

Kwolok
Jan 4, 2022
I have to do some work on a windows machine, and I cannot do the work on WSL, it has to be on windows proper.

Anyone have a recommendations for things like what terminal to use, what package manager to use (something similar to brew would be nice) etc for setting up a coding environment on windows. On mac everything feels great but on windows it all feels terrible. Will still use vscode. But obviously terminal/powershell sucks and I don't even know how to easily use things like nvm etc.

Doktor Avalanche
Dec 30, 2008

there's "nvm for windows"

Kwolok
Jan 4, 2022
Yeah I grabbed that. Turns out Windows terminal works decently well and nvm for Windows and git for Windows gets me enough of the way there.

Now I just need to figure out some system to quickly switch my keyboard, mouse and main monitor between my two laptops

cruft
Oct 25, 2007

Combat Pretzel posted:

Speaking of TC39 things, the goddamn IETF needs to get off their asses to finalize their timezones poo poo, so that Temporal can be finished.

OMG yes :agreed: so hard hhrrrrrrrrrrgh

I'm maintaining a site that displays schedules for an international conference; JavaScript's complete lack of standardized time zone handling is a frickin' nightmare.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
just installed our node_modules with bun instead of npm and it was 1.7 seconds vs. 14

are you loving kidding me?

prom candy
Dec 16, 2005

Only I may dance

teen phone cutie posted:

just installed our node_modules with bun instead of npm and it was 1.7 seconds vs. 14

are you loving kidding me?

yeah bun is very exciting

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
these are the type of software projects that make me feel like i need to be doing something else with my life. this is 1000x cooler than anything i'll ever work on

Adbot
ADBOT LOVES YOU

smackfu
Jun 7, 2004

teen phone cutie posted:

just installed our node_modules with bun instead of npm and it was 1.7 seconds vs. 14

are you loving kidding me?

Wonder where they are getting the speed from. I guess part of it is just not being written in node.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply