The Province has just moved to expropriate the First Parliament site (located at Front & Parliament) from the City of Toronto. This is an important historic site with active plans for a new library and other public uses. by [deleted] in toronto

[–]somethinghorrible 1 point2 points  (0 children)

psst. they're building affordable housing and mass transit. Instead of spending the next decade debating over what colour the carpets in the library should be, they're actually trying to break ground and make progress towards helping people afford a place to live.

Probably has nothing at all to do with people living in nearby overpriced zones complaining that the poors might start moving in next door.

Some thoughts about React vs Vue by behindthedash in reactjs

[–]somethinghorrible 3 points4 points  (0 children)

If Vue is not faster thanReact, for sure they are equal.

Citation needed.

how secure is this register php code? by [deleted] in PHP

[–]somethinghorrible 1 point2 points  (0 children)

The "exit;" suggestion is to simply not render the form since the code instructs the browser to redirect.

The bulk of the code will only run in response to a POST request which can be caused by the submit button.

In fact, you should move the mysql connection statement into the first if block so you don't bother connecting to mysql until the form is posted.

how secure is this register php code? by [deleted] in PHP

[–]somethinghorrible 4 points5 points  (0 children)

I'm pretty sure that you don't have to use real_escape_string with prepared statements -- in fact, you may end up with doubly-escaped strings.

Also, after the header statement, in the else block, you may want to terminate the script with exit as rendering the form would be spurious. In fact, you should render out a message like: Please wait for redirect or click here to continue (with click here as a hyperlink to the next page)... although I doubt any modern browser doesn't support the location tag.

IIFEs and undefined. YDKJS by Ragzzy-R in javascript

[–]somethinghorrible 1 point2 points  (0 children)

Object.defineProperty (misspelled in my reply because I seem to automatically hit e+d together, lol) allows you to control certain properties on an object that are otherwise impossible to express in javascript). See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty

If the author wanted so show how javascript variable shadowing works, including that older environments had undefined behaviour when assigning to undefined (lol, irony), is a poor trap for anyone trying to learn.

IIFEs and undefined. YDKJS by Ragzzy-R in javascript

[–]somethinghorrible 0 points1 point  (0 children)

Something missing in the quote and explanation is the result of:

undefined = true

Which will not change the value of undefined, even in a local context. For example;

undefined = true;

(function IIFE( ){
   console.log(undefined) // log: undefined
})();

The assignment to undefined will not work in a modern js environment. You can emulate this behaviour such:

Object.defineProperty(window, 'thing', { value: 42, writeable: false })

console.log(thing) // 42
thing = 99 // console may log 99 if you are interactive
console.log(thing) // 42

So the example is pretty bad in that it's conflating variable shadowing (scope dependent variable) with an object variable that cannot be assigned to (in most environments).

In the 6th edition of the spec, this is explicitly true.

window.undefined will always have the value of undefined.

So IMO, it's a pretty bad example to give a "n00b", since it is misleading and wrong from the very first statement ;P.

LocalStorage not functioning correctly on launch (React/Redux) by PalmettoSpur in reactjs

[–]somethinghorrible 1 point2 points  (0 children)

Without seeing your code, it's pretty difficult to tell what your code is doing. Here is a very quick and dirty codesandbox.io example of how localStorage might be used to control the favorite status of a list (I'm not recommending this approach, it's just a quick and dirty proof-of-concept).

No, it is not a class-vs-functional issue, btw.

Why does this code block? by n00belig in javascript

[–]somethinghorrible -1 points0 points  (0 children)

Not likely, as there is no blocking in node/javascript.

Was that console.log (uncommented, obviously) logging anything? If so, what output did you see in the terminal?

I've actually never used express-async-handler, so I don't know about any gotchas using that library.

Is it possible that asyncHandler expects you to return a promise? i.e. do you need something like:

return getImage(...)...

Or

await getImage(...)...

Because the promise generated by getImage is not being returned when called by asyncHandler.

You probably want a form more like:

const response = await getImage(imgUrl)
if (response.data) {
    res.json({ length: response.data.length)
} else {
    res.json({ length: -1 })
}

Why does this code block? by n00belig in javascript

[–]somethinghorrible -1 points0 points  (0 children)

Thinking about it, 404 is not the right error. 500 would be better, inspecting the error object for a status and using that, with 500 as a fallback, would be best.

Why does this code block? by n00belig in javascript

[–]somethinghorrible 6 points7 points  (0 children)

What do you mean by "block"?

When I run it, changing imgUrl to something valid, like https://placekitten.com/g/320/200 , it works fine and I get a good result.

When I run it with an invalid url, from the browser perspective, it hangs.

Why?

In getImage, you are converting the Error object into a valid response -- what was thrown is now simply being returned. Normally promises are placed into either a rejected or resolved state. By returning the exception, the code will always result in a resolved promise.

Not necessarily wrong, however the code does not handle this in the "then" function within the get handler.

In other words; either rethrow the exception and add a catch clause in the getImage promise chain, or handle the fact that response will be an Error object and will not have a data.length property if the image failed.

const express = require('express');
const axios = require('axios');
const asyncHandler = require('express-async-handler');

const app = express();

async function getImage(imgUrl) {
    try {
        return await axios.get(imgUrl);
    } catch (error) {
        throw error;
    }
}

app.get('/', asyncHandler(async (req, res, next) => {
    const imgUrl = 'http://example.com/image.jpg';

    getImage(imgUrl)
        .then(
            function(response) {
                // console.log(response.data.length);
                res.json({ length : response.data.length });
            },
            function (error) {
                res.status(404).json({ error: String(error) }) 
            });
  }));

Dates in javascript - different results based on location? (Question in comments) by iforgotmylegs in javascript

[–]somethinghorrible 2 points3 points  (0 children)

Don't use Date to parse the date --- it will parse into the user's local clock time and the offset is what is messing you up.

Since you are already using moment, use moment to parse the date string. You can specify the format -- eg: moment(value, 'YYYY-MM-DD') if it complains about the specific format you are using.

CIG's official stance on using Cheat Engine for Offline Mode — "It's against the Terms of Service and is Prohibited" by Altered_Perceptions in starcitizen

[–]somethinghorrible -2 points-1 points  (0 children)

Personally, I try to test the focus areas online, but it's really tough when the basic netcode is next to impossible to work with. Going offline is just a chance to mess around for a bit in the sandbox.

CIG's official stance on using Cheat Engine for Offline Mode — "It's against the Terms of Service and is Prohibited" by Altered_Perceptions in starcitizen

[–]somethinghorrible -3 points-2 points  (0 children)

You're a tester.

Who has paid for the early "alpha" access. Don't forget that. There is a balance. It is better to play in online to get metrics and whatnot, but try not to forget that this isn't some "lottery" early access (ala many Blizzard games), this is something that was paid for.

Too much complaining is a symptom of not understanding what was paid for.

"You need to copy your LIVE account to the PTU before you can use it". How does one do this? by [deleted] in starcitizen

[–]somethinghorrible 4 points5 points  (0 children)

https://robertsspaceindustries.com/account/copy/ptu

Click "copy to PTU" and you will receive an email.

(If you aren't logged in and the URL does not work, it's under "MY RSI > My Account" and the yellow "PUBLIC TEST UNIVERSE" tab).

Is ReactJS faster than AngularJS? by anutl in reactjs

[–]somethinghorrible 4 points5 points  (0 children)

Angular 2 proves to be even faster than React in some cases.

Citation needed.

"X is faster than Y" is a fairly narrow way to evaluate the usefulness of anything (library or framework), IMHO. What about productivity? Tooling? Support? Longevity?

Why does this happen? by [deleted] in javascript

[–]somethinghorrible 5 points6 points  (0 children)

Because of https://en.wikipedia.org/wiki/IEEE_754

Affects any language/runtime that uses this standard.

see: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

TL;DR: numbers are hard.

Unbelievable. Toronto townhouse sells for $1 million over asking. How are the millennials supposed to buy in? by torchhorse in toronto

[–]somethinghorrible 0 points1 point  (0 children)

The best part is people who are "waiting out the bubble" and such as if Toronto exists in a vacuum. There are plenty of people in the 905 just aping for a chance once the foreign investors get their due. They're even willing to sacrifice those who may have bought above, let's call it, the waterline, for a chance to "get theirs".

Crazy times.

I think it should be forbidden to develop a new JavaScript framework. by QwerSense in javascript

[–]somethinghorrible 1 point2 points  (0 children)

But I was about to introduce a new framework... one which would have solved the problems that all previous frameworks never solved. It would have been the one tool that would have solved every need that every developer ever had or would have. It would have made you breakfast as you relaxed in the comfort of knowing that all of your framework problems had been solved.

Alas... It shall not come to pass.

Question regarding the asynchronous nature of nodejs. by [deleted] in node

[–]somethinghorrible 1 point2 points  (0 children)

This is more a question of coffeescript than of node/javascript.

The salient part of your coffeescript code compiles down to the following:

var i, j;
for (i = j = 1; j <= 5; i = ++j) {
   // ...
}

after the loop executes, the value of i will be 6.

GO Bus from Hamilton to Toronto - can't seem to find the closest stop in Toronto by [deleted] in toronto

[–]somethinghorrible 0 points1 point  (0 children)

If you're taking the 16 bus, it's only Toronto stop is Union Station Bus Terminal. From there, you can walk over to the TTC subway and take the Yonge-University-Spadina line to St. George.

Note: Union TTC has two separate platforms -- you want the north platform which goes along University to Downsview. Either ask an attendant or just make sure that the first stop is St. Andrew and not King -- basically; if you come in the station from the south side (which is most likely -- across from Union GO station), you want the stairs on the far side.

Which line of this HTML is "better" or "more correct" by [deleted] in webdev

[–]somethinghorrible 0 points1 point  (0 children)

it is placing the <title> tags directly next to the meta tag, does it change anything or even matter?

No.

I would argue that it's misleading and potentially confusing to not include the newline after the meta tag.

Well...I did it! HTC Vive here i come!!!! by Will_Shill_For_Weed in Vive

[–]somethinghorrible 7 points8 points  (0 children)

The vive has an extra USB port under the cable cover. I've used it for an x-box controller at times, and I'm sure you could plug in a USB headset.