2nd
Nov 2018
Albert Cardona II
Nov 02 2018 02:51 UTC
@sjames1958gm how you been brother :)
enestatli
@enestatli
Nov 02 2018 07:52 UTC
what are the key differences between Python 2 and 3?
catalin560
@catalin560
Nov 02 2018 08:07 UTC
anybody got a challenge for me? I'm kinda bored
@ezioda004
Nov 02 2018 08:09 UTC
@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 UTC
@ezioda004
Nov 02 2018 08:11 UTC
@catalin560 Have you tried project euler section? Its got pretty decent algorithms
enestatli
@enestatli
Nov 02 2018 08:12 UTC
@ezioda004 thanks bro, I thought you were asleep :D
@ezioda004
Nov 02 2018 08:12 UTC
@enestatli Hah, not yet :smile:
catalin560
@catalin560
Nov 02 2018 08:42 UTC
@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 UTC
@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 UTC


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 UTC
@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 UTC
@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 UTC
🤔
catalin560
@catalin560
Nov 02 2018 12:40 UTC
@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 UTC

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 UTC
hmm 🤔 wont that push undef in my arr?
Blauelf
@Blauelf
Nov 02 2018 13:06 UTC
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 UTC
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 UTC
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 UTC
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 UTC

@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 UTC
what do you mean "room"? :D
Stephen James
@sjames1958gm
Nov 02 2018 13:24 UTC
@daddycardona good - haven't been on lately - working three jobs :)
Blauelf
@Blauelf
Nov 02 2018 13:24 UTC
@enestatli Chat room, channel, whatever. Maybe I'm old.
enestatli
@enestatli
Nov 02 2018 13:24 UTC
oh this chat only for JS
sorry :D
Blauelf
@Blauelf
Nov 02 2018 13:25 UTC
Well, you got an explanation of what happened in your Python code.
enestatli
@enestatli
Nov 02 2018 13:25 UTC
@Blauelf int() function will be work, withouth import math module?
Blauelf
@Blauelf
Nov 02 2018 13:25 UTC
That's not a maths function.
enestatli
@enestatli
Nov 02 2018 13:26 UTC
okay, thanks a lot bro! :)
Matthew
@RoutinePoutine
Nov 02 2018 14:46 UTC
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 UTC
Do you mean the Deferreds?
Christopher McCormack
@cmccormack
Nov 02 2018 14:54 UTC
@RoutinePoutine maybe check out this series
Jason Luboff
@JLuboff
Nov 02 2018 15:21 UTC
Morning
Christopher McCormack
@cmccormack
Nov 02 2018 15:21 UTC
@JLuboff yo
what's up
Jason Luboff
@JLuboff
Nov 02 2018 15:22 UTC
It's Friday...thankfully
Just getting settled into work
you?
Markus Kiili
@Masd925
Nov 02 2018 15:24 UTC
Yo.
Christopher McCormack
@cmccormack
Nov 02 2018 15:24 UTC
@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 UTC
@Masd925 Hey man...break any records lately?
@cmccormack github/git process with FCC?
Markus Kiili
@Masd925
Nov 02 2018 15:26 UTC
@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 UTC
@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 UTC
@cmccormack Could you rub some of that git knowledge into me, please.
Jason Luboff
@JLuboff
Nov 02 2018 15:27 UTC
@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 UTC
@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 UTC
@cmccormack So.. went into a meeting yesterday...have another project to work on
Christopher McCormack
@cmccormack
Nov 02 2018 15:30 UTC
Is that good?
Jason Luboff
@JLuboff
Nov 02 2018 15:31 UTC
Ya...although it means I'll have two projects overlapping
Christopher McCormack
@cmccormack
Nov 02 2018 15:33 UTC
make them prioritize, you're only one person!
Jason Luboff
@JLuboff
Nov 02 2018 15:34 UTC
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 UTC
@Masd925 FCC employee made a guide for updating another person's PR if that's useful link
catalin560
@catalin560
Nov 02 2018 15:36 UTC
@Masd925 what competitions are you into?
Jason Luboff
@JLuboff
Nov 02 2018 15:38 UTC
@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 UTC
🤔
Blauelf
@Blauelf
Nov 02 2018 15:43 UTC
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 UTC
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 UTC
stop bullying @Masd925 , you guys are just jealous :laughing:
Jason Luboff
@JLuboff
Nov 02 2018 15:46 UTC
No bullying here
Markus Kiili
@Masd925
Nov 02 2018 15:46 UTC
@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 UTC
30 years? People that old are in this channel?
Christopher McCormack
@cmccormack
Nov 02 2018 15:47 UTC
@Masd925 this is helpful if you ever want to sync a fork of a repo
Jason Luboff
@JLuboff
Nov 02 2018 15:49 UTC
@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 UTC
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 UTC
@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 UTC
30 years of competing in chess means he's likely even older than me (35).
Markus Kiili
@Masd925
Nov 02 2018 15:53 UTC
@Blauelf I'm 45, which is like really old.
Blauelf
@Blauelf
Nov 02 2018 15:54 UTC
Oh no, in just 10 years I am like really old...
Christopher McCormack
@cmccormack
Nov 02 2018 15:54 UTC
@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 UTC
You all are old. I'm just a a young wipper-snapper at 30
Markus Kiili
@Masd925
Nov 02 2018 15:57 UTC
@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 UTC
until one day you're so old you fill up with air like a puffer fish
Blauelf
@Blauelf
Nov 02 2018 16:13 UTC
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 UTC
why helium?
Blauelf
@Blauelf
Nov 02 2018 16:14 UTC
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 UTC
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 UTC
that's funny haha
Blauelf
@Blauelf
Nov 02 2018 16:37 UTC
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 UTC
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 UTC
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 UTC
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 UTC
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 UTC
There was a shortage of helium here for a while
Blauelf
@Blauelf
Nov 02 2018 16:52 UTC
Hmm... does maths mode work like I think it does? $^3\mathrm{He}$ $\mathrm{H}_2$ Oh yes, it does!
Christopher McCormack
@cmccormack
Nov 02 2018 16:53 UTC
math's mode?
Blauelf
@Blauelf
Nov 02 2018 16:53 UTC
@cmccormack Problem with Helium is basically what bricked the iPhones. It's hard to contain.
Maths mode, I mean $\KaTeX$
Christopher McCormack
@cmccormack
Nov 02 2018 16:54 UTC
ah yeah that works
Blauelf
@Blauelf
Nov 02 2018 16:54 UTC
Like $$^3\mathrm{He}$$ for $^3\mathrm{He}$
Christopher McCormack
@cmccormack
Nov 02 2018 16:54 UTC
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 UTC
Like $\mathcal{O}(n \log n)$?
Christopher McCormack
@cmccormack
Nov 02 2018 16:55 UTC
yeah
Blauelf
@Blauelf
Nov 02 2018 16:55 UTC
There's mathjax if you don't have built-in support.
Christopher McCormack
@cmccormack
Nov 02 2018 16:58 UTC
mathjax sounds like a bad cereal that kids hate
Blauelf
@Blauelf
Nov 02 2018 17:00 UTC
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 UTC
@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 UTC
@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 UTC
@123xylem Your space characters after the commas might hurt. Also, why exactly that kind of string?
Chris Cullen
@123xylem
Nov 02 2018 17:13 UTC
@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 UTC
Triple backticks.
Christopher McCormack
@cmccormack
Nov 02 2018 17:14 UTC

Code

Chris Cullen
@123xylem
Nov 02 2018 17:14 UTC
ah
regApproved outputs = /\b(["visa"|"mastercard"])\b/gi
Christopher McCormack
@cmccormack
Nov 02 2018 17:15 UTC
you can also label the language by adding something like
js
Code

Blauelf
@Blauelf
Nov 02 2018 17:15 UTC
@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 UTC
also are you trying to use \b? Why double backslashes?
Blauelf
@Blauelf
Nov 02 2018 17:16 UTC
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 UTC
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 UTC
Chris Cullen
@123xylem
Nov 02 2018 17:17 UTC
And I need it to match my data attribute
Blauelf
@Blauelf
Nov 02 2018 17:17 UTC
@123xylem The square brackets and quotation marks should not go into the regular expression.
Christopher McCormack
@cmccormack
Nov 02 2018 17:17 UTC
when you paste it like that we may lose information
/\b(visa|mastercard)\b/gi
Blauelf
@Blauelf
Nov 02 2018 17:21 UTC
@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 UTC
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 UTC
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 UTC
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 UTC
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 UTC
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 UTC
@cmccormack alright!! thanks
Christopher McCormack
@cmccormack
Nov 02 2018 17:47 UTC
@shubhamsoni2617 :thumbsup:
@matrixersp
Nov 02 2018 18:25 UTC

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 UTC
@matrixersp can you post the file that actually runs your server?
Pagnito
@Pagnito
Nov 02 2018 18:38 UTC
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 UTC
scrolling to what?
an HTML element?
Pagnito
@Pagnito
Nov 02 2018 18:43 UTC
nah i mean, when user scolls down to lets say about page, activate 'this' animation
Christopher McCormack
@cmccormack
Nov 02 2018 18:43 UTC
scrollspy?
that still depends on scrolling down to an element
Pagnito
@Pagnito
Nov 02 2018 18:44 UTC
i mean i would would sort of like a scrollspy i guess
it*
but no, not scrollspy
Nate Mallison
@NJM8
Nov 02 2018 18:45 UTC
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 UTC
oh hold on i gotta restart tunnel
Nate Mallison
@NJM8
Nov 02 2018 18:47 UTC
if (iMeetCondition) {
if (iMeetCondition.condition) {
return iMeetCondition.condition
} else {
//oops continue on to next block
}
} else if (something) {
//continue on here
}
Nov 02 2018 18:47 UTC
@NJM8 what?
flat if statements? (no else)
Christopher McCormack
@cmccormack
Nov 02 2018 18:47 UTC
@NJM8 remove both else
Nov 02 2018 18:48 UTC
if (IMeetCondition && iMeetCondition.condition) {
return iMeetCondition.condition;
}
if (something) {
//...
}
Christopher McCormack
@cmccormack
Nov 02 2018 18:48 UTC
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 UTC
oh yeah. hmmm
Christopher McCormack
@cmccormack
Nov 02 2018 18:48 UTC
then let the logic fall through that function
Nov 02 2018 18:48 UTC
@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 UTC
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 UTC
oh man...you guys won't like my code then
Nate Mallison
@NJM8
Nov 02 2018 18:51 UTC
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 UTC
So can error.response.data exist without ...error.message?
Nov 02 2018 18:52 UTC
@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 UTC
@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];
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);
}
Nov 02 2018 18:53 UTC
AAHHH MY EYES
Nate Mallison
@NJM8
Nov 02 2018 18:54 UTC
Burn it at the stake
Nov 02 2018 18:54 UTC
@JLuboff Do you have a linter? It looks like your using let but doesn't seem like you need to (could use const)
Nate Mallison
@NJM8
Nov 02 2018 18:55 UTC
Jason Luboff
@JLuboff
Nov 02 2018 18:55 UTC
I am but guess it didn’t catch it. I’ll check after lunch
Nov 02 2018 19:34 UTC
Damn, I thought I was done with a feature then realized my approach is totally wrong -_-
Christopher McCormack
@cmccormack
Nov 02 2018 19:56 UTC
Albert Cardona II
Nov 02 2018 20:02 UTC
@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 UTC
@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
Nov 02 2018 21:04 UTC
@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 UTC
@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
Nov 02 2018 21:17 UTC
@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 UTC
hello world
Nov 02 2018 21:19 UTC
hello
Jason Luboff
@JLuboff
Nov 02 2018 21:19 UTC
Nov 02 2018 21:21 UTC
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 UTC
Ah...intersting and good to know
DMZ
@DMZ011
Nov 02 2018 21:22 UTC
guys, any idea how to secure API keys in a JS app?
Jason Luboff
@JLuboff
Nov 02 2018 21:23 UTC
Front or backend?
DMZ
@DMZ011
Nov 02 2018 21:23 UTC
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 UTC
Oh.. if it was backend I would so use something like dotenv but..for front end... ehh....
DMZ
@DMZ011
Nov 02 2018 21:24 UTC
let's say u wanna make a github page
or even codepen
Nov 02 2018 21:24 UTC
@DMZ011 Will you be using API keys on the front-end? For what exactly?
DMZ
@DMZ011
Nov 02 2018 21:24 UTC
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
Nov 02 2018 21:25 UTC
Idk if you can make a bot on the front-end, you need a server
DMZ
@DMZ011
Nov 02 2018 21:25 UTC
yeah, I have the server
for the bot
Nov 02 2018 21:25 UTC
So the API keys should be on the server
Jason Luboff
@JLuboff
Nov 02 2018 21:25 UTC
make the API call from the backend
DMZ
@DMZ011
Nov 02 2018 21:25 UTC
but u can also program the front end for it
yeah
Nov 02 2018 21:25 UTC

but u can also program the front end for it

What do you mean?

DMZ
@DMZ011
Nov 02 2018 21:26 UTC
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"
Nov 02 2018 21:27 UTC
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 UTC
Too many statements, buffer overflow
DMZ
@DMZ011
Nov 02 2018 21:27 UTC
:joy_cat:
it can be actually one large statement, but I like to hit enter a lot haha
Nov 02 2018 21:28 UTC
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 UTC
ok give me few mins
i'll be back & explain
Jason Luboff
@JLuboff
Nov 02 2018 21:29 UTC
Is that how you text also?
For some reason, its always annoyed me when people text like that :joy:
Nov 02 2018 21:30 UTC
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 UTC
: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"
Nov 02 2018 21:39 UTC
Ah I see, I looked at the documentation
DMZ
@DMZ011
Nov 02 2018 21:39 UTC
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?
Nov 02 2018 21:40 UTC
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 UTC
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 UTC
Are you sure they aren't suggesting you do that from your backend?
DMZ
@DMZ011
Nov 02 2018 21:42 UTC
no, they have the code sample from the front end
let me check the code again :S
Nov 02 2018 21:44 UTC
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 UTC
that makes a lot more sense
Nov 02 2018 21:45 UTC
This way the actual secret is passed between two servers, and the client doesn't know
DMZ
@DMZ011
Nov 02 2018 21:45 UTC
Christopher McCormack
@cmccormack
Nov 02 2018 21:45 UTC
and is how most auth like oauth works
Nov 02 2018 21:45 UTC
This sorta pattern is used a lot for a lot of APIs
@cmccormack Yes
DMZ
@DMZ011
Nov 02 2018 21:46 UTC
see the JS code in there
Nov 02 2018 21:46 UTC
When I first figured it out I was confused AF. But it makes sense
Christopher McCormack
@cmccormack
Nov 02 2018 21:46 UTC
@DMZ011 yeah man read the page
first option is server to server
DMZ
@DMZ011
Nov 02 2018 21:46 UTC
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://webchat.botframework.com/api/tokens", true);
xhr.send();

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 UTC
second is to basically share your secret
that's why there's a big warning
DMZ
@DMZ011
Nov 02 2018 21:47 UTC
but are they dumb or what?
Christopher McCormack
@cmccormack
Nov 02 2018 21:47 UTC
to allow step 2?
not really you could use that internally if you wanted
DMZ
@DMZ011
Nov 02 2018 21:47 UTC
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 UTC
like if I built a webapp for work it wouldn't matter
Nov 02 2018 21:47 UTC
DMZ
@DMZ011
Nov 02 2018 21:47 UTC
xhr.setRequestHeader('Authorization', 'BotConnector ' + 'YOUR SECRET HERE');
specifically this part
this is where they add the secret
Nov 02 2018 21:48 UTC
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 UTC
looks like I'll do what @cmccormack said
Nov 02 2018 21:49 UTC
wait never mind, I see
DMZ
@DMZ011
Nov 02 2018 21:49 UTC
and just use the secret since i'll use it internally
Christopher McCormack
@cmccormack
Nov 02 2018 21:49 UTC
yeah the backend is steps 1-3
it just doesn't show the code
err 1 -2
DMZ
@DMZ011
Nov 02 2018 21:49 UTC
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 UTC

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

Nov 02 2018 21:50 UTC
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 UTC
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 UTC
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 UTC
but what if am in cloud?
Christopher McCormack
@cmccormack
Nov 02 2018 21:53 UTC
then you should sober up
DMZ
@DMZ011
Nov 02 2018 21:53 UTC
:joy_cat:
Christopher McCormack
@cmccormack
Nov 02 2018 21:54 UTC
cloud like VPS?
DMZ
@DMZ011
Nov 02 2018 21:54 UTC
I hate everything related to authentication
like Office 365
Nov 02 2018 21:55 UTC
cloud is too generic
DMZ
@DMZ011
Nov 02 2018 21:55 UTC
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 UTC
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 UTC
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"
Nov 02 2018 21:57 UTC
It depends on how you distribute the product
and how the product integrates with the bot
DMZ
@DMZ011
Nov 02 2018 21:57 UTC
@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
Nov 02 2018 21:58 UTC
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 UTC
I can have JavaScript or C# code running in the cloud, without having any server whatsoever using Azure Functions
probably can use that
Nov 02 2018 21:59 UTC
DMZ
@DMZ011
Nov 02 2018 21:59 UTC
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
:joy_cat:
Jason Luboff
@JLuboff
Nov 02 2018 22:00 UTC
:(
DMZ
@DMZ011
Nov 02 2018 22:00 UTC
haha
so far my bot gets the current weather, and converts currencies
Nov 02 2018 22:09 UTC
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 UTC
format the server
Christopher McCormack
@cmccormack
Nov 02 2018 22:27 UTC
@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 UTC
:joy:
Sick burn bro
Nov 02 2018 22:28 UTC
pssh I've given up on that XD
Christopher McCormack
@cmccormack
Nov 02 2018 22:28 UTC
I like to pretend that's what he's talking about because I don't really understand most of that corporate app talk
Jason Luboff
@JLuboff
Nov 02 2018 22:29 UTC
I'm telling you, you gotta start making apps for work ;)
Jason Luboff
@JLuboff
Nov 02 2018 22:43 UTC
Nothing like some pen and paper to hash out ideas
Christopher McCormack
@cmccormack
Nov 02 2018 22:46 UTC
apps for work is how I start not liking programming
Jason Luboff
@JLuboff
Nov 02 2018 22:46 UTC
Or you start liking it more!
Christopher McCormack
@cmccormack
Nov 02 2018 22:48 UTC
we'll see
the problem is they suggest I make these tools and then provide me zero time in the day to do it
Nov 02 2018 22:50 UTC
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 UTC
@cmccormack That could be an issue
@bradtaniguchi Don't you make apps in general for work? Or are you normally refactoring current apps?
Nov 02 2018 22:51 UTC
@JLuboff I usually make new stuff, last few months I've been refactoring a current one
Jason Luboff
@JLuboff
Nov 02 2018 22:53 UTC
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 UTC
@cmccormack zero time in the day to do it, that's why u stay up at night coding
Nov 02 2018 22:57 UTC
I've been burnt out after work, rather not think about code :/
DMZ
@DMZ011
Nov 02 2018 22:57 UTC
@bradtaniguchi I caught u at like 10 pm the other day here
Nov 02 2018 22:57 UTC
Yea I probably had my chromebook on, but I was not coding
DMZ
@DMZ011
Nov 02 2018 22:58 UTC
aaah .. was reading someone else's code then :P
@JLuboff disappears after 5pm Fridays
Christopher McCormack
@cmccormack
Nov 02 2018 22:58 UTC
@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 UTC
@cmccormack what r u working on?
Jason Luboff
@JLuboff
Nov 02 2018 23:01 UTC
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 UTC
everyone should go to the cloud
Christopher McCormack
@cmccormack
Nov 02 2018 23:03 UTC
@DMZ011 haha that's a good question
for work?
or myself?
DMZ
@DMZ011
Nov 02 2018 23:03 UTC
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 UTC
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 UTC
@cmccormack for urself
Christopher McCormack
@cmccormack
Nov 02 2018 23:04 UTC
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 UTC
@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 UTC
@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
Nov 02 2018 23:05 UTC
control = more work
more work = less time = less money
DMZ
@DMZ011
Nov 02 2018 23:06 UTC
@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
Nov 02 2018 23:07 UTC
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 UTC
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 UTC
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 UTC
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 UTC
Eh...agree to disagree on some things :)
DMZ
@DMZ011
Nov 02 2018 23:11 UTC
:P
Nov 02 2018 23:11 UTC
@JLuboff Is biased too, he's the guy that gets paid todo all that stuff right haha
DMZ
@DMZ011
Nov 02 2018 23:11 UTC
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
Nov 02 2018 23:12 UTC
@DMZ011 does MS support hybrid on prem+cloud solutions?
DMZ
@DMZ011
Nov 02 2018 23:12 UTC
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 UTC
@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 UTC
u can have exchange local, with some users in exchange online
Nov 02 2018 23:13 UTC
@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 UTC
@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
Nov 02 2018 23:42 UTC
Hmm good to know
Pagnito
@Pagnito
Nov 02 2018 23:49 UTC
anyone got security alert on their repos on github?
Christopher McCormack
@cmccormack
Nov 02 2018 23:51 UTC
all the time
DMZ
@DMZ011
Nov 02 2018 23:53 UTC
wait @cmccormack wht do u mean by IA QA?
Christopher McCormack
@cmccormack
Nov 02 2018 23:56 UTC
it's the last cert
information assurance and quality assurance I believe
Jason Luboff
@JLuboff
Nov 02 2018 23:56 UTC
Alright.. I'm out fellas. Have a good weekend
DMZ
@DMZ011
Nov 02 2018 23:56 UTC
oh ok
@JLuboff see
you
later
:P