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
Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I don't see any element with the ID "leftSide". I only see an element with a class of "leftSide". You either need to add an ID or use document.querySelector(".leftSide")

Adbot
ADBOT LOVES YOU

ModeSix
Mar 14, 2009

Suspicious Dish posted:

I don't see any element with the ID "leftSide". I only see an element with a class of "leftSide". You either need to add an ID or use document.querySelector(".leftSide")

Doh! Thank you so much, that makes perfect sense.

I'm completely new to javascript and I really appreciate your help.

ModeSix fucked around with this message at 17:25 on Feb 4, 2016

Obliterati
Nov 13, 2012

Pain is inevitable.
Suffering is optional.
Thunderdome is forever.

ModeSix posted:

Doh! Thank you so much, that makes perfect sense.

I'm completely new to javascript and I really appreciate your help.

I am pretty new to js (and coding) and I run into problems like this all the time. One of the easiest ways to check what's going on in this situation is to call console.log(); on anything/everything involved in creating that variable so's you know where in the chain you're slipping up.

Munkeymon
Aug 14, 2003

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



Well you have class="leftSide" but you're searching for ID, so probably change that.

e: dang you guys work fast

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

ModeSix posted:

Doh! Thank you so much, that makes perfect sense.

I'm completely new to javascript and I really appreciate your help.

Just to clarify in case it isn't obvious, since getElementById couldn't find the element it returned null, and that caused your error later when you tried to call appendChild on it.

Also since you're new to javascript, I strongly recommend you put "use strict"; at the beginning of your scripts. While it wouldn't have helped you out here, strict mode makes many common bugs easier to track down.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

ModeSix posted:

So I am doing an online course learning javascript, and one of the assignments is using DOM to add elements to a page.

I am getting an error when I load the page "Uncaught TypeError: Cannot read properly 'appendChild' of null".

I have the script waiting for the onload before executing.

Please help, this doesn't make any sense to me why this isn't working.



http://pastebin.com/m833DMJJ
Other people have already answered this, but in general, JSFiddle or Plunker or Codepen are a better place to put your JS code samples when you're asking for help because people can play with them right there without any extra work

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Obliterati posted:

I am pretty new to js (and coding) and I run into problems like this all the time. One of the easiest ways to check what's going on in this situation is to call console.log(); on anything/everything involved in creating that variable so's you know where in the chain you're slipping up.

Sometimes, yes. But since the developer tools are already open, I would put a breakpoint there and just step through the code. In a loop it's a pain in the rear end, but in a simple case like that, it is very useful.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Wheany posted:

In a loop it's a pain in the rear end
Only insofar as you have to set a conditional breakpoint to only break on the thing you want

ModeSix
Mar 14, 2009

Vulture Culture posted:

Other people have already answered this, but in general, JSFiddle or Plunker or Codepen are a better place to put your JS code samples when you're asking for help because people can play with them right there without any extra work

Thanks, these will be infinitely useful.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

So I've got a site that's got an intermittent issue - scrolling gets disabled by a piece of javascript adding "overflow: hidden;" to the body in a style attribute. Unfortunately, the code base is huge, and we have a dozen+ third party scripts coming in. (It's a nightmare.)

Does anyone have a way, purely programmatically, that I could monitor a node and note the file and line number (or even just the code or function name) that's modifying it? MutationObservers can watch, but they don't seem to be able to identify the function that actually changed it.

I know I can do this with DOM breakpoints locally, but I'm having trouble reproducing it myself locally, so I'd rather have something I can put out and get reports back on.

Heskie
Aug 10, 2002

EVGA Longoria posted:

So I've got a site that's got an intermittent issue - scrolling gets disabled by a piece of javascript adding "overflow: hidden;" to the body in a style attribute. Unfortunately, the code base is huge, and we have a dozen+ third party scripts coming in. (It's a nightmare.)

Does anyone have a way, purely programmatically, that I could monitor a node and note the file and line number (or even just the code or function name) that's modifying it? MutationObservers can watch, but they don't seem to be able to identify the function that actually changed it.

I know I can do this with DOM breakpoints locally, but I'm having trouble reproducing it myself locally, so I'd rather have something I can put out and get reports back on.

Could you use Chrome Dev Tools 'Break on..' on the body?



I think this breaks on the line of code causing the issue. It should be highlighted in the Sources tab.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Heskie posted:

Could you use Chrome Dev Tools 'Break on..' on the body?



I think this breaks on the line of code causing the issue. It should be highlighted in the Sources tab.

Unfortunately, that then requires me to be able to reproduce it locally. It's an intermittent/rare issue, and I've yet to reproduce it myself.

I'm toying with the idea of using a phantomjs script to do reload the pages a few thousand times with a breakpoint until I can reproduce it, but I'm holding out hope there's something I can hook into.

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

EVGA Longoria posted:

Unfortunately, that then requires me to be able to reproduce it locally. It's an intermittent/rare issue, and I've yet to reproduce it myself.

I'm toying with the idea of using a phantomjs script to do reload the pages a few thousand times with a breakpoint until I can reproduce it, but I'm holding out hope there's something I can hook into.

Are you sure it's a random fluke from your code, or is it possibly environmental?

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Skandranon posted:

Are you sure it's a random fluke from your code, or is it possibly environmental?

Doubt it's environmental - we have seen it with pretty much every browser/os combo under the sun. The problem is it's mostly coming through from feedback left by users, so we're not sure exactly how often it's happening. It's also on our legacy platform, so people have been reluctant to actually add real tracking on the issue.

I'm going to look into setting up a mutation tracker that can report when it occurs for us to get a true idea of how often it happens - but while I'm doing that, I figured I'd try to find something that could solve the issue. Since breaking on dom manipulation is possible, I was hoping there was a simple bit of code I could put out there that would at least give me a trace of modifying code.

Sedro
Dec 31, 2008
You can get a stack trace programmatically by calling Error().stack, but I assume a mutation tracker runs asynchronously to the actual mutation code.

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
Is there a way to remove all event listeners from a page using the console? Specifically I'm thinking of lovely streaming sites that are filled with all kinds of onclick bullshit.

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Sedro posted:

You can get a stack trace programmatically by calling Error().stack, but I assume a mutation tracker runs asynchronously to the actual mutation code.

code:
Error
    at Error (native)
    at <anonymous>:5:17
    at Array.forEach (native)
    at MutationObserver.<anonymous> (<anonymous>:4:13)
Yeah, looks like the stack trace ends up being for the anonymous function so no joy.

Oh well, was a long shot. Thanks for the help.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
Sorry if this is super-obvious but have you used Chrome/FF dev tools to do a global search through loaded JS files for the string 'body'?

EVGA Longoria
Dec 25, 2005

Let's go exploring!

Vulture Culture posted:

Sorry if this is super-obvious but have you used Chrome/FF dev tools to do a global search through loaded JS files for the string 'body'?

I've tried, but the problem comes in that there's 94 line results in the JS for 'body' on any given page, at a minimum, and most of that is 3rd party code that's coming through minified. I'm kind of bashing my head against it, but I'm not making headway.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

EVGA Longoria posted:

I've tried, but the problem comes in that there's 94 line results in the JS for 'body' on any given page, at a minimum, and most of that is 3rd party code that's coming through minified. I'm kind of bashing my head against it, but I'm not making headway.

Enable pretty printing

Firefox, lower left corner


Chrome, middle-ish of the window, lower left corner of the source view (e: actually, that depends on whether you have the console visible in the debugger and how high it is)

qntm
Jun 17, 2009

Wheany posted:

Enable pretty printing

Firefox, lower left corner


Chrome, middle-ish of the window, lower left corner of the source view (e: actually, that depends on whether you have the console visible in the debugger and how high it is)


Cripies, that's the least discoverable option I've ever seen. Thank you for pointing it out.

aBagorn
Aug 26, 2004
So what's the best way to extract binary data from XML and pass it on to an API?

My application is basically functioning as a bridge between two APIs, I make a call to the first, and the response is along these lines:

code:

<root>
    <something>
         <data> 
             **binary data here (base64 encoded string)
        </data>
    </something>
</root>

I need to pull the contents of the data element and then pass it along to the email manager API, which will include it as an attachment.


E: I figured it out. I was having issues because the base64 string I was pulling out was too big for the default limit for my other API. Increased the parser size limit and worked like a charm

aBagorn fucked around with this message at 21:22 on Feb 14, 2016

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
I'm making multiple API calls inside of a Promise.all (thank you bluebird). Currently I'm saving the response objects to separate JSON files. I need to clean up the data some before it's ready for postgres. It feels really dumb and bulky to write to the separate JSON files with FS, only to turn around and gently caress with them immediately after.

Is there a node module or best practice that would allow me to perform simple filter/maps operations on the response objects I get back as I get them so I can skip the writing with FileSystem step?

I mean I guess I could just try to parse it inside of the promise but it seems messy.

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

Raskolnikov2089 posted:

I'm making multiple API calls inside of a Promise.all (thank you bluebird). Currently I'm saving the response objects to separate JSON files. I need to clean up the data some before it's ready for postgres. It feels really dumb and bulky to write to the separate JSON files with FS, only to turn around and gently caress with them immediately after.

Is there a node module or best practice that would allow me to perform simple filter/maps operations on the response objects I get back as I get them so I can skip the writing with FileSystem step?

I mean I guess I could just try to parse it inside of the promise but it seems messy.

I wouldn't process them inline, but you can easily break the processing out to a separate function. You can also have the promises aggregated by bluebird broken out to separate functions to further make things pretty. There isn't really any other way to do what you want, any node module you could be imagining is just going to provide wrappers that essentially process the data in the promises.

Odette
Mar 19, 2011

Skandranon posted:

I wouldn't process them inline, but you can easily break the processing out to a separate function. You can also have the promises aggregated by bluebird broken out to separate functions to further make things pretty. There isn't really any other way to do what you want, any node module you could be imagining is just going to provide wrappers that essentially process the data in the promises.

I made a small website parser that demonstrates this functionality. What you want to look at is getStory in fictionpress-scraper.js.

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic

Skandranon posted:

I wouldn't process them inline, but you can easily break the processing out to a separate function. You can also have the promises aggregated by bluebird broken out to separate functions to further make things pretty. There isn't really any other way to do what you want, any node module you could be imagining is just going to provide wrappers that essentially process the data in the promises.

The more experience I get with back-end, the more I realize how inelegant and ugly it all is.

It's kind of reassuring in a way. I keep feeling like my approach is super hacky and amateurish and then I see other implementations and realize I wasn't far off the mark.

Raskolnikov2089
Nov 3, 2006

Schizzy to the matic
Working with API rate limits, is wrapping my requests in a setTimeout a bad way to go about it?

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

Raskolnikov2089 posted:

Working with API rate limits, is wrapping my requests in a setTimeout a bad way to go about it?

Depends how you are doing it? It doesn't magically solve your problems, it depends how you are using them.

MrMoo
Sep 14, 2000

Raskolnikov2089 posted:

Working with API rate limits, is wrapping my requests in a setTimeout a bad way to go about it?

Not many APIs available, one can add requestIdleCallback to better integrate with animation if you are not calling in a service worker.

ModeSix
Mar 14, 2009

Angular is a whore.

So I am trying to do form validation and take the form data and use push() to an array.

It appears to work fine, but two problems.
1) The form doesn't get cleared (this isn't really important yet so I'm not even going to focus on it in this question)

2) When I hit submit it appears to append the data to the array, because it can be sorted, filtered etc. But if I modify what is in the form, it changes the data in the array.

I tried to set up a jsfiddle but I really don't get it, so here's my HTML.

http://pastebin.com/c4N6s0xh

Now here's the script.

http://pastebin.com/gC4KRSRg

The console log shows the form data correctly, and it actually moves the data up into the array (or so it appears). If I modify any data that is in the form the corresponding array data is changed for the new entry. I also cannot submit a second additional entry, just one submission and that's it.

I really am stumped because this should work based off of everything I've read.

IronDoge
Nov 6, 2008

You have to reset the model of the newcomment object after the submit, like so:
code:
$scope.newcomment.author = "";
$scope.newcomment.comment = "";
Also when you're appending the object to the array, you need to make a copy of it. Otherwise you're linking your new comment to the results array and it'll just change to whatever is being typed in your form.

See my changes here:
http://codepen.io/jowang/pen/jWoKPm?editors=1111

I believe in JSFiddle you have to bootstrap the Angular app to get it to work:
https://docs.angularjs.org/guide/bootstrap

IronDoge fucked around with this message at 16:57 on Feb 19, 2016

Munkeymon
Aug 14, 2003

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



IronDoge posted:

I believe in JSFiddle you have to bootstrap the Angular app to get it to work:
https://docs.angularjs.org/guide/bootstrap

Nah, you just have to set Load Type to nowrap https://jsfiddle.net/v1adfpj1/

ModeSix
Mar 14, 2009

IronDoge posted:

You have to reset the model of the newcomment object after the submit, like so:
code:
$scope.newcomment.author = "";
$scope.newcomment.comment = "";
Also when you're appending the object to the array, you need to make a copy of it. Otherwise you're linking your new comment to the results array and it'll just change to whatever is being typed in your form.

See my changes here:
http://codepen.io/jowang/pen/jWoKPm?editors=1111

I believe in JSFiddle you have to bootstrap the Angular app to get it to work:
https://docs.angularjs.org/guide/bootstrap

Oh wow, thank you so much!

I was originally trying to do what you've shown me, but I couldn't figure out the syntax for it, but now that I see what you've written it's really clear and makes a lot of sense.

Also, thanks for showing me codepen, seems more intuitive than jsfiddle.

ModeSix fucked around with this message at 17:43 on Feb 19, 2016

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
Edit nevermind but I do have anohter question.

I am using node to spawn a child process that is creating an ssh tunnel. However it needs a password (no keys cannot be used in this system). How do I tell node to supply ssh with a password (since there is no additonal command line parameters for passing a password), and I cannot get any additional packages like sshpass.

Knifegrab fucked around with this message at 03:35 on Feb 25, 2016

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

Knifegrab posted:

Edit nevermind but I do have anohter question.

I am using node to spawn a child process that is creating an ssh tunnel. However it needs a password (no keys cannot be used in this system). How do I tell node to supply ssh with a password (since there is no additonal command line parameters for passing a password), and I cannot get any additional packages like sshpass.

You would have to re-implement what SSHPass does: "Sshpass utilizes the pty(7) interface to control the TTY for ssh"

There is no other way.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Why the OpenSSH guys don't bother creating a usable SSH library, I don't know.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Suspicious Dish posted:

Why the OpenSSH guys don't bother creating a usable SSH library, I don't know.

Well, it turns out that may have been a very good thing.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

MALE SHOEGAZE posted:

Well, it turns out that may have been a very good thing.

why

ModeSix
Mar 14, 2009


http://heartbleed.com/

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

what does an unrelated library have to do with anything

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