These are chat archives for FreeCodeCamp/HelpJavaScript

2nd
Nov 2018
Albert Cardona II
@daddycardona
Nov 02 2018 02:51
@sjames1958gm how you been brother :)
enestatli
@enestatli
Nov 02 2018 07:52
what are the key differences between Python 2 and 3?
catalin560
@catalin560
Nov 02 2018 08:07
anybody got a challenge for me? I'm kinda bored
Aditya
@ezioda004
Nov 02 2018 08:09
@enestatli I believe not a whole lot, print statement has changed and some other minor changes from 2 to 3.
@catalin560 Like algorithms?
catalin560
@catalin560
Nov 02 2018 08:10
yes please
Aditya
@ezioda004
Nov 02 2018 08:11
@catalin560 Have you tried project euler section? Its got pretty decent algorithms
enestatli
@enestatli
Nov 02 2018 08:12
@ezioda004 thanks bro, I thought you were asleep :D
Aditya
@ezioda004
Nov 02 2018 08:12
@enestatli Hah, not yet :smile:
catalin560
@catalin560
Nov 02 2018 08:42
@ezioda004 I know about the euler project but I didn't knew it migrated to fcc. I think I remember a couple of them
guess this should keep my occupied when I get bored at work hehe :laughing:
Claudio Restifo
@Marmiz
Nov 02 2018 08:57
@catalin560 the other day I found this pretty fun to do. It's a simplified version of an interview question:
Convert a number to a string, the contents of which depend on the number's factors.

- If the number has 3 as a factor, output 'Pling'.
- If the number has 5 as a factor, output 'Plang'.
- If the number has 7 as a factor, output 'Plong'.
- If the number does not have 3, 5, or 7 as a factor,
  just pass the number's digits straight through.

## Examples

- 28's factors are 1, 2, 4, **7**, 14, 28.
  - In raindrop-speak, this would be a simple "Plong".
- 30's factors are 1, 2, **3**, **5**, 6, 10, 15, 30.
  - In raindrop-speak, this would be a "PlingPlang".
- 34 has four factors: 1, 2, 17, and 34.
  - In raindrop-speak, this would be "34".
Chris Cullen
@123xylem
Nov 02 2018 10:24

```
var payOptionsString = "a,b,c,d,e";
$(".loading tr").hide().filter(function() {
var rtnData = "";

 regExApproved    = new RegExp('\\b(' + payOptionsString + ')\\b', 'gi');

 rtnData = (
    $(this).attr("data-payment").match(regExApproved)     
    );

return rtnData;
}).fadeIn("fast");

});
});
``
How can I get a regex to find words in my string and return elements with data -attributes of the same kind?

catalin560
@catalin560
Nov 02 2018 12:22
@Marmiz done
function numToStr(n) {
    let i = n+1,
        finalArr = [],
        strObj = {
        3: "Pling",
        5: "Plang",
        7: "Plong"
    };
    while (i--) {
        if (n % i === 0) {
            finalArr.push(strObj[i] ? strObj[i]+", " : i+", ");
        }
    }
    return finalArr.reverse().join("");
}
numToStr(30);
//1, 2, Pling, Plang, 6, 10, 15, 30,
Blauelf
@Blauelf
Nov 02 2018 12:26
@catalin560 I don't think that's the desired output, if I understand it correctly, it should return just a string "PlingPlang" for 30.
Looks like a variation of our all favourite FizzBuzz.
catalin560
@catalin560
Nov 02 2018 12:31
🤔
catalin560
@catalin560
Nov 02 2018 12:40
@Blauelf well the question is kinda confusing but if that is the desired output then I guess this becomes even easier:
function numToStr(n) {
    let i = n+1,
        finalArr = [],
        strObj = {
        3: "Pling",
        5: "Plang",
        7: "Plong"
    };
    while (i--) {
        if (n % i === 0 && strObj[i]) {
            finalArr.push(strObj[i]);
        }
    }
    return finalArr.reverse().join("") || n;
}
numToStr(28);
//Plong
numToStr(30);
//PlingPlang
numToStr(34);
//34
Blauelf
@Blauelf
Nov 02 2018 13:03

Why not just

function numToStr(n) {
    const finalArr = [];
    const strObj = {
        3: "Pling",
        5: "Plang",
        7: "Plong"
    };
    for (let i in strObj) {
        if (n % i === 0) {
            finalArr.push(strObj[i]);
        }
    }
    return finalArr.join("") || n;
}

?

catalin560
@catalin560
Nov 02 2018 13:04
hmm 🤔 wont that push undef in my arr?
Blauelf
@Blauelf
Nov 02 2018 13:06
I iterate over all the enumerable properties in strObj. Unless somebody extended Object.prototype with an enumerable property, that works. Could use some if (strObj.hasOwnProperty(i) && n % i === 0) to eliminate that problem.
catalin560
@catalin560
Nov 02 2018 13:09
ah I see! good to know :smile: I was aware of for ... in ... loops but can't remember why I avoid them
i think there is also a for...of...???
Blauelf
@Blauelf
Nov 02 2018 13:11
for..of is for iterable objects. This thing isn't iterable. for..in on the other hand just iterates all the enumerable properties, own or inherited, in no particular order. Numeric properties are usually put first, non-numeric in order of creation. With slight differences on older IE.
enestatli
@enestatli
Nov 02 2018 13:12
def is_int(x):
  if x % 1 == 0:
    return True
  return False

print is_int(raw_input("Number: "))

why gives error, when I try some number

Traceback (most recent call last):
File "python", line 8, in <module>
File "python", line 2, in is_int
TypeError: not all arguments converted during string formatting

Blauelf
@Blauelf
Nov 02 2018 13:22

@enestatli Are you writing in wrong room or is it my browser mixing rooms again?

The % operator on strings is for formatting. It was the predecessor of .format method and now f"" format strings.

You need to convert to a number first, which could fail, but that's not necessarily bad. So you could use something like

def is_int(x):
    try:
        int(x) #fails if non-integer
        return True #Note to myself: In Python, booleans start uppercase
    except ValueError:
        return False
enestatli
@enestatli
Nov 02 2018 13:23
what do you mean "room"? :D
Stephen James
@sjames1958gm
Nov 02 2018 13:24
@daddycardona good - haven't been on lately - working three jobs :)
Blauelf
@Blauelf
Nov 02 2018 13:24
@enestatli Chat room, channel, whatever. Maybe I'm old.
enestatli
@enestatli
Nov 02 2018 13:24
oh this chat only for JS
sorry :D
Blauelf
@Blauelf
Nov 02 2018 13:25
Well, you got an explanation of what happened in your Python code.
enestatli
@enestatli
Nov 02 2018 13:25
@Blauelf int() function will be work, withouth import math module?
Blauelf
@Blauelf
Nov 02 2018 13:25
That's not a maths function.
enestatli
@enestatli
Nov 02 2018 13:26
okay, thanks a lot bro! :)
Matthew
@RoutinePoutine
Nov 02 2018 14:46
Are Async Await, Fetch, and the jQuery ASYNC functions created equal, or is there a way to rank them in terms of efficiency?
Blauelf
@Blauelf
Nov 02 2018 14:52
Do you mean the Deferreds?
Christopher McCormack
@cmccormack
Nov 02 2018 14:54
@RoutinePoutine maybe check out this series
Jason Luboff
@JLuboff
Nov 02 2018 15:21
Morning
Christopher McCormack
@cmccormack
Nov 02 2018 15:21
@JLuboff yo
what's up
Jason Luboff
@JLuboff
Nov 02 2018 15:22
It's Friday...thankfully
Just getting settled into work
you?
Markus Kiili
@Masd925
Nov 02 2018 15:24
Yo.
Christopher McCormack
@cmccormack
Nov 02 2018 15:24
@Masd925 hi!
@JLuboff trying to learn this github/git process with FCC, man it can be complicated
then work
Jason Luboff
@JLuboff
Nov 02 2018 15:25
@Masd925 Hey man...break any records lately?
@cmccormack github/git process with FCC?
Markus Kiili
@Masd925
Nov 02 2018 15:26
@JLuboff No, sorry. Next competitions are in the late spring, so no big news before that most likely.
Christopher McCormack
@cmccormack
Nov 02 2018 15:26
@JLuboff yeah with those 10,000+ pull requests for hacktoberfest, I'm learning the process for review/closing/updating/merging/rebasing etc..
Markus Kiili
@Masd925
Nov 02 2018 15:27
@cmccormack Could you rub some of that git knowledge into me, please.
Jason Luboff
@JLuboff
Nov 02 2018 15:27
@Masd925 Ah.. I'll be waiting to hear back from you than in regards to that
@cmccormack oh...gross... :joy:
Christopher McCormack
@cmccormack
Nov 02 2018 15:28
@Masd925 I am not the right person atm to answer any questions hahaha still trying to get a good understanding
Getting there though
Jason Luboff
@JLuboff
Nov 02 2018 15:30
@cmccormack So.. went into a meeting yesterday...have another project to work on
Christopher McCormack
@cmccormack
Nov 02 2018 15:30
Is that good?
Jason Luboff
@JLuboff
Nov 02 2018 15:31
Ya...although it means I'll have two projects overlapping
Christopher McCormack
@cmccormack
Nov 02 2018 15:33
make them prioritize, you're only one person!
Jason Luboff
@JLuboff
Nov 02 2018 15:34
True true. This project I probably won't even be starting until December so not a huge deal
I still need to get all the info and what not. But it's going to be similar to my last project, so I'll probably have a lot of reusuable components
Christopher McCormack
@cmccormack
Nov 02 2018 15:36
@Masd925 FCC employee made a guide for updating another person's PR if that's useful link
catalin560
@catalin560
Nov 02 2018 15:36
@Masd925 what competitions are you into?
Jason Luboff
@JLuboff
Nov 02 2018 15:38
@catalin560 He does freediving (I believe thats the right term) competitions
Holds his breathe for like 6-7 minutes or something
catalin560
@catalin560
Nov 02 2018 15:41
🤔
Blauelf
@Blauelf
Nov 02 2018 15:43
Doesn't he live somewhere in the north (Finland?), where water is pretty cold? But, maybe that's even helping, slowing down your whole system.
Jason Luboff
@JLuboff
Nov 02 2018 15:44
Ya, he is in Finland (atleast according to his profile location as seen by hovering over his picture)
catalin560
@catalin560
Nov 02 2018 15:46
stop bullying @Masd925 , you guys are just jealous :laughing:
Jason Luboff
@JLuboff
Nov 02 2018 15:46
No bullying here
Markus Kiili
@Masd925
Nov 02 2018 15:46
@catalin560 I have competed in chess for over 30 years (but not really that good in it) and in freediving for a couple of years.
Blauelf
@Blauelf
Nov 02 2018 15:47
30 years? People that old are in this channel?
Christopher McCormack
@cmccormack
Nov 02 2018 15:47
@Masd925 this is helpful if you ever want to sync a fork of a repo
Jason Luboff
@JLuboff
Nov 02 2018 15:49
@Blauelf ...I mean...technically I'm that old (30) lol
And I've competed in life for over 30 years now!
Blauelf
@Blauelf
Nov 02 2018 15:50
I meant - people competing in chess for 30 years. While I know people who played chess before entering school (don't know how precisely they followed the rules), they probably did not compete until later.
catalin560
@catalin560
Nov 02 2018 15:51
@Masd925 huh, I thought you were competing in programming :confused: @Blauelf don't think 30 is that old of an age, I think its the perfect time to love/hate life, ying/yang and that stuff :laughing:
Blauelf
@Blauelf
Nov 02 2018 15:52
30 years of competing in chess means he's likely even older than me (35).
Markus Kiili
@Masd925
Nov 02 2018 15:53
@Blauelf I'm 45, which is like really old.
Blauelf
@Blauelf
Nov 02 2018 15:54
Oh no, in just 10 years I am like really old...
Christopher McCormack
@cmccormack
Nov 02 2018 15:54
@Blauelf hey then we're the same age!
@JLuboff is always calling me old so at least I'm in good company :D
Jason Luboff
@JLuboff
Nov 02 2018 15:56
You all are old. I'm just a a young wipper-snapper at 30
Markus Kiili
@Masd925
Nov 02 2018 15:57
@JLuboff The secret for holding breath is being old. Flesh gets weaker and softer and you can force more air into lungs.
Christopher McCormack
@cmccormack
Nov 02 2018 16:01
until one day you're so old you fill up with air like a puffer fish
Blauelf
@Blauelf
Nov 02 2018 16:13
Just imagining a @Masd925 filled with helium floating in the air :D
BTW, did you know helium shuts down modern Apple devices? Stops their internal clocks.
Christopher McCormack
@cmccormack
Nov 02 2018 16:14
why helium?
Blauelf
@Blauelf
Nov 02 2018 16:14
Because it's very small. Hydrogen has about the same effect.
Read about a helium leak in an NMRI system that basically bricked about 40 iPhones (most of which recovered in the following days).
Blauelf
@Blauelf
Nov 02 2018 16:20
Yeah, that's a massive helium leak they had, our helium cooling at the ion accelerator had only a few litres (I think it was not cooling magnets, that's just a boring linear ion accelerator).
Christopher McCormack
@cmccormack
Nov 02 2018 16:21
that's funny haha
Blauelf
@Blauelf
Nov 02 2018 16:37
We probably were just cooling our targets with that helium pump. Pretty annoying squeaky sound. Well, the whole machine made all sorts of noises, as it's all the time pumping any remaining gas out. Turbopumps with their high pitch, rotary vane pumps with their low pitch, all kinds of other pumps, plus fans for cooling the equipment... But hey, that's 6MeV maximum (2x 3MeV by reversing polarity at one point, stripping negative ions of electrons).
Blauelf
@Blauelf
Nov 02 2018 16:42
Liquid helium is not exactly a cheap thing, unlike liquid nitrogen or liquid argon which can be distilled from air (we had our own air liquifier at the physics department). So losing 120 litres of He, yeah.
Christopher McCormack
@cmccormack
Nov 02 2018 16:42
I don't know much about what you just said, but I really like the pretty pictures in that article
well helium is a limited resource right?
Blauelf
@Blauelf
Nov 02 2018 16:45
I think it's separated from natural gas. So pretty much, yeah. In the atmosphere, it is lighter than most gases (all but 3He and H2), so it will probably easily evaporate into space.
Christopher McCormack
@cmccormack
Nov 02 2018 16:48
I'm going to start hoarding helium in underground tanks
while it is still relatively cheap :grin:
Jason Luboff
@JLuboff
Nov 02 2018 16:49
There was a shortage of helium here for a while
Blauelf
@Blauelf
Nov 02 2018 16:52
Hmm... does maths mode work like I think it does? 3He^3\mathrm{He} H2\mathrm{H}_2 Oh yes, it does!
Christopher McCormack
@cmccormack
Nov 02 2018 16:53
math's mode?
Blauelf
@Blauelf
Nov 02 2018 16:53
@cmccormack Problem with Helium is basically what bricked the iPhones. It's hard to contain.
Maths mode, I mean KaTeX\KaTeX
Christopher McCormack
@cmccormack
Nov 02 2018 16:54
ah yeah that works
Blauelf
@Blauelf
Nov 02 2018 16:54
Like $$^3\mathrm{He}$$ for 3He^3\mathrm{He}
Christopher McCormack
@cmccormack
Nov 02 2018 16:54
I was using that for big O notation the other day
I still need to determine if that works in markdown on github so we can make pretty a lot of the formulas
Blauelf
@Blauelf
Nov 02 2018 16:55
Like O(nlogn)\mathcal{O}(n \log n)?
Christopher McCormack
@cmccormack
Nov 02 2018 16:55
yeah
Blauelf
@Blauelf
Nov 02 2018 16:55
There's mathjax if you don't have built-in support.
Christopher McCormack
@cmccormack
Nov 02 2018 16:58
mathjax sounds like a bad cereal that kids hate
Blauelf
@Blauelf
Nov 02 2018 17:00
Maybe it is. Fruit loops shaped like numbers and operators. You may eat them only if you arrange them to an equation that holds true.
Chris Cullen
@123xylem
Nov 02 2018 17:01
@Blauelf
Hey man
Can someone help me match my REGEX to my data-attribute?!
*
https://pastebin.com/Bvh2Xj9U
Christopher McCormack
@cmccormack
Nov 02 2018 17:02
@123xylem it's easier to help if you share this in an online editor like codepen or repl.it
Blauelf
@Blauelf
Nov 02 2018 17:04
@123xylem Your space characters after the commas might hurt. Also, why exactly that kind of string?
Chris Cullen
@123xylem
Nov 02 2018 17:13
@cmccormack @Blauelf
var string = "car, boat, Anotherrandomword';
    var regApproved=    new RegExp(`\\b(${string.split(',').join('|')})\\b`, 'gi')
                // console.log(regApproved);

                rtnData = (

                $(this).attr("data-payment").match(regApproved)
                );
Blauelf
@Blauelf
Nov 02 2018 17:13
Triple backticks.
Christopher McCormack
@cmccormack
Nov 02 2018 17:14
```
Code
```
Chris Cullen
@123xylem
Nov 02 2018 17:14
ah
regApproved outputs = /\b(["visa"|"mastercard"])\b/gi
Christopher McCormack
@cmccormack
Nov 02 2018 17:15
you can also label the language by adding something like
```js
Code
```
Blauelf
@Blauelf
Nov 02 2018 17:15
@123xylem You have non-matching quotation characters. Double quotes left, single quotes right. Make them same type.
Christopher McCormack
@cmccormack
Nov 02 2018 17:16
also are you trying to use \b? Why double backslashes?
Blauelf
@Blauelf
Nov 02 2018 17:16
Double backslashes because that's a string literal.
You don't want to see how to use a literal backslash there :P
Chris Cullen
@123xylem
Nov 02 2018 17:16
Ah the string is just an example
the real out put is this so far:
/\b(["visa"|"mastercard"])\b/gi
that is my reApproved
Christopher McCormack
@cmccormack
Nov 02 2018 17:17
please use the formatting
Chris Cullen
@123xylem
Nov 02 2018 17:17
And I need it to match my data attribute
Blauelf
@Blauelf
Nov 02 2018 17:17
@123xylem The square brackets and quotation marks should not go into the regular expression.
Christopher McCormack
@cmccormack
Nov 02 2018 17:17
when you paste it like that we may lose information
/\b(visa|mastercard)\b/gi
Blauelf
@Blauelf
Nov 02 2018 17:21
@123xylem Also, does your string have these spaces after comma? If so, you should strip them, like .split(/\s*,\s*/) (this does not strip spaces from front or back of the string, only around the comma)
I'd prefer an array, like myArray = ["visa", "mastercard"]; and then myArray.join("|").
Chris Cullen
@123xylem
Nov 02 2018 17:23
this is the data-attribute value Im trying to match "all, visa, mastercard, ideal, entropay"
So maybe I need a comma after results
Blauelf
@Blauelf
Nov 02 2018 17:35
Now I'm more confused than before. What are possible strings that should be matched, what are strings that should not be matched?
Christopher McCormack
@cmccormack
Nov 02 2018 17:42
Please try to provide examples that help us understand what you're trying to do @123xylem don't make us guess. Can you provide an example element as well, with the data-attribute?
Shubham soni
@shubhamsoni2617
Nov 02 2018 17:44
function check(x) {
    if(x=='undefined'){
        return 'pass argument';
    }
    if(typeof(x)!=='number'){
    return 'not a number';
    }

return x;
}

console.log(check(2)); // expecting output: 2  <<actual
console.log(check('John')); // expecting output: not a number <<actual
console.log(check());  // expecting output: pass argument actual: not a number
I am not getting expected result for 3rd case... anyone please
Christopher McCormack
@cmccormack
Nov 02 2018 17:44
undefined is not a string
@shubhamsoni2617 either use typeof x == 'undefined' or x == undefined
you also do not need a second if statement if you return in the first
Shubham soni
@shubhamsoni2617
Nov 02 2018 17:46
@cmccormack alright!! thanks
Christopher McCormack
@cmccormack
Nov 02 2018 17:47
@shubhamsoni2617 :thumbsup:
Mohammed Boudad
@matrixersp
Nov 02 2018 18:25

Hey everyone, I'm following a tutorial on how to create a chat app using nodejs-websocket, although I followed the tutorial word by word, I get this error:

WebSocket connection to 'ws://127.0.0.1:8001/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

These files can be helpful: Client.js Server.js App.js

Christopher McCormack
@cmccormack
Nov 02 2018 18:30
@matrixersp can you post the file that actually runs your server?
Pagnito
@Pagnito
Nov 02 2018 18:38
hey anyone have any advice on creating scroll animations working properly with different screen sizes
atm im using cases to animate things at different points on differnt sccreen sizes
tho i wonder if im maybe missing something
Christopher McCormack
@cmccormack
Nov 02 2018 18:39
scrolling to what?
an HTML element?
Pagnito
@Pagnito
Nov 02 2018 18:43
nah i mean, when user scolls down to lets say about page, activate 'this' animation
Christopher McCormack
@cmccormack
Nov 02 2018 18:43
scrollspy?
that still depends on scrolling down to an element
Pagnito
@Pagnito
Nov 02 2018 18:44
i mean i would would sort of like a scrollspy i guess
it*
but no, not scrollspy
click about
Nate Mallison
@NJM8
Nov 02 2018 18:45
Anyone know if there is a way to pass control of an if statement back to the next else if?
Pagnito
@Pagnito
Nov 02 2018 18:46
oh hold on i gotta restart tunnel
Nate Mallison
@NJM8
Nov 02 2018 18:47
if (iMeetCondition) {
  if (iMeetCondition.condition) {
    return iMeetCondition.condition
  } else {
    //oops continue on to next block
  }
} else if (something) {
  //continue on here
}
Brad
@bradtaniguchi
Nov 02 2018 18:47
@NJM8 what?
flat if statements? (no else)
Christopher McCormack
@cmccormack
Nov 02 2018 18:47
@NJM8 remove both else
Brad
@bradtaniguchi
Nov 02 2018 18:48
if (IMeetCondition && iMeetCondition.condition) {
  return iMeetCondition.condition;
}
if (something) {
  //...
}
Christopher McCormack
@cmccormack
Nov 02 2018 18:48
if I ever feel the need to use an else if, I move that logic to a function and just use returns :)
Nate Mallison
@NJM8
Nov 02 2018 18:48
oh yeah. hmmm
Christopher McCormack
@cmccormack
Nov 02 2018 18:48
then let the logic fall through that function
Brad
@bradtaniguchi
Nov 02 2018 18:48
@cmccormack Yea same here, my conditionals never have else's and everything "falls thru" so there's minimal nesting
Christopher McCormack
@cmccormack
Nov 02 2018 18:49
unless maybe a tricky little validator or something
IMO conditional statements are the easiest way to cause problems in code
I know they are needed but there are other ways to implement that logic that are far safer
Jason Luboff
@JLuboff
Nov 02 2018 18:50
oh man...you guys won't like my code then
Nate Mallison
@NJM8
Nov 02 2018 18:51
it's a request interceptor. basically on 404 I want to check if error.response.data.error.message meets a certain message then do something, but nested object access throws errors if the object doesn't exist. Hypothetically it should always exist as the api always returns it. But that isn't safe enough for me. And I really don't want to do this:
if (error.response && error.response.data && error.response.data.error etc etc)
You guys should see my input validator on my JS calculator. what a mess haha
Jason Luboff
@JLuboff
Nov 02 2018 18:52
So can error.response.data exist without ...error.message?
Brad
@bradtaniguchi
Nov 02 2018 18:52
@JLuboff Don't tell me your code has nested logic within nested logic :'(
@NJM8 I have a helper method to "grab" nested properties, I use it for that sorta stuff, and to validate incoming requests to make sure it "has all the values". But I use is sparingly, since I can't log the actual thing missing (its all or nothing)
Jason Luboff
@JLuboff
Nov 02 2018 18:53
@bradtaniguchi :trollface: (Guess I don't need the else if...could just be an if)
    if (updateHazardAndControl.length && checkForHazard(updateHazardAndControl[0].hazardAndControls)) {
      let controlIDArray = [...updateHazardAndControl[0].hazardAndControls[index].controlIDs];
      let controlNameArray = [...updateHazardAndControl[0].hazardAndControls[index].controlNames];
      //Category not found in array, and checkbox is checked
      if (controlIDArray.indexOf(categoryID) < 0 && checkboxState) {
        controlIDArray.push(categoryID);
        controlNameArray.push(categoryName);
        updateHazardAndControl[0].hazardAndControls[index].controlIDs = controlIDArray;
        updateHazardAndControl[0].hazardAndControls[index].controlNames = controlNameArray;
      }
      //Category foun in array, checkbox is unchecked
      else if (controlIDArray.indexOf(categoryID) > -1 && !checkboxState) {
        const spliceIndex = Number(controlIDArray.indexOf(categoryID));

        controlIDArray.splice(spliceIndex, 1);
        controlNameArray.splice(spliceIndex, 1);
        updateHazardAndControl[0].hazardAndControls[index].controlIDs = controlIDArray;
        updateHazardAndControl[0].hazardAndControls[index].controlNames = controlNameArray;
      }
    } else {
      const obj = {
        stepNumber,
        stepDescription: this.state.inputArray[stepNumber - 1],
        hazardAndControls: [
          {
            hazardID: currentSelectedHazardID,
            hazardName: this.state.currentSelectedHazardName,
            controlIDs: [categoryID],
            controlNames: [categoryName]
          }
        ]
      };
      updateHazardAndControl.push(obj);
    }
Brad
@bradtaniguchi
Nov 02 2018 18:53
AAHHH MY EYES
Nate Mallison
@NJM8
Nov 02 2018 18:54
Burn it at the stake
Brad
@bradtaniguchi
Nov 02 2018 18:54
@JLuboff Do you have a linter? It looks like your using let but doesn't seem like you need to (could use const)
Jason Luboff
@JLuboff
Nov 02 2018 18:55
I am but guess it didn’t catch it. I’ll check after lunch
Brad
@bradtaniguchi
Nov 02 2018 19:34
Damn, I thought I was done with a feature then realized my approach is totally wrong -_-
Christopher McCormack
@cmccormack
Nov 02 2018 19:56
That's why you should start with the correct approach, duh
Albert Cardona II
@daddycardona
Nov 02 2018 20:02
@sjames1958gm i understand I only work one though so I get you must be tired. I have worked 3 jobs before and said never again :) So are them jobs dealing with coding?
Jason Luboff
@JLuboff
Nov 02 2018 20:13
@bradtaniguchi Took a look... Doesn't flag it either as const or let but I have another variable declared with let that if I chagne it to const it flags.. So.. I gotta check that. I'm using AirBNB's eslint config which for the node side, would flag it but seems like their React config is a bit different
Brad
@bradtaniguchi
Nov 02 2018 21:04
@JLuboff Prolly just a config thing that is more lenient, your compiling your code down to es5 right? Is that how React works haha? If so at the end of the day it doesn't matter since it turns into var
Jason Luboff
@JLuboff
Nov 02 2018 21:14
@bradtaniguchi Mmmmm...I...I don't know. I'm using CRA with a couple additional polyfills. I'm guessing it does polyfill most things to es5 since it works in IE
But.. const and let both have full support in IE
Brad
@bradtaniguchi
Nov 02 2018 21:17
@JLuboff Not sure, when I look at compile code for our Angular app (which gets transfered to es5) it has var's. Regardless it's a minor grip that lies more with code quality than performance (even tho the usage of const does increase performance slightly)
DMZ
@DMZ011
Nov 02 2018 21:18
hello world
Brad
@bradtaniguchi
Nov 02 2018 21:19
hello
Jason Luboff
@JLuboff
Nov 02 2018 21:19
@bradtaniguchi I had no idea that there was a performance gain
Brad
@bradtaniguchi
Nov 02 2018 21:21
Yes, the engine can use the fact the reference/value of const wont change to increase performance
Jason Luboff
@JLuboff
Nov 02 2018 21:21
Ah...intersting and good to know
DMZ
@DMZ011
Nov 02 2018 21:22
guys, any idea how to secure API keys in a JS app?
Jason Luboff
@JLuboff
Nov 02 2018 21:23
Front or backend?
DMZ
@DMZ011
Nov 02 2018 21:23
I was reading this thing from Microsoft, and they say if you want to secure the "secret" for ur app, then use tokens instead
so am like ok cool, i'll use tokens, how do I generate the tokens? they say: make a call to a web service from ur app and provide the secret :joy_cat:
@JLuboff front end
Jason Luboff
@JLuboff
Nov 02 2018 21:24
Oh.. if it was backend I would so use something like dotenv but..for front end... ehh....
DMZ
@DMZ011
Nov 02 2018 21:24
let's say u wanna make a github page
or even codepen
Brad
@bradtaniguchi
Nov 02 2018 21:24
@DMZ011 Will you be using API keys on the front-end? For what exactly?
DMZ
@DMZ011
Nov 02 2018 21:24
my manager asked me to make a bot
using bot framework from MS
but he needs to be hosted inside office 365
so am using something called: spfx
Brad
@bradtaniguchi
Nov 02 2018 21:25
Idk if you can make a bot on the front-end, you need a server
DMZ
@DMZ011
Nov 02 2018 21:25
yeah, I have the server
for the bot
Brad
@bradtaniguchi
Nov 02 2018 21:25
So the API keys should be on the server
Jason Luboff
@JLuboff
Nov 02 2018 21:25
make the API call from the backend
DMZ
@DMZ011
Nov 02 2018 21:25
but u can also program the front end for it
yeah
Brad
@bradtaniguchi
Nov 02 2018 21:25

but u can also program the front end for it

What do you mean?

DMZ
@DMZ011
Nov 02 2018 21:26
I mean
the bot has 2 things
the backend and the front end
the page itself where u type in the chat
that says the bot name
that shows ur name
the frame itself
that contains the conversation
in a web page
I need to embed the bot in a webpage
so I need to insert some code, and add the ID for the bot in Azure, this ID can be either "secret" or "token"
Brad
@bradtaniguchi
Nov 02 2018 21:27
Hmm interesting, is this the recommended setup for this bot? Or is this how you want/told todo it?
Jason Luboff
@JLuboff
Nov 02 2018 21:27
Too many statements, buffer overflow
DMZ
@DMZ011
Nov 02 2018 21:27
:joy_cat:
it can be actually one large statement, but I like to hit enter a lot haha
Brad
@bradtaniguchi
Nov 02 2018 21:28
Seems like youd want the client-side to get data from the server, but the server has the actual bot. Your calling to many things "the bot"
DMZ
@DMZ011
Nov 02 2018 21:28
ok give me few mins
i'll be back & explain
Jason Luboff
@JLuboff
Nov 02 2018 21:29
Is that how you text also?
For some reason, its always annoyed me when people text like that :joy:
Brad
@bradtaniguchi
Nov 02 2018 21:30
Yea I hate it, just type out your message and send your entire thing. Especially with notifications, its terrible. Like you have a 255 character limit (when texting) USE IT
DMZ
@DMZ011
Nov 02 2018 21:35
:joy_cat:
yeah that's how I text haha
ok here's what's going on, the bot itself (server side) is hosted in Azure, Azure provides what's called "Channels" so you can add the bot to Slack, Skype, or embed it as an iframe to any page
but I don't want to just embed it, because I want to change some stuff in there, like the colors, write some client side code from the client and send it to the bot (to the server side of the bot in Azure) .. so they provide something called "direct line" which allows u to use typescript or angular or react and add the client side to ur applicatoin
and u can provide a reference to the server side bot, so ur client side bot application knows which bot in Azure to connect to, u do that using either "tokens" or "secret"
Brad
@bradtaniguchi
Nov 02 2018 21:39
Ah I see, I looked at the documentation
DMZ
@DMZ011
Nov 02 2018 21:39
but.. I don't wanna share the secret, and MS say in their docs if u don't want to share the secret or making it hard for others to add the bot to their pages, use tokens.. am like ok cool
how do i use tokens? they say: make a request in ur app, in the request include the secret.. and u'll get back the token .. that was a WTF moment
how do I hide the secret by making a call with my secret included to generate the token?
Brad
@bradtaniguchi
Nov 02 2018 21:40
Which part are you having trouble with? You said you were able to call MS to get your token right?
DMZ
@DMZ011
Nov 02 2018 21:41
the thing is, I wanna secure the "secret"
I don't want it to appear in my client app
I wanna use only tokens, but MS's way in generating the tokens is by making a call to a specific url, with the secret in there .. so how is that securing the secret?
Christopher McCormack
@cmccormack
Nov 02 2018 21:42
Are you sure they aren't suggesting you do that from your backend?
DMZ
@DMZ011
Nov 02 2018 21:42
no, they have the code sample from the front end
let me check the code again :S
Brad
@bradtaniguchi
Nov 02 2018 21:44
You make the call to MS from your server, and return what MS returns to your server to your front-end
The code sample shows you how to use the token from your server (which got it from the MS server)
Christopher McCormack
@cmccormack
Nov 02 2018 21:45
that makes a lot more sense
Brad
@bradtaniguchi
Nov 02 2018 21:45
This way the actual secret is passed between two servers, and the client doesn't know
Christopher McCormack
@cmccormack
Nov 02 2018 21:45
and is how most auth like oauth works
Brad
@bradtaniguchi
Nov 02 2018 21:45
This sorta pattern is used a lot for a lot of APIs
@cmccormack Yes
DMZ
@DMZ011
Nov 02 2018 21:46
see the JS code in there
Brad
@bradtaniguchi
Nov 02 2018 21:46
When I first figured it out I was confused AF. But it makes sense
Christopher McCormack
@cmccormack
Nov 02 2018 21:46
@DMZ011 yeah man read the page
first option is server to server
DMZ
@DMZ011
Nov 02 2018 21:46
var xhr = new XMLHttpRequest();
    xhr.open('GET', "https://webchat.botframework.com/api/tokens", true);
    xhr.setRequestHeader('Authorization', 'BotConnector ' + 'YOUR SECRET HERE');
    xhr.send();
    xhr.onreadystatechange = processRequest;

    function processRequest(e) {
      if (xhr.readyState == 4  && xhr.status == 200) {
        var response = JSON.parse(xhr.responseText);
        document.getElementById("chat").src="https://webchat.botframework.com/embed/lucas-direct-line?t="+response
      }
    }
ah yeah
Christopher McCormack
@cmccormack
Nov 02 2018 21:46
second is to basically share your secret
that's why there's a big warning
DMZ
@DMZ011
Nov 02 2018 21:47
but are they dumb or what?
Christopher McCormack
@cmccormack
Nov 02 2018 21:47
to allow step 2?
not really you could use that internally if you wanted
DMZ
@DMZ011
Nov 02 2018 21:47
like how can they say: don't share the secret, use tokens, then in their how to generate token section, they do it by using the secret?
Christopher McCormack
@cmccormack
Nov 02 2018 21:47
like if I built a webapp for work it wouldn't matter
Brad
@bradtaniguchi
Nov 02 2018 21:47
@DMZ011 I don't see what your talking about
DMZ
@DMZ011
Nov 02 2018 21:47
@bradtaniguchi look at the code
xhr.setRequestHeader('Authorization', 'BotConnector ' + 'YOUR SECRET HERE');
specifically this part
this is where they add the secret
Brad
@bradtaniguchi
Nov 02 2018 21:48
They have no code for backend implementation, which uses the token from MS
The example is for client-side only, which is not recommended
DMZ
@DMZ011
Nov 02 2018 21:49
looks like I'll do what @cmccormack said
Brad
@bradtaniguchi
Nov 02 2018 21:49
wait never mind, I see
DMZ
@DMZ011
Nov 02 2018 21:49
and just use the secret since i'll use it internally
Christopher McCormack
@cmccormack
Nov 02 2018 21:49
yeah the backend is steps 1-3
it just doesn't show the code
err 1 -2
DMZ
@DMZ011
Nov 02 2018 21:49
and cross my fingers no smart dev in there to steal the secret and use it somewhere else
Christopher McCormack
@cmccormack
Nov 02 2018 21:50

Use this option if you can execute a server-to-server request to exchange your web chat secret for a temporary token, and if you want to make it difficult for other developers to embed your bot in their websites. Although using this option will not absolutely prevent other developers from embedding your bot in their websites, it does make it difficult for them to do so.

To exchange your secret for a token and generate the embed:

Issue a GET request to https://webchat.botframework.com/api/tokens and pass your web chat secret via the Authorization header. The Authorization header uses the BotConnector scheme and includes your secret, as shown in the example request below. // <== this is backend

The response to your GET request will contain the token (surrounded with quotation marks) that can be used to start a conversation by rendering the web chat control within an iframe. A token is valid for one conversation only; to start another conversation, you must generate a new token. // Pass this to your frontend via whatever means

Brad
@bradtaniguchi
Nov 02 2018 21:50
The part where it says YOUR SECRET HERE is actually the token again, not the secret. The front-end doesn't get the secret
DMZ
@DMZ011
Nov 02 2018 21:51
am confused
how is it the secret again?
@cmccormack I get what u mean, so I do the call from the server, and pass the generated token to the client?
Christopher McCormack
@cmccormack
Nov 02 2018 21:52
yes
server is secure because it should be TLS encrypted
and then it's only on your server the token is passed to your app
DMZ
@DMZ011
Nov 02 2018 21:53
but what if am in cloud?
Christopher McCormack
@cmccormack
Nov 02 2018 21:53
then you should sober up
DMZ
@DMZ011
Nov 02 2018 21:53
:joy_cat:
Christopher McCormack
@cmccormack
Nov 02 2018 21:54
cloud like VPS?
DMZ
@DMZ011
Nov 02 2018 21:54
I hate everything related to authentication
like Office 365
Brad
@bradtaniguchi
Nov 02 2018 21:55
cloud is too generic
DMZ
@DMZ011
Nov 02 2018 21:55
as an example, let's say I wanna make a bot, add it as a part of a product, this product can be installed in many environments.. so I can sell it to you and to Brad.. you guys get my product, add it to your office 365 subscription, and use my bot there
Jason Luboff
@JLuboff
Nov 02 2018 21:56
I've tried using Office 365 API on a couple of occasions...never been successful with what I wanted lol
DMZ
@DMZ011
Nov 02 2018 21:56
in this case, how can I secure the key that's gonna be used in both your environments?
@JLuboff yeah it's complicated ... "like my facebook status"
Brad
@bradtaniguchi
Nov 02 2018 21:57
It depends on how you distribute the product
and how the product integrates with the bot
DMZ
@DMZ011
Nov 02 2018 21:57
@bradtaniguchi I would just put the product on MS app store, where they open their intranets, and can install it there.. they get my bot plus other stuff as well packaged together
Brad
@bradtaniguchi
Nov 02 2018 21:58
Idk how MS app store works, or your apps architecture. Your key could be on some server up in the MS cloud, or it can be moved in locally with the rest of the "product" I have no idea.
Or its installed on my intranet, on some server rack I own, or on an Azure server rack in the cloud.
DMZ
@DMZ011
Nov 02 2018 21:59
I can have JavaScript or C# code running in the cloud, without having any server whatsoever using Azure Functions
probably can use that
Brad
@bradtaniguchi
Nov 02 2018 21:59
it depends on your product.
DMZ
@DMZ011
Nov 02 2018 21:59
might be the solution looking into that, will check it
but thanks guys! I'll look into the server to server thingy
and I won't send short messages
like this one
and annoy @JLuboff
that's bad
:joy_cat:
Jason Luboff
@JLuboff
Nov 02 2018 22:00
:(
DMZ
@DMZ011
Nov 02 2018 22:00
haha
so far my bot gets the current weather, and converts currencies
Brad
@bradtaniguchi
Nov 02 2018 22:09
Gosh darnit, I thought I had this down. Realize there's a bug (fix it), then realize I took a wrong approach(refactor it), update how we debug the app with new logging features, then realize I took ANOTHER wrong approach, FINALLY get it working properly, and then realize it needs to be optimized for A MISSING FEATURE. FFFFFUUUUUUUUU
Alright rant over :D
DMZ
@DMZ011
Nov 02 2018 22:12
format the server
Christopher McCormack
@cmccormack
Nov 02 2018 22:27
@bradtaniguchi man some day you'll finally finish that tic tac toe game I believe in you!
Jason Luboff
@JLuboff
Nov 02 2018 22:28
:joy:
Sick burn bro
Brad
@bradtaniguchi
Nov 02 2018 22:28
pssh I've given up on that XD
Christopher McCormack
@cmccormack
Nov 02 2018 22:28
I like to pretend that's what he's talking about because I don't really understand most of that corporate app talk
@bradtaniguchi lol
Jason Luboff
@JLuboff
Nov 02 2018 22:29
I'm telling you, you gotta start making apps for work ;)
Jason Luboff
@JLuboff
Nov 02 2018 22:43
Nothing like some pen and paper to hash out ideas
Christopher McCormack
@cmccormack
Nov 02 2018 22:46
apps for work is how I start not liking programming
Jason Luboff
@JLuboff
Nov 02 2018 22:46
Or you start liking it more!
Christopher McCormack
@cmccormack
Nov 02 2018 22:48
we'll see
the problem is they suggest I make these tools and then provide me zero time in the day to do it
Brad
@bradtaniguchi
Nov 02 2018 22:50
I've made a few apps for work in my spare time. Great time to try out new things. Only 1 ever got off the ground tho haha
Jason Luboff
@JLuboff
Nov 02 2018 22:50
@cmccormack That could be an issue
@bradtaniguchi Don't you make apps in general for work? Or are you normally refactoring current apps?
Brad
@bradtaniguchi
Nov 02 2018 22:51
@JLuboff I usually make new stuff, last few months I've been refactoring a current one
Jason Luboff
@JLuboff
Nov 02 2018 22:53
Ah
Wonder how many Databse tables I'm going to end up with for this project...currently my drawing has 7 but think I may have a couple additional
DMZ
@DMZ011
Nov 02 2018 22:56
@cmccormack zero time in the day to do it, that's why u stay up at night coding
Brad
@bradtaniguchi
Nov 02 2018 22:57
I've been burnt out after work, rather not think about code :/
DMZ
@DMZ011
Nov 02 2018 22:57
@bradtaniguchi I caught u at like 10 pm the other day here
Brad
@bradtaniguchi
Nov 02 2018 22:57
Yea I probably had my chromebook on, but I was not coding
DMZ
@DMZ011
Nov 02 2018 22:58
aaah .. was reading someone else's code then :P
@JLuboff disappears after 5pm Fridays
Christopher McCormack
@cmccormack
Nov 02 2018 22:58
@DMZ011 lately I'm up at night working too, then afterwards trying to find time to code for myself
not enough time in the day!
DMZ
@DMZ011
Nov 02 2018 22:59
@cmccormack what r u working on?
Jason Luboff
@JLuboff
Nov 02 2018 23:01
Yup.. I'm out at 5 PM back Monday 8 am hah
Shit. Just realized an issue in my database design..and in my front end code grrr..
DMZ
@DMZ011
Nov 02 2018 23:02
everyone should go to the cloud
Christopher McCormack
@cmccormack
Nov 02 2018 23:03
@DMZ011 haha that's a good question
for work?
or myself?
DMZ
@DMZ011
Nov 02 2018 23:03
i remember back in 2011, this dude was telling me: i am learning this cloud stuff, it's gonna be a big thing
Jason Luboff
@JLuboff
Nov 02 2018 23:03
I disagree. Mission critical app that can't have any downtime == no bueno in the cloud where there could be down time
DMZ
@DMZ011
Nov 02 2018 23:03
@cmccormack for urself
Christopher McCormack
@cmccormack
Nov 02 2018 23:04
For myself right now I'm a bit focused on learning git on a big scale by learning how FCC manages their repos,
finishing up the last IA QA project as well
then I think I'm going to start making some clones of major websites
DMZ
@DMZ011
Nov 02 2018 23:04
@JLuboff u can have downtime on prem as well, server crashes u gotta have load balancing or cluster for sql, network issues, etc
if u go cloud, and a request fails, MS will spin up a new server right away to accept requests
if too many requests, they'll load new VMs on the fly to serve them
Jason Luboff
@JLuboff
Nov 02 2018 23:05
@DMZ011 Ya but you can more readily control that having local equipment. Your internet goes down, it doesn't matter what you do, cloud aint going to work
Brad
@bradtaniguchi
Nov 02 2018 23:05
control = more work
more work = less time = less money
DMZ
@DMZ011
Nov 02 2018 23:06
@JLuboff if ur internet goes down, that means other important apps would go down as well.. plus most of the decent apps will use CDNs, or things related to the internet
Brad
@bradtaniguchi
Nov 02 2018 23:07
but then I'm biased, like @DMZ011. I work for a company that works with companies to migrate to the cloud hehe
DMZ
@DMZ011
Nov 02 2018 23:07
security wise, Microsoft securing the servers against latest hacking programs, etc.. is way more secure than depending on ur network admins
who would be way less experience than MS specialists
Jason Luboff
@JLuboff
Nov 02 2018 23:08
Thats an assumtion, you don't know the experience of each companys network/server admins ;)
Just becuase someone works for MS doesn't mean they know more
How many times do they need to refer you to the next level support?
DMZ
@DMZ011
Nov 02 2018 23:08
am not talking about the people who do the support
am talking about the people behind the creation of office 365 itself
and the people responsible directly of the servers
not the people doing support in india under MS's name
ur solution's security comes from the security of Office 365 itself, and am sure MS spends more time and thoughts securing their stuff more than any other company
plus the costs of creating a new server, support for existing servers, patching, etc.. etc.. all the hassle of having something on prem
Jason Luboff
@JLuboff
Nov 02 2018 23:10
Eh...agree to disagree on some things :)
DMZ
@DMZ011
Nov 02 2018 23:11
:P
Brad
@bradtaniguchi
Nov 02 2018 23:11
@JLuboff Is biased too, he's the guy that gets paid todo all that stuff right haha
DMZ
@DMZ011
Nov 02 2018 23:11
i get paid to do both actually
but when my manager tells me: hey we have these projects to work on, I just go cloud
Brad
@bradtaniguchi
Nov 02 2018 23:12
@DMZ011 does MS support hybrid on prem+cloud solutions?
DMZ
@DMZ011
Nov 02 2018 23:12
I have to work with on prem servers sometimes, but it's awful
@bradtaniguchi yeah, u can have hybrid solutions with everything
u can have some users in AD local, and some in Azure AD
Jason Luboff
@JLuboff
Nov 02 2018 23:13
@bradtaniguchi Ya.. sort of. As I'm the Systems Developer now.. I'm doing less with the server/network side of things except for SQL Server
DMZ
@DMZ011
Nov 02 2018 23:13
u can have exchange local, with some users in exchange online
Brad
@bradtaniguchi
Nov 02 2018 23:13
@DMZ011 Does MS have any good Kubernetes support? I heard google released hybrid solutions for that, not sure how it works. Just wondering if MS has the same capabilities
DMZ
@DMZ011
Nov 02 2018 23:14
@bradtaniguchi I worked on this project, where I was using PowerBI (online service), to connect to on prem servers, pull data from SQL tables, and make reports charts that are viewed from dynamics
@bradtaniguchi they have azure services for docker and Kubernetes
I know that morgan stanley are taking their whole intranet to the cloud, but during the transition they're doing some hybrid stuff
Brad
@bradtaniguchi
Nov 02 2018 23:42
Hmm good to know
Pagnito
@Pagnito
Nov 02 2018 23:49
anyone got security alert on their repos on github?
Christopher McCormack
@cmccormack
Nov 02 2018 23:51
all the time
DMZ
@DMZ011
Nov 02 2018 23:53
wait @cmccormack wht do u mean by IA QA?
Christopher McCormack
@cmccormack
Nov 02 2018 23:56
it's the last cert
information assurance and quality assurance I believe
Jason Luboff
@JLuboff
Nov 02 2018 23:56
Alright.. I'm out fellas. Have a good weekend
DMZ
@DMZ011
Nov 02 2018 23:56
oh ok
@JLuboff see
you
later
:P