JavaScript

Topic: Anything JavaScript, ECMAScript including Node, React, ...
JK.
Jun 24, 2023 06:41
I'm thinking that if the call has something like children.flat(1) or grandchildren.flat(1) in the middle that would mean it is already flattened before it gets to the flatMap and it might work that way?
JK.
Jun 24, 2023 06:40
[
{"id": 1, "name": "parent test1", children: [{"child_id": 1, "child_name": "child one"}, {"child_id": 2, "child_name": "child two", grandchildren: [{"grandchild_id": 1, "grandchild_name": "grandchild one"}]}] }
]

// converts to

[
{"id": 1, "name": "parent test1"},  // just the parent object fields
{"id": 1, "name": "parent test1", "child_id": 1, "child_name": "child one"},  // parent fields and child one fields
{"id": 1, "name": "parent test1", "child_id": 2, "child_name": "child two"},  // parent fields and child two fields
JK.
Jun 24, 2023 06:39
@VLAZ-onstrike- that works very nicely thanks... is it possible to do to multiple levels? eg parent -> child -> grandchild? I know flatmap is like a shorthand for .map().flat(1) so I'm not sure if this would be possible? eg
JK.
Jun 23, 2023 11:25
@VLAZ-onstrike- thanks will give it a try
JK.
Jun 23, 2023 10:16
[
{"id": 1, "name": "parent test1", children: [{"child_id": 1, "child_name": "child one"}, {"child_id": 2, "child_name": "child two"}] }
]

// converts to

[
{"id": 1, "name": "parent test1"},  // just the parent object fields
{"id": 1, "name": "parent test1", "child_id": 1, "child_name": "child one"},  // parent object fields and child one fields
{"id": 1, "name": "parent test1", "child_id": 2, "child_name": "child two"},  // parent object fields and child two fields
]
JK.
Jun 23, 2023 10:16
Hey - terminology question, what do you call in functional programming when you want to expand one object into an array of objects? So I can google it haha. eg object has parent key and array of child objects. But I want to convert to an array. Somewhat like doing a left join in sql. I can do it easy with nested forEach loops but thats not functional... eg:
JK.
Mar 5, 2021 22:11
Yeah that works thanks heaps, even if is a bit ugly. I'll need to consider which one will we should use
JK.
Mar 5, 2021 22:06
Updated, will flow thru sometime soonish
JK.
Mar 5, 2021 22:05
Yikes. default pic only cos I havent changed it. Not my fault
JK.
Mar 5, 2021 22:03
Also for future readers of the code, they cant easily see that I only wanted to pass foo, bar into MyThing and not all of the props available
JK.
Mar 5, 2021 22:01
Ah yeah, I did think about <MyThing {...this.props} /> but that will pass all props from the parent component. Many will not be used by MyThing, isnt that ineffiecent?
JK.
Mar 5, 2021 22:00
{...foo} doesnt work either (makes sense, its not an array or map)
JK.
Mar 5, 2021 21:58
No it says '...' expected
JK.
Mar 5, 2021 21:57
One minute pls while I try ...
JK.
Mar 5, 2021 21:57
Without any brackets
JK.
Mar 5, 2021 21:56
I know with boolean fields you can just use the name <MyThing booleanField />
JK.
Mar 5, 2021 21:56
I dont know, thats why I'm asking :)
JK.
Mar 5, 2021 21:55
Is it bad in React to be constantly repeating prop names? eg <MyThing foo={foo} bar={bar} test={test} x={x} y={y} />

It seems repetitive to have propName={propName} all over the place. Cheers
JK.
Mar 11, 2018 22:16
Actually I'm trying to figure out how to change the headers. Trying to remove the Express header, it fails in the same way - nothing at all happens.
JK.
Mar 11, 2018 22:12
Sorry I did.
JK.
Mar 11, 2018 22:11
The compiled js returns next()

    app.use(function(req, res, next) {
        res.setHeader("X-does-this-even-work", "nope");
        return next();
    })
JK.
Mar 11, 2018 22:08
Yes, coffeescript. Sorry I tried to use slack style lol
JK.
Mar 11, 2018 22:08
Yeah, output doesn't have the header:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 7327
ETag: "1540810979"
Date: Sun, 11 Mar 2018 21:57:45 GMT
Connection: keep-alive
JK.
Mar 11, 2018 22:06
Hey guys, what do you do when res.setHeader does nothing at all? No error, and no header?
```
app = express()
app.use connectTimeout "120s"
app.use errorHandler() if process.env.NODE_ENV == "dev"

app.use (req, res, next) ->
res.setHeader("X-does-this-even-work", "nope")
next()

routes = require "./routes"
routes.attachTo app

server = app.listen process.env.PORT, =>
host = server.address().address
port = server.address().port
```
Its not caching. The Date header shows that it has got a response right now. I'm just lost and scratching my head
JK.
Jul 28, 2017 06:58
@KarelG thanks, that makes sense that it uses SOP. I have a problem with an old verion of an ios app writing something to localStorage, and then the updated version not being able to read it. From what you've said I can rule out the possibility of the new version not having access to localstorage because both versions will have the same scheme/host/port tuple
JK.
Jul 28, 2017 05:54
I have a question thats a bit too broad to ask on SO.. :) How exactly does localstorage prevent access from other sites? Whats the mechanism? Does anyone here know much about this?
JK.
Jul 28, 2017 05:53
Hi :)
 
JK.
Feb 12, 2020 22:56
Your entire question was What is the equivalent of the following syntax of Java in Python? an_image.bandNames(). My comment is longer than your question. Why should anyone be bothered to do something when you cannot be bothered to do it yourself. You must show that you have attempted to solve the problem by yourself.
 

SO Close Vote Reviewers

This room is for support and discussion about reviewing and co...
JK.
Nov 22, 2019 00:39
sorry I messed up tags first time I tried
JK.
May 18, 2016 05:23
JK.
Apr 11, 2016 03:09
Lol @Jarrod. I came here to recommend the same Q for close
JK.
Feb 24, 2016 21:28
sorry - didnt know how this room works :)
JK.
Feb 24, 2016 21:27
Hi, can we get some more close votes on this please, completely off topic : stackoverflow.com/questions/35059302/…
JK.
Oct 8, 2015 23:16
Hi all, can we get some close votes on this please, it looks waaaay to broad: stackoverflow.com/questions/33027364/…
 

 SOCVR Request Graveyard

This room is ONLY to receive action requests (cv-pls, etc.) fr...
JK.
Nov 22, 2019 00:39
not a question, just whining about azure's rules: stackoverflow.com/questions/58984769/…
JK.
Nov 21, 2019 23:52
[cv-pls] can we get some close votes on this weird rant about azure? stackoverflow.com/questions/58984769/…
JK.
Jun 30, 2016 04:39
 
JK.
Sep 10, 2019 11:06
This was an unprovoked attack on a new user - No, there was a lot of provocation. (who has since deleted their account and will probably never return) and what exactly are we missing by having this person gone? Just means we wont have a bunch more lazy questions from them.
4
JK.
Sep 10, 2019 11:06
And why exactly is this 'be nice' policy not applied to the question asker? It's not nice to be asking others to do something when you simply cannot be bothered to do it yourself.
2
 
JK.
Jul 26, 2019 17:59
This is a pretty transparent and cynical move. It's very obviously designed so that negative meta questions are not shown to the peasants. We see straight through this.
 
JK.
Sep 27, 2018 14:49
+1 Exactly. If a question is unclear I'll vote to close even if its only a few seconds old. Users should only submit a question if it is already clear and answerable.
 
JK.
Jul 28, 2017 23:23
Hi, anyone know about localstorage on ios? apple.stackexchange.com/q/293227/249087 thanks :)
JK.
Jul 28, 2017 09:44
Anyone know much about transffering apps between developer accounts? I've made a transfer but the new version released from the new dev account cannot read localstorage written by the old version of the app released from the original dev account?
JK.
Jul 28, 2017 09:43
Hi
 
JK.
Jun 4, 2015 10:44
No of course you cant do this, it is an awful idea. How would you like it if some website forced an exe onto your computer and then ran it automatically? You can only do it so the user voluntarily downloads and voluntarily runs it themselves.
 

C#

General discussions about the c# language, Squirrels | gist.gi...
JK.
May 10, 2015 22:47
Can we get some close votes on this please? stackoverflow.com/q/27378707/325727
JK.
Feb 2, 2015 22:43
Can we get some close votes on this one please: stackoverflow.com/q/28041882/325727 thanks :)
 

MVC Mini Profiler

Discussion about Mini Profiler
JK
Aug 26, 2011 02:01
$.ajaxSetup({
data: "{}",
dataFilter: function (data) {
var msg;

if (data == "") {
msg = data;
}
else if (typeof (JSON) !== 'undefined' && typeof (JSON.parse) === 'function') {
msg = JSON.parse(data);
}
else {
msg = eval('(' + data + ')');
}

if (msg.hasOwnProperty('d')) {
return msg.d;
}
else {
return msg;
}
}
});
JK
Aug 26, 2011 02:01
its a critical feature I cant turn off
JK
Aug 26, 2011 02:01
damn .. its the ajax setup (copied direct from encosia.com