|
Vulture Culture posted:3D is Cartesian for sanity, 2D generally isn't, for terrible reasons. Hmm, https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/ #12 matches my recollection, which is that dealing with 2D coordinates means lower-left origin. That's an old doc, though, and my memories are almost as old, so maybe they changed that in some modern revision?
|
# ? Oct 23, 2015 00:36 |
|
|
# ? Jun 5, 2024 07:04 |
|
Subjunctive posted:Hmm, https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/ #12 matches my recollection, which is that dealing with 2D coordinates means lower-left origin. That's an old doc, though, and my memories are almost as old, so maybe they changed that in some modern revision? quote:Most 2D rendering APIs mimic writers and use a 2D coordinate system where the origin is in the upper left-hand corner of the screen or window (at least by default). On the other hand, 3D rendering APIs adopt the mathematically minded convention and assume a lower left-hand origin for their 3D coordinate systems. I think what you'll find is that if a particular API or library is designed for both 2D and 3D, lower-left origin will probably be used, while most 2D-only frameworks use an upper-left origin.
|
# ? Oct 23, 2015 00:54 |
|
Ah yes, that makes sense. Thanks.
|
# ? Oct 23, 2015 01:11 |
|
Direct3D has (-1, -1) as top left. The only difference between the two is how the default view matrix is set up. Also, I believe that sampling a texture at (0, 0) in OpenGL samples the top left texel. Suspicious Dish fucked around with this message at 03:02 on Oct 23, 2015 |
# ? Oct 23, 2015 03:00 |
|
What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous. Second question, should I primarily use let or const? Assuming the variable doesn't need to be mutable.
|
# ? Oct 23, 2015 03:01 |
|
Depressing Box posted:What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous. I prefer let, as that's how I'd rather my variables be scoped. However, if you have reason to want function scoping, use var.
|
# ? Oct 23, 2015 03:03 |
|
Skandranon posted:I prefer let, as that's how I'd rather my variables be scoped. However, if you have reason to want function scoping, use var. Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const?
|
# ? Oct 23, 2015 03:11 |
|
Jest is too slow. I use mocha or karma depending on my mood.
|
# ? Oct 23, 2015 04:40 |
|
Vulture Culture posted:3D is Cartesian for sanity, 2D generally isn't, for terrible reasons. Once again BMP is the best image format.
|
# ? Oct 23, 2015 11:20 |
|
Depressing Box posted:Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const? I use const for immutable data for clarity. When using Babel to transpile to ES5 the const check is handled while compiling, the actual output is a var (same with let); so for now I'd say there's no performance hit at all! I think its unlikely there would be any performance implications once its hit browsers and we stop transpiling.
|
# ? Oct 23, 2015 17:25 |
|
Depressing Box posted:Would you still use let (instead of const) if the data isn't mutable? Is there a drawback, performance or otherwise, to using const? Use const when you are trying to convey the concept that THIS doesn't change. It doesn't really do anything for the computer. Don't try using it to somehow optimize memory usage.
|
# ? Oct 23, 2015 17:31 |
|
necrotic posted:I use const for immutable data for clarity. When using Babel to transpile to ES5 the const check is handled while compiling, the actual output is a var (same with let); so for now I'd say there's no performance hit at all! I think its unlikely there would be any performance implications once its hit browsers and we stop transpiling. Ah, I didn't realize the checks were just during compilation, that's cool. Skandranon posted:Use const when you are trying to convey the concept that THIS doesn't change. It doesn't really do anything for the computer. Don't try using it to somehow optimize memory usage. Yeah, I've just been using it to indicate (and lightly enforce) immutability. I was burned pretty hard by unexpected state mutation on a previous project, so this time I'm leaning heavily into stuff like Immutable.js/Redux/RxJs.
|
# ? Oct 23, 2015 17:53 |
|
Depressing Box posted:Ah, I didn't realize the checks were just during compilation, that's cool. I wasn't 100% sure either. I find the online REPL useful for figuring out how Babel transpiles things.
|
# ? Oct 23, 2015 17:58 |
|
That's pretty handy. Interestingly enough, it looks like Babel has an optional transformer (part of "High compliancy" mode in the REPL) that will add TDZ checks to the compiled code.
|
# ? Oct 23, 2015 18:17 |
|
Depressing Box posted:That's pretty handy. Interestingly enough, it looks like Babel has an optional transformer (part of "High compliancy" mode in the REPL) that will add TDZ checks to the compiled code. That could be useful for development!
|
# ? Oct 23, 2015 20:11 |
|
necrotic posted:That could be useful for development! Definitely. I'll probably put it in the development env alongside the typecheck plugin. Thermopyle posted:Jest is too slow. This helped a lot! I just finished rewriting my tests to work in Mocha (not that hard), and I'm already appreciating the lack of Jest's magical black box mocking system. Also, you weren't kidding about the speed. Run time for the same tests (two React components and a couple utility functions):
|
# ? Oct 23, 2015 21:07 |
|
Depressing Box posted:What's everyone using for unit tests, especially with React? I just started a new project with React/Redux and I want to at least keep the big pieces under control. I wrote some basic tests in Jest, and they work (after I disabled auto-mocking), but its sparse documentation and occasionally wonkiness make me nervous. 1) mocha with js-dom is pretty nice. Jest has some really nice ideas but holy hell is it slow. 2) I use const unless I absolutely need let. Like others have said, even though it doesn't do much/anything, const is nice for indicating that a value doesn't change, and readable/understandable code is a great thing.
|
# ? Oct 24, 2015 01:30 |
|
I use 'let' generally, since it's easier to type and I find it easier to read. I'll use const in outer scopes where I define constants, only to be more expressive. Accidentally reassigning a variable is the least of my problems.
|
# ? Oct 24, 2015 01:56 |
|
I use const everywhere until I have to switch to let. Even though const doesn't really do anything, my IDE (webstorm) (ok, really I use PyCharm, but same thing) warns me when I try to change a variable created as const. I then can evaluate whether I really want to change the variable to let or fix my design. This helps me avoid mistakes.
|
# ? Oct 24, 2015 02:16 |
|
I'm attempting to write something for google sheet that will search for an item name on a sheet, then copy its price to another. Here's what I have:code:
I'm also having trouble stopping the for loop once the first condition is met so it doesn't look for the second or third. Any tips on this would be great.
|
# ? Oct 27, 2015 18:56 |
|
Revalis Enai posted:
You can use break to end execution of a loop early, or return from it and it will stop as well. EDIT: examples! JavaScript code:
Lumpy fucked around with this message at 19:09 on Oct 27, 2015 |
# ? Oct 27, 2015 19:04 |
|
Lumpy posted:You can use break to end execution of a loop early, or return from it and it will stop as well. I tried to add break; at the end of the first condition like this: code:
|
# ? Oct 27, 2015 21:59 |
|
Revalis Enai posted:I tried to add break; at the end of the first condition like this: There's a lot... not "wrong" but maybe "misunderstood" in this. Firstly, your loops will explode should they ever run to completion, as doing this: anArray[anArray.length] will always go past the end of the array. Secondly, without seeing the rest of it, you might be having global variable issues: there's lots of seemingly global things in your code (again, they might not be, but I can't tell from what you've posted) that could be the cause. Thirdly, both the first and second conditionals set the value of itemcode to the same thing, so even if you break there, you'll get the same value, since they are both setting to 3035. (Fourthly, I hope your code isn't really indented like that )
|
# ? Oct 27, 2015 22:22 |
|
Bluebird just blew up. I haven't changed a single thing in my code or dependencies, or anything. It was working perfectly before this.code:
JavaScript code:
EDIT: Solved the issue by rolling back to the previous version of bluebird that I was currently using. I still don't know why it blew up because nothing changed. Eh. EDIT2: The bluebird library changed the promisify/promisifyAll functions, this solved my problem: JavaScript code:
Odette fucked around with this message at 05:56 on Oct 28, 2015 |
# ? Oct 28, 2015 00:55 |
|
Lumpy posted:There's a lot... not "wrong" but maybe "misunderstood" in this. Firstly, your loops will explode should they ever run to completion, as doing this: anArray[anArray.length] will always go past the end of the array. Secondly, without seeing the rest of it, you might be having global variable issues: there's lots of seemingly global things in your code (again, they might not be, but I can't tell from what you've posted) that could be the cause. Thirdly, both the first and second conditionals set the value of itemcode to the same thing, so even if you break there, you'll get the same value, since they are both setting to 3035. (Fourthly, I hope your code isn't really indented like that ) Sorry, I'm a novice with programming in general, so if there's something fundamentally wrong with the code please let me know. The code I posted initially is the whole thing, with the for loop part repeated for each item. Other than the conditional part, the code executes fine on google sheet, which is what it's meant for. As far as I know the code is supposed to grab all cells with value into an array, then search through the array for item that contain certain strings. Once it finds the cell containing the strings, it picks up the price value, which is 1-5 columns away depending on which data source I'm working with, then assigns the proper item code, which is used to search for the proper row on our main spreadsheet to copy the price value to. Also from what I learned so far, google action script is a dumbed down java script and does not like global anything, so all of the code I have needs to be in the same function.
|
# ? Oct 28, 2015 02:32 |
|
Revalis Enai posted:Sorry, I'm a novice with programming in general, so if there's something fundamentally wrong with the code please let me know. The code I posted initially is the whole thing, with the for loop part repeated for each item. Other than the conditional part, the code executes fine on google sheet, which is what it's meant for. As far as I know the code is supposed to grab all cells with value into an array, then search through the array for item that contain certain strings. Once it finds the cell containing the strings, it picks up the price value, which is 1-5 columns away depending on which data source I'm working with, then assigns the proper item code, which is used to search for the proper row on our main spreadsheet to copy the price value to. I've never done Google sheet coding, but I'd gladly take a crack at it. Do you have a shareable copy or just a few rows? You can PM me if you want.
|
# ? Oct 28, 2015 06:09 |
|
I wrote a little node script to read a file, do a search and replace, then write the file. When I run it on my Mac and then open the newly written file in vim there's now an unnecessary carriage return ("^M" character) at the end of every line. I thought this was a DOS / Windows thing so I'm not sure why node is putting them there. Is there any way to stop Node doing that?
|
# ? Oct 30, 2015 16:38 |
|
fuf posted:I wrote a little node script to read a file, do a search and replace, then write the file. I've not had that problem, but I also don't use vim that much. You should be able clean it up with regex while you're doing the search and replace, just use this selection and replace it with nothing: code:
|
# ? Oct 31, 2015 03:08 |
|
Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code http://pastebin.com/x9nvragZ Now eBay are pretty restrictive and bounced it with this error. "Your listing cannot contain javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href." I searched the script and it uses replace 3 times. Can anyone advise how to remove this from the script? These are the areas with the replace.... code:
code:
code:
thegasman2000 fucked around with this message at 15:32 on Nov 4, 2015 |
# ? Nov 4, 2015 15:29 |
|
thegasman2000 posted:Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code This might be too much to hope for but will a script with JavaScript code:
|
# ? Nov 4, 2015 16:47 |
|
thegasman2000 posted:Java Script gurus I need a helping hand... I have ZERO JS knowledge and whilst making an ebay template I used some existing code. This is the code I enjoy trying to circumvent poorly-implemented input sanitisation routines as much as the next person, but if eBay says you can't use JavaScript, have you considered not using JavaScript?
|
# ? Nov 4, 2015 16:50 |
|
qntm posted:I enjoy trying to circumvent poorly-implemented input sanitisation routines as much as the next person, but if eBay says you can't use JavaScript, have you considered not using JavaScript? They don't say you cant use it they just restrict what you can and cant do... Which is where it gets fun! I abandoned that script but thanks for the effort Munkeymon. It didn't work for me but I found one that works and was accepted.
|
# ? Nov 4, 2015 17:02 |
|
Aww, now I want to sell something on eBay just to see if I can get around their filter :\ Was the error message something about '.replace' because you can do it with prototype['replace'], too.
|
# ? Nov 4, 2015 17:11 |
|
Or prototype['rep'+'lace']
|
# ? Nov 4, 2015 17:51 |
|
Or just className["replace"], not sure why the prototype is being referenced.
|
# ? Nov 4, 2015 19:58 |
|
Because then it's not a member of every String and element.className.repalce is undefined.
|
# ? Nov 4, 2015 22:48 |
|
Oh, I meant at the call site, sorry.
|
# ? Nov 4, 2015 23:39 |
|
Speaking of, and I'm kinda laughing at myself for even thinking about this, but is there any way to sandbox Javascript in the browser? Like, lets say I have some widget that has a bunch of methods attached to it, and I want to allow user-written scripts that can interact with this widget. As in, User A writes a script on the site, and User B loads the script and runs it.... WITHOUT needing to worry about his computer blowing up or known terrorists now knowing his credit card number and his mother's maiden name. Just from the top of my head, I'd want to ban DOM manipulations except via the widget's method calls, or modifying the widget itself, or the use the eval function, or access to cookies, or to load any external objects, or who knows what else. Is this possible natively?
|
# ? Nov 5, 2015 11:35 |
|
Things like CoderPad exist, so it's definitely doable.
|
# ? Nov 5, 2015 13:16 |
|
|
# ? Jun 5, 2024 07:04 |
|
German Joey posted:Speaking of, and I'm kinda laughing at myself for even thinking about this, but is there any way to sandbox Javascript in the browser? Like, lets say I have some widget that has a bunch of methods attached to it, and I want to allow user-written scripts that can interact with this widget. As in, User A writes a script on the site, and User B loads the script and runs it.... WITHOUT needing to worry about his computer blowing up or known terrorists now knowing his credit card number and his mother's maiden name. Just from the top of my head, I'd want to ban DOM manipulations except via the widget's method calls, or modifying the widget itself, or the use the eval function, or access to cookies, or to load any external objects, or who knows what else. Is this possible natively? The requirement for making it so the script interacts with the widget means you should probably look into having the widget render on the server with the user script executing on the server as well (like using node / Rhino) - some of the codepad utilities will run the javascript in an iframe, but since the script needs to interact with the widget, it'll be nearly impossible to lock everything down client side.
|
# ? Nov 5, 2015 14:06 |