« first day (2079 days earlier)      last day (2868 days later) » 
00:00 - 14:0014:00 - 00:00

2:08 PM
morning guys
does anyone know how to write a while loop with promises with.then() .then()
 
@Ming Hi, I'm ok with promises, I can try to help - what's your exact problem?
 
Hey all! Could anyone help me try and work out what practice / technique this code is using? I'm not sure if it is obfuscation or not?

http://pastebin.com/WNuUeB9U

Backstory for anyone interested: I am trying to improve my javascript knowledge and I am looking through the source code of a game called slither.io
 
@user1527354 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.
 
@Ming do you mean chaining promises?
 
I know the ws.onmessage is todo with websockets, I am more interested in the code inside the function
 
2:11 PM
@user1527354 minification.
 
Ah right
 
@grasshopper not chaining it . but letting the promise run in a loop.
 
It's just parsing some data @user1527354
 
using array buffers yeah?
 
I can have many .then().then() but i want to loop it based on some condition. just curious on the design pattern @grasshopper
 
2:12 PM
@Ming well, first of all - promises are not run any more than numbers. Promises are proxies for values - functions are run and those functions return promises. Once you have the promise the action has already begun typically.
Second, is that promises chain. You can .then promises to create new promises.
 
@Ming I'm rusty on my JS but i feel like what you might need is q.all then you can loop through the responses?
 
@grasshopper don't use q.
 
Is it common practice to have if statements like that? Meaning getting data returned then seeing what the first character is then using that inside if conditions e.g if (8 == e || 7 == e || 5 == e && "3" != h || 6 == e && "3" != h)
 
Whats wrong with q?
 
var results = [];
for(var i = 0; i < myArray.length; i++) {
   results.push(someAction(myArray[i]));
}
// this @Ming ?
 
2:13 PM
@grasshopper there is a better alternative
 
so much has changed lol
 
@grasshopper first of all - full disclosure - I'm a collaborator in Q and have push access and added a feature to it. Second - it's and old library designed to prototype the idea of promises in JavaScript - native promises are now available as well as other alternatives that are faster like bluebird (full disclosure again, I am also a bluebird collaborator).
 
@littlepootisso which library should i use now? or is it built into ES6?
oh ok I do remember people saying ES6 promised promises among other things
 
@user1527354 those are "yoda conditions", if you forget a = you get a type error and not an assignment. It's doing parsing or a protocol probably.
@grasshopper promises are now native in all modern browsers. I recommend bluebird since it gives better stack traces and does better error handling and has a ton of helpers.
 
@BenjaminGruenbaum this is my problem
Promise.resolve(someFunction)
.then(someFunction)
.then(someFunction)
.then(someFunction)
if (conditionTrue) {
	.then(someFunction)
}
else {
	break
}
i cant just place an if statement in a a promise chain right?
 
2:16 PM
@BenjaminGruenbaum Aha 'yoda', that's brilliant. But I mean the way he/she is getting data back through the socket calling Uint8Array(b.data) on the data and then h = String.fromCharCode(b[2]), then checking the value of h.
 
or this
Promise.resolve(someFunction)
.then(someFunction)
.then(someFunction)
.then(someFunction)
do {
	.then(someFunction)
}
while (conditionTrue)
@BenjaminGruenbaum
 
@Ming yes - that's fine, what do you mean by "break"ing? Promises emulate regular code - I'd chain conditionally.
Doing do/while is pretty simple, you chain on the condition - let me show you an example with for.
 
Are they just getting random bits of data like "hFEDsSEsesefsef£$dfdsadsadsadf" then just doing if("h" = h(first character)) { // }
 
Note that bluebird also ships with helpers like Promise.map and Promise.each
Promise.all(myArray.map(x => fn())).then(... // running a function concurrently
myArray.reduce((prev, cur) => prev.then(cur), Promise.resolve()); // sequentially
Or with a for loop, more imepratively:
var q = Promise.resolve();
arr.forEach(el => {
   q = q.then(() => fn(el));
});
 
@BenjaminGruenbaum That is the connect function yeah. But I'm trying to find a way of understanding the data that is getting passed back
 
2:19 PM
Oh, use something like wireshark if you want to intercept and inspect the data - if it's just websocket the chrome devtools do a pretty ok job
 
But I think it is encrypted? something about array buffers I think?
 
This is what you need
They just made some protocol, that's fine, lots of people do it used to be very common in older days.
 
What are your favorite sublime text packages
 
I don't use sublime anymore, I use atom and visual studio code and webstorm mostly.
 
@BenjaminGruenbaum That looks interesting, thanks!
 
2:21 PM
I use sublime just for text, and a little when I have to edit old stuff
@user1527354 enjoy
 
g Move snake
G Move snake
 
Yup, basically they did all your work for you and reverse engineered it
make a contribution there :)
 
Wish I hadn't spent the past 3 hours attempting it!
 
@BenjaminGruenbaum has atom gotten faster?
 
A little googling can save a lot of time :)
@grasshopper yes, but it's still not great, vscode gotten a lot more stable though - still a little buggy but then again so is sublime.
Has all the general features one needs.
 
2:26 PM
ok, maybe I'll install idk. I was an early adopter but it would take quite a bit of time to start and freeze alot.
 
@BenjaminGruenbaum i'm trying something like this. but it does not work
function num(x) {
	return {
		value: x + 10
	}
}

Promise.resolve(num(10))
.then(function(x) {
	var count = 0
	while (x.value < 100 || count < 50) {
		count++;
		return x.value;
	}
})
.then(function(x) {
	console.log(x)
	})
its meant to print
20
30
40
50
... so on
 
Wait, you just want to write a while loop inside a promise chain? I thought you wanted to perform an asynchronous action in the loop...
Promises represent a singular value.
It's immutable, once you set it it's set. If you want multiple values promises can't do that.
(By design of course, promises solve a very specific problem)
You can look at an observable library like RxJS or xstream or use event emitters if you need multiple values, but honesty if it's synchronous do not use them.
 
i'm working with a library that has methods implemented as promises. thats why wondering how to loop in a promise chain
 
Also, promises aren't magic or special with return, doing a return always finishes a function immediately (unless another keyword follows it that does something quirky - like throw` and take you to a finally.
@Ming again, promises are proxies for values, you can't "loop" promises, you can check for their value and compose values.
You can sequence functions that return promises.
 
any way to solve this? apart form using libraries like RxJS
 
2:32 PM
Maybe you want generators or async iterators? Async iterators are iterators for promises, your code above would be close to working with them but they're still a stage 1 proposal.
@Ming solve what? I don't understand the actual problem you're trying to solve.
 
i want to implement that code i pasted earlier.
 
You can map over arrays of promises, but promises are for one-time things, if you have a continuous promises you need async iterators or observables (at a language level) or event emitters for other stuff.
 
but like you mentioned there were problems.
 
The code you posted before doesn't make sense. You could just place the console.log in the loop. This is only hard if the steps do something asynchronous.
 
2:47 PM
will generators be of use in this case @BenjaminGruenbaum
 
1 message moved to Trash can
@user1527354 Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq. For posting large code blocks, use a paste site like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
@BenjaminGruenbaum Does the value "254" mean anything in this bit of code? Like does it get converted into a character or something?

http://pastie.org/10889931
 
it's probably an 8-bit state thing
254 is 11111110 in binary
which means that out of 8 options maybe the first seven are on and the last is off
or something
 
Oh right so it's not a character code or something
 
shouldn't be
 
usually characters start with 011(0|1) (lowercase) or 001(0|1) (uppercase), with other cases which are usually below the uppercase range if you're dealing with ASCII
 
I think they are just using 253 as a flag itself
But why would they have to convert it to 8bit?
could they not have just sent 253 to the server?
 
@Ming async iterators.
async function*() {
 
@BenjaminGruenbaum thanks. will check it out.
 
3:12 PM
O_O mom?
 
Anyone pretty familiar with bootstraps grid system? I'm have a question about the containers.. just need to talk through it with someone
 
@FilipDupanović happens
 
@Michael shoot and take cover from the flexbox backfire
 
i havent learned flexbox stuff yet
 
3:18 PM
Hahaha, nice
 
@littlepootis nobody likes badly resynchronized videos… don't you notice the lips don't match the sounds?
 
the parts where he's disclosing that he's banking out with his hands clean are perfectly synced
 
Jes
Hi Friends
Need some help to read a log with regex
can somebody come to my rescue?
Jun 10 14:10:47 gvsansw03 raslogd: AUDIT, 2016/06/10-14:10:46 (EDT), [ZONE-3007], INFO, ZONE, admin/admin/192.168.250.18/ssh/CLI, .....thats my log string and i want to read each work and store in strings vars.
first 15chars will be timestamp
need to get the work AUDIT.. how?
 
where are your logs?
 
Jes
Jun 10 14:10:47 gvsansw03 raslogd: AUDIT, 2016/06/10-14:10:46 (EDT), [ZONE-3007], INFO, ZONE, admin/admin/192.168.250.18/ssh/CLI,
thats from the log file
 
Jes
3:41 PM
@FilipDupanović thanks but i m doing this in JAVA
 
try this exact match with a capturing group ^.{15}\s\w+\s\w+:(.*)$; it should capture the bit after the ts, server and service
 
@bwoebi It's got pretty good Up:Down vote ratio, same w8 m8.
 
coz regex is basic for java
 
Why would uint8array cause an maximum call stack size exceeded error o.0
 
Jes
3:52 PM
@FilipDupanović thanks coudl you pls tel what does this mean
w+ means?
 
means that a match will require one or more alphanumeric characters
 
Jes
thank you
 
@user1527354 that mostly happens if you have recursion... what's your code..
 
@Jes sorry, I forgot the introduction, please hop over to regexr.com, it will help you compose/decompose your expressions
 
@cswl I think it's two web sockets calling each other? Can we go into a seperate chat?
 
3:59 PM
make an mcve.. and maybe we can all help.. no one is going to debug your application for you..
 
mcve?
 
> Brexit sounds better than UKexist
 
not EUfault
 
@littlepootis "bremain"
why is that not a thing
 
EU supposedly has a lot of regulations that contain the word pillow in them when translated to English
 
4:31 PM
95
Q: Is it safe to keep a MacBook in the fridge to cool it down?

kenorbI've a got longstanding problem with laptops overheating (MacBook Air/Pro) and it's not only related to one machine. The laptops are overheating especially during hot days (summer). I've found that keeping them in the fridge for half an hour makes a dramatic difference in their performance. Howe...

 
@Victor hi
 
can't pull out a dry Mac out of a fridge, can't put wet money into boiling water to dry it off... why can't life simply htm basic for Java with jQuery?
 
4:46 PM
I've been trying to use this answer to check if a point is inside the circle but it doesn't seem to be working correctly. Here's my equation: var r = Math.pow((conn.snake.body.x - 0), 2) + Math.pow((conn.snake.body.y - 0), 2);. It seems to work fine but when I check if it's less than Radius^2, I always get true. Strangely, when I try to output Radius^2 inside the console, I always get 2, even when I add text before/after it.
In case you're wondering, the radius is 21600
 
5:07 PM
@RowanHarley code?
There's something wrong with your code, apparently.
That formula is correct.
 
5:22 PM
Well in that code, you are subtracting the radius from x and y coordinates... also in the above code you don't need to subtract zero... inCircle = ({x,y},r)=>x*x+y*y<r*r
 
I've also tryed subtracting 0 instead of the radius.
 
What is your coordinate system?
 
The ^ is not the exponentiation operator. It's the bitwise xor operator.
 
Oh.. totally missed that part.. o_O
 
I'm using the Cartesian coordinate system as far as I know
 
5:26 PM
^
 
@RowanHarley Replace R^2 with Math.pow(R,2).
 
new feature in ES2016, the exponential operator.. ** :O
4
 
I've changed that but now I don't get any message when the point goes outside the circle
 
Yes, do you know why?
 
5:33 PM
I just saw R being subtracted and stopped reading the code.. I'm a lazy person :|
 
Hmm... not really sure, is it the < operator?
 
@RowanHarley you should add a .gitignore to your repo...
 
I probably should. Never really understood the point of them
I'm gonna have a bit of a read up on it now
 
Also you totally copied that CONTRIBUTING from a java project..
 
I know
Couldn't really think of what to add
I'm gonna change that later
It was well-written anyways so...
 
5:47 PM
The code doesn't even follow those guidelines.. There's tabs everywhere :|
 
I've just fixed that! oops...
@cswl Any other mistakes... -__-
 
The whole code is a mess.. refactor it.. even better rewrite it...
 
what do you mean? The comments or just the code in general
 
@RowanHarley It's the condition
 
So I'm doing something wrong with the positioning then
 
6:04 PM
you know what spaghetti code is?
 
ya
That's mine isn't it...
 
 
2 hours later…
8:12 PM
My tripod is complete :D
 
8:25 PM
how should I build a nice 2-column news feed in a responsive ui?
I would use flexbox, but AFAIK every item of a flex box gets the same height
 
9:11 PM
@Victor your knowledge is highly incomplete ;)
 
@towc regarding flexbox or in general?
 
not sure about in general and I'm not that rude :P
meant in flexbox
sorry
 
just for fact, I am currently using a classic two column layout, but will not keep the reading order on mobile, when columns get lined one above the other
@towc it's ok
@towc could you please tell me where I'm wrong then?
 
flex box elements can have different height and widths
just try it :)
 
9:27 PM
can you guys explain whats wrong with my code?
Usually this works but somehow I dont get the updated values anymore
 
wow, 896
 
lol
nevermind
i found the issue. Im so dumb at times
It was rounding it down to 0 the entire time since I parsed the number as an int
 
good job :)
 
@towc ya its from a friend of mine. Crazy huh?
By the way, im going to release my CSS preprocessor soon, written in C :D
right now you can only set variables.
 
9:45 PM
Ok so I'm testing a directive in angular. I'm doing element = $compile("<my-directive></directive>")($rootScope); and $rootScope.$digest(), but my element is just a string that looks like "<my-directive></my-directive>". I probably missed something obvious, what's the usual obvious stuff people miss on this?
I also tried $rootScope.$apply() per someone's suggestion but that didn't work either
 
10:17 PM
Anybody use Steam for games? Looking at options to buy a game? What's a Steam "4-pack"? I see no way to get more info
 
you know a 6 pack?
a 4 pack is a 6 pack after going to Burger King
 
@taco That usually means you get 4 copies of whatever it is
 
Thanks, Satan
@VeronicaDeane so I would get 3 keys to give to friends?
 
ok interesting.
thanks
 
10:35 PM
howdy
 
hi
 
i need helping compiling my node into java
trolling :)
 
11:00 PM
:d
 
Using ReactJS: Is it preferred to call setState() once with multiple values instead of multiple times in a row? Is it "cheaper"?
As setState() calls other methods it should be cheaper to just call it once, right?
 
11:28 PM
yes, probably
don't think you have to be concerned much about the component API, though; React's element tree reconciliation is probably what's going to be slowing you down the most
 
00:00 - 14:0014:00 - 00:00

« first day (2079 days earlier)      last day (2868 days later) »