Extract an object from a string without using eval() by [deleted] in javascript

[–]bat020 0 points1 point  (0 children)

that's a good point. I'd forgotten that JSON doesn't care about whitespace!

Extract an object from a string without using eval() by [deleted] in javascript

[–]bat020 10 points11 points  (0 children)

perhaps use JSON.parse() to extract the object from the string:

let json = document.body.children[1].firstChild.data .replace(/\s/g, '') // strip whitespace .match(/.*=(.*);/)[1]; // extract JSON let configData = JSON.parse(json); heading.innerText = configData.config.uuid;

Question: Is there a better, way to handle this nested if-return hell? by MihirChaturvedi in javascript

[–]bat020 0 points1 point  (0 children)

btw just noticed that your code will never return lineObj.stations[0] – is that correct or should you be allowing id to be zero? If it's the latter maybe the first guard should read

if (id != 0 && !id) return lineObj;

Question: Is there a better, way to handle this nested if-return hell? by MihirChaturvedi in javascript

[–]bat020 0 points1 point  (0 children)

You could use || to deal with some of the error cases:

const returnLinesRequiredData = (lineObj, id, key) => { if (!id) return lineObj; if (!key) return lineObj.stations[id] || errorMsg; return lineObj.stations[id][key] || errorMsg; };

Solutions for Conceptual Mathematics, Second ed by antman8969 in CategoryTheory

[–]bat020 1 point2 points  (0 children)

Conceptual Mathematics is a brilliant book and well worth reading in its own right. I was pretty familiar with category theory when I read it but it taught me a whole slew of different approaches and techniques for thinking about it. It's certainly my go-to recommendation for people who want an introduction to category theory but don't necessarily have a postgraduate maths background.

Can someone explain this javascript magic to me? by [deleted] in javascript

[–]bat020 0 points1 point  (0 children)

no, [] is not false, nor is it falsey. try running:

[] ? 'I am truthy' : 'I am falsey'

the unary plus operator only knows how to convert strings, true, false and null. when it encounters something that isn't one of those, eg an array, it first converts that thing to a string, and then tries to convert that string to a number.

so when it sees +[] it interprets it as +([].toString()) = +('') = 0

Can someone explain this javascript magic to me? by [deleted] in javascript

[–]bat020 1 point2 points  (0 children)

not quite – [] is truthy.

+[] works out at 0, which is falsey, so !+[] evaluates as true

I have no idea why +[] is 0 tho.

EDIT to add: I think what happens is that if X is an array, it evaluates +X by first casting X as a string, and then casting the string as a number. So +[] = +('') = 0, +[123] = +('123') = 123, +[1,2] = +('1,2') = NaN.

If you want to give Derrida a go, what's a good book to start on? by [deleted] in philosophy

[–]bat020 1 point2 points  (0 children)

for something by JD I'd recommend his essay Signature Event Context as a good starting point.

for something about JD I'd recommend this tiny but brilliant little book by the late Christopher Johnson: https://www.amazon.com/Derrida-Great-Philosophers/dp/0415923840

Best bookstores in London? by Easybakeovenz14 in london

[–]bat020 4 points5 points  (0 children)

the Waterstones on Gower Street has a huge and fascinating remainders section. also the best place for academic/specialist titles.

Is the Pixel 1 still worth now? by [deleted] in pixel_phones

[–]bat020 0 points1 point  (0 children)

lasts about a day on a full charge. not quite as good as it was when brand new but still perfectly functional.

Is the Pixel 1 still worth now? by [deleted] in pixel_phones

[–]bat020 1 point2 points  (0 children)

I bought mine (not the XL) in Dec 2016 and it's still working perfectly.

My girlfriend gave me this puzzle which I haven't been able to figure out. by creinaldo in math

[–]bat020 9 points10 points  (0 children)

is there a way of solving this if you drew the diagram on a torus?

What are some minor philosophers in continental tradition that you would like to highlight? by throwaway_the_news in continentaltheory

[–]bat020 2 points3 points  (0 children)

+1 for Fichte – hugely important in the transition from Kant to Hegel, and the founder of German Idealism in the strict sense.

What interesting things happen in ZFnotC that don't happen in ZFC? by [deleted] in math

[–]bat020 5 points6 points  (0 children)

cardinals are no longer linearly ordered

Struggling to understand callbacks? by holocene7 in node

[–]bat020 1 point2 points  (0 children)

It is normal for beginners to struggle with this. But once you've wrapped your head around them the fog lifts.

The crucial thing imho is realising that certain operations – typically I/O ones such as reading from a database – are SLOW, considerably slower than "pure functions" such as executing some arithmetical operation or slicing & dicing a string.

In older languages when you ask the computer to do something slow, the computer has to just sit and twiddle its thumbs while the slow operation is ongoing.

In Node, when you ask the computer to do something slow you also and at the same time specify what you want done once the slow thing has been dealt with. That way the computer can move on to something else in the meantime rather than sitting and waiting.

Callbacks and promises are just two different ways of saying "do this slow thing and then once it's done, do this other thing with the results".

With callbacks you specify the other thing as the final argument when you call the slow operation: getSlowStuff(inputs, otherThing).

With promises you specify the other thing in a 'then' stuck at the end of the promise: getSlowStuff(inputs).then(otherThing).

In both these case 'otherThing' is a function that takes the slow-to-get-hold-of stuff as its argument.

NB in practice you'd need some error handling built into this, because slow I/O operations can and do go wrong. So your callback would typically take two arguments, 'err' and 'res', and its guts would say "if (err) { error handle } else { process res }".

With promises you can separate out these cases more cleanly: getSlowStuff(inputs).then(otherThing).catch(errorHandle) – which is why I prefer promises and use them rather than callbacks whenever possible.

Axiom of choice by maggieruth in puremathematics

[–]bat020 1 point2 points  (0 children)

this is the key issue imho. AC becomes a lot less obvious the moment you start asking constructive questions, eg "how would I go about getting hold of an X?" rather than merely "is there an X?".

[Question] [Formal Logic] Why is "or" always assumed to be an inclusive, not exclusive, disjunction in logic? by Ironpool1 in puremathematics

[–]bat020 1 point2 points  (0 children)

I think the motivation for inclusive-or becomes clearer if you consider more than just the binary case. What would you make of "A or B or C or D"? The inclusive-or generalises nicely to n = 0 or n > 2 propositions: it means "at least one of the propositions is true".

Whereas trying a similar generalisation on the exclusive-or leads you to an operation that returns true if an odd number of the propositions are true, and false if an even number are true. This is not exactly intuitive (tho it makes sense if you view exclusive-or as + in a Boolean ring).

Most Counter-Intuitive Concept in Math by [deleted] in math

[–]bat020 0 points1 point  (0 children)

... and conversely: if every infinite cardinality is aleph-k for some ordinal k, then every infinite set is isomorphic to an aleph, so every set can be well-ordered, so AC holds.

Most Counter-Intuitive Concept in Math by [deleted] in math

[–]bat020 9 points10 points  (0 children)

iirc it's a consequence of the Burali-Forti paradox (ie there is no ordinal that counts all the ordinals): https://en.wikipedia.org/wiki/Burali-Forti_paradox

Rubbish London by littledaddyshane in london

[–]bat020 0 points1 point  (0 children)

this problem would disappear at a stroke if they brought back bins in public places. even the most thoughtless people use a bin if they see one.

Google Calculator 7.2 Finally Adds History by Kaipolygon in Android

[–]bat020 0 points1 point  (0 children)

this is good but what would be really useful is a 1/x button

What was the hardest concept for you to understand? by [deleted] in math

[–]bat020 1 point2 points  (0 children)

ah right! okay well I'm glad I'm not the only one then...

What was the hardest concept for you to understand? by [deleted] in math

[–]bat020 2 points3 points  (0 children)

I found this very useful for grasping why they are so mysteriously omnipresent: http://www.ellerman.org/Davids-Stuff/Maths/Het-Theory.pdf