|
Lumpy posted:What is "estimating"? Is that when you first hear the arbitrary deadline imposed on you? Because even just getting the tooling all set up correctly, if you can do typescript just fine already, will likely take you more than three days, unless you already happen to use an overcomplicated set of tooling that can trivially flip over from javascript to typescript.
|
# ¿ Dec 13, 2018 05:57 |
|
|
# ¿ May 16, 2024 15:41 |
|
Is there a lazy way in Javascript to avoid making this mistake I always make when doing adventofcode sort of things?code:
|
# ¿ Dec 16, 2018 07:12 |
|
Dumb Lowtax posted:You can put a unary + operator in front of the variable to force it to cast to a number even if string, which is just one character to type as opposed to parseInt, so maybe then you'll remember to? But it will at least make it less annoying and verbose when I notice and do the retroactive correction. vvvv Yeah, I got it, but that's where it's too late for me to cultivate a habit of doing it - converting at use-time rather than at capture-time. roomforthetuna fucked around with this message at 08:00 on Dec 16, 2018 |
# ¿ Dec 16, 2018 07:27 |
|
Dumb Lowtax posted:Yeah it's hard coming out of line.match. I doubt there's a way to use the + operator on the call itself that respects the destructuring of the returned object. code:
|
# ¿ Dec 16, 2018 17:45 |
|
Dumb Lowtax posted:That seems MUCH better and more explicit to the reader. First line is about strings, second line is about numbers. Learning about the unary plus already paid off today though, I'm pretty sure it saved me enough time to gain a position, and having talked about it also kept me from making the "forgetting to turn strings into numbers" mistake again, so thanks!
|
# ¿ Dec 17, 2018 07:23 |
|
Argh I have spent two days trying to make this poo poo work. How do you set up two typescript modules, one of which depends on the other, without going through a full publish and import rigmarole every time you change the dependency one? The internet is all "use yarn link or npm link but it won't work lol" which is true, it doesn't work. Today I found yarn workspaces that sounded good but the instructions for that are like "here's how you create a workspace, ha ha that is all, good luck actually using it". So I've got a yarn workspace that as expected includes symlinks to my local modules and installs of all the other dependencies, but now what, how do I actually build a thing here, the tsconfig.json file is now inside a symlink inside node_modules which presumably is not how you're supposed to use that, and I have no loving idea how this is going to eventually tie in with webpack. Is my main project's package.json supposed to *be* the workspace-defining one? Also something about typescript project references and "tsc --build" maybe? Maybe it can perform the build inside the node_modules folder?
|
# ¿ Jan 4, 2019 07:45 |
|
Aha, I found a sort-of answer to my question, which is that evidently webpack is doing something a bit different from the way package.json people think you'll be building stuff. As such, having code:
The one remaining difficulty I was having was that for some reason a 'package' in that path that was only exporting one function (a debug-log function that's basically just a wrapper around console.log whose purpose is to be stripped out in a production build) was simultaneously "not found" and capable of whining about syntax errors or the function from it not being found if I changed its name. I just moved that file arbitrarily into one of the other packages and from there it worked fine. Mysterious. So obviously I'm not super comfortable with what I have going on, but it does build now, and doesn't require any extra command-line operations to pick up on dependencies being updated, so the setup finally meets pretty much all the criteria I had. Relatedly, has anyone here done anything with WebRTC? That's nearly as much of a clusterfuck to get going as webpack+typescript+npm. I got that working too, finally, and all it requires is like 14 messages through two server connections in order to establish one peer-to-peer connection.
|
# ¿ Jan 6, 2019 06:18 |
|
Tip posted:That's disheartening, I'm about to start work on some new features that I planned to use WebRTC for... Maybe I'll just do it the old fashioned way instead. Nolgthorn posted:Are you sure you're designing something that needs webpack+typescript+npm? I imagine you are hitting yourself in the foot with a hammer because of all that tooling. WebRTC is just one of those things, the spec is designed by committee and so even though it's P2P you need like 2-5 intermediary or ancillary servers that do whatever. I have reduced it to not using npm to control my own libraries - I was going to open-source my WebRTC wrapping library and its server sibling, but npm being a pain in the rear end has persuaded me not to (which is funny because I got the feeling npm is to some extent designed as "you open-source or you pay!" but somehow it became so annoying that I'm not even going to open-source the thing I was intending to.)
|
# ¿ Jan 6, 2019 22:58 |
|
Nolgthorn posted:Not to tell you how to do it but I'd just compile separate js files as needed, then use the `async` html tag. Bingo bongo and it's done. The only thing typescript's compiler is bizarrely still missing is iife, so I use something lightweight like buble when I need it if I'm using typescript.
|
# ¿ Jan 7, 2019 02:35 |
|
Dominoes posted:What method do you recommend for causing a long calculation to not block the main thread? code:
|
# ¿ Jan 7, 2019 02:40 |
|
Dominoes posted:This appears to work as a quick in-place fix! Much easier than I'd assumed. Of note, the call to await moment_() must be at the top of the func; eg the slow code below.
|
# ¿ Jan 7, 2019 04:37 |
|
MrMoo posted:Sounds like you are holding it wrong. The spec has changed a lot which is the most annoying. I have a video wall setup to render a 16K video with it. 1. one peer sends an RTCSessionDescriptionInit to the other via the server. 2. the other peer applies that one and generates a response one, sends that RTCSessionDescriptionInit to the first peer. 3. both peers now start generating IceCandidates, which it seems to be recommended you communicate as soon as they are generated. In my test case, each side generated 6 RTCIceCandidateInit objects, which makes it 14 messages through the server total. I figure you probably could clump all the IceCandidates together into one message each way, since more are generated even if you don't send them, but I'm not sure if that would be better or worse (also not sure if the list is communicated via the callback with some kind of a null-terminator at the end or what, none of the examples were clear on why it's valid for an IceCandidateEvent to have its 'candidate' property unset.)
|
# ¿ Jan 8, 2019 02:31 |
|
Dumb Lowtax posted:I have a key-value collection of arrays, and each array is expected to be the same length. But if your data is going to/from JSON or something then you might be just front-loading the extra pass to do that.
|
# ¿ Jan 8, 2019 06:16 |
|
Siddhartha Glutamate posted:The biggest problem I have is that the variable game.playerMoves, which right now logs the color of one of the four options the player has, will at first show the correct selection, but then it will double the selection. So if on the first turn the player clicks on the blue X the log will read "blue" then on the second turn if the player clicks red it will log "blue, red, red" and each additional time through it will log the click multiple times instead of once. I think the problem you have (that you described, not from the CodePen) is that you're calling numCrunch before each turn, and you never remove the eventListeners from your buttons, so on the first turn they each have one eventListener, on the second turn they have two, etc. You could either remove the eventListeners and add them again after each move (which would be good if you want buttons to be nonresponsive while noises are playing or something), or just leave them active until the game is over and not add them repeatedly.
|
# ¿ Jan 11, 2019 05:59 |
|
roomforthetuna posted:Aha, I found a sort-of answer to my question, which is that evidently webpack is doing something a bit different from the way package.json people think you'll be building stuff. As such, having I didn't ever quite resolve why some packages would would, but I found the reason for the failure is that "baseUrl": "C:/herp/derp" in tsconfig.json gets transformed by the loader module into "C:/herp/derp/C:/herp/derp" by going through code that says if (!path.Absolute(yourPath)) then append it to current working directory. If you instead (or additionally) put it in webpack.config like code:
|
# ¿ Jan 20, 2019 17:30 |
|
Dominoes posted:Hey dudes. What's the best way to refresh data from a server every 30 seconds or so? So points to using setInterval, but the answers are mainly from 2010, so not sure if its' still the best way. Eg call a fetch functino from setInterval. Don't think I need websockets for this.
|
# ¿ Jan 21, 2019 04:33 |
|
Rahu posted:My question is, is there some way I can add an object to res.locals (or the request or response objects in general) and keep the typescript compiler aware of its type? I've defined an interface named LoginStatus that describes the properties of this object. Just tried this in the typescript playground and it seems to work: code:
|
# ¿ Jan 21, 2019 18:41 |
|
Dominoes posted:Another one: Is there an elegant way to dedupe an array of tuples? code:
And if you want to make it generic you're going to be doing something even worse like transforming your tuples into JSON strings, then you can put *those* into a set to remove duplicates and then de-JSON the elements of the set afterwards.
|
# ¿ Jan 22, 2019 01:24 |
|
Roadie posted:Fun fact: It's also dependent on the specific interaction of map and JSON.stringify/parse, so if you swap those for other functions weird poo poo might happen. Like yeah this behavior is specific to a reversible mapping to/from a unique identifier, but if you switched the JSON functions for any other reversible to/from unique value serializer/deserializer the outcome would be the same. I mean yeah, if you switched them out for other functions like ... parseInt and console.log then weird poo poo would happen, but it's always the case that if you swap out a function for a function that does something different then something different will happen. How is this case special such that you're remarking on it?
|
# ¿ Jan 26, 2019 04:34 |
|
Roadie posted:Array.map supplies three arguments to its callback, not one. If you use a whateverParsing function that isn't as quick to dump non-matching args as the JSON.x ones are, it'll use those to do...... something. But you're right that it's dependent on the specific implementation, in that it's technically undefined behavior to use JSON.stringify this way, since its second parameter is documented as a function or an array of filters or null or unset, and array.map will feed it an index which is a number which is none of those things, and its third parameter is documented as as a string or number or null, and array.map will feed it an array in that position.
|
# ¿ Jan 26, 2019 07:16 |
|
Kraus posted:But, the leaderboards on that site claim that it can be done in as little as 33 characters. Does anyone have any idea how?
|
# ¿ Jan 30, 2019 17:44 |
|
Doom Mathematic posted:
And then save some chars with the recursion effect: JavaScript code:
|
# ¿ Jan 30, 2019 18:57 |
|
Dumb Lowtax posted:I feel like if you've got a good background on pointers and references from a C++ background or a quality CS intro class you just don't ever have that misunderstanding
|
# ¿ Feb 3, 2019 01:36 |
|
Nolgthorn posted:What pitfalls
|
# ¿ Feb 3, 2019 07:52 |
|
FSMC posted:I have been writing code like that but I don't understand how it works. If things can run out of order am I just getting lucky or are simple statements be guaranteed to run in order? Javascript is hard single-threaded. If you want it to handle events or promises in the middle of your function you have to essentially make the rest of your function be triggered by an event or promise that will resolve later than the one you want to wait for.
|
# ¿ Feb 9, 2019 22:01 |
|
FSMC posted:If I write an AI in a single function that takes an hour to run, as long as I haven't used promises or timers will js just wait for it to finish before moving on with the rest of the code? Edit: and "single function" isn't important, you could have it be 90 functions across multiple modules, if the function that was called doesn't return and doesn't yield to a timer or await a promise in some way the outcome is the same even if it called a bunch of other functions repeatedly or whatever.
|
# ¿ Feb 10, 2019 04:27 |
|
FSMC posted:I've managed to lose this post a few times so I'll keep this brief. The code I had problems with was something like this. I just wanted it to get the state of one device then move onto the next. But what actually happened was the the loop the second get in the loop would start before the first one had a response. So there were errors as the first in the loop was waiting for a response and the second trying to ask a device for its state. In the end I had to get rid of loops made a messy function which called itself with the index of the next device to get. To get the result you expected, you could do code:
(Also, there's rarely any point in mixing await and 'then' syntax in the same function.) (Also, debug-stepping through forEach sucks balls.)
|
# ¿ Feb 11, 2019 01:03 |
|
Strong Sauce posted:there is a slight difference between the for control flow statement and foreach array iterator. The forEach is effectively the same as a for loop that calls the provided function for each entry. The difference is that if that's an async function, when it hits an await or similar, it returns flow back to its caller (in the form of returning an unresolved promise under the hood). If the caller then doesn't 'await' the result of that promise, which forEach does not, then the caller moves on to whatever is next in its sequence, in this case the next subject of the forEach. Given a regular non-async function though, a forEach executes the entries sequentially like any other for loop.
|
# ¿ Feb 11, 2019 04:54 |
|
Strong Sauce posted:where whatever code in those functions are determined by the response time of the IO being called. then yes, i agree, and that is essentially what i said.
|
# ¿ Feb 11, 2019 07:10 |
|
necrotic posted:Using firebase you can just toss your site up on a static host (including firebase, which has a static site hosting option). The mongo approach requires running your own backend for the mongo access.
|
# ¿ Mar 15, 2019 01:29 |
|
Munkeymon posted:IIRC, the Sources UI will present the option to jump to the implementation of a symbol when you're stepping through in debug because then it actually knows for sure what the implementation is. Otherwise, due to the nature of the language, it'd be an educated guess no better or not much better than a text search.
|
# ¿ Mar 20, 2019 15:43 |
|
Doom Mathematic posted:You're doing i.html, which will return undefined because i is a number, which has no html property. I think you want something like linktoList[i], which is a DOM element you can do more work with. Edit: oh wait, ltl *is* the length, and then you don't have the list. Don't do that. Edit2: oh wait, you do have the list, but then you re-perform the search to construct the list in order to make ltl contain its length. Madness. linktoList.length, man! roomforthetuna fucked around with this message at 00:02 on Mar 27, 2019 |
# ¿ Mar 26, 2019 23:59 |
|
Generally codegolf sites give you something shorter than document.write to work with, so there's probably like 10 characters saved there in the number you're citing unless it was explicitly specified this many characters with document.write.
|
# ¿ Apr 4, 2019 03:00 |
|
I don't use Parcel, but I back the recommendation anyway, because unless you want to do some wacky combination like typescript with dynamic module loading it's way less of a headache than the alternatives.
|
# ¿ Apr 10, 2019 03:35 |
|
Nolgthorn posted:If you've got some digital clocks on your page. You've got javascript that loops though all the ".clock" elements and starts updating them every second that passes, but you want them in different timezones you might set "data-timezone" attributes so that in your javascript you just have to look at the element's "data.timezone".
|
# ¿ Apr 11, 2019 00:31 |
|
The Dark Wind posted:Edit: So is it standard practice that if you have awaited something in a child of a child of a child, it's pretty much async/awaits up the tree? code:
|
# ¿ May 3, 2019 04:08 |
|
Newf posted:"Do not block the main thread" is a thing in javascript for the web. I assume it's also the case for an express app that handles client requests. It's actually as simple as making sure all of the stuff you do doesn't have an infinite or long-running loop (I guess this is why I think it was Airbnb has a style guide that forbids loop style flow control entirely, only allowing forEach style iterator loops). There are basically no blocking functions in the ecosystem, so the only way to block is to not come out of a loop. There is no linting for this, because it's basically the Halting problem. But you can do like Airbnb and forbid all flow control if you're a nutcase. Edit: unit testing with 100% coverage is fairly good for ensuring no infinite loops too, but there are ways you could trick it. Edit2: vvvv I didn't want to address actual threads in JS, because the question was fundamentally misled enough that it clearly wasn't about advanced concepts like WebWorkers. roomforthetuna fucked around with this message at 23:08 on May 4, 2019 |
# ¿ May 4, 2019 15:29 |
|
This seems like a good place for this rant, even though it's not directly JS/TS - today I learned that Dart is a stupid language for chumps. Because it's touted as type-safe, but unlike Typescript literally anything can be null whenever it feels like it. List of strings? More like null or list of null-or-strings! Hope you like handling all possible null cases in all your functions every loving time! I'd been using it for several weeks at work under the impression that it was like Typescript where a type means what you say, and today a reviewer suggested I might want to include tests for what my function does if my list of objects contains nulls and I like was "wait, what the gently caress, my list can contain nulls?" I thought the reviewer was mistaken, but no, the language really is that poo poo. And I mean it's not "can contain nulls" like you can coerce Typescript into doing, it's just flat out happy to accept ["foo", null, "bar"] as a parameter of type List<String>. I realize Javascript is happy to mix nulls and things too, but that's 100% dynamic typing, Javascript doesn't claim to be type safe so it's expected. Dart is mostly even more type safe oriented than Typescript, but then it goes and pulls this loving nonsense, what the gently caress. Don't use Dart. (Even Javascript can do compile-time null-rejection if you use the Closure compiler and ask for non-nullable types!) roomforthetuna fucked around with this message at 02:19 on May 8, 2019 |
# ¿ May 8, 2019 02:17 |
|
Volguus posted:I used dart in a flutter project recently and it wasnt that bad. I was just learning flutter and dart so the code i wrote was very much not pretty, but for the most part things worked as expected. It's barely better than Javascript at that point, in that as you say "for the most part things work as expected". Allowing surprise nulls is just a loving travesty though for a typed language. I'm using it for Flutter too, which is quite a hefty paradigm shift from any other UI stuff I've done, gives it a bit of a steep learning curve for doing anything advanced, but I don't mind that. I wouldn't even really mind the null thing if it wasn't just so obnoxious. Unexpected nulls are barely even a thing in C++ for the last 8 years, who would make a new language and let them be a thing? It'd also be okay for small solo projects where I can be confident I won't pass myself null values, but for team things you've gotta handle any edge cases your functions make possible that some jackwagon might do, which means basically every function has to begin with "assert(arg!= null); assert(!listArg.contains(null));" which is stupid as gently caress. (Or you have to make a crapload of use of the "?." and "??" operators, which would be wonderful operators for using on parameters that you've described as null-or-a-type.) In other newish languages that completely gently caress up handling of nulls: Go (click Run, then compare main() against the output, the rest of the stuff is just there as a sort of vaguely-realistic setup for that lovely behavior.)
|
# ¿ May 8, 2019 05:09 |
|
|
# ¿ May 16, 2024 15:41 |
|
Munkeymon posted:Dart was kind of a mashup of Java and JS, so I'm not sure why you'd expect it to be any better about non-null types than those languages. Rust and Kotlin are the two up-and-coming languages I can think of that even have them, with C# getting them soonish. Hell, maybe Java got them in 9, but I'm not up on new Java features. Java has an @Nullable annotation (a variety of them even!) so linters can tell you to gently caress off with your possibly-nulls. The fact that so many versions of that exist really should have informed a language-maker that there was a desire for this feature. I wouldn't have particularly expected Dart to be decent in isolation, I expected it to be decent because a team had chosen to use it, and why would you choose to use a language that's worse than Typescript or C++, in a company where lots of people already know Typescript and C++?
|
# ¿ May 8, 2019 15:39 |