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
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

ufarn posted:

Thinking of saying gently caress it and going with Standard (npm install standard). Anyone run into any issues or edge cases that soured them on using it?

2 spaces instead of 4 for indentation is unforgivable.

Adbot
ADBOT LOVES YOU

ufarn
May 30, 2009

Lumpy posted:

2 spaces instead of 4 for indentation is unforgivable.
Yeah, I'm a 4 spaces, double quotes kind of person, but I'm currently waiting for jshint and jscs to migrate to eslint while I have to update stylelint every week and troubleshoot all the issues that comes with that, and I'm losing my loving mind over it at this point.

Huzanko
Aug 4, 2015

by FactsAreUseless

Lumpy posted:

2 spaces instead of 4 for indentation is unforgivable.

Absolutely true.

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

bomblol
Jul 17, 2009

my first crapatar

Chenghiz posted:

It's good to have a linter setup and enforcing a code style can be useful but I think their stance on semicolons is dumb. As long as you don't mind the rules they set I don't think you'll have any issues though.

https://github.com/Flet/semistandard


i cant get over how this bit in the show implies that when people use spaces, theyre actually pressing space 4 times. I guess they're all using notepad.exe?

lunar detritus
May 6, 2009




Or eslint + airbnb's styleguide config plugin.
Also, javascript without semicolons can gently caress off.

Thermopyle
Jul 1, 2003

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

Yes, I wish everyone would just use airbnb's guide and get on with it.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





semicolons are useless. single quotes are the best. two spaces is better than four.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Strong Sauce posted:

semicolons are useless. single quotes are the best. two spaces is better than four.

correct except for the semicolon bit. there's no reason whatsoever not to use them and they remove a ton of ambiguity. it's the same with people that try to be clever and don't use braces for single line blocks.

bomblol
Jul 17, 2009

my first crapatar

Blinkz0rz posted:

correct except for the semicolon bit. there's no reason whatsoever not to use them and they remove a ton of ambiguity. it's the same with people that try to be clever and don't use braces for single line blocks.

they remove a ton of ambiguity? JS has a spec, there is no ambiguity. you cant start a line with a (. Where is the ambiguity?
can yall grandpas with your semicolons and 4 space indent and stuff keep your dumb preferences in the JRE.NET++ 9.3 styleguide or w.e along with the grumpy dude who gets kicked out of conferences for being an rear end in a top hat/wrote the book that encouraged everyone to write terrible JS for 10 years

vvvvvv standard js is like the third most popular javascript style guide. the accepted answer on that SO is literally someone saying he prefers semicolons because java and PHP use them

bomblol fucked around with this message at 01:24 on Sep 19, 2016

biznatchio
Mar 31, 2001


Buglord
Remember when it was a big fad among Javascript 'developers' to not use semicolons because.... well, I guess because they wanted to be unique snowflakes?

That dumb movement died out awfully quickly.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





biznatchio posted:

Remember when it was a big fad among Javascript 'developers' to not use semicolons because.... well, I guess because they wanted to be unique snowflakes?

That dumb movement died out awfully quickly.

nah dude you're just not hip with the latest javascript frameworks. only the uncool people use semicolons now.

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

bomblol posted:

they remove a ton of ambiguity? JS has a spec, there is no ambiguity. you cant start a line with a (. Where is the ambiguity?
can yall grandpas with your semicolons and 4 space indent and stuff keep your dumb preferences in the JRE.NET++ 9.3 styleguide or w.e along with the grumpy dude who gets kicked out of conferences for being an rear end in a top hat/wrote the book that encouraged everyone to write terrible JS for 10 years

vvvvvv standard js is like the third most popular javascript style guide. the accepted answer on that SO is literally someone saying he prefers semicolons because java and PHP use them

Yes, they do. If you omit you're at the whims of ASI anyway, so why not use them and be explicit and never get bit by that gotcha?

But oh, can't be explicit, gotta be clever, gotta go fast.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
But the gotchas exist regardless of whether you use semicolons or not?

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
Yeah, I should amend my comment to be:

"Be verbose, be explicit, be safe. Stop trying to do clever things. Clever things only make you feel smart. Everyone else hates you for them."

SurgicalOntologist
Jun 17, 2004

Cross-posting a question from the Bokeh Google Group.

For those that don't know, Bokeh is a Python graphing library that implements its front end with JavaScript. I have a Bokeh Server app that contains both Python server-side callbacks and JavaScript client-side callbacks. Posting here because I suspect the solution is more likely to involve JavaScript trickery than anything else.

I'm trying to link the currentTime property of an HTML5 video with the currently selected row of a Bokeh table (SlickGrid). I have video -> table working by using video.ontimeupdate to change the data of a dummy plot object, which then triggers a Python callback where I change the table selection (I need at least part of this loop to be server-side as there is some other data manipulation going on in the Python callback that changes another plot on the page). Going the other way, I have the option of running either a server-side or client-side callback. Ideally, I'd have a client-side callback that changes the video.currentTime property allowing everything else to trigger as normal . What actually happens is the callbacks trigger each other back and forth several times.

quote:

I have a tricky case of circular callbacks and I'm wondering if anyone has any thoughts.

Basically, I have a HTML5 video whose currentTime property I want linked to the currently selected row of a DataTable. Currently this is mediated through a dummy glyph (until https://github.com/bokeh/bokeh/issues/3674 at least) with something like time_glyph.data_source.set('data', {'time': [video.currentTime]}); in video.ontimeupdate. I have a server-side callback for that source where I update the selection of the data table (as well as a bunch of other things). Works great!

Now, I'm trying to link things in the other direction, so the user can use the arrow keys in the data table to go back and forth in the video. My first try was with some CustomJS callback like video.currentTime = cb_obj.get('selected')['1d'].indices[0] / 10; Of course, this leads to a circular callback problem.

Anyone have any ideas for a workaround? I'm stumped.

geeves
Sep 16, 2004

Blinkz0rz posted:

Yeah, I should amend my comment to be:

"Be verbose, be explicit, be safe. Stop trying to do clever things. Clever things only make you feel smart. Everyone else hates you for them."

A company I worked for fired a couple of CMU JavaScript Bros for not adhering to our style guide. They had other issues too, but we were sick of denying their pull requests and having them break the build because it wouldn't pass JSLint, etc. They had other issues as well, mostly their attitude (and they were certain they were creating the new snapchat), but still it just carried over and dealing with them during code reviews, etc. became a nightmare because of it.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
The thing is senicolons/not semicolons is not really about explicit/not explicit if you're using a proper linting system already, it is just as much a aesthetic preference as code indenting.

In my own small self owned company (2 people) we write semicolon free with ESLint/Typescript. It's not hard, we've never been bitten in the extraordinarily limited number of ASI gotchas because we lint and structure our code properly anyway.

When we contract for places with established style guides of course we just follow their convention. People will complain about JavaScript bros, but the sin is non-adherence to a style guide/local convention/linter, not semicolon free or tabs vs spaces or whatever.

edit: actually I'll go one more, a file with or without semicolons is functionally identical because that's how it works, replacing 'semicolon-newline' with 'newline' across an entire file will result in the exact same code execution. Inserting semicolons does not turn off ASI. The only place where entering semicolons makes a difference is multiple statements on a single line. Following this logic you can easily make the case that semicolons are useless line noise. I say this not to WIN the argument about which one is right, consistency is the only 'right', just to clear up what semicolon free actually is.

Maluco Marinero fucked around with this message at 00:32 on Sep 20, 2016

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Blinkz0rz posted:

Yeah, I should amend my comment to be:

"Be verbose, be explicit, be safe. Stop trying to do clever things. Clever things only make you feel smart. Everyone else hates you for them."

Some programmers treat verbosity as a virtue, but I'm going to disagree with "be verbose." That doesn't mean sacrificing clarity in order to be concise, but needless verbosity just decreases the signal-to-noise ratio. You want to put the least burden possible on whoever's reading your code, and that sometimes means less of it, not more. Just try to be as clear as possible and forget about if you're writing too much or too little.

That said I prefer to insert semicolons. I don't think they make much difference either way in the verbosity debate, but it's pretty ingrained from other languages, so I pretty much do it out of habit.

an skeleton
Apr 23, 2012

scowls @ u
Need suggestions for front end integration testing. Project will be in react. Considering nightwatchjs.

Thermopyle
Jul 1, 2003

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

an skeleton posted:

Need suggestions for front end integration testing. Project will be in react. Considering nightwatchjs.

Does it have to be js? I've never really been happy with anything I've found in js-land.

I always use python+selenium+unittest and have been fairly happy. Well at least as happy as you can get when doing the lovely job of writing frontend integration tests.

SurgicalOntologist
Jun 17, 2004

SurgicalOntologist posted:

Cross-posting a question from the Bokeh Google Group.

For those that don't know, Bokeh is a Python graphing library that implements its front end with JavaScript. I have a Bokeh Server app that contains both Python server-side callbacks and JavaScript client-side callbacks. Posting here because I suspect the solution is more likely to involve JavaScript trickery than anything else.

I'm trying to link the currentTime property of an HTML5 video with the currently selected row of a Bokeh table (SlickGrid). I have video -> table working by using video.ontimeupdate to change the data of a dummy plot object, which then triggers a Python callback where I change the table selection (I need at least part of this loop to be server-side as there is some other data manipulation going on in the Python callback that changes another plot on the page). Going the other way, I have the option of running either a server-side or client-side callback. Ideally, I'd have a client-side callback that changes the video.currentTime property allowing everything else to trigger as normal . What actually happens is the callbacks trigger each other back and forth several times.

quote:

I have a tricky case of circular callbacks and I'm wondering if anyone has any thoughts.

Basically, I have a HTML5 video whose currentTime property I want linked to the currently selected row of a DataTable. Currently this is mediated through a dummy glyph (until https://github.com/bokeh/bokeh/issues/3674 at least) with something like time_glyph.data_source.set('data', {'time': [video.currentTime]}); in video.ontimeupdate. I have a server-side callback for that source where I update the selection of the data table (as well as a bunch of other things). Works great!

Now, I'm trying to link things in the other direction, so the user can use the arrow keys in the data table to go back and forth in the video. My first try was with some CustomJS callback like video.currentTime = cb_obj.get('selected')['1d'].indices[0] / 10; Of course, this leads to a circular callback problem.

Anyone have any ideas for a workaround? I'm stumped.

Anyone have any ideas here?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SurgicalOntologist posted:

Anyone have any ideas here?

Can you cache responses client side? I mean manually, using (I'm guessing) video's currentTime rounded to some number of seconds as the key.

Flag the origin of each event and add logic to not trigger a new request from the client if the origin was the client?

You could also have a global 'awaiting response' flag that, say, drops new requests instead of sending them.

Just curious, but are you expecting this to work over internet, intranet or localhost latency, because I'm skeptical this can be done reliably over the internet.

SurgicalOntologist
Jun 17, 2004

Oh, nice, a global flag seems pretty straightforward. Don't know why I didn't think of that.

There is some lag that causes the updates to lose synchronization with the video when it's not running locally. That should be fixable with an update flag I would imagine--only trigger a new update if the last one has completed. If we're only updating the animation every 10 frames instead of every frame, that's perfectly fine.

That said, this is just a proof of concept and does not need to support more than one user at a time. The eventual use case is for internal use so intranet-only supporting a handful of concurrent users is ideal, but if every user needs to run their own local version that's not a big deal either.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



If you're letting the use jog the video around, caching responses is probably going to be the best UX. I'm not talking about anything complicated, either:

JavaScript code:
var cache = {};
function maybeMakeRequest (forTime) {
    var cacheKey = forTime.toFixed(1).toString();
    if (cache[cacheKey]) {
        return cache[cacheKey];
    } else {
        cache[cacheKey] = makeRequest(forTime);//this is your existing method
        return cache[cacheKey];
    }
}
E: spellang

SurgicalOntologist
Jun 17, 2004

I'm not sure how to fit that into what I'm already doing. I'm not generating responses on my own. Rather, the ontimeupdate callback of the video is triggering a callback in the framework I'm using (Bokeh). Bokeh triggers a server-side Python callback which moves around several elements in the app.

My existing method is literally just

JavaScript code:
video.ontimeupdate = function() {
	time_glyph.data_source.set('data', {'time': [video.currentTime]});}
(changing a glyph's data triggers a callback; time_glyph is a dummy glyph with no graphical representation because currently there's no other way to trigger a callback). So, not much to cache. I could do some limited caching on the Python side but I'm not sure how much it would help (and even there, I'm not generating the entire response but just adjusting many glyph's data sources and letting Bokeh figure out how to represent that).

Maybe there's some way to short circuit the Bokeh machinery and cache the JSON payload that it uses to communicate between the client and the Python server, but I don't know how to get a reference to that. I'm adding it to the to-do list though so I will eventually look into it.

Thanks for your thoughts, much appreciated. This is my first foray into anything close to webdev and a lot is new to me.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Do you write any code for time_glyph to get data or is all that done for you in Bokeh?

I did try Bokeh one time but was slightly discouraged because I couldn't figure out how to mess with the front-end code immediately, heh.

SurgicalOntologist
Jun 17, 2004

That is the code for time_glyph to get data. I'm setting its data to the current time, so that the Python server-side code will be able to reference it to get the current time for other operations.

ddiddles
Oct 21, 2008

Roses are red, violets are blue, I'm a schizophrenic and so am I
So I'm trying to get a better understanding of the this keyword, and i ran into something that confuses me. It's probably because I dont understand JS objects fully, but this code:

code:
var testObject = {
  objectMethod : function() {
    console.log(this);
    
    function objectMethodFunction() {
      console.log(this);
    }
    
    objectMethodFunction();
  }

}

testObject.objectMethod();

Then I log the value of this with objectMethod, i get the object back, which I expected, but the objectMethodFunction inside of the method logs the window object, and I can't really understand why.

ddiddles fucked around with this message at 02:43 on Sep 23, 2016

There Will Be Penalty
May 18, 2002

Makes a great pet!

ddiddles posted:

So I'm trying to get a better understanding of the this keyword, and i ran into something that confuses me. It's probably because I dont understand JS objects fully, but this code:

code:
var testObject = {
  objectMethod : function() {
    console.log(this);
    
    function objectMethodFunction() {
      console.log(this);
    }
    
    objectMethodFunction();
  }

}

testObject.objectMethod();

Then I log the value of this with objectMethod, i get the object back, which I expected, but the objectMethodFunction inside of the method logs the window object, and I can't really understand why.

if you call a function as a method on an object, the `this` value is the object it's invoked on.
if you call a function as a function (without an object), the `this` value is either the global object (in non-strict mode) or `undefined` (in strict mode).
The value of `this` in the objectMethod call does not apply to inner nested functions like objectMethodFunction.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
In javascript "this" is "the thing left of the dot"

If there is nothing "left of the dot", "this" is undefined (in strict mode, which you should always use)

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Wheany posted:

In javascript "this" is "the thing left of the dot"

If there is nothing "left of the dot", "this" is undefined (in strict mode, which you should always use)

What about in arrow functions....

bomblol
Jul 17, 2009

my first crapatar

ddiddles posted:

So I'm trying to get a better understanding of the this keyword,
How about a too better understanding of this
https://github.com/getify/You-Dont-Know-JS/tree/master/this%20%26%20object%20prototypes

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SurgicalOntologist posted:

That is the code for time_glyph to get data. I'm setting its data to the current time, so that the Python server-side code will be able to reference it to get the current time for other operations.

Technically, that's a handler for an event on the video node. I'm asking if data_source.set() is some auto-generated magic or if you wrote it. I'm guessing it's magic, though.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Lumpy posted:

What about in arrow functions....
:ssh: or new, bind, apply or call

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Wheany posted:

In javascript "this" is "the thing left of the dot"

If there is nothing "left of the dot", "this" is undefined (in strict mode, which you should always use)

This is not always true. This is true when a function on an object when the function is called on that object, but if that function then gets passed to some other callback mechanism (promise, message bus, etc), the meaning of "this" will change.

SurgicalOntologist
Jun 17, 2004

Munkeymon posted:

Technically, that's a handler for an event on the video node. I'm asking if data_source.set() is some auto-generated magic or if you wrote it. I'm guessing it's magic, though.

Oh, I see what you're asking. Yeah, everything else is Bokeh magic.

I think the best chance of being able to cache something is to cache the JSON payload that the Bokeh server sends in response to that event. It should be the same for any given time. Chances are they don't expose this but I'll request it and either get it added to their todo list or get some pointers on how to accomplish it.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SurgicalOntologist posted:

Oh, I see what you're asking. Yeah, everything else is Bokeh magic.

I think the best chance of being able to cache something is to cache the JSON payload that the Bokeh server sends in response to that event. It should be the same for any given time. Chances are they don't expose this but I'll request it and either get it added to their todo list or get some pointers on how to accomplish it.

Yes, that's exactly what I was suggesting upthread. However, I just realized that, if your server responds so quickly with data that you just get a little bit of lag doing it this way, that you should be able to compute it all ahead of time by iterating over the gradations in your dataset and squirting that into a script node somewhere so you don't have to make a server round-trip at all. That would eliminate latency at the cost of page load time.

Looks like you could make a script node with bokeh.embed and then your video update handler would just grab values out of the global object it leaves laying around. You just have to give the object a predictable name.

ddiddles
Oct 21, 2008

Roses are red, violets are blue, I'm a schizophrenic and so am I

Oh man thats awesome, thanks!

BobFossil
Jun 17, 2005

Note to self: I hate whites.
I just want to show the current date minus 12 months and 3 months then strip out the time and GMT info - why are the dates wrong? :(

code:
   var now = new Date();
   var threemonthsago = new Date(now.getFullYear(), now.getMonth() - 3, now.getDay());
   var twelvemonthsago = new Date(now.getFullYear() - 1, now.getMonth(), now.getDay());

   document.getElementById('3monthsago').innerText = threemonthsago;
   document.getElementById('12monthsago').innerText = twelvemonthsago;
   
https://jsfiddle.net/2jktgxjo/

Adbot
ADBOT LOVES YOU

Kekekela
Oct 28, 2004

BobFossil posted:

I just want to show the current date minus 12 months and 3 months then strip out the time and GMT info - why are the dates wrong? :(

code:
   var now = new Date();
   var threemonthsago = new Date(now.getFullYear(), now.getMonth() - 3, now.getDay());
   var twelvemonthsago = new Date(now.getFullYear() - 1, now.getMonth(), now.getDay());

   document.getElementById('3monthsago').innerText = threemonthsago;
   document.getElementById('12monthsago').innerText = twelvemonthsago;
   
https://jsfiddle.net/2jktgxjo/

You want getDate (which returns the day part of the date) not getDay, which returns 1 for Monday, 2 for Tuesday, 3 for Wednesday etc

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