« first day (3082 days earlier)      last day (1852 days later) » 

12:37 AM
Is the behavior for document.getElementById("form")["action"] and document.getElementById("form").getAttribute("action") supposed to be different?
 
12:51 AM
Hey guys, how could I improve the logic of the following func:
const arraySwitch = (array?: string[], newElement?: string) => {
    let newArray: string[] = []
    if (array) newArray = array
    if (!newElement) throw Error('No element to add/remove')
    // Determine if element exists
    const newUserIndex = newArray.indexOf(newElement)
    // If exists remove it
    if (newUserIndex > -1) return newArray.splice(newUserIndex, 1)
    // If not, add it
    newArray.push(newElement)
    return newArray
}
What I'm trying to achieve is to determine whether to add or remove an element of an array, if it exists it must be removed, but it it doesn't exist then it must be added
 
1:04 AM
probably turn it into a map
but that introduces it's own problems
return array.indexOf(ele) !== -1 ? [...array, ele] : array.splice(array.indexOf(ele), 1);
@JonathanSolorzano the above but remove array.indexOf(ele) to its own variable like const i = array.indexOf(ele)
so:
(array, ele)=>{
    const i = array.indexOf(ele);
    return i !== -1 ? [...array, ele] : array.splice(i, 1);
}
 
morn
 
good morning
 
 
1 hour later…
2:17 AM
Good morning!
@DemCodeLines Yes. When action is empty, the former will return the page url, while the later should return empty or null. Spec: w3.org/TR/html5/sec-forms.html#dom-htmlformelement-action
@JonathanSolorzano Note that !newElement will be true if newElement is empty string, zero, false, NaN, which are not null or undefined. Otherwise, the logic is quite sound and as efficient as it can be without adding more assumptions.
 
hii
is this the right for for react questions?
 
@ValerioZhang Yes. But since there is only you and me and I don't know React, you may not get immediate answer. :(
 
:(
haha thanks
 
I tried to learn React a few times but I never get pass JSX. It's crazy to me >_<
 
So I guess you could theoretically configure window.location properties:
 
2:35 AM
@DemCodeLines From my experience, these unusual use cases are not covered by spec and may varies from browser to browser and from version to version.
 
@ValerioZhang I'll be around for a few minutes if you still have a React question
 
@Sheepy Ideally, I'd like all requests being made from the frontend client to have a custom parameter added to them before they are sent off. Too bad there's no way to intercept all network traffic
@Sheepy Try React/TypeScript
 
@DemCodeLines You mean not even with Fetch api?
 
If someone is doing window.location = ... in their javascript function, there's no way to intercept it without overriding the setter for window.location and adding this parameter.
 
I see.
@DemCodeLines Maybe. My current job don't demand it and I don't have as much free time to spare on new programming lang/tools as I used to.
But then, I need a new job. Let's see how our new maid goes. She should arrive tomorrow.
 
user1596138
2:49 AM
@ValerioZhang What were you going to ask?
 
user1596138
This is definitely the right place.
 
i'm having an issue when serving my react build on my webserver. whenever i go to a new route my static js files aren't correctly being loaded. on the index page its using the right path, but when i go to a different route - the static files are being requested using the absolute url.
/static/css/1.65fcf2e7.chunk.css

example/static/css/1.65fcf2e7.chunk.css
any ideas on how i can fix this?
this only occurs when i reload a page on a different route
 
 
3 hours later…
5:49 AM
@ValerioZhang are you using react router?
 
yes
@DavidKamer
 
 
2 hours later…
7:58 AM
@ValerioZhang hmm, if the file is being generated, then it's not necessarily a bad thing if the path is absolute
That's just where the file is "officially" being hosted from
absolute paths are only a bad thing when you absolutely need them to be relative
 
8:46 AM
hello , i'm trying to ajax to a different domain .. currently i'm using local host
const req = new XMLHttpRequest();
req.open('http://127.0.0.1:5000/','POST' , "/test");

output in chrome console is >> 'XMLHttpRequest': 'http://127.0.0.1:5000' is not a valid HTTP method.
 
XMLHttpRequest.open(method, url, async)
POST should be first, then "/test"
@za001a no need to provide the domain (it's implied if it is in the same domain)
 
@Neil i know it's a chrome extention so it's a different domain
so req.open('POST' ,'127.0.0.1:5000', "/test");
right ?
 
I didn't know that chrome extensions had access to XHR
 
@za001a XMLHttpRequest is very much a standard object for ajax requests
So you need to call it as it expects
If there is another function you can call, you should be calling that instead I presume
 
@MadaraUchiha of course it does.
 
8:52 AM
req.open('POST' , '/test');
 
@Neil where to add the other domain tho ? ... i can use it with forms easily but i've never done it with ajax
 
If it is cross-domain, you need CORS
req.open('POST' , 'http://127.0.0.1:5000/test'); maybe?
but again, this will fail without setting up CORS
 
@za001a Different port is considered different domain. A webpage on port 80 making XHR to port 5000 will always be CORS. You need to setup the server on port 5000 to return a special http header: developer.mozilla.org/en-US/docs/Web/HTTP/CORS
 
@za001a Why is it "of course"? You don't have most of the DOM's APIs, you don't have anything on document nor most of the things on window.
 
(And if you don't control the target server, sorry you can't do it with client side js.)
 
8:56 AM
@Neil From inside of an extension?
 
@MadaraUchiha I don't know what that's about honestly
 
@za001a Yeah. Are you writing a browser extension or a website?
 
Seems like it works differently from an extension
You need to request permission for the domain you're trying to XHR from
 
an extension which talks to a third party site is a scary thing
I'll just say that
 
@Sheepy i'll take a look at it and yes its an extention
@MadaraUchiha i've done it earlier with forms action and it worked , i assume ajax should work as well .
 
9:00 AM
... Form action?
What kind of extension are you building?
 
What is a webdevelopment platform?
Is it the same as a framework?
 
@Sheepy thank you !!
 
Is a webdevelopment platform something like Heroku?
A place where you can host your files
 
@MadaraUchiha in form action="http://127.0.0.1:5000/test" worked
i was just asking so i can learn how to ajax it as well.
 
9:03 AM
@za001a I know what a form action is
Forms are not very common in extensions though
 
@xingZì A platform that aims to faciliate web development. It's pretty board and can include web frameworks and things like wordpress.org's online service.
 
if forms worked that means CROS is already open , right @Sheepy ?
 
@za001a Nope. CORS does not apply to form submit. The point of CORS is to restrict your ability to read data from cross-domain, so that for example you can't read the user's facebook or ig data through ajax (if the user is already logged in to those site).
And you can't read the result of a form submit, so it does not subject to CORS.
 
You're basically ensuring that the receiving server "consents" to being called via ajax from domains other than its own
 
Or, in case of browser extension, you request the permissions and the user consents that you can read from those sites.
 
9:13 AM
I don't think that's what CORS does, though user may still need to approve of that
though I admit I could be wrong on that score
I don't write a lot of (none) extensions
 
Does that look like valid JS ?
ctx.auth0Token = ctx.auth0Token || (await (ctx.auth0TokenPromise = ctx.auth0TokenPromise || auth0.clientCredentialsGrant({
       audience: 'https://auth0--demo.auth0.com/api/v2/',
    }))).access_token;
 
Yes an extension need to list every site you want to read from (or just say all sites) and the users will be prompted with the list. They can deny it.
@ShrekOverflow The syntax looks good to me.
 
Omg sheepy!
I am getting a statusCode Error when using that
 
shrek, the await is not on the right place
 
are you sure?
 
9:16 AM
Hi Shrek~
 
put it at auth0.clientCredentialsGrant
and don't forget to add async beforehand
 
but i also want to cache the promise itself
 
oh
 
in case there are more than 1 people doing this
see the phrablem?
i mean obviously a function like
function getAT(){
// check token
// check for promise for token
}

Would work too
but i wanted to one line that sthuff
 
don't try to one-line that. It's affecting readability
 
9:26 AM
use that approach you just posted
 
@Neil @Sheepy thank you but i actually want to allow users to pull their own data from my website once the Ajax a request.
i'm not trying access other websites
@Neil @Sheepy
my point is if i can submit form to my website then the connection is already open between my website and the extention which means i suppose to be be able to send and recieve data as much as i like . either via forum submittion or via ajax ..
 
@za001a Chrome does not know and cannot confirm whether the server is yours. So your extension will need to specifically request permissions to read from the site. Connection is normally not under our control; we can make independent requests (whether with link, form, or ajax) and different types of requests subject to different rules.
 
@Sheepy so what i should do ? i have both front and backend (python) open
lets say that i want to deal with the CROS , from where i should start ?
 
9:43 AM
Option 1) Stick with form if you don't need to know what happens. You can auto-submit a form with js without messing with CORS.
Option 2) Add the site permissions to your extension and you should be able to do xhr, after the user approve it. Link: https://developer.chrome.com/apps/xhr#requesting-permission
 
I'm going with option 2
"permissions": [ "tabs", "storage" ,"http://127.0.0.1:5000/*" ]
i have those permissions already in my manifest
@Sheepy maybe it's not a permission problem ?
 
@za001a What is the exact error you are getting now?
 
@Sheepy Uncaught DOMException: Failed to execute 'open' on 'XMLHttpRequest': 'http://127.0.0.1:5000' is not a valid HTTP method.
hold on
it's working
i was modiofiyng different copy of the file and that's why it wasnt working
 
Good :) Yup. It happens.
 
sorry to bother u
if anyone interested that is what have worked with me
req.open('POST' , "http://127.0.0.1:5000/test");
@Neil @Sheepy thanks alot
 
9:55 AM
😬 you guys are too serious
and nice :)
  async function getAccessToken() {
    if (ctx.auth0Token){
      return ctx.auth0Token;
    }
    if (ctx.auth0TokenPromise) {
      return ctx.auth0TokenPromise;
    }
    ctx.auth0TokenPromise = auth0.clientCredentialsGrant({
       audience: 'https://auth0-demo.auth0.com/api/v2/',
    });
    ctx.auth0Token = await ctx.auth0TokenPromise;
    return ctx.auth0Token;
  }
That good?
 
@ShrekOverflow I would always return a promise, even if it is already resolved
 
there is more stuff I need to do on it
hmm actually nvm
 
I think this code translates to a slightly different logic from your earlier one-liner. If this code works then you better keep it.
 
hey response was blocked from CROS "Cross-Origin Read Blocking (CORB) blocked cross-origin response 127.0.0.1:5000/test with MIME type application/json. See chromestatus.com/feature/5629709824032768 for more detail"
 
It does 😛 and I am keeping it
I also was on 0 coffee so I see where the other one liner would fail
 
10:02 AM
@za001a well there you go.. told ya :P
 
Where have you been SHeepy?
 
I had understood that it was working though
 
@Neil is there is a way around that ?
 
@za001a Ok that's a relatively new restriction. This is as far as I can help today, good luck >_<
 
@za001a There is no workaround for this, unless not calling the server via ajax is a workaround
 
10:04 AM
@Neil it is an async function ...
 
@KarelG and so it is always converted to a promise in any case?
 
yes.
it wraps all returns in a promise object
even if you do
 
Then one could make an argument for not forcing it to coerce from a promise to a token
unless it absolutely must be resolved
 
let foo = async _ => 1;
or if you cannot read it
 
@Sheepy thank you
@Neil how i should response to the ajax then ? because i can read the sent data on my server so if iam trying to leak data the data were already leaked
 
10:07 AM
async function foo() {
  return 1;
}
then you can do
foo().then(...)
 
@za001a You need to add CORS headers to the request, and your server needs to be able to handle CORS requests at your origin domain
 
@ShrekOverflow Been taking care of my baby, got depression, and escape into writing game mods and other stuffs. I mean, when I am not arguing and thinking about things that you think about when you are depressed.
 
YIKES!
 
@Neil All async functions return a Promise
Even when there's no return or when there's a throw.
 
10:09 AM
@Neil could you give me an example please ? i'm not sure what you are talking about and i'm pretty sure that i'm not to leak anything so i don't mind following any rule
 
a throw in an async function is wrapped as a reject()
 
well in my defense, I don't program often in javascript
 
@Neil my Manifest : "permissions": [ "tabs", "storage" ,"http://127.0.0.1:5000/*" ]
and my request is like that
req.open('POST' , "http://127.0.0.1:5000/test");
ok i will check it out
 
Don't take shortcuts is my advice. Read the whole thing
 
10:25 AM
Last question, I have two arrays I am trying to find what elements were added removed (because the api will need two seperate calls for this). The way I am _envisioning_ this is as following.

const added = new.filter(x => !old.includes(x));
const removed = old.filter(x => !new.includes(x));
Can't be this easy, can it?
 
@ShrekOverflow sure it is
 
that example shows nicely where there should be a reverse predicate stuff
 
10:40 AM
@ShrekOverflow Well, if you don't want O(n^2) performance, try this: added = old.reduce( ( d, e ) => ( d.remove( e ), d ), new Set( new ) ) /* Set */
Though, to be frank, I'll use the simpler code for trivial arrays.
 
^
 
I'm not obessed with performance, ok? I just can't help it when I see what amounts to a bubble sort >.<
 
Doing a quick performance check
Takes 2 ms at 1000, and 122 at 10k
probably safe for anything 1000 or less
beyond that, even if there were a remote possibility, I'd do something a bit more sophisticated
 
Like a Worker. Yay!
Try it on an Atom Z3740 and it may be another story.
 
10:59 AM
@Sheepy use plain old for-loop?
 
@KarelG How would you do this without getting O(n^2)?
 
Maybe if the arrays are already sorted, then one loop will be lightning fast. Many assumptions here, of course.
 
yeah but you can't exclude the sorting.. if it takes you two O(n) passes and O(n log n) to sort, then it's technically O(n log n)
they'd already have to be sorted
 
yup, with a sorted array
that can be done at the server
 
Going off. Nice chatting and wasting quality time discussing millisecond optimisations!
 
11:04 AM
triple -'s sheepy!
and baaaae
 
@KarelG baa~
 
@Sheepy And you know you love us for it!
 
11:23 AM
any folks here worked with ANTLR? Just want to know if it is possible to convert this grammar into javascript? It has got a bit of Java api calls in it...not sure if they are antlr api's or something else (i.e. some other java api)...
 
@deostroll well, technically yes.. if you mean to ask if there is a program that will do this automatically for you, I don't know
My guess is that there are tools which when given a grammar, it will create a parser in javascript, but you may have to do some trimming to that
 
my hunch is antlr should do it...however I have not used that tool before...
 
I suppose an alternative approach might be to convert java to javascript maybe?
I think I'd look for a tool like ANTLR which works for javascript first
that seems like that'd work but it'd be an ugly solution
 
 
1 hour later…
12:29 PM
2
Q: What is the | operator used for in Typescript?

Code ApprenticeGoogling this only returns results to do with the numerical applications of bitwise operators, so I'd like to ask it on SO. I was reading through the @ngrx docs, and I saw this bit of code: export class Increment implements Action { readonly type = CounterActionTypes.INCREMENT; } export clas...

such an anwer hijack
 
well, time was given
if OP wants to answer in the comments, that's what they risk.
I've seen much much quicker jackings
 
@KarelG Meh, what @rlemon said.
 
did not flag it tho. I just understand it :P
 
1:31 PM
I usually only answer in comments these days. It's not usually worth my time to write a full, well thought out, technical solution
I don't get paid for this ilk
 
I just give a pointer if it is somewhat obvious
then I see someone [use my pointer to formulate|posting] an answer
 
Anyone here familiar enough with NGRX Entity that could help settle a discussion between me and my coworker?
 
no clue what that is. I doubt some of us would know what that is
 
Updating a partial entity in the store is to be done with updateMany or UpsertMany?

FE:
products: productEntityAdapter.updateMany(Object.values(action.payload.entities.product), quotingState.products)

or

products: productEntityAdapter.upsertMany(Object.values(action.payload.entities.product), quotingState.products)
 
> Entity State adapter for managing record collections.
 
1:39 PM
provided that the payload contains values / fields not yet inside the store. Let's say that store for products has their ID and name but I would like to add price to that too
 
@KarelG NgRx is relatively well known, it's the redux for angular made on top of rx.js
@Maartenw Upsert is like update except it inserts if it doesn't already exist
You should ask yourself if you want that, especially given that you say that they are partial entities.
 
Hmm see I would do it with an upsert
id(pin): 1
name(pin): "server"
code(pin): "1"
quantity(pin): 1
billingType(pin): "GB"
unitPrice(pin): 0
isTiered(pin): true
hasRelated(pin): false
After fetching the details should become
billingType: "GB"
code: "1"
fixedprice: 0
fixedpricecost: 0
id: 1
name: "server"
quantity: 1
tiers: (5) [{…}, {…}, {…}, {…}, {…}]
unitPrice: 0
unitpricecost: 0
To be more concise: i have written the code and it properly works with upsert. My coworker says it is not the proper way to do it and I should write it with an updateMany. My argument being that for example, tiers is not inside the store. so it should be added
updatemany does not return an error, but expected behavior is it updates any values that differ from the payload, but does not add the tiers array for it does not already exist on the product entity inside the store
 
2:15 PM
I am not a fan of "upsert" thing
 
@Jhawins No, but I want it.
 
@KarelG why not?
I've always thought that to be a major pain in the ass
There should be all three imho
insert when you only want to add, update only when you want to update, and upsert for when you don't care
 
hi , anyone with experince on Cross-Origin Read Blocking (CORB) ?
 
I've never even heard of CORB
sounds like corn on the cob
 
basically they are blocking Ajax to different dom
 
2:24 PM
Ah, so it looks like it blocks resources based on context
That's a dangerous game to play
 
not really ... any extention for chrome and firefox might include login
which often sends Ajax to the server and get a respons
i just dont know how to do it right
i've managed to send the request fine but i cant send back a response
i got this error : Cross-Origin Read Blocking (CORB) blocked cross-origin response 127.0.0.1:5000/test with MIME type application/json. See chromestatus.com/feature/5629709824032768 for more details
 
Can you show the code you're using to retrieve the json?
 
sure it's fairly simple
 
1 message moved to Trash can
@za001a 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
 
my js Ajax code:

const req = new XMLHttpRequest();
req.open('POST' , "http://127.0.0.1:5000/test");

req.onload = ()=>{

  var res = JSON.parse(req.responseText);
  console.log('the response from the server = > ',res)
}
const data = new FormData();
data.append('x', y);
req.send(data);
 
2:31 PM
Have you tried adding the ` "X-Content-Type-Options: nosniff"` to the response headers from the server? It was mentioned in the article
 
what does it do ?
 
No idea, lol
Remember, I hadn't heard of this before
I'm just reading the article, same as you
 
ah ok i've tried to read it as well but do u mean i should add X-Content-Type-Options: nosniff to the response json from the server ?
 
no, add it to the headers in the response
 
i'm still new to all of this , not sure what do u mean by headers ?
 
2:35 PM
Do you have access to the server code?
 
yes ofc its localhost
 
Hmm do timers "continue" if the computer is in standby?
 
Well on your server, it serves up HTTP responses. When you're constructing your response, to send the JSON, you need to set headers on the response object
 
Or is there another way to set a timeout to occur at a specific date & time?
 
You can google how to do this with your specific framework that you're using
"how to set response headers on <framework name>"
 
2:38 PM
i'm currently using python flask <<< that is the framework , right ?
 
probably. I don't know anything about it, so I can't help you further
 
alright thank you :) :)
 
@Neil it is vague and usually not clear what really happened.
update? or insert?
 
what's vague about it? If it doesn't exist? insert. I fit does exist, update
 
I love upsert.
in very specific scenarios
 
2:45 PM
yes but the problem is that if you want to add a row where a key should be unique, it updates an existing record instead of inserting it. The reason is a rally condition. If there is two threads that has a same id by coincidence, the first data is overwritten and lost with upsert. By doing an insert, you get feedback that the unique constraint is failing and thus you can retry the insert with a different id.
if you don't give fuck about that, you can go with upsert ofc. But I avoid that in my code. It is also enforced as rule during coderev
 
-12
Q: Single sign on (SSO) login system

Suraj NiralaHow can be implement single sign on login system in Php like google single sign on login system. Any developer implemented of SSO

oof
 
hmm
 
@ndugger You're not being very welcoming.
 
(When you can't tell if people are serious or not when they say that anymore)
 
*fry face*
 
2:58 PM
yOu'Re BeInG uNwElCoMiNg
 

« first day (3082 days earlier)      last day (1852 days later) »