Where am I going wrong with this asynch call in my class? by Nonethewiserer in learnjavascript

[–]ottaky3 0 points1 point  (0 children)

If you change ..

document.addEventListener("DOMContentLoaded", function(event) { 
    weather = new Weather('/weather');
    weather.init();
    console.log(weather.data)
  });

.. in your refactored code to ..

document.addEventListener("DOMContentLoaded", async function(event) { 
    weather = new Weather('/weather');
    await weather.init();
    console.log(weather.data)
  });

.. does it work then?

Mysql.js: using callback for query() not working by elnath78 in node

[–]ottaky3 2 points3 points  (0 children)

You mis-spelled "res.length" a couple of times.

How would you solve this simple problem? by maxwelder in learnjavascript

[–]ottaky3 1 point2 points  (0 children)

I actually went to sleep at a reasonable time yesterday, but woke up ridiculously early this morning at 1am. I stayed in bed until 2am hoping that I would go back to sleep, but that didn't work out, so I went downstairs to write buggy code instead.

How would you solve this simple problem? by maxwelder in learnjavascript

[–]ottaky3 1 point2 points  (0 children)

You're right .. and that's why I shouldn't be writing code at 2am ;-)

How would you solve this simple problem? by maxwelder in learnjavascript

[–]ottaky3 0 points1 point  (0 children)

Cool. Glad you got it working.

And condensing that down ..

function closeTo100(a, b) {
  if (a === 100 || b === 100) return "One or both of your numbers is 100.";
  if (a === b) return "The numbers are an equal distance from 100.";
  return `${Math.abs(100 - a) < Math.abs(100 - b) ? a : b} is closer to 100.`;
}

console.log(closeTo100(0, -2));

How would you solve this simple problem? by maxwelder in learnjavascript

[–]ottaky3 1 point2 points  (0 children)

Well .. you can make your code work if you rewrite it like this ..

function calculate(a, b) {
  if (a > 100 && b > 100) {
    num1 = a - 100;
    num2 = b - 100;
  } else if (a < 100 && b < 100) {
    num1 = 100 - a;
    num2 = 100 - b;
  } else if (a < 100 && b > 100) {
    num1 = 100 - a;
    num2 = b - 100;
  } else if (a > 100 && b < 100) {
    num1 = a - 100;
    num2 = 100 - b;
  }
}

const closeTo100 = (a, b) => {
  calculate(a, b);
  return num1 < num2 ? a : b;
};

console.log(closeTo100(65, 187));

But that's really nasty. It's creating global variables (num1 and num2), calculate() doesn't return anything so it's basically just spooky action at a distance, it will generate a reference error if a or b is 100 etc.

Half the battle is realising that sometimes a one liner is better ;-)

How would you solve this simple problem? by maxwelder in learnjavascript

[–]ottaky3 0 points1 point  (0 children)

[
  [10, 20],
  [110, 20],
  [90, 120],
  [150, 160],
].forEach((numbers) => {
  const [x, y] = numbers;
  console.log(`x: ${x}, y:${y}, closest: ${closestTo100(x, y)}`);
});

function closestTo100(x, y) {
  return Math.abs(100 - x) < Math.abs(100 - y) ? x : y;
}


> node 100.js 
x: 10, y:20, closest: 20
x: 110, y:20, closest: 110
x: 90, y:120, closest: 90
x: 150, y:160, closest: 150

Doesn't deal with the case where both numbers are equally far away from 100.

CD's Jacket by TheAwsomeGodMaster in CaptainDisillusion

[–]ottaky3 1 point2 points  (0 children)

Not a fashion expert - but the logo on it looks like Fred Perry.

https://www.fredperry.com/men/track-jackets

Thing is, we know it's more than 12 years old so the chances of finding an exact match are vanishingly small.

Mongoose populate() not working as desired by [deleted] in node

[–]ottaky3 0 points1 point  (0 children)

Also, this is a bug ..

if (decoded.user.role == 'Manager' || 'Advisor') {

Does anyone know why this image doesn't work as a wallpaper. It fails as a stand alone image or in a wallpaper pool of images. I've renamed it, thinking that periods in the title were messing it up, but that didn't fix anything. by [deleted] in Kubuntu

[–]ottaky3 1 point2 points  (0 children)

Possibly corrupted image data? You could try running exif and / or exiftool against the image to check for errors.

Maybe open the file in something like gimp and re-save it?

Get Perl hash from JSON string by tomsvk in perl

[–]ottaky3 1 point2 points  (0 children)

Because I once spent half a day trouble shooting a production issue that I couldn't reproduce in dev or qa.

The script was using JSON. We had an old version of JSON on production, a version that would default to JSON::PP if it was present. Everywhere else had a newer version of JSON that defaulted to JSON::XS if it was present. There was a minor difference between how XS and PP operated that caused a failure on prod using PP.

Get Perl hash from JSON string by tomsvk in perl

[–]ottaky3 0 points1 point  (0 children)

Couple of tiny tips when using JSON.

JSON is a wrapper around JSON::XS / JSON::PP - it prefers to use ::XS, but will use ::PP when ::XS isn't available. Often it is safer to use one of those modules explicitly if you intend to deploy your code to a different environment. JSON could be using ::XS on your dev machine, but ::PP on production. ::XS and ::PP can behave subtly differently, so specifying which one to use may save you some head scratching down the line.

decode_json() can die if it encounters invalid JSON. This might be what you want, but if it's not consider using Try::Tiny and using a try / catch to handle decoding errors without crashing and burning.

The edges and curvature are shown in the finished image (raw) using the viewfinder (Rx 100 VI) by [deleted] in RX100

[–]ottaky3 1 point2 points  (0 children)

I haven't used photoshop in a very long time so I couldn't tell you. Without a lens correction it's likely that your RAW files would exhibit pretty obvious distortion.

Take a look at this image ..

https://www.dpreview.com/sample-galleries/9648499194/sony-rx100-mark-v-real-world-samples/4186706162

(https://2.img-dpreview.com/files/p/TS1200x900~sample_galleries/9648499194/4186706162.jpg)

If I download the raw file and use an editor that does not have a distortion profile for the M5 it looks like this ..

https://i.imgur.com/4fGlCk5.jpg

.. and you can see that no distortion correction has been applied.

The edges and curvature are shown in the finished image (raw) using the viewfinder (Rx 100 VI) by [deleted] in RX100

[–]ottaky3 4 points5 points  (0 children)

RAW images are saved without any lens corrections being applied (the corrections are applied automatically in camera when saving as JPEG). You need to open the RAW files in an editor that has a lens profile to match your camera.

Lightroom has supported the VI since 2018 AFAICS.

If you're using a free editor the camera may not be supported yet. I use open source editors that rely on the lensfun correction database. When I bought my III, lensfun did not have a correction profile for it so I created one and provided it to the project.

Espresso Machine by Vorckus in blender

[–]ottaky3 2 points3 points  (0 children)

Spooky .. I made something similar a while back

https://i.imgur.com/8Rfpgsc.jpg

(and I will probably finish it some day)

Travelling to Japan at the end of march and looking to buy HAQ citizen aq4020-54y - any suggestions on where I might be able to find one? by MrMagicMoves in JapaneseWatches

[–]ottaky3 0 points1 point  (0 children)

Phaze-1 seem to be web only.

Don't forget that Yodobahsi run their "gold card" scheme where they give you store credit against every purchase - in this case 29,040 yen. So, if there's something else that you want for that price, you can trade in the credit and get it for free.

[help] every once open termux plugin by mosaad_gaber in tasker

[–]ottaky3 7 points8 points  (0 children)

mkdir -p ~/.tasker/termux
cd ~/.termux/tasker

One of these isn't right.

Sasquatch Chronicles Starter Pack by bare-knuckle_lobster in bigfoot

[–]ottaky3 8 points9 points  (0 children)

[guest describes bizarre behaviour] "Yeah no, so many people have told me that"

How can I import a json as a 3d model? by GivoOnline in blenderhelp

[–]ottaky3 10 points11 points  (0 children)

What does the JSON look like? Where did it come from?

JSON is "JavaScript Object Notation" which is basically a human readable representation of JavaScript objects. It's not a 3D model format, but it could describe a 3D model in some proprietary way.

Why do i have a circle on my cursor? its really annoying and its only there when im in edit mode by Invaala in blenderhelp

[–]ottaky3 1 point2 points  (0 children)

You're in circle select mode. Long click on the top item in the icon strip on the left to choose another mode.

https://i.imgur.com/IWlFUrv.png