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
0zzyRocks
Jul 10, 2001

Lord of the broken bong

Thermopyle posted:

If you use Jetbrains IDE's, they integrate spy.js.

https://www.youtube.com/watch?v=vPIbwxzC5cU

That was really cool, thanks for sharing!

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

0zzyRocks posted:

That was really cool, thanks for sharing!

It's worth noting that this works if you're using any (that I'm aware of) of their IDE's. So, for example, I use PyCharm, which lets me work on my backend code as well as frontend code in the same IDE and I can use spyjs on the JS frontend code. I know for a fact that this holds for IntelliJ & RubyMine. I'm sure it must be the same for others.

Now, everything doesn't get updated at the exact same time across their IDE's. Like, I'm waiting on Facebooks React JSX to be supported. It will be implemented in WebStorm 9 first and then come to PyCharm thereafter. I haven't ever had to wait very long for a feature to make its way from one to the other, though.

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
So I'm giving Node a try after making my first ever web app in Django, just for the sake of trying something new. I know all these JS dudes push nosql really hard but I'm just not that into it. How do people normally work with SQL in Node? I see a few ORMs around, but it is tough to get best practices on this stuff because it seems like the Node ecosystem is still really heavily in flux. So, assuming I'd like to work w/ Postgres, should I just manually write all of my SQL or is one of the ORMS (bookshelf, sequelize, etc) in a good state? I'm using express, if that matters in any way at all.

The Insect Court
Nov 22, 2012

by FactsAreUseless

peepsalot posted:

Any tips, recommended reading, suggested tools to step up my profiling/optimization game?

I have some particularly computationally expensive code that I am trying to optimize for speed. I've been using the built in dev tools in chrome browser to do CPU profiling, looking at which functions are taking up the most time and seeing if/how I can make them more efficient. The profile data representations given by chrome seem kinda clunky to me though, like I'm not seeing any info on a call count for functions, and the overall nested interface feels a bit tedious to navigate for complex code, etc.

I just feel like 'There's Got To Be A Better Way!'

You could take a look at http://google.github.io/tracing-framework/index.html if Chrome's default dev tools aren't extensive enough.

And if by "computationally expensive code" you mean numeric code rather than just currently slow code you might want to take a look at typed arrays.

MrMoo
Sep 14, 2000

The Insect Court posted:

You could take a look at http://google.github.io/tracing-framework/index.html if Chrome's default dev tools aren't extensive enough.


Nice although appears nothing much more than a search front end to the existing chrome://tracing data. The biggest issue is usually the fault is with GC and there is nothing one can do with that outside of closed environments. There is command line flag to enable an API to manually initiate GC and you can custom build chrome to increase the frequency of GC.

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL

The March Hare posted:

So I'm giving Node a try after making my first ever web app in Django, just for the sake of trying something new. I know all these JS dudes push nosql really hard but I'm just not that into it. How do people normally work with SQL in Node? I see a few ORMs around, but it is tough to get best practices on this stuff because it seems like the Node ecosystem is still really heavily in flux. So, assuming I'd like to work w/ Postgres, should I just manually write all of my SQL or is one of the ORMS (bookshelf, sequelize, etc) in a good state? I'm using express, if that matters in any way at all.

I'm using Node with SQL Server and doing a mix of manually writing queries and calling stored procedures. There's also this but I'm not sure how stable it is yet and also not sure how tied to mysql (vs pgsql) it is.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

MrMoo posted:

Nice although appears nothing much more than a search front end to the existing chrome://tracing data. The biggest issue is usually the fault is with GC and there is nothing one can do with that outside of closed environments. There is command line flag to enable an API to manually initiate GC and you can custom build chrome to increase the frequency of GC.

GC will make things stutter, but shouldn't hurt throughput that much unless you're triggering full collections all the time via huge numbers of allocations (and you have a huge live graph).

If that's the case, then doing your own object pooling can help, but can be pretty complex.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Is there any way of an img tag with a src attribute coming into existence without the browser immediately downloading the image?

I've tried document.createElement('img') and then setting the src attribute, without first adding the img tag to the DOM tree. I also tried creating a DocumentFragment, appending a div into it and then setting the div's innerHTML to an img tag.

Both methods immediately send a request to the host and downloaded the image.

I want to replace the images on some image-heavy pages with links, using greasemonkey, but that is pointless if the images start to download regardless of if they're ever visible, or even part of the DOM tree. I'm not going to make an HTML parser in Javascript just to do it.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
You could just not make an img tag with a src attribute until you actually want the browser to start loading whatever src points to.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

I think he's dealing with an existing page. If you fire at document.ready then most images will still be queued, so you can swap out their src before they start clogging the network.

There's a disabled thing in Awful.app's post view that does something similar, if you want to dig into that source a bit.

The Insect Court
Nov 22, 2012

by FactsAreUseless

Wheany posted:

Is there any way of an img tag with a src attribute coming into existence without the browser immediately downloading the image?

No, but you can catch document.ready and call window.stop, which will stop page subresources from loading if they haven't already.


edit: Setting src to about :blank gives a broken image icon(as least in the version of Chrome I'm using). The best solution is probably using a data URI, a quick search indicates that "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" is a 1 pixel transparent gif, which seems to work for me.

The Insect Court fucked around with this message at 02:36 on Sep 17, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

The Insect Court posted:

No, but you can catch document.ready and call window.stop, which will stop page subresources from loading if they haven't already.

That's a good way to gently caress up your deferred script loading. Just walk the collection of image tags and remove their sources or set them to about :blank or a placeholder, don't mess with the rest of the connection state.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Subjunctive posted:

That's a good way to gently caress up your deferred script loading. Just walk the collection of image tags and remove their sources or set them to about :blank or a placeholder, don't mess with the rest of the connection state.

From what I can tell, once an image has been queued for downloading, it cannot be unqueued, so changing the src attributes is useless if the intention is never to download the images, or only download a certain subset of them.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Wheany posted:

From what I can tell, once an image has been queued for downloading, it cannot be unqueued, so changing the src attributes is useless if the intention is never to download the images, or only download a certain subset of them.

You can stop an image (or anything else) download by doing something like:

code:
if(window.stop !== undefined)
{
     window.stop();
}
else if(document.execCommand !== undefined)
{
// ie
     document.execCommand("Stop", false);
}
This will trigger the onabort of everything that has an onabort (like ajax calls) so it's usually a Bad Idea to use.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Bruegels Fuckbooks posted:

You can stop an image (or anything else) download by doing something like:

code:
if(window.stop !== undefined)
{
     window.stop();
}
else if(document.execCommand !== undefined)
{
// ie
     document.execCommand("Stop", false);
}
This will trigger the onabort of everything that has an onabort (like ajax calls) so it's usually a Bad Idea to use.

This is exactly what was suggested 3 posts up (and what Subjunctive was responding to).

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Hmm, since I would be receiving HTML with Xmlhttprequest, I guess I could just replace img src with img data-src or something before using innerhtml to create a DOM tree, then set the src attribute only on the images I actually want loaded.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Wheany posted:

Hmm, since I would be receiving HTML with Xmlhttprequest, I guess I could just replace img src with img data-src or something before using innerhtml to create a DOM tree, then set the src attribute only on the images I actually want loaded.

I've done this, it worked out pretty well

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
Is there some animosity/drama between Lo-Dash and Underscore.js?

Lo-Dash's website seems like it's taking swipes at Underscore.

Fish Ladder Theory
Jun 7, 2005

jdalton, the main contributor to lodash (creator?) opens a shitload of issues on underscores repo, but has almost no commits there. Go on the open issue list and cmd-F his name. poo poo like this

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The whole point of lodash is to be underscore but better, so I'm not sure what could be surprising about the website focusing on how it's better than underscore.

Skiant
Mar 10, 2013
JDalton stated in a video that basically he submitted a PR for Underscore aiming to improve cross-browser compatibility, which got merged and then reverted because of concerns regarding file size.
He then decided to go ahead and fork Underscore, make sure it would behave properly from a browser to another AND add the custom build feature which would address the file size issues.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS

Skiant posted:

JDalton stated in a video that basically he submitted a PR for Underscore aiming to improve cross-browser compatibility, which got merged and then reverted because of concerns regarding file size.
He then decided to go ahead and fork Underscore, make sure it would behave properly from a browser to another AND add the custom build feature which would address the file size issues.

https://github.com/jashkenas/underscore/commit/4e4bc194c0a0e06aa8f7633695ad10030d871a2b comments here

im with jdalton on this one

lunar detritus
May 6, 2009



drat, jashkenas acts like a child in that thread. I mean, who "bans" someone who is actively trying to help?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Oh.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





The concern isn't about file size (although they do mention it), it is more because jashkenas does not believe that sparse arrays will ever be used, and therefore its okay to break that part of JS for a miniscule speed boost. jdalton's counter is that the way underscore is written makes it slow and that accounting for sparse arrays 1) keeps compatibility and 2) not that bad to check.

The tickets I've submitted for jashkenas related projects are always a pain. For one, he thinks its fine to spit out rewritten tokens in the lexer (instead of you know in the rewriter) for CoffeeScript. So you're not guaranteed that the position of the code you've written in CoffeeScript will be represented the same internally. This doesn't matter to 99% of the people who don't care as long as the output is correct javascript, but it causes headaches for the remaining 1% who need CoffeeScript's parser/lexer to be accurate.

Then there was the whole semver brouhaha.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Speaking as someone who broke them in various ways a couple of times, sparse arrays happen.

Combining reduce and reduceRight is dumb.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I sometimes wish that jashkenas was the sort of person to get bored with projects and move on to other things once other people are contributing. He has a pretty solid track record at creating useful new things, but is much worse as a maintainer of things people depend on.

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

Plorkyeran posted:

I sometimes wish that jashkenas was the sort of person to get bored with projects and move on to other things once other people are contributing. He has a pretty solid track record at creating useful new things, but is much worse as a maintainer of things people depend on.

Honestly, this is about 80% of devs I work with. Creating a brand new thing that solves an unsolved problem is fun and cool. Responding to bug reports and requests for minor tweaks is boring and people complaining about your unique vision. Guys like that see themselves as visionaries and creators and if anyone has a problem with what they've made (even if that problem is "it doesn't work right"), it's because they just don't understand how brilliant your code is.

Skiant
Mar 10, 2013

LeftistMuslimObama posted:

Honestly, this is about 80% of devs I work with. Creating a brand new thing that solves an unsolved problem is fun and cool. Responding to bug reports and requests for minor tweaks is boring and people complaining about your unique vision. Guys like that see themselves as visionaries and creators and if anyone has a problem with what they've made (even if that problem is "it doesn't work right"), it's because they just don't understand how brilliant your code is.

That sounds exactly like the two assholes that got fired a few months ago when I could demonstrate to the boss how using an open-source framework like Angular could be an improvement over their own home-made thing.

My Rhythmic Crotch
Jan 13, 2011

Any knockout gurus in the house? I am having no luck getting a simple computed observable to work. I've got a table bound to a VM, and within that chunk, I'm trying to use a computed observable.
code:
<tbody  data-bind="foreach: { data: orders, afterAdd: renderHandler }">
...
<div data-bind="visible: !editing(), text: $parent.customerDisp(), click: edit"></div>
The problem is that it seems the current object is never passed to the customerDisp method.
code:
self.customerDisp = ko.computed(function(order) {
            console.log(order);
            return "some text";
        }, self);
This results in 'order' being undefined within the customerDisp method. Adding $data to the call does not seem to be correct either:
code:
<div data-bind="visible: !editing(), text: $parent.customerDisp($data), click: edit"></div>
That will attempt to write the current object to the customerDisp method which is not what I want to do at all... I am starting to think that the "computed observable" might not be the right thing to use in this particular instance.

edit: the answer turned out to be moving the ko.computed from the ViewModel to the object. That way, I can access the object's properties and do the dumb logic crap that I need. I have no idea why most of the knockout documentation seems to suggest putting ko.computed methods in the ViewModel.

My Rhythmic Crotch fucked around with this message at 17:00 on Sep 23, 2014

darthbob88
Oct 13, 2011

YOSPOS
Question: is there a way to reload files from within JS? As in, one script finds that another file is too old, and sends back to the server for an updated version of that script. The files are all external, but semantic versioning is not an option, the old and new files must have the same filename. I suspect that either there's a simple one-line solution, or it's impossible.

Not my idea, but I don't understand the problem well enough to tell my boss his idea is impossible.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

darthbob88 posted:

Question: is there a way to reload files from within JS? As in, one script finds that another file is too old, and sends back to the server for an updated version of that script. The files are all external, but semantic versioning is not an option, the old and new files must have the same filename. I suspect that either there's a simple one-line solution, or it's impossible.

Not my idea, but I don't understand the problem well enough to tell my boss his idea is impossible.

Maybe with some fuckery like this:
JavaScript code:
var scriptTag = document.createElement("script"); 
scriptTag.src="filename.js?cacheBuster=" + new Date().getTime(); 
document.head.appendChild(scriptTag);

necrotic
Aug 2, 2005
I owe my brother big time for this!

Wheany posted:

Maybe with some fuckery like this:
JavaScript code:
var scriptTag = document.createElement("script"); 
scriptTag.src="filename.js?cacheBuster=" + new Date().getTime(); 
document.head.appendChild(scriptTag);

Yeah, something like this should work. You'll want to make sure you are handling "unloading" the old script (unhooking events, stopping timers, etc...) though.

darthbob88
Oct 13, 2011

YOSPOS

necrotic posted:

Yeah, something like this should work. You'll want to make sure you are handling "unloading" the old script (unhooking events, stopping timers, etc...) though.

That was the second or third best possible solution I could come up with apart from "don't do it, it'll all end in tears". I can probably integrate it with the existing file loading methods, and assuming things go the way I expect them to, any file reloading should come before event hooking and timers.

The Insect Court
Nov 22, 2012

by FactsAreUseless

darthbob88 posted:

Question: is there a way to reload files from within JS? As in, one script finds that another file is too old, and sends back to the server for an updated version of that script. The files are all external, but semantic versioning is not an option, the old and new files must have the same filename. I suspect that either there's a simple one-line solution, or it's impossible.

Not my idea, but I don't understand the problem well enough to tell my boss his idea is impossible.

This sounds like exactly the sort of thing you should be handling at the HTTP layer which already has cache control mechanisms. Of course, HTTP automatically handles cached resources to see if a new version of a resource needs to be fetched, so I'm not quite certain what you're trying to accomplish here. If the idea is to fetch a resource from server A, but ignore it if it's too old and instead fetch resource from server B, the obvious question is why not just fetch the resource from server B in the first place. If you really have to do it in Javascript, then I'd say construct a GET request with the If-Modified-Since header set to the appropriate time, and check to see if you get a 304 back.

If the idea is to update, without page reload, a script file used on a SPA when a newer version becomes available on the server then that sounds like a disaster in the making.

The Insect Court fucked around with this message at 00:21 on Sep 30, 2014

darthbob88
Oct 13, 2011

YOSPOS

The Insect Court posted:

This sounds like exactly the sort of thing you should be handling at the HTTP layer which already has cache control mechanisms. Of course, HTTP automatically handles cached resources to see if a new version of a resource needs to be fetched, so I'm not quite certain what you're trying to accomplish here. If the idea is to fetch a resource from server A, but ignore it if it's too old and instead fetch resource from server B, the obvious question is why not just fetch the resource from server B in the first place. If you really have to do it in Javascript, then I'd say construct a GET request with the If-Modified-Since header set to the appropriate time, and check to see if you get a 304 back.

If the idea is to update, without page reload, a script file used on a SPA when a newer version becomes available on the server then that sounds like a disaster in the making.

I don't entirely understand it either; it's my boss's idea, and he also doesn't understand enough JS to know why it's impossible. It's actually not just age, it's more like "in response to certain conditions, which will change by the time I actually implement them, and which will also probably include a flag in the script loaded from server A, be prepared to replace those files with ones from server B". So just relying on HTTP's built-in caching won't help, but Wheany's solution would probably do the trick. I would appreciate some elaboration on how exactly this is going to turn out badly, if only so I can explain to my boss why this is the worst idea since Sriracha-brand sex lube.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

darthbob88 posted:

"in response to certain conditions, which will change by the time I actually implement them, and which will also probably include a flag in the script loaded from server A, be prepared to replace those files with ones from server B".

Your description is too vague to really say anything. What files? What do they do?

Just replacing an image with another is no big deal. Replacing a bit of Javascript could be a big deal, depending on what it does. If it is just a simple one-off script that runs without context and doesn't have side-effects, replacing it won't be a problem. If a script creates global variables or registers event handlers, cleaning those up before replacing the script can be a pain in the rear end.

If you have no idea what I'm talking about, it will be a pain in the rear end.

darthbob88
Oct 13, 2011

YOSPOS
You already answered my question above, but the resources I need are two JS files, and if things work the way I think they will, the files would be replaced before they could create any event handlers. So, shouldn't be a problem, assuming I understand what the boss wants. If it does turn out to be a problem, I'll just bounce it back to him.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
So, browser downloads old JS file by making an HTTP request, the JS file itself checks if it's the newest version, and if not... downloads a new JS file by making an HTTP request?

Why not just provide the new JS file in step 1?

Adbot
ADBOT LOVES YOU

DholmbladRU
May 4, 2006
nevermind. ios webview issue

DholmbladRU fucked around with this message at 20:30 on Oct 1, 2014

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