Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dross
Sep 26, 2006

Every night he puts his hot dogs in the trees so the pigeons can't get them.

dev bootcamp instructor posted:



JavaScript code:
const promisesExample = () => {
  return new Promise((resolve, reject) => {
    $.ajax("someExampleUrl")
      .done((data) => {
        resolve(data);
      })
      .fail((error) => {
        reject(error);
      });
  });
};

Adbot
ADBOT LOVES YOU

QuarkJets
Sep 8, 2008

KernelSlanders posted:

Python code:
DOES_NOT_EXIST_VALUE = "DNE"
NULL_VALUE = "NULL"
EV2 = "ev2"
EV3 = "ev3"

I can only hope that this is code accessing a really poorly designed database

Ranzear
Jul 25, 2013

LDAP

It is ... a true horror.

Now how the gently caress do I give anyone but the root account permissions to add more users.

(Edit: Also, it's loving black magic and I love it.)

Ranzear fucked around with this message at 06:40 on Oct 18, 2017

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Just accidentally made a commit message rhyme and didn't realize until after it was too late :v:

Pollyanna
Mar 5, 2005

Milk's on them.



I’m so glad I stay away from promises as much as possible.

Eleeleth
Jun 21, 2009

Damn, that is one suave eel.

is the horror here using jquery ajax in 2017?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Rubellavator posted:

We joked about autogenerating a class that is x times larger than the codebase that just counts to a million or something with a single test to cover it.

It would probably crash due to having too much code in one method/class. Hell, I think that problem was shown in this thread just recently. I just like to bring it up because that's just one of those things that messes with people. "You mean that's a thing?"

Dross
Sep 26, 2006

Every night he puts his hot dogs in the trees so the pigeons can't get them.

Tomie knows me posted:

is the horror here using jquery ajax in 2017?

That and putting a function that already uses the promise API inside another promise unnecessarily when the second layer doesn't do anything to the returned data

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Dross posted:

That and putting a function that already uses the promise API inside another promise unnecessarily when the second layer doesn't do anything to the returned data

jQuery doesn't use the real promise API, though

Dross
Sep 26, 2006

Every night he puts his hot dogs in the trees so the pigeons can't get them.

Is that really relevant here? Like is there an actual good reason for doing it the quoted way when you can chain .then and .catch off of a returned AJAX call or include them in a Promise.all the same as any other promise?

necrotic
Aug 2, 2005
I owe my brother big time for this!

Pollyanna posted:

I’m so glad I stay away from promises as much as possible.

Promises are great

Odette
Mar 19, 2011

necrotic posted:

Promises are great

Better than callbacks, that's for sure.

Coffee Mugshot
Jun 26, 2010

by Lowtax

Pollyanna posted:

I’m so glad I stay away from promises as much as possible.

You also had a similar sentiment to switch statements. I don't really think programming is about avoiding completely harmless/innocuous things because someone blogged about it affecting their performance once.

Pollyanna
Mar 5, 2005

Milk's on them.


Coffee Mugshot posted:

You also had a similar sentiment to switch statements. I don't really think programming is about avoiding completely harmless/innocuous things because someone blogged about it affecting their performance once.

True. I guess I worded that badly - it's moreso that I have no loving clue what's going on there so it's really on me. :downs:

McGlockenshire
Dec 16, 2005

GOLLOCKS!
From the AMD CPU thread,

repiv posted:

https://www.youtube.com/watch?v=UMzXMvOaTZk

tldr: AMDs NVMe RAID driver installs outdated, exploitable copies of Apache and PHP just to host the config UI, and configures them to run as SYSTEM (i.e. root) and listen on all external network interfaces :psyboom:

Why yes, I always install XAMPP with my drivers. Keep watching, it gets worse.

McGlockenshire fucked around with this message at 00:49 on Oct 19, 2017

MrMoo
Sep 14, 2000

Sounds like standard HP SCSI controller software :shrug:

reversefungi
Nov 27, 2003

Master of the high hat!

necrotic posted:

Promises are great

And once you're using promises, you're a simple step away from using async/await which is fantastic.

Odette
Mar 19, 2011

The Dark Wind posted:

And once you're using promises, you're a simple step away from using async/await which is fantastic.

Where did async/await originate? I remember using it in C# a few years ago (with try/catch, which works really with JS async/await), and it seems to have become more common.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Odette posted:

Where did async/await originate? I remember using it in C# a few years ago (with try/catch, which works really with JS async/await), and it seems to have become more common.

C# introduced the async / await keywords.

They were inspired by the F# async {} expression, which had been around for a few years then; though C# async/await is a strictly ad-hoc, compiler-level implementation of what in F# is just a library-level feature that uses the language's generic wrapper and unwrapper syntax ({} and let!, respectively).

In fact, some F# libraries have since taken to including an alternative task {} expression for easier C# interop and better performance.

NihilCredo fucked around with this message at 07:25 on Oct 19, 2017

QuarkJets
Sep 8, 2008

promises are fine but oaths are definitely better

eternal moral vigilance transcends all other features

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Watch out for my new polyfill library, pinkyswear.js

Doom Mathematic
Sep 2, 2008

Suspicious Dish posted:

Watch out for my new polyfill library, pinkyswear.js

?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

gently caress me

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Suspicious Dish posted:

gently caress me

I'd do this if programming knowledge was an STD.

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

QuarkJets posted:

promises are fine but oaths are definitely better

eternal moral vigilance transcends all other features
Agreed, that's why I write all async code in Vigil

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Dross posted:

Is that really relevant here? Like is there an actual good reason for doing it the quoted way when you can chain .then and .catch off of a returned AJAX call or include them in a Promise.all the same as any other promise?

If you're using Promises elsewhere, it's worth wrapping the nonstandard Promise-alike so you don't have to think about it later, but I'm not going to claim that's the least bad way to do it.

Suspicious Dish posted:

gently caress me

lol

canis minor
May 4, 2011

Stackoverflow posted:

> How would I go about setting the position of a JavaScript object using HTML/CSS.

<body>
<h1>Bouncing Ball Animation</h1>
<div id = "bounce"><script src = "Bounce.js" type = "text/javascript"></script></div>
</body>

quote:

To center an html element horizontally, I think the easiest way would be margin: auto. To center it vertically, there's always flexbox. If you want to use javascript (probably more cross-browser):

var b = $('#bounce');
b.css('margin-top', window.innerHeight/2 - b.height()/2);

:suicide:

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Just got here from "Funny Forum Quotes" and am really upset that I didn't know about this entire subforum while I spent the whole week struggling with Promises code making an express server. I ended up just making them all happen in a serial way.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Jesus Christ there's so much horror to unravel here.

AstuteCat
May 4, 2007

Hey guys, long time lurker, first time code-shamer.

I'm doing a code review for a contractor and while this isn't the worst code I've ever seen from this particular individual, it's also baffling just how much pointless complexity has been added here:

code:
switch (symbol) {
        case "<":
          if ((parseInt(actualValue) > parseInt(valueToSearch)) || (parseInt(actualValue) == parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
        
        case ">":
          if ((parseInt(actualValue) < parseInt(valueToSearch))  || (parseInt(actualValue) == parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        case "<=":
          if ((parseInt(actualValue) > parseInt(valueToSearch)) && (parseInt(actualValue) != parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        case ">=":
          if ((parseInt(actualValue) < parseInt(valueToSearch)) && (parseInt(actualValue) != parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        default:
          return true;
          break;
      }

QuarkJets
Sep 8, 2008

how broken does your brain have to be to always think in opposites like that

iospace
Jan 19, 2038


AstuteCat posted:

Hey guys, long time lurker, first time code-shamer.

I'm doing a code review for a contractor and while this isn't the worst code I've ever seen from this particular individual, it's also baffling just how much pointless complexity has been added here:

code:
switch (symbol) {
        case "<":
          if ((parseInt(actualValue) > parseInt(valueToSearch)) || (parseInt(actualValue) == parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
        
        case ">":
          if ((parseInt(actualValue) < parseInt(valueToSearch))  || (parseInt(actualValue) == parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        case "<=":
          if ((parseInt(actualValue) > parseInt(valueToSearch)) && (parseInt(actualValue) != parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        case ">=":
          if ((parseInt(actualValue) < parseInt(valueToSearch)) && (parseInt(actualValue) != parseInt(valueToSearch))) {
            return false;
          }
          return true;
          break;
      
        default:
          return true;
          break;
      }

Please present the award that your avatar has to the person who wrote that. Thank you.

quiggy
Aug 7, 2010

[in Russian] Oof.


AstuteCat posted:

code:
  
        default:
          return true;
          break;

I think this is my favorite part. Did your finger slide off the shift key and you wrote ',' instead of '<'? Looks like your answer is true!

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Best part is checking if a > b && a != b, you know, just in case! Sometimes 9 is the same as 8 even after it's been determined that it's greater. You gotta watch that edge case.

Is this all they meant to do?

code:
let a = Number(actualValue), s = Number(valueToSearch);

switch (symbol) 
{ case "<" : return a <  s;
  case ">" : return a >  s;
  case "<=": return a <= s;    
  case ">=": return a >= s;
  default  : return true;
}
In whatever context it's in, does this much even make sense to do there?

Happy Thread fucked around with this message at 18:16 on Oct 20, 2017

AstuteCat
May 4, 2007

Dumb Lowtax posted:

Best part is checking if a > b && a != b, you know, just in case! Sometimes 9 is the same as 8 even after it's been determined that it's greater. You gotta watch that edge case.

Is this all they meant to do?

code:
let a = Number(actualValue), s = Number(valueToSearch);

switch (symbol) 
{ case "<" : return a <  p;
  case ">" : return a >  p;
  case "<=": return a <= p;    
  case ">=": return a >= p;
  default: return true;
}

Yes. That is all that this function, far as I can tell, is intended to do.

Fake Edit: Update on the code review that should have really been over with by now:



Edit: I think what makes this particular egregious is that he actually has the operators in the switch statement -- like, they are RIGHT THERE.

AstuteCat fucked around with this message at 16:42 on Oct 20, 2017

Rubellavator
Aug 16, 2007

E: dumb me

CPColin
Sep 9, 2003

Big ol' smile.

AstuteCat posted:

Edit: I think what makes this particular egregious is that he actually has the operators in the switch statement -- like, they are RIGHT THERE.

Click that "Create JIRA issue" link and title it, "Remove (employee)'s JIRA access."

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
Send them the equivalent short code and make them justify why it's any longer

I'd love to see their code surrounding this

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



AstuteCat posted:

Yes. That is all that this function, far as I can tell, is intended to do.

Fake Edit: Update on the code review that should have really been over with by now:



Edit: I think what makes this particular egregious is that he actually has the operators in the switch statement -- like, they are RIGHT THERE.

Well you wouldn't want your bools backwards would you?!

Adbot
ADBOT LOVES YOU

Rubellavator
Aug 16, 2007

Just have them change the code and if their unit tests still pass then they will understand right?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply