|
Haystack posted:So I'm looking for a resource to help my wife get up to speed with browser javascript. Just a basic, solid introduction to ES6. She learns best by tinkering, so I'm thinking something that has a lot of interactive code and example projects to mess with. She's got a fair amount of experience with PHP so it doesn't have to be bare basics. Any suggestions? I have seen this recommended a lot by people, and a quick glance at it doesn't raise any flags: https://eloquentjavascript.net/
|
# ? Sep 17, 2021 13:33 |
|
|
# ? May 16, 2024 12:35 |
|
Lumpy posted:I have seen this recommended a lot by people, and a quick glance at it doesn't raise any flags: https://eloquentjavascript.net/ I read through this while building an API in node and I would recommend it. Coming from a python background it was easy to pick up JavaScript with this book. I also liked You Don't Know JS Yet by Kyle Simpson.
|
# ? Sep 17, 2021 13:55 |
|
I'll keep this short, I'm looking for some NodeJS app fixing help, I put a blurb in the Goons for Hire thread.
|
# ? Sep 18, 2021 08:54 |
|
Typescript shenanigans: Using GraphQL we manually mode types for things we'd get back from queries: JavaScript code:
However, auto-generating types from the graphQL schema / queries itself was added, and was doing great for new stuff. However it generates types like so: JavaScript code:
Is there a way to convert one enum to another or use them interchangeably? The plan is to make the auto-gen enums use PROPER_CASE, but trying to temporarily get one thing working before embarking on the headache of updating code all over the place. EDIT: I did this, and it seems to work: JavaScript code:
Lumpy fucked around with this message at 18:48 on Sep 21, 2021 |
# ? Sep 21, 2021 18:19 |
|
Haystack posted:So I'm looking for a resource to help my wife get up to speed with browser javascript. Just a basic, solid introduction to ES6. She learns best by tinkering, so I'm thinking something that has a lot of interactive code and example projects to mess with. She's got a fair amount of experience with PHP so it doesn't have to be bare basics. Any suggestions? It's not really a course but I like w3schools tutorials: https://www.w3schools.com/js/DEFAULT.asp
|
# ? Sep 23, 2021 19:59 |
|
I wrote a personal project for the web but I want to make a command-line version (it's a password generator). Being lazy I don't feel like rewriting it in Python or bash or whatever, so I tried rhino, which works except that I'd like to interact with the clipboard. I'm not finding much that would suggest it's possible without the browser (navigator.clipboard.writeText) but figured I'd ask. Basically I want to do $ pw some_seed_value and have the generated password written to the clipboard rather than flopped out on the terminal for all to see. If it's not obvious, I'm in a Linux environment.
|
# ? Sep 26, 2021 05:21 |
|
https://github.com/sindresorhus/clipboardy something like this
|
# ? Sep 26, 2021 05:55 |
|
grr, npm I was hoping to keep this under 60GB... Edit, why use one language when you can use two: #!/bin/bash pwjs $1 $2 $3 | xsel -i Tad Naff fucked around with this message at 06:13 on Sep 26, 2021 |
# ? Sep 26, 2021 05:58 |
|
this jquery question might not make sense because I dunno wtf I'm doing but... I have an ajax call that gets the contents of a simple html page: JavaScript code:
code:
With jquery I could do something like: JavaScript code:
I basically want: JavaScript code:
EDIT: lol I think I was overthinking this a bit. I just had to load the result into a random hidden div and then do my thing on that: JavaScript code:
fuf fucked around with this message at 17:38 on Sep 27, 2021 |
# ? Sep 27, 2021 17:30 |
|
fuf posted:... It's also dangerous to write the contents of the response as HTML to your page in order to "parse" it. Doing so opens you up to potential code execution attacks, such as if there is a script tag present (and there are numerous other ways to trigger script execution without a script tag too) If there's really no way around making a request to a page full of HTML, there are better and safer ways to accomplish it, like the DOMParser API: JavaScript code:
|
# ? Sep 27, 2021 18:07 |
|
Since it's using $.each I assume it's some horrifically legacy codebase that just needs to stay alive in maintenance mode. That being said, you can also do something like $('li', $(yourHtmlString).context).each() instead of appending it to the page
|
# ? Sep 27, 2021 18:29 |
|
it's a random little project running completely locally so no real concerns about security or bad practice is $.each totally out of date or something?
|
# ? Sep 27, 2021 18:33 |
|
Pretty much 99% of jquery is now part of the standard $("li").each -> document.querySelectorAll("li").forEach, for example
|
# ? Sep 27, 2021 19:23 |
|
Biowarfare posted:Pretty much 99% of jquery is now part of the standard Note that for dumb legacy reasons you can use forEach there but not map, so you'll often want to do <fixed>[...document.querySelectorAll("li")]</fixed> so you can just treat it like a normal array with all the normal array stuff.
|
# ? Sep 27, 2021 19:50 |
|
When I have multiple modules with loose Javascript statements in the main body (in Node.JS), outside of a function, as long these modules are somehow referenced, will that code execute when the application starts up? What about static class constructors? I'm wondering if it's possible to implement some self-registering semantic for endpoints of my web service. Or what's a good way to go about it?
|
# ? Oct 6, 2021 15:59 |
|
There's something a coworker did that I think is unnecessary, but I want to double-check that I'm not going crazy here (since these coworkers are generally more competent than me at most programming tasks, but I'm starting to wonder if they might lack some really basic javascript/html stuff). Basically the guy in question put some controls for a feature inside of a form element, but the form element does nothing and is never submitted (and as far as I can tell never will be). All functionality is just controlled by the JS and the only submission is an AJAX request (whose parameters are also just pulled from the html using JS). Putting stuff inside of a form that is never being submitted doesn't make sense, right?
|
# ? Oct 7, 2021 08:19 |
|
Ytlaya posted:There's something a coworker did that I think is unnecessary, but I want to double-check that I'm not going crazy here (since these coworkers are generally more competent than me at most programming tasks, but I'm starting to wonder if they might lack some really basic javascript/html stuff). I believe you'd want to keep the form element there for semantic/screen reader reasons.
|
# ? Oct 7, 2021 12:42 |
|
fsif posted:I believe you'd want to keep the form element there for semantic/screen reader reasons. This 100%, and some people (like me) consider this a major issue.
|
# ? Oct 7, 2021 13:47 |
|
+1 to using the form element for the semantic intent. The AJAX submission is still a submission. Using the form's native submission behavior is not the decider on when form should be used. I had the damnedest time trying to convince some mobile engineers who got merged into my web-focused team to use semantic anything and they just ended up ignoring me. Now none of our input elements have labels associated with them
|
# ? Oct 7, 2021 15:47 |
|
fsif posted:I believe you'd want to keep the form element there for semantic/screen reader reasons. Ah thanks, I hadn't considered that.
|
# ? Oct 7, 2021 18:21 |
|
Cugel the Clever posted:I had the damnedest time trying to convince some mobile engineers who got merged into my web-focused team to use semantic anything and they just ended up ignoring me. Now none of our input elements have labels associated with them Just start filling up the backlog with bugs that link to git blame on the specific lines that miss the attributes. That'll make you popular really fast.
|
# ? Oct 7, 2021 19:49 |
|
fsif posted:I believe you'd want to keep the form element there for semantic/screen reader reasons. Also basic ease-of-development stuff, like hooking onto the onsubmit event on the form meaning that you don't have to add individual keyboard event handlers to everything to support using the enter key properly.
|
# ? Oct 7, 2021 19:58 |
|
If it fits what you need to do, you can also feed the form element to the FormData constructor to have it do some of the work of generating name-value pairs for you.
|
# ? Oct 8, 2021 01:11 |
|
Do Javascript or its specific runtimes happen to have an intrinsic to quickly hash strings, for implementing fast custom hash tables or poo poo like that?
|
# ? Oct 14, 2021 12:55 |
|
Node has https://nodejs.org/dist/latest-v14.x/docs/api/crypto.html#crypto_class_hash but it doesn't have the equivalent of hashCode in Java or GetHashCode in .Net. This being an interpreted language you can alway monkey patch it in though: https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
|
# ? Oct 14, 2021 15:47 |
|
I'm using that one already for creating hashes of database queries and parameters for caching. So that one runs faster than a pure JS implementation then?
|
# ? Oct 14, 2021 16:01 |
|
Which one? I'd guess one of the answers from SO would be faster because there's probably both overhead in calling out to native code and 'extra' algorithmic complexity when doing cryptographically sound one-way hashes if you're using the crypto module in Node. That'd be pretty easy to benchmark, though.
|
# ? Oct 14, 2021 20:44 |
|
i'm having a senior moment....how do I perform a POST fetch with a body like this in postman?code:
code:
|
# ? Oct 16, 2021 01:12 |
|
Fixins posted:but I have no clue how to handle the where and the fields. thanks for any help code:
code:
Body doesn't have to be json, that's just a commonly used way of making it easily parseable across different languages and platforms.
|
# ? Oct 16, 2021 01:29 |
|
Ahhh okay cool. The server accepts JSON too but all their tutorials use raw text. now to figure out how to get ESlint to stop removing the ' around Authorization
|
# ? Oct 16, 2021 01:33 |
|
Fixins posted:Ahhh okay cool. The server accepts JSON too but all their tutorials use raw text. I found this suggestion about http Authorization header and how to modify the eslint to stop doing it. https://github.com/prettier/prettier-vscode/issues/172 I am only responding because I do web app security testing and whenever I see Authorization headers, I just want to stop testing. It always turns out I need to set up a bunch of new cookie jars and slow testing because it can always get hosed if a different dev developed a different part of the application.
|
# ? Oct 17, 2021 18:22 |
|
What's a good semantic to deal with user sessions and authentication in a React SPA? Right now, when the user loads the page, the App.jsx "frame/wrapper" checks with upstream whether the authentication token is still valid and either renders the login form or the React Router routing stuff. If said token times out, so far how I have things, it'll break the application (one reason I guess because things closer to the root of the DOM don't have a need to re-render and the effects don't run). How to handle this better? Just run a timer that refreshes the token/session in background, so long the application is open in the browser?
|
# ? Oct 19, 2021 22:39 |
|
Already posted this in the general web dev thread, but I meant to post in this probably more relevant thread. Oops. I'm trying to get an infinite "marquee" of logos going, but I can't find anything for it in React. Something like this: https://www.apple.com/apple-tv-plus/ with the marquee/carousel of shows. I'd like to do it in React Spring or Framer Motion, because I plan on trying that for other animations and I'd like to keep from installing too many things. Here's a codesandbox for a Framer Motion attempt: https://codesandbox.io/s/stupefied-lamarr-mqlvk
|
# ? Oct 19, 2021 22:50 |
|
Objects drive me fukkin insane. I'm trying to use the Shopify API and I get the following as a response:code:
Here is the code I have so far: code:
worms butthole guy fucked around with this message at 03:05 on Oct 21, 2021 |
# ? Oct 21, 2021 03:01 |
|
I don't know if this will help but this is how many loops I had to run in order to get my desires result: code:
|
# ? Oct 21, 2021 03:20 |
|
Fixins posted:4 loops !! In such situations, my pattern is to add a helper function to extract, process, derive, flatten & adapt poorly formed data into a clean form for the UI. code:
|
# ? Oct 21, 2021 10:44 |
|
ynohtna posted:In such situations, my pattern is to add a helper function to extract, process, derive, flatten & adapt poorly formed data into a clean form for the UI. This is very good and smart advice. Even if your data comes back magically in the perfect shape for your UI, you should still create that function and just have it do nothing. When then data shape from the server changes, and it will, you will be happy you did.
|
# ? Oct 21, 2021 14:23 |
|
Oh sweet thanks for that I'm going to try it. I should just run the four loops in that function then, right
worms butthole guy fucked around with this message at 15:35 on Oct 21, 2021 |
# ? Oct 21, 2021 15:31 |
|
It looks like edges is an array, so you couldn't access it via product.edges.node.title?
|
# ? Oct 21, 2021 19:51 |
|
|
# ? May 16, 2024 12:35 |
|
No it returns as undefined oddly
|
# ? Oct 21, 2021 20:03 |