« first day (2873 days earlier)      last day (2299 days later) » 

00:00
its funny because this is so far removed from my original question
it wasn't a contradiction, i was suggesting the other way around. the second sentence was if the other way around wasn't possible, use an array instead
if you just want an answer to a question then use the main site, not chat
otherwise people will discuss what you're doing
dont mind discussing
but we arent discussing my question lol
What was the original question
you asked for the best way to do it, same browser window or multiple browser windows
and then when people said multiple browser windows you wanted to know about communicating between them
with same browser window i asked if anyone could recommend a good framework for designing window type functionality within a browser
00:03
and then we said just use multiple websockets
and then you said you can't do that, so i'm trying to figure out why you can't
websocketarray could be like a timeline. It can be like blockchain. Your wesocket array can be the token
Like
a window system within a browser tab?
yes kind of
What does this have to do with websockets
i am tryign to write a poker game
backend is in c#
frontend in javascript
simple example of funcgtionality is to login
get table list
open a few tables
and sit down/play
00:06
And what's the problem?
i said iw as thinking about eitehr implementing it on one page in one browser, or have the table list in one browser, and when you open up new tables it opens up new browser windows with that table on it
david and others suggested to use REST api
i said i am not using rest i am using websockets
they said to use a system where everytable is opened up in a new browser window and establish a new websocket on every table
i made my case that it doesnt make sense to reestablish a new websocket for every table i open
Actually, this seems like a great idea. every time you log in your web socket array grows. Your authentication becomes more secure with each game play. seems like an awesome idea. I am going to patent this.
Yeah you wouldn't create a new connection per table
*not reestablish, establish
i made the case that to me, it makes much more sense, and this is how i coded it, to have one server, that opens up a ws connection when you log in through the main portal, and have it manage all communication to and thro
messages are parsed when they are received and dispatched accordingly in the service
I'm not really seeing the issue
Just create a room for each game, then have users join it
00:11
well my issue is
Don't create a new connection per user-game
i asked
if i were to create new browser windows for each table
would it be possible to relay ws message to and thro the parent browser window that opened them
Sure
So if the main client portal receives ws msg, update table X, client portal knows that browser window that holds table X needs to be updated
and updates it
Just have all of a user's connections join a room
Then broadcast to that room
00:14
i dont think youre understadning me
Probably not
i go to mypokerpage.com . it establishes ws connection, logs into service, i open up a few tables that are each in their own browser window
i receive ws message in main window, update table X
can i then forward that ws message to the browser window that houses that table
Or just send the message directly to window x
how do i do that
Give it a separate connection
00:16
lol
:43742646
@Meredith you good with algorithms and data structures?
I guess
i didn't say to use rest :P
Meredith
Yeah you wouldn't create a new connection per table
Meredith
yst 20:16
Give it a separate connection
Yeah
00:17
i said allow multiple websockets per user
You probably want to run the games in the same tab
Like I said earlier
how would you traverse a binary tree in linear time?
what if he opens two tabs? will one of them just not work?
what do yo mean how
Why?
00:18
do you know what a binary tree is?
because that's what will happen at the moment
two tabs of what
I just want to know how you would approach it
the website
If they open two tabs you can send the data to both tabs
Duplicate the data in a linked list
00:19
is the list sorted?
that was to rick
misunderstood what he asked
easiest way is recursive algorithm
but it has to be linear
and?
linear with respect to how many nodes there are?
or leaves
recursive will touch same object more than once
no it wont
@david what are you talking about
@david i dont understand why you cant accept the fact that only one login is allowed at a time
any number of leaves why do the number of leaves matter
00:22
i am clarifying what youre asking
since you said linear and i offered you a linear algorithm
that you said isnt linear
@cubesnyc it's not that i don't accept it, i'm just trying to explain to you that it's silly, and comes about because you're doing something wrong
I am saying a pure recursive answer will mean you would need to walk back up the stack
@david its silly?
to traverse the adjacent nodes
@david have you ever played on a poker site before?
who cares if you have to walk back up the stack
its linear
class Node { public Node leftNode, rightNode }
00:27
by walking back up the stack frames you will be touching the same node more than once. after having exhausted the first base branch
that means double work O(n^2)
Can we get back on topic
so according to you
No one cares that you just took a data structures class
i am touching every node, the total amount of node times
I think we need to get back to fundamentals, all this talk of web sockets, frameworks is making us lose track of the things that really matter. Node lists, binary trees and arrays, maps, and associative arrays. @cubesnyc so what would that look like. you can write it in C
00:31
what would what look like?
the code
to the recursive function?
ya
Or just draw a picture of your traversal algorithm and you'll see that it isn't linear
Also making an algorithm recursive rather than iterative rarely changes the performance characteristics
Just hides certain details
Man America's Got Talent pissed me off
00:34
So just draw a picture of a (directed) binary tree and try to traverse it
@Merdith I have traversed and I have done it recursively and iteratively. I have yet to see a linear time solution
Constant time traversal?
linear time
	int CountNodes(Node parentNode)
	{
		int count = 0;

		if (parentNode == null)
			return 0;
		else if (parentNode.leftNode == parentNode.rightNode == null)
			return 1;
		else
			return count + CountNodes(parentNode.leftNode) + CountNodes(parentNode.rightNode);
	}
1 message moved to Trash can
@cubesnyc Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
00:37
class Node
{
	public Node leftNode;
	public Node rightNode;
}
use ctrl-k
The linear algorithm is duplicating all insertions/deletions in a linked list
thats linear time buddy
we will see
what do you mean we will see
lol
how is it not linear time
00:42
I don't know yet, but I am going to be counting the iterations
Just use your brain?
recursive functions have frames. it's not strait forward
Recursively traversing a linked list does not require a stack
there is if there is a return
What is that even supposed to mean
Like really
00:46
it means he is is using tail end recursion
first off all
your assertion that its n^2 is flat out wrong
I didn't say your apprach was O(n^2)
but it isnt
lets say you have 3 nodes
parent and two child
Yeah actually it might be linear now that I'm thinking about it more
count(parent) => 0 + count(left) + count(right) => 0 + 1 + count(right) => 0 + 1 + 1 => 2
according to you that should have taken 9 steps
00:51
clarly your example is contrived. what is happening when you first step into the left node? you go to the next left node
and so on
untill you reach null and then you exit
then you check the right and left nodes as you walk back up the left most chaing looking for a right and a left
fno its not contrived
btw count should be initialized to 1 not zero
when you return a value
and walk back up the stack
I am saying, that you are rewalking the path
you continue from the same instruction you left
Whether you iterate a list once or twice, you still get O(n)
if you have to go two block sup and two blocks left
does it matter if you go left up left up
or can you only go left left up up
00:58
I only trust @KendallFrey with this stuff. epxlain how two passes is still considered O(n)
lol
Because 2 * O(n) = O(2n) = O(n)
big-o notation explicitly ignores constant factors
if a line is defined as f(x)= x + n
is it no longer a line if its 2x + n?
Gooood Dam it!!!!!!!!!!!!! I have been forsaken. cool that makes sense
If you're still on the binary tree thing, then yeah the recursive approach should be linear.
i still dont see how its O(2n)
01:01
How what is?
recursive
I'd say it's O(3n)
but constant factors are arbitrary and don't actually mean anything
It "visits" each node three times. Once entering it, once moving from right to left, and once exiting
assuming something like visit() { this.right.visit(); this.left.visit(); }
^ true that! Sorry @Meredith I needed a mansplination. @KendallFrey you are my go to Timecomplexity guy :)
01:04
right
your welcome for the code
youre
umm, i thought i was going to see somerhing new
@cubesnyc maybe if you have done it iteratively I would have been more impressed.
What does it mean to iteratively traverse a recursive data structure?
using a while loop and an stack
But how would that even work?
i just think its funny how i spent 20 minutes explaining it to you and you didnt thank me when you came to terms with me being right
01:08
you mean pushing to a stack and iterating breadth-first?
you were right for the wrong reasons. there is a difference
my wrong reason being what?
@KendallFrey correct
@cubesnyc because you took it as dogma that you were walking the nodes only once
i dont know what yo umean by walking
the machine code would pick up from where you left off in the stack
if by walking you meant returning to the stack then ok you got me
its o(n^2) or whatever retarded number you came up with
I think it's important to be right because of the fact and logic. If I wanted to take things on dogma i would have become a scientologist or born again christian
01:17
You seem to accept logic dogmatically :)
and yet you refused to accept either
and when i showed you how its linear
you called it a contrived example
@cubesnyc it was contrived because your sample was small, and it didn't adress what your method was actually doing.
im pretty sure you still dont know how it works
@KendallFrey it is my achiles heel :) knowing why something is wrong is better than just knowing why something is right
@cubesnyc I explained it to you after you provided that contrived example
maybe you think you explained it
but you didnt explain anything that proved your point
why dont you write up the code to do it iteratively
and see which one takes longer
02:06
@KendallFrey I was trying to figure out if it's O(n * c) or O(n * depth)
Because obviously if it's times a constant, it's linear
But depth can grow with n
depth doesn't affect any given node, only breadth will affect that, and that's fixed for a binary tree
Oh yeah that's a very easy answer
Which makes the traversal complexity O(min(depth, breadth) * n)
well no, depth doesn't factor in at all
It does if it's wider than it is tall
and strictly speaking neither does breadth
No, it doesn't
02:11
Why not?
Well, why would it?
> depth doesn't affect any given node
idk tbh
Unless you know of something I missed
trees are so hard to reason with sometimes
But you do have to visit each node twice, right?
It depends what you mean by "visit"
but in any case, depth doesn't affect that
02:13
But breadth does
depends
it doesn't increase complexity though
In the sense that O(2n) is the same as O(n)?
i have a library that uses styled-components. i also have an app that uses styled-components and my library. when i build that i get broken styles and message in the console saying "It looks like there are several instances of 'styled-components' initialized in this application."
even if you include a constant factor, you don't get twice the constant with twice the breadth
So in both senses
idk this is too hard for me to think about after taking my sleeping pills
02:15
my questions then are a) is it really not viable to have two installed styled-components? and b) what is a strategy to fix this? is requiring style-components as a peer dependency of my library a reasonable solution?
(don't try to solve leetcode problems after 10mg of ambien take it from me)
There's probably a logarithm in there somewhere
I doubt it
There's always a logarithm
if it depends on the depth then there's a logarithm, the depth is going to be log(n)
base 2
where there's a question there's a logarithm
02:17
You can redistribute any constant added by breadth among the child nodes, bringing it back to 1
but for traversal i doubt the depth matters
Oh wait yeah it clicked now
Yeah depth and breadth don't matter
i build my library to a bundle.js file and then import it in my app. so my app's webpack pass than makes a bundle.js from that bundle.js plus the app presumably. is this bad practice?
Is this what you guys are trying to analyse the complexity of? jsfiddle.net/ctrlfrk/zfoqsh60/5
user8871181
Can someone please answer a simple question for me..?
02:30
@demonhunter24 Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
we won't know if we can answer it till you ask @demonhunter24
user8871181
In the following function I have two statements.
1 message moved to Trash can
@demonhunter24 Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
user8871181
to be fired before the first statemnt
user8871181
....I keep accidentally hitting ENTER instead of SHIFT + ENTER
02:34
i think you need to click on the 'fixed font' button that appears next to send
or ctrl+k
What's up?!
user8871181
Let me start that again:

In the following function I have two statements
- First I get an element by ID
- Then I perform an alert

    function myFunction() {
        document.getElementById("demo").style.display = "none";
        alert("Alert!");
    }

I am generally curios as to why the `alert` is fired before the `document.getElementById()` because according to <a href=“w3schools.com/js/js_statements.asp”>W3 Schools</a> JavaScript statements are “executed, one by one, in the same order as they are written.”.
Put it in jsfiddle
user8871181
I am simply asking why an alert is fired before anything else regardless of it's written order.
hello
@demonhunter24 it isn't
02:41
Hi
What happens when you try
@demonhunter24 what I suspect is: they're executed in the order they are written, but the page only re-renders once everything is finished
however there's no guarantee of exactly when the browser ---
what david said
function myFunction() {
    document.getElementById("demo").style.display = "none";
    alert(document.getElementById("demo").style.display);
}
user8871181
@david that makes sense..
02:42
Yeah try what Meredith posted, you'll see that the style value is updated, but the page just hasn't refreshed yet.
and it won't refresh till you dismiss the alert
user8871181
are you saying that the function will "run through" and only change the appearence of the page after all code has finished executing?
It updates when it feels like updating
user8871181
:D
there's no exact specification on when the browser must flip the screen
yes, repainting the page is quite a slow process so you don't really want it to happen while your code is running
you should maybe look up reflows and repaints if you want to learn more about it
they're quite important performance considerations
user8871181
02:44
any good references?
Chrome puts out a ton of blog posts
I would just go through them
all browsers act mostly like described in this link
i haven't read articles on them in like 5 years... just do a google search and some good stuff should hopefully come up
user8871181
ok, thanks for shedding some light. And clarifying how the page rendering behavior works.
You're welcome :D
03:24
can i use instancing with styled components?
e.g. make runtime instances of SC so that when i have two versions of SC they don't clash?
 
3 hours later…
06:25
@david comprehending it makes your life sometimes easier: both on short and long term than just looking for code, copying it over and "checking if it works"
06:36
I am handling exceptions in ajax in a way that in case of a successful operation I am outputting JSON data and HTML in case of error, since the dataType is json in ajax. I am able to handle the exceptions well
In this a OK OK logic?? I guess there are better ways to do so
can anyone suggest me ??
@AbhijitBorkakoty You mean the returned output from the server is html or json?
no, bad idea
@Neil in case of succesful operation output is json and html in case of exception
You can add html to a json response if that's what you want, but make the response standard
probably json with a simple property indicating if the response is good or bad
if it is bad, you know to show the html also passed with the json response
@Neil but if I output json in case of exception, then the success method calls itself, and it is no longer an exception
true, so you'll need to create the exception yourself
06:42
how do I call error method in ajax and not success
in other words, exception doesn't occur when you parse result from server
success should not be called right??
exception occurs when you read your json and your json shows that the request didn't go well
just return with {error: message}
it is "success"-ful in the sense that you parsed it
06:43
and after parsing, check if error is present. If so, prompt that error
add an additional check that it went well
error method does get called if I output json
critical errors should respond with HTTP 500 which you can catch by looking at the state
error method does not get called if I output json
@AbhijitBorkakoty you're redefining what success and error mean in this situation
success = valid json returned from server, error = gibberish? wtf?
06:44
you have to re-factor the server code a bit. A request should respond with an uniform answer
on success, add an additional check
You mean I will perform a check in success method of ajax if the json is correct or not
if valid json has property called "isOk" and "isOk" value is "false", then throw an exception
> just return with {error: message}
yes, exactly
you're just adding another layer
at this point server always returns json
06:45
i usually return with {errors: ...} (all my api methods do that)
if it doesn't, then it is a serious issue :P
@KarelG well okay, if you want to be elitist then fine ;)
it makes life easier and allows you to have one function to handle requests
Okay got it. last question .... How do I throw an exception from success method in ajax??
you do not have to create an exception "branch". Just handle the flow appropriately
like
and also KarelG makes a good point.. it doesn't have to be an exception
you just have to handle that situation, that's all
06:47
const json = JSON.parse(...)
if (json.errors) {
  showErrors(json.errors);
}
else {
  handle success
}
got it...just show the error message on a div or something
right
and showErrors displays a prompt or overlay or a red box on the top or whatever
@Neil i console.error HTTP 500+ errors with 'something went nuts' :P
okay thanks...but the doubt is why is there a error method in ajax
is success does everythinh
server failure like HTTP 500
does it handle 500 error automatically
??
06:51
@KarelG nice
"some eldritch horror got loose... run!"
@AbhijitBorkakoty because you're parsing html as json
So the exception is thrown for that reason
It isn't "ajax" handling that error for you.. you've caused it
there is a function to parse json safely
I have that in my main module:
function tryParseToJson(text) {
    if (text) {
        try {
            const jsonObj = JSON.parse(text);
            if (jsonObj && (typeof jsonObj === "object")) return jsonObj;
        }
        catch (e) { }
    }
    return null;
}
does not break the flow

« first day (2873 days earlier)      last day (2299 days later) »