« first day (3015 days earlier)      last day (2158 days later) » 

01:51
morn
 
3 hours later…
05:06
morning people
 
1 hour later…
06:09
how to detect mongodb database changes in nodejs ?
i found mubsub and socket-io-mongodb libraries but they does not seems to be active in git repo
06:41
@jagdish just went through this myself lol
you have to convert the database to a replica set and then watch for changes on whatever collection you want
@davidkamer i found way to watch on capped collection also
really isnt there any other alternative ?
I spent about 5 hours looking for one monday/tuesday...
I never spend 5 hours looking for something...
you could do an interval that checks the db every 100ms but that is evil beyond anything I know lol
replicating database seems evil too
but converting to a replica set only takes 2 lines of code. You update the config file and run a command if I remember correctly
you don't actually have to have more than one
i have 2 apps and 1 db
both for edit and watch
so i will have to make 2 sockets on each side
and its bad
07:00
2 sockets on each side?
yea i am already retrieving data using socket
but it is non capped
capped?
non-capped
now for viewing i will have to use socket for capped and socket for non capped
can you explain what you mean by capped? Like limited usage?
and generally you only need one socket server. Two would only be needed if you want to sandbox one from external network
currently i have db with non capped collection
to update -modify data
can not have live sockets on non-capped collection
so to have watch on db live i will have to make another socket and connection with capped collection
07:12
@jagdish That probably means you have an issue with your arch if it is that important
not till now
but i guess i will have
we cant update /modify document in capped collection thats my problem
only retrieve and insert
Shouldn't you just not repeat data?
I mean I guess if it makes sense, but why wouldn't you be okay with leaking data if you even need a db? I could see how you might use that, but doesn't seem like something one would do given a situation where you had that much data to process...
like once you get that level of traffic, usually you have the resources to deal with the extra data
and if you're using a db that implies the need for permanence
what do you mean with "capped"?
07:20
so I guess if you're in the grey area of short term permanence and and not enough money/resources then maybe capped is a good idea... but then you could just cache the data somewhere imo
like reddis is probably a better option at that point
@KarelG first time I heard of it too
at least in this context lol
so, a fixed length collection
or "static" collection
seems to me like something for redis
yup redis is a good idea ..
and hey, if you have low memory, just make your swap partition huge lol
^^this is a joke by the way, but knock yourself out trying it
i think its a location data ...
07:28
@NilasisSen yeah but at that point, you should abstract the data and filter data out yourself
like "it was here from 12-22-2018 to 1-1-2019"
instead of just throwing all the data away
ya if that's a requirement . or else just throw it :P
when i use mubsub or socket.io-mongodb from npm they creates capped collection
and i they detects changes on that collection
now this capped collection can only have insert and retrieve of data
we can not modify them
you can transform a collection to a capped one
so when serving the watch socket, give it a copy of the collection and make it capped
(or just cap it. Not sure if it reflects to the other socket. But seems plausible if both shares same instances)
 
1 hour later…
09:00
Hi
@Osakr 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.
09:16
Hey guys. I am working with HTTP requests atm and I am just wondering if it is possible to write a wrapper function for XMLHTTPRequest where I would be able to call the function like this. Would i need to use await and sync to do that? or do I need to insert a callback inside getUserMessagesByToken?

const userComments = serverstub.getUserMessagesByToken(localStorage.token);
Do you know about Fetch API ?
it is a promised based ajax request.
there, you can use async function and await fetch inside to be able to do that
09:36
Hi, before I post this as a question at SO, I though i'd ask it here:
I have an array, say `name=['a','b','c'];`, and a `values=[1,2,3]`. I want to end up with `{a:1, b:2, c:3}`
Yeah I know, but for the labs we're suppose to use XMLHttpRequest :P.
However I managed to do a wrapper function with sync and await together with XMLHttpRequest. @karelG
Im looking for a lightweight solution, and if possible a native function
@Martijn reduce
I prefer not to loop, as im already in a loop (I have many values, on name)
hm, that seems promising
not to loop? You are going to walk through the array already
there is no solution without "loop"
09:40
Sure, but a native js function might browse more efficient than a loop by me :)
a for loop is the simplest and fastest way if you want
then i'll loop haha
easier to make/understand too
you can do it quickly
like
    const matchValuesToKeys = (values)=>{
        const parsed = {};
        for(let i=0; i<columns.length; i++){
            parsed[columns[i]] = values[i]
        }
        return parsed;
    };
@Martijn Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
09:44
const mixAndStirr = (names, values) => {
  const obj = {};
  for(let i = 0; i < names.length || i < values.length; ++i) obj[names[i]] = values[i];
  return obj;
}
Thanks, working perfectly :)
Was thinking too complicated, it's still morning here
Hey what is wrong here? Should xmlHttpRequest or login functions also be async?
https://pastebin.com/eetB5cYq
Hey there fellows :)
I'm kind of fan of syntaxic sugar and was asking myself if there was a shorter way of writting this ?
argv.website === 'naissance' ? 'naissance' : 'fairepart'
if (argv.website !== 'naissance') {
  argv.website = 'fairepart';
}
depending on what the context is
Thats not really shorter, hehe
09:51
@Martijn because there's no assignment on his side
havent been here in a while
@sockevalley Lmao, did you even read how async/await works? You can't just tack it onto a standard callback
@BenFortune lol no, clearly not enough. How should you proceed in my case?
I read here before:
https://javascript.info/async-await
you are using await on a non-promise object.
so what it does is not waiting, just processing. Make it as a promise
Right...the callback doesn't contain a promise object
I reckon that I should wrap request.onreadystatechange inside a promise object and resolve it once it has finished?
10:03
meh, just use fetch
That would result in me not learning it :P
you can argue that you are learning something, using the right functionalities for your task
you don't use a screwdriver to nail a nail.
I did it :D Thanks for all the support, you guys have been like the captain of the orville to me... like how he was for alara etc. cheerios
who? ._.
The Orville is a Seth McFarlane version of Star trek
semi seriues scifi, semi comedy. IMO quite a good balans between the both, I enjoyed watching it :)
10:17
For sure, if you like his humour and sci-fi then that show is for you. I was referencing the lastest episode in season two which recently aired :)
Hi guys, can somebody give me some advise on where I can find some tuttorials on how using webpack with babel-preset-env and browser list?
@KostyukRostyslav 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.
@KostyukRostyslav are those information not on webpack itself ?
I used that before. Or you can just google with those words to end on blogs
There are fine, but I still can't find answare on one question. When I have webpack.config.js file and I have my babel.config.js. Do I need to import babel configuration manually or babel-loader will do it for me?
@KarelG thank you for replay
Hi there
Can you take a look at this question
0
Q: Add or avoid adding a property in an object depending on a boolean within the object itself

OsakrBasically I wonder if I could avoid adding a property into an object if a variable is false but from inside the object. So let's say I have this object: var obj = { foo: 'bar', bar: 'foo' }; Now I want to rewrite the same object but I only want to add the second property if a new variable, wh...

10:31
the color indicates that it as an answer already
Yes
but read my edit
it has been answered very well
a right
how ever I'm looking for any other was of doing it without spread operator
no spread operator. ok
If there is no other way of doing it, for me would be also a valid answer
10:34
I think there is a way without using spread
One more thing, if you think that is a good question I would be so happy to see an upvote :)
but it depends of your reason of not using the spread.
is it for browser compatibility?
no
it's because I use ExtJS
and when I compile the app it fails because it doesn't support spread operator
It would if I pay the license of the new version
but since it is not my decision, i cant haha
ah.
better to add that. There is a way :)
do you want to know it?
of course
10:38
!!> let b = false; const obj = Object.assign({foo: 'bar'}, (b ? {lele: 'lele'} : {})); obj
@KarelG {"foo":"bar"}
if you make b true, then the second object is added
Which version of ExtJs are you using?
I tried to do that
but without the Object.assign
im testing it and ill tell you
thanks you
@sriya 4.2
oh, there is a comment mentioning object.assign
@Osakr You should have mentioned that, as it really reduces your options. The duplicate I commented a bit ago may have more alternatives: stackoverflow.com/questions/11704267/… - Not to mention, the same answer that bergi provided in the marked duplicate also includes an alternative without the spread operator, using Object.assign. — Tyler Roper Jan 11 at 16:45
gotcha leave it as it is
10:42
Alright didn't see it
It does work perfectly
Thank you so much
By the way
do you think that the question is good? I mean, I usually get downvoted and I try to do good questions since I try to edit and flag bad questions
but I always got downvoted or not voted at all :D
well, some of yours question got asked by others. The thing with this community is that "decent" question gets dowvotes very fast if it is kinda straightforward or got asked already
yeah, a lot of it is just mob mentality, don't take it personally
I just point to the dupe or explain the little bit to assist the OP instead of downvote
yes, I always try to find first if it has been already answered but since my english is not good enough I don't find it xD
you can try to learn how to work with SO search tool
10:48
All it takes is the first guy to read it to think it's a duplicate, and the first downvote tends to encourage the rest to follow
eg looking for a python question, search in python questions
that can be done with [python]
yeah, I know
but the words are not the same when I do the question haha
yet, it happens that i am not able to find a good question while another did.
it helps to try to explain the problem to yourself in different ways
sometimes that even gives you new insight you didn't have before, but at the very least, , it helps you search for the answer
yes, indeed
 
1 hour later…
12:10
Hi
i am trying to implement the logger for the node js using winston, morgan and winston-daily-rotate-file packages
the problem is when if it is a network request the log file and the folder is not creating
if i change something in the code and save it then the folder and the file will create
anyone has gone through this problem
you need to clarify that more:
> when if it is a network request the log file and the folder is not creating
!!afk lunch
so I have an old vice
with jaws that were welded in
should I try to get them out?
12:42
@BartekBanachewicz yes.
Keep in mind that I have no experience whatsoever in this subject, and very likely, the result of listening to my advice is risk of fire or utter catastrophic failure.
@BartekBanachewicz I am curious about the reason for that
better support?
 
1 hour later…
13:52
better grip
I want to see some pics tho
Trying to imagine it :P
wiiiiiiiiiiiiiiiinstooooooooooooooooooooon
got your favourite!
@Neil oh
@KarelG typically when one goes missing and someone can't be bothered to find a replacement that's the easiest way to repair one
also yeah, if the jaws aren't properly maintained, it at least keeps them in place
 
2 hours later…
16:09
for a number isn't shifting >> the bits by 1 the same as dividing by 2 and truncating?
user1596138
No?
user1596138
!!> 9 >> 1
@Jhawins 4
user1596138
Yes?
user1596138
Idk lol
16:12
ya brah think before you leap lol
!!>4>>1
!!>5>>1
user1596138
Hey I used a question mark
yes
so is >> 2 also dividy by 4
16:22
hold on let me see if i can get my counter example
!!>Math.trunc((-2 + -1)/2)
@Rick -1
!!>(-2+-1)>>1
@Rick -2
maybe it's the order
of operations
😐
16:25
@KevinB just say it!!!
it's probably something stupid I'm not seeing.
'm still not seeing it, so if you see my mistake point it out
what are you not seeing
why I getting two different results -1 and -2
Because you're performing two different operations
they should yield the same result
why?
16:31
!!>-2+-1
@Rick -3
!!>Math.trunc(-3/2)
@Rick -1
!!>-3 >>1
@Rick -2
16:33
so shifting the bits by 1 on a negative number is not the same as dividing by 2 and truncating
why would it be
I thought it was a shortcut clearly it is not
@kevinB how would you calculate the middle index in an array of length 2
quick math
So how would you do that?
show me some quick math toward accomplishing that goal
that will also work for negative numbers
of course it has to work for array sizes of any length
17:01
you could do this (start +1-end)/2+end but I don't like it. I want something shorter
I take that back that won't worth either
@Rick Sure it is, as long as you use the bitwise definition of truncate
@Rick What the hell exactly is your goal?
@KendallFrey but I won't get the correct values for negative numbers
let me try to put the problem into words
one sec
You want the middle index in an array with 2 items, but it may be any number of items, including negative?
@Rick You just need to adjust your notion of correctness ;)
I basically want what the ( x>> 1) but a mathematical operation that yields the same result
with x being any number
with a signed shift, I assume?
17:13
just shifted by 1
I don't think you understood me
a signed shift will turn -2 into -1
an unsigned shift will turn -2 into 2^n-1
I want the signed shift result
As for the mathematical operation, I think you want rounding toward negative infinity
so Math.floor()
Yes, I believe so
17:23
any way I can make this shorter const mid= (max, min)=>Math.floor((max + 1- min) / 2+min)
What is your obsession with 'shorter'? Is this a coding challenge?
shorter is useless
(max + min) / 2
And if you want rounding up, like it looks like that does, use ceil instead of floor
I'll have to use ceil for negative numbers and floor for positive numbers
So, trunc?
Make your damn mind up
17:32
it won't work with trunc the offset after dividing by 2 won't create a contiguous negative-to-positive number line
Nurse, he's talking nonsense again
imagine you are creating a segmented tree and you needed to create boundaries on each branch representing an interval. if you have a negative number that should be your left most boundary. your intervals need to represent the intervals at every step of the number line
Why are you working with integers and intervals at the same time? Intervals are continuous.
because integers are both positive and negative and you can segment without complicating the logic
But they're not continuous
17:42
in a node tree they are
What
integers are not continuous
They are as discrete as discrete can be
that's why you add and divide by 2 and more toward the nearest int
>>1 works fine but can't use it in production code
I need to find an alternative
Why not?
it's not readable
It's just as readable as doing it with floor()
Especially if you comment like you're supposed to
17:49
Why would something having readability problems be a reason to not use it in production?
I have to write so that a dumb person can make sense of it.
That's an impossible problem, in general
18:49
Making it short could entirely be the opposite of making it easy to understand
19:13
582
Q: Uncatchable ChuckNorrisException

Max CharasIs it possible to construct a snippet of code in Java that would make a hypothetical java.lang.ChuckNorrisException uncatchable? Thoughts that came to mind are using for example interceptors or aspect-oriented programming.

 
1 hour later…
20:18
figured it out
🚽
@KevinB aren't you curious?
I went and polluted the math forums looking for an answer. Turns out it might have been a glitch all along.
not even a little
20:35
no, i find it a waste of time to interact with you.
2
that hurt
21:06
🔥
21:39
Is it time-intensive to copy objects? For example, if I want to build a map counting occurrences in an array, I thought of doing this:

const addToMap = (map, e) => Object.assign({}, map, { [e]: (map[e] || 0) + 1 });
const buildMap = a => a.reduce(addToMap, {});

I wanted to create a pure, single-purpose function, instead of having addToMap mutate the object as a side effect. The trade-off though is that it has to copy the object everytime. I don't think this is a memory concern, but does it take a long time to copy a large object?
22:03
to me, it seems like an expensive solution to the problem
or.. i guess, maybe i'm not understanding the goal of that specific change
like, you're already not mutating a
if you were to just mutate the {} you are passing to reduce, you'd still not be mutating a
I don't see a reason to avoid mutating the object you created in buildMap
Hey guys, I'm running into this really weird problem
I have a cross-origin preflighted PUT request that works on Chrome
and it does not work on Firefox
everything is the same in the preflights on both
but in the actual PUT request, Firefox doesn't receive any CORS headers back
whereas Chrome gets the expected access-control-allow-credentials/origin
yeah it's super weird but I don't think it could possibly be server-side because the host is Google Cloud Storage
(hence the cross-origin request)
that's really weird. id on't see any information online related to firefox issues with cors on GCS, are you sure it isn't some kind of console setting hiding that information?
I don't think so, because the requests themselves are failing -- I'm getting CORS errors in the console
"access-control-allow-origin header not present" etc
weirdly enough, I am getting a 200 back, even on those failed cross-origin reqs
works in safari lmao
also works in safari using a Firefox user agent
although the safari inspector isn't showing the preflight at all so I don't know what the deal is with that
22:30
hey what software do you guys use to mock up UX?
I'm on Windows but don't think Paint will cut it :P
vscode
?
like an extension?
or you mock it up with code?
@forresthopkinsa are you configuring cors yourself? Some browsers are less forgiving about syntax when setting headers. I just use the cors npm package, might want to give it a shot: https://www.npmjs.com/package/cors

Also I would try going incognito, disabling browser plugins, etc

I'm no expert, just my 2 cents.
well, it's from google cloud storage
There's no reason that firefox should be receiving the headers differently
@KevinB I've only used heroku to deploy my express backends, not really familiar with google cloud but I assumed that you just deploy your own backend. I read that article, but it seemed to be a generic article explaining cors?
22:38
toward the end
> Note: CORS configuration only affects requests to XML API endpoints. JSON API endpoints allow CORS requests, regardless of CORS settings on the target bucket. Requests to the endpoint storage.cloud.google.com do not allow CORS requests.
@BrianJ i mock it up with code, so that when i demo it i can make code changes on the fly via dev tools to end up with a final-ish result
oh so he would need to create a proxy service to GCR?
sorry for double ping
@BrianJ I have no experience, but I would try looking at Producthunt: https://www.producthunt.com/search?q=mockup

Recent release that did pretty well: https://www.producthunt.com/posts/cleanmock

May also be worth a browse: https://www.producthunt.com/topics/design-tools
no probs
I'm starting a new react pet project, want to do some mocks first but I guess code mock is just as easy
i used to use photoshop, but i'm just much faster building it out directly
22:41
ok yeah I was thinking photoshop as I could do with upskilling on it
thinking of moving more into front end dev in my next job
so would be good to be able to mock up stuff for presentations
@KevinB, back to my question re: copying arrays. So you're saying that it is in fact "expensive" to copy objects and that you would just mutate the input object in addToMap? Note that Airbnb style guide (ESLint) complains about param re-assign, even in the reduce callback.
eh, i dont know that it's actually expensive
but doing A vs not doing A, doing A is going to cost more, right?
yea i read somewhere else that JS manages its own memory, so developers shouldn't worry about it (in response to my exact question)
but i wanted more confirmation
yeah i tend to not think about such things till i'm faced with a problem.
build it in the way that makes the most sense to me
right. well im preparing for my first dev job interviews, so how would you solve that problem in an interview setting? I just thought pure functions without side effects are considered good practice. I realize I'm over-optimizing.
I build maps really often in those code challenges
22:46
Just found the issue I have been trying to solve for months:
I actually don't spend very much time writing javascript
Put a class name in a style attribute: style="info-cont"
@JBis, it must've been hard to solve an issue you couldn't even find!
I am actually an idiot
22:48
saw a fun one on SO today, someone couldn't figure out why typesecript wouldn't install
23:07
Is their documentation on how scale effects positioning?
Take a look here
The text becomes relative to its parent
i assume applying a transform also applies a position
that doesn't seem documented. Well maybe it does:
8
Q: How to suspress the position: relative when using translate

Gundonit seems that using transform: translateY(1px); also causes the element to gain an extra position: relative;-behaviour. Is there a way to suspress this? Here is a example on codepen.io. I would like to position the whitebox absolutely to the green one, not the parent (red) one.

> If the property has a value different than none, a stacking context will be created. In that case, the object will act as a containing block for any position: fixed elements that it contains.
@KevinB interesting
i've never had/seen this issue before, so all i can do is test/research, :p
23:13
wondering why it adds a stacking context
that seems random
23:40
0
A: How to create array from a for in javascript?

TagasDid you even try? Create a new Array first, then in your for loop, you can append each element to that array: let arr = []; for(var i=0; i<personal.custom.length; i++){ arr.push(personal.custom[i].name); } console.log(arr);

@BrianJ No, that's exactly what I'm trying to avoid -- users are uploading huge files (100+ GB) and so proxying that data is unacceptable. Besides, it's working in other browsers, CORS and all.

« first day (3015 days earlier)      last day (2158 days later) »