« first day (2113 days earlier)      last day (3060 days later) » 

00:09
is this a good room to get an answer to this kind of question: stackoverflow.com/questions/38648560/…?
@Pyrodante Doesn't hurt to ask, but I have no idea about your question.
fair
well here is to hoping :)
I have the following logic to implement in JS: X might be expired or unprofitable; I have an ajax call I can use to find out each one separately. The user could be internal or external. If the user is external and the quote is expired, he can't use it. If he's internal, he is given a choice to use it. If the quote is unprofitable, he can't use it regardless.
It would be straightforward enough in a procedural language: get expiry; if expired and external, reject, else if expired and internal, ask, else... etc.
I've tried to do this in JS and gotten hosed up, and (of course) get told I should not use synchronous ajax calls.
So I'm trying to organize logic around asynch calls, and MAN is that a pain. Essentially I cannot pass parameters to downstream calls.
I can do it with a bunch of global variables; is there any other way?
@arcy Have you tried promises?
No. Not familiar with promises. What is that?
00:16
It's the "modern" way of doing async
Oh, god. Does it involve another library?
No
Unless you happen to need a feature that's not built-in, but that's unlikely
Well, besides your description, what is it.
?
The old way of doing async involved a lot of nested callbacks. Promises use sequential callbacks instead.
If you want some examples, check out the documentation
What version of JS is required?
00:18
Any current browser
Except IE, apparently
Oh, good.
If it won't work in IE, I won't be able to use it.
It says Edge is supported though
I assume bluebird works on IE, if you need to support legacy browsers
bluebird is a promise library
(sigh) am NOT going to be able to sell going to different versions of JS or jQuery, extra libraries are dodgy.
What about babel?
Care to give me a quick rundown on nested callbacks?
re: babel, please see above. I assume that's another library
00:21
No, it's a precompiler
No help, I'm afraid.
Why are you dead set on avoiding best practices?
I'm not, and there's no reason to attempt to be insulting.
I do not choose my programming environment; very few programmers do.
Introducing a new library in a medium-sized system is no small affair.
Weird
If you must use traditional async, be prepared for ugly code
I've been programming over 30 years, for many different companies and organizations in many situations. It is common.
What is weird to me is how often, when someone says "best practices", they aren't talking about practices, but about some nifty new tool that may or may not survive the year.
00:24
That doesn't mean I shouldn't ridicule people who decide to avoid industry-leading best practices, be they management, customers, or whoever.
Well, I only have your opinion on the 'best' part, and even the 'industry-leading' part.
@arcy Promises are not a nifty tool, they have been used in other languages for years.
@arcy There are plenty of people that chat here that can back me up on this.
And they might be fine, but I can't use something that won't support IE, even old IE
As for your original question, traditional async boils down to this:
myAsyncFunction(foo, bar, function() { /* everything that should happen after the async operation is finished goes here. */ })
are you defining something to be called by my application code here?
Or is this the async function called by ajax?
00:28
When you call async code, you pass it a function to be called when it's finished.
The async function will call your code again when appropriate
Ok, so I make an ajax request with "r = $.ajax({ url: x, datatype:"text" });"
then "r.done(function(result) { /*etc.*/ }" is executed when the ajax call is done.
all right so far?
so 1 ajax call can return its result; the 'done()' method can test it; is there any way to give another value (say, t/f for whether the user is internal) to the 'done()' function besides a global variable?
This is where it seems to me start getting ugly...
What do you mean?
> give another value to the 'done()' function
I have different logic to execute based on 1. the result of the ajax call and 2. whether the user is internal.
00:34
you don't give a value to the function, you give it a callback function
the done() method is called when ajax is done.
Yes, so any logic that happens after the ajax is complete must go in that function
ok - I would like it to include, in its logic, a test of a value that is not involved in the ajax call, but is known to the caller of ajax
where do I put it?
Put it in a variable outside of the done function, and it should be accessible inside the function
aka global variable. Well, was hoping there was something else.
00:36
It doesn't have to be a global variable, unless your code is in the global scope to begin with
ok
Even then it's not technically necessary, but that's the easiest way
How is this value stored, if not in a variable in the first place?
Yes, it's in a variable; was asking how to get it known to the callback routine.
If the callback is in the same scope as the variable, it will just work
ok. haven't messed with scopes much in JS
I alter code that our JS person (and probably 2 or 3 before him) wrote; am not a JS programmer within the meaning of the act.
00:41
ah
so, global variable for that; now there's the matter of the second ajax call. do I have to make that from the callback function of the first ajax call?
yes, exactly
You mentioned "nested callbacks"; I don't see anything I recognize as 'nested' here
This is when traditional async gets icky
Unless you meant the ajax call within the ajax callback
00:42
@arcy Calling async within callbacks for other async, i.e. nested callbacks
@arcy yeah
I see
reminds me of my assembler days
You're going to tell me to alter the stack pointer any time now, I just know it.
Doing that in JS would be immensely fun
Well, thanks -- guess I at least have some confirmation that I'm going down the only path liable to be open to me.
"fun" that is
I can't ditch IE; I can't introduce a new library. And you say Promises won't work with IE?
00:46
Well, MDN says so
I suppose we can trust them for that, anyway.
Thanks for the help.
01:01
@SterlingArcher nice
01:38
hey. anyone happen to be familiar with including additional js files in a Spring web setup?
somehow the function I defined in mine is not available...
02:25
@Loktar I saw, but I have a total of $4 to my name for the next 3 weeks :(
03:20
How do i access the element in a directive's link function during an ng-repeat?
<directive ng-repeat = "i in [1,2,3]> </directive>

link: function(scope, elem, attrs){
           $(elem).on('click', function(e){
                   alert({{i}});
            }
}
03:41
Hey does anyone remember which good eats episode he talks about brandy/cognac in
Any one want to help me in swift?
@jasbath Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
It's the steak au poivre episode I think
@Meredith whats good eats ep
It's a great cooking show
03:48
@Meredith Do you swift by any chance ?
No
What's your question though
@GioraGuttsait No, you can't do that, sadly.
I had an array, I followed a tut on youtube and the way he setup things is really complicated so every site I go on trying to change my string text to a different colour in the array it fails on me and gives a lot of errors
What do you mean setup things
What tutorial? Code?
03:50
Like how he created the project
And its boilerplate?
@Meredith yeah
My advice: create a project using the best practices you know (if swift has an equivalent to Yeoman, use that), then try to adapt his code to that
HP Spectre looks sleek
Usually your issue comes from not using best practices when starting a project
Or the person who's helping you isn't using best practices
Or both
03:53
@Meredith I'm new to swift so maybe thats why
It's 100% why
Which isn't a problem at all, just take your time
I am
Yeah if you're working in a new environment, I recommend using yeoman
Definitely check it out
You don't really need it once you're used to an environment, but it's a good way to see how pros structure their apps
what is yeoman?
It generates projects
03:57
link?
It's pretty straightforward
You need node in order to use it, but you're in the javascript chat so yeah
Although if your IDE or the tool you use has a generator, you should use that instead of yeoman's.
I have no knowledge of java, just came by to see if there was a swift dev in here or not
This is not the Java room.
Yeah we're pretty sensitive about that
04:00
About what?
We write javascript, not java
Mistaking JavaScript for Java.
My bad I had no idea
04:57
how can i replace

this sentence has `some code` and `and here too`

to make it highlight.. i am lookging for regext to replace them

this sentence has <span class='code'>some code</span> and <span class='code'>and here too</span>

I tried to get this but, there are syntax hightlighters but i just need this simple regular express to convert this.
you have no idea what you've done
@Rafee not using regexp seems like a good idea
05:14
MOARNING ALL
I wonder the course in life one must take to get far enough in coding to know to come to the chat room on stack overflow to get a question about swift and they know it kinda relates to java... but yet also now know that there is a difference between java and javascript
!!tell Pyrodante how
@choz Invalid /tell arguments. Use /help for usage info
@Pyrodante 9/10
@Rafee You can write a simple parser.
``````````````````````
05:21
:cough: regex101.com :cough:
But you'll need to handle edge cases
@Pyrodante no, regex sucks. Don't use that for this.
I mean... that's true, but he also could use that for regex at some other point
but I agree, not best solution here
It's just a code.. nobody dies if he uses regex..
Nvm what i said.. I just realised he wanted to match code with regex..
And please tell me its not html code that you want to match with regex..
No, he wants to replace oops with oops.
Wait, SO's parser fucked up.
Even for the worst case, I can help him with regex..
I can help wishing him a very good luck..
05:28
I mean.. there's this:
^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)
But it lacks the flexibility that a parser offers.
what's the point of writing it like this? new Date(...[2016, 5, 6])
> Bruh.. I know ES6
Lol.. exactly
JavaScript Docs.SO if full of bad examples.. :|
06:19
@cswl it shows the emotional state of the writer. In a world were everything is getting closer to following a monotonial robot-like existance, the author decided he wanted to differ. He wanted to show how important was it for him to change the world, aware of the risks he could cause. His life has clearly left him no choice. He thinks of every part of a date to have it's own meaning, while still being unified under a complementary container, a metaphor for life and all of the things in it
4
heh
you're so shallow guys
and gals
chao cac co o/
@Nimphious nudge
hey guys
i am having issue in angular js
hope you can help me out
06:34
!!welcome blankHead
@blankHead Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
ok thanks
0
Q: angularjs:-how to implement click on div for image to be loaded

blankHeadHi I am trying to implement a click event after the div is loaded.. the following is my html file:- <script type="text/ng-template" id="grid-12"> <div class="row" id="grid-121"> <div class="col-sm-12" style="border: 1px solid;min-height: 300px;"> <input ng-click="onChange($fil...

we're missing Angular users in the room >.>
> Me:"You can't just judge someone by the brand of car that they drive..." Wife: "No, but I mean like you know that those bastard Toyota drivers are doing the same to us, right?" Me: "I think you're missing the point. .."
06:55
@blankHead I dont understand your question at all..
Can you explain a bit more? What happens if you click on that input file.. Does it call $scope.onChange function properly?
Then, what are you trying to achieve?
What does $file return?
the issue is when i click on a particular div I can open a modal for options,but when i am trying out on image for eg when i have two images on a div want to trigger the modal twice i am not able to achieve it
@blankHead once you realize how to hook clicking on a div with its event handler in angular, the problem is no longer an issue with angular I hope you realize
You have a handler that does something the first time and something else the second time
lol Forgot about my nudge.
user4196492
07:05
I'm back at it again trying to figure out gravity. I am so close. It works pretty well, but I think I'm doing something wrong...
You can do this by using states, or by reassigning the event handler
user4196492
oops I lost the link hang on
@pebble225 why? Floating in the air sometimes?
user4196492
it is in space
user4196492
07:06
I play a lot of Universe Sandbox 2 and I wanted to replicated it in 2D
@pebble225 oh, I thought you were talking about a library named gravity ;)
user4196492
yea simulating gravity
user4196492
@Nimphious I need to look into this code...
user4196492
it is beast
07:08
It's probably a bit rough. IIRC i wrote it in less than an hour. But it works eh.
user4196492
does that use any plugins? or is it raw Javascript?
Raw.
Always raw, baby.
user4196492
sweet
user4196492
and I need to be able to test circle intersections
@Neil I know.. but the issue is I am not able to map the images with the respective div and thats what is creating an issue
07:10
Circle collision is just sqrt((x1-x2)^2+(y1-y2)^2)<(r1+r2)
@blankHead if you can do it for one, you can replicate the same behavior in n other divs
Or distance < sum of radii.
@Nimphious distance minus their radii has to be positive
user4196492
@Nimphious that easy??
user4196492
I found a page that made it sper complicated
07:13
Yeah.
user4196492
2 enourmous functions
But since they're moving you'd probably want to do something more sophisticated like this gamasutra.com/view/feature/131790/…
user4196492
it was calculating point intersections tho
user4196492
I can read that oage as easily as I can read Chinese
Doing collisions like this, it's best to try to quit early.
user4196492
07:16
in motion? I would check every tick though
Would be neat to calculate projectories so you know the precise moment when they collide
user4196492
:) yea
So first you'd do a really broad-phase collision test, like AABB vs AABB where the dimensions of each AABB are squares centered on the current position of each body, with a width/height of their velocity plus their radius multiplied by two.
You'd have to simulate in worker and just show it in the main thread
That test is super easy to calculate and super cheap, and will eliminate collisions between 99% of distant bodies, so we only do expensive tests on close bodies.
07:17
Dammit.. my internet was dead.. @blankHead Have you solved it already?
Then you'd do the sphere x sphere sweep test.
True, square roots are a bit expensive
Easy to perform square box check first
Or for bonus points use dot product to determine if the motion vectors are facing each other, and only do the sweep test if that test succeeds.
@Nimphious that may not be more efficient
user4196492
I need brain surgery. all that is left was the melted juice from the maths stuff that I just read. I really need to take trigonometry and Calculus if I expect to succeed in a Computer Science major...
07:19
Trig and Calc are super handy. I've never taken trig or calc classes and I feel it, but learning the stuff isn't super hard.
If you feel the need to take classes for that stuff I'd highly recommend it. It can only help.
@pebble225 in reality, you hardly ever use this type of math unless you're say, simulating universes...
user4196492
like in Universe Sandbox 2 ;)
user4196492
you know what game I'm talking about right?
Shader math, physics collision math, some specific instances of motion in 3d, all can use trig and calculus.
Though some of the most fun programs to write require a bit of math: games, simulators, etc
07:21
Getting a good understanding of calculus and trig functions will help a lot in building your own shaders and working with physics libraries or even rolling your own simple collision setup for specific cases.
@Nimphious true, but again, that is not what most programs deal with
user4196492
@Nimphious Tried copy-pasting this code into an html file. Getting null reference errors! :(
You'll want to either put the javascript in the body, or wrap it to only run after the body loads.
You're putting it in the header, right?
I'm pretty sure that code just jumps straight into adding an element to the body, which if you run as a header level script will go "Uhh, there is no body man, what do I do?"
hi guys
@JohnyNassar Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
user4196492
07:26
@Nimphious that did it! :)
@CapricaSix OKAY
thanks
@towc Such deep thinking.
@cswl you misspelled derp
got this html:
   [ universe
    - div 1
      - div 2
      - div 3
under another div universe element, assuming we don't know anything about that
07:41
We know that it is not a parent to itself
assuming I got the div universe element stored in JS, how do I get div 1 using .querySelector?
element.firstChild
but that's not querySelector
@towc do you not even know if div 1 is first child?
I do
07:43
Is that some random HTML notation I'm not familiar with?
How is that HTML?
I want to fill a datatable with data from my MySQL database, I'm using PHP to connect my form to the database. My question is how can I display my data in a datatable? Can I use $_POST only or should I used an ajax call and JS?
thanks
<div universe>
  <div 1>
    <div 2></div>
    <div 3></div>
  </div>
</div>
element.querySelector('div:first-child')
Are there ever more than one parent div to the universe div?
@FilipDupanović but that can also select div 2, it can cause confusion
although it will work
@Nimphious yes, and we don't know anything about that
could be divs, could be navs, mains...
07:45
Do you want to also select those as well?
no, I just have div universe stored in js
and no, don't you dare use querySelector( 'div[universe]' )
Wait. So you have, in your js, a variable that contains the universe div?
oh, if you don't have the parent div, try: document.querySelector('div[universe] > div:first-child')
indeed
Why not just use universe.children[0] then?
07:46
universe.children [0]
Why are you using queryselector if you already have the element stored in js?
@Nimphious because it's better to follow the code style I was given and use querySelector -_-
@Nimphious ah, beat me to it
So, querySelector will query the DOM using the CSS selector you specify to return an element. querySelectorAll will do the same but return an array of all matches.
user4196492
should I update an objects position before or after I update it's velocity?
user4196492
07:47
in space gravity
@towc no, that is arguable. Selector is not efficient when you're literally just grabbing the first child
@towc element.firstChild and get back to work!!!
@Nimphious hello, this is javascript, I'm glad you 2 met
no one is paying you to write code but to move money faster!!!
07:47
@Neil do I really need to answer that?
@Nimphious what you said was true, but really not relevant
So if you MUST use query selector, why are you not able to do it the way @FilipDupanović said?
I need to use .querySelector
hmm, so do you have an idea what could work for you @towc?
@towc you're self imposing a restriction to do something that is not better in terms of performance
2 mins ago, by towc
and no, don't you dare use querySelector( 'div[universe]' )
07:48
why can't you use div[universe] in the query?
that was right before his message
universe.querySelector('div:first-child') would return the first div.
@FilipDupanović the element is going to be arbitrarly choosable, I only know it's a div
yeah sorry about that query, I was authoring my message when you said you don't want that query
You don't NEED to use querySelector( 'div[universe]' ) because you "already have the elements in your JS" which means you already have the universe element stored in a variable somewhere, right?
Or was that a miscommunication?
07:49
5 mins ago, by towc
@FilipDupanović but that can also select div 2, it can cause confusion
It COULD also select div 2, but it wouldn't.
@FilipDupanović you were already writing it when I pressed enter :P I was talking to nimph
querySelector will give you the first instance.
07:51
Like I said which was apparently irrelevant, querySelectorAll is what might trip you up there.
1 min ago, by towc
5 mins ago, by towc
@FilipDupanović but that can also select div 2, it can cause confusion
Holy shit.
I'm out.
6 mins ago, by towc
although it will work
> Document.querySelector () Returns the first element within the document (using depth-first ore-order traversal of the document's nodes...)
@Nimphious I bet you've never written code for it to be readable XD
07:51
...
you just write it to make it work, right?
It seems that the order is well defined
which is fair enough, but not what I'm looking for
@Neil confusion for the reader
You know CSS doesn't support parent selectors, right?
There's a > selector but not a < selector.
@Nimphious you mean parent?
07:52
can you fiddle this with a problematic situation?
Yeah my bad.
@towc ... you want to use querySelector, and you don't want to use what works because of readability
@FilipDupanović I'm given an element (that I know is going to be a div, but that's all I know) written from a module someone else wrote, and because modules are supposed to be independent I can't know if it has a universe attribute or similar
Since you can't select backwards using parent selectors, and you don't have perfect information about your heirarchy beyond the universe element, and there's no differentiation between your divs other than this random attribute "universe" which you're not allowed to select for, it's impossible to exclude the problematic case.
@towc I think using element.firstChild is legit, because it's just a special case of walking the child tree
07:54
So because of this, the only thing you know is the heirarchy will be something like div > div > [div, div]
@FilipDupanović of course it's legit
@Nimphious there's a fairly complex selector that I know will work, but it's just not readable XD you're so wrong
Which is?
More readable than that, I think is not possible
What is the "complex selector that [you] know will work"?
Please I want to learn it, that would be very valuable knowledge.
07:56
@FilipDupanović yeah, but the code everyone is writing is consistently using .querySelector, which is nice. I don't want to be the odd intern
Not going to tell us?
Ok buddy.
@Nimphious very. Whenever I am in a situation in which I have a selector that works, but dammit, it is just too readable, we can all remember this
I know right.
Maybe you could throw in a jquery selector to pass to querySelector. That would be both ugly and inefficient
@Nimphious is right, for this, you wouldn't need a query selector; is there someone you can ask to do a hallway review if not using a query selector would convey more clearly what's going on?

« first day (2113 days earlier)      last day (3060 days later) »