These are chat archives for FreeCodeCamp/HelpJavaScript

7th
Dec 2018
rajashrikawade
@rajashrikawade
Dec 07 2018 00:05
Hello
I am new to this group
I am working on javascript coding challenge
Basic JavaScript: Replacing If Else Chains with Switch and getting error -chainToSwitch("John") should be "" (empty string)
chainToSwitch(156) should be "" (empty string)

Here is my code - function chainToSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "bob":
answer = "Marley";
break;
case 42:
answer = "The Answer";
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
answer = "Ate Nine";
break;
default:
answer = "default";
break;
}

// Only change code above this line
return answer;
}

// Change this value to test
chainToSwitch(7);

could you please tell me what I am missing
Jason Luboff
@JLuboff
Dec 07 2018 00:12
Your default answer should be "" not "default"
Amit Patel
@AmitP88
Dec 07 2018 00:20
@JLuboff hey man, I got it to work. Thanks man! and thanks @bradtaniguchi for helping me understand why it wasn't working. I feel like I learned something :)
Jason Luboff
@JLuboff
Dec 07 2018 00:24
Glad you got it :thumbsup:
Brad
@bradtaniguchi
Dec 07 2018 00:25
@AmitP88 np :D
rajashrikawade
@rajashrikawade
Dec 07 2018 00:45
@JLuboff - Thank you
Pagnito
@Pagnito
Dec 07 2018 01:02
yo brad
@bradtaniguchi
Brad
@bradtaniguchi
Dec 07 2018 01:03
@Pagnito Yes
Pagnito
@Pagnito
Dec 07 2018 01:04
im using facebook strategy for auth and using a jwt token, Im sending it back to the client via res.cookie. Then im saving that cookie in localstorage, but then i thought is there a point to even save it in local storage if its in my cookies?
Brad
@bradtaniguchi
Dec 07 2018 01:08
not too sure, I know that saving JWT's in localStorage is kinda of a security risk. Do you require the jwt to be saved between loads or does your backend handle the session using the cookie?
Pagnito
@Pagnito
Dec 07 2018 01:16
well atm i have the facebook strategy res.cookie('auth', token);
then on the front end im using that token to send a request check if user is logged in and get back decoded user info
Brad
@bradtaniguchi
Dec 07 2018 01:18
So your backend only uses the res.cookie to identify the user. We ran into a similar case ourselves, we ended up saving the user's information in a global variable (more or less) rather than localStorage, since localStorage is somewhat of a security risk, and is an "extra state" that needs to be handled.
I'd only use localStorage for the user JWT if you want to limit request calls between loads of the page, but its generally more complexity for little gain.
Pagnito
@Pagnito
Dec 07 2018 01:19
i see, it does seem i can jus use the cookie itself to check
Pagnito
@Pagnito
Dec 07 2018 01:29
the only concern i have is i cant set httpOnly for te cookie so only the browser can read it @bradtaniguchi
what if i use jwt strategy WIT fb stratgy
ille use fb to sign up and log in, and jwt strategy from passport to keep ppl logged in, that was i can use their jwt authenticate, and set jwt as auth header and make it httpOnly in the cookies
my brain is tellin me to leave this for tomorrow
Brad
@bradtaniguchi
Dec 07 2018 01:32
hehe I would
Pagnito
@Pagnito
Dec 07 2018 01:32
lol
Brad
@bradtaniguchi
Dec 07 2018 01:37
Security isn't one of those things I would rush haha
Nate Mallison
@NJM8
Dec 07 2018 03:30
Anyone on? I
I'm in need of an ELI5 git moment
Claudio Restifo
@Marmiz
Dec 07 2018 03:47
Oh geez, try asking and let's hope someone will be able to do so :)
Ashan mohammed
@Ashanzeroxster_twitter
Dec 07 2018 04:49

whats wrong in my code? I am trying to create table rows for a existing table in js

function createTable() {
var tbl = document.getElementsByTagName('table');

var tblbdy = document.createElement('tbody');

for (var i = 0; i <= 99; i++){

  var tblrw = document.createElement('tr');

  for (var j = 0; j <= 7; j++){

    var tbltd = document.createElement('td');
    var tbldata = document.createTextNode(j);

    tbltd.appendChild(tbldata);
    tblrw.appendChild(tbltd);

  }

  tblbdy.appendChild(tblrw);


}

  tbl.appendChild(tblbdy);

  alert("done");

}

createTable();

Adel
@AdelMahjoub
Dec 07 2018 05:37
@Pagnito for jwt, spa / api , easier to set the token in the bearer header
Pagnito
@Pagnito
Dec 07 2018 05:39
Ya thats what i waa thinkin..tho only way i know of takin using it on the back end is thru jwt passport strategy
Adel
@AdelMahjoub
Dec 07 2018 05:43
@Pagnito which http client are you using in the client app
@Pagnito axios, request, node http, jquery ?
Pagnito
@Pagnito
Dec 07 2018 05:43
Axios
But i might end up using regular fetch because im gonna write a register worker
Service worker*
Adel
@AdelMahjoub
Dec 07 2018 05:44
@Pagnito try set withCredentials to true
// `withCredentials` indicates whether or not cross-site Access-Control requests
  // should be made using credentials
@Pagnito thats one of the causes the browser ignore the cookie header
Pagnito
@Pagnito
Dec 07 2018 05:46
I see...im proly gonna do it tomorrow tho...im takina break till i go to sleep
Adel
@AdelMahjoub
Dec 07 2018 05:48
by default the browser send stored cookies to the origin server, but this seems to not work with ajax requests
@Pagnito np
from rfc 6265
When a user agent receives a Set-Cookie header field in an HTTP
response, the user agent MAY ignore the Set-Cookie header field in
its entirety. For example, the user agent might wish to block
responses to "third-party" requests from setting cookies (see
Section 7.1).
Tiago Correia
@tiagocorreiaalmeida
Dec 07 2018 10:13
Good morning everyone, anyone around who has used AWS S3?
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 15:09
can someone help me with regular expressions?
for this challenge: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case/
i tried:
return str.split(/_|\W|[A-Z]/).join("-").toLowerCase();
first of all why /\W/ doesnt also include _ ?
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 15:16
isnt W for everything except numbers and characters?
|and second i tried [A-Z] but that also gives me a problem with everything thats capital while only wanna match the capitals that are followed by another letter
Jason Luboff
@JLuboff
Dec 07 2018 16:10
Morning :wave:
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 16:10
aternoon :p
Jason Luboff
@JLuboff
Dec 07 2018 16:11
That too! :)
Zaza
@ForkInSpace
Dec 07 2018 16:17
Morning all!
Jason Luboff
@JLuboff
Dec 07 2018 16:17
Morning
creator0323
@Amasian
Dec 07 2018 16:21
Have a great day all :)
Zaza
@ForkInSpace
Dec 07 2018 16:30
Has anyone built a search filter in react similar to the one of Airbnb?
Jason Luboff
@JLuboff
Dec 07 2018 16:31
No...no I have not
Zaza
@ForkInSpace
Dec 07 2018 16:31
Why not ?
jk
Thinking to build that for fun but Not really sure how to go about it
Suggestions welcome
Jason Luboff
@JLuboff
Dec 07 2018 16:42
I suggest...potato
Zaza
@ForkInSpace
Dec 07 2018 16:45
Elaborate please?
Jason Luboff
@JLuboff
Dec 07 2018 16:46
Eh.. when this place was more popping.. I used to assist others and would often times use potato as my variable name
Zaza
@ForkInSpace
Dec 07 2018 16:47
hmm.. who would have thought
Jason Luboff
@JLuboff
Dec 07 2018 16:47
People who were around than... lol
Zaza
@ForkInSpace
Dec 07 2018 16:50
tatos
Christopher McCormack
@cmccormack
Dec 07 2018 16:51
🥔🥔 @JLuboff :wave: 🥔🥔🥔
Jason Luboff
@JLuboff
Dec 07 2018 16:52
TATERS!
Whats up man
Christopher McCormack
@cmccormack
Dec 07 2018 16:52
nm at the office today to get my laptop fixed up
also company party tonight, should be fun
Jason Luboff
@JLuboff
Dec 07 2018 16:53
Oh nice
Whats wrong with your laptop?
Christopher McCormack
@cmccormack
Dec 07 2018 16:54
just some wireless cert issue
all fixed up now I believe
Jason Luboff
@JLuboff
Dec 07 2018 16:54
Cool
Christopher McCormack
@cmccormack
Dec 07 2018 16:55
what you up to today
Adel
@AdelMahjoub
Dec 07 2018 16:59
hi
@cmccormack do you have some personal notes regarding Marko
Christopher McCormack
@cmccormack
Dec 07 2018 17:01
@AdelMahjoub oh I've never used it
I was just spreading the word :)
Adel
@AdelMahjoub
Dec 07 2018 17:01
@cmccormack :laughing:
@cmccormack a trap ?
I'll review what changes on Angular 7 then
And react is everywhere now, a lot of e-commerce sites uses react
that react dev tools is almost blue all time :laughing:
I'll spread the word then for marko, for what reason idk,
God of war is the game of the year btw
and 4 prises for Rdr2
but Dead cells got best action game award
Christopher McCormack
@cmccormack
Dec 07 2018 17:12
it was funny that's all haha
ohh both GoW and Dead Cells are on my wishlist for xmas :)
Jason Luboff
@JLuboff
Dec 07 2018 17:12
@cmccormack Roughly same things as yesterday. Keep working on this SSRS report.. React app, etc
Holy shit. Reading this SQL article about Memory allocation to the server.. and he surveyed ~1400 servers... and one server was hosting 4.2TB of data..and only had 16GB RAM allocated :joy:
Adel
@AdelMahjoub
Dec 07 2018 17:19
@cmccormack dead cells is somewhat difficult, if you like action roguelike games you mau like it
Christopher McCormack
@cmccormack
Dec 07 2018 17:20
sure do
Adel
@AdelMahjoub
Dec 07 2018 17:20
you may like the messenger too, finished 100% both
12 ~ 15h games tho, some replay value
Christopher McCormack
@cmccormack
Dec 07 2018 17:27
not sure i've even heard of it
oh on switch as well, nice
looks like contra
oops Ninja Gaiden, not Contra :D
Adel
@AdelMahjoub
Dec 07 2018 17:31
only at the start it looks like ninja gaiden, then the real game begins, cant spoil you more :laughing:
and the chip tunes are epic
DMZ
@DMZ011
Dec 07 2018 17:36
Hola amigos!
Aditya
@ezioda004
Dec 07 2018 17:37
@thodorisanta It doesnt include _ because reasons, this is JS, we are not reasonable people. If you wanna match capitals followed by another letter (upper/lower) then you can do /[A-Z](?=[A-Za-z])/
Christopher McCormack
@cmccormack
Dec 07 2018 17:37
@AdelMahjoub nice I'll check it out!
@DMZ011 hiya
Jason Luboff
@JLuboff
Dec 07 2018 17:38
Yo
Aditya
@ezioda004
Dec 07 2018 17:40
Hey fellas, how it going?
DMZ
@DMZ011
Dec 07 2018 17:42
going well, how's it going with everyone?
Christopher McCormack
@cmccormack
Dec 07 2018 17:44
@ezioda004 hi
Aditya
@ezioda004
Dec 07 2018 17:45
@cmccormack :wave:
DMZ
@DMZ011
Dec 07 2018 17:45
guys, I need MAJOR help
Jason Luboff
@JLuboff
Dec 07 2018 17:45
Doing a okay!
Jason Luboff
@JLuboff
Dec 07 2018 17:50
You said you need major help...but then left us hanging
DMZ
@DMZ011
Dec 07 2018 17:51
ah
haha
well
I see people always talk about "if you want to learn more, collaborate on open source projects", but how do you actually do that?
I've never worked on a project with someone else
it's always a solo thing for me, so 1- I don't know how to collaborate with someone else on the same project (I know about git, etc)
2- if I find an open source project, how do I know what to do in there? I can see the issues and requested features, etc, but I wouldn't know which files to edit, etc
for example, I can see some open source projects related to O365, which is the area am working with right now, but am not sure how to start
ehutchllew
@ehutchllew
Dec 07 2018 17:55
@DMZ011 If you want to contribute to OS or even work with other people you MUST MUST MUST get familiar with source control (git).
DMZ
@DMZ011
Dec 07 2018 17:55
am familiar with source control through vscode, (commit, push, pull)
not sure if there's anything more I need to know about it
I tried it on 2 different machines, to see how it goes
I have this server, so I made 2 Win 10 VMs, and started trying it out (as if 3 people are working on it)
Jason Luboff
@JLuboff
Dec 07 2018 17:57
You will need to know more than commit/push/pull.
DMZ
@DMZ011
Dec 07 2018 17:57
but then, in real world, when I open ANY open source project and I say: i'll start contributing here, I just go blank
Jason Luboff
@JLuboff
Dec 07 2018 17:57
branch, merge, etc
Aditya
@ezioda004
Dec 07 2018 17:57
Wow you are collaborating with yourself
DMZ
@DMZ011
Dec 07 2018 17:57
^ exactly haha
which is nice, when I go and make a pull request from the other machine, am like: I wonder what changes there might be :joy_cat:
then I'd act surprised: OMG did he just change that?!
no seriously, so how would I start with it?
the open source projects
Aditya
@ezioda004
Dec 07 2018 17:59
Review: Seems good :heavy_check_mark: , thanks for adding the feature me!
DMZ
@DMZ011
Dec 07 2018 17:59
hahahaha
I didn't try the review part..!
Aditya
@ezioda004
Dec 07 2018 18:00
I think chingu cohort is a thing where you collaborate with other people of your skill level
DMZ
@DMZ011
Dec 07 2018 18:00
what's that?
DMZ
@DMZ011
Dec 07 2018 18:00
found it
Aditya
@ezioda004
Dec 07 2018 18:00
I've only heard about it but its worth a shot
DMZ
@DMZ011
Dec 07 2018 18:02
aha
Aditya
@ezioda004
Dec 07 2018 18:04
I'm not sure what fccs official stance is on that but I've seen many people on the forum joining the cohort to collaborate
DMZ
@DMZ011
Dec 07 2018 18:04
the reason why I joined FCC is because they said they'd let people collaborate on open source, charity projects, etc
but there's none of that
Aditya
@ezioda004
Dec 07 2018 18:05
You can contribute to fcc..
ehutchllew
@ehutchllew
Dec 07 2018 18:06
@DMZ011 Pretty sure you have to get through a good portion of FCC before they link you up with charities.
Aditya
@ezioda004
Dec 07 2018 18:06
That collaborating thing was in old curriculum I think, like you had to have all the certificates to be eligible for that
DMZ
@DMZ011
Dec 07 2018 18:07
hmm
Aditya
@ezioda004
Dec 07 2018 18:07
I'm not even sure if they link you anymore
ehutchllew
@ehutchllew
Dec 07 2018 18:07
And really for open source, just find a project that interests you, look at it's codebase, see if there is anything you can add (even just a simple style change or w/e) and submit a Pull Request.
But again, you have to really familiarize yourself with Git before attempting this.
Pagnito
@Pagnito
Dec 07 2018 18:07
hey how come some ppl use admin.database() and some ppl use firebase.database()?
DMZ
@DMZ011
Dec 07 2018 18:07
hmm
do u guys contribute to open source projects?
Aditya
@ezioda004
Dec 07 2018 18:09
I do to fcc, check my github (shameless plug) ;)
DMZ
@DMZ011
Dec 07 2018 18:09
so u fork any project u want to contribute to?
Aditya
@ezioda004
Dec 07 2018 18:11
Thats a first step, yes
ehutchllew
@ehutchllew
Dec 07 2018 18:12
you don't have to fork
DMZ
@DMZ011
Dec 07 2018 18:13
aha
Aditya
@ezioda004
Dec 07 2018 18:14
A fork is made nonetheless, even if you directly edit file on github
DMZ
@DMZ011
Dec 07 2018 18:14
ok i'll give it a shot
i'll do simple things and see how it goes
ehutchllew
@ehutchllew
Dec 07 2018 18:15
You're saying even if clone the project, create you're own branch, it's forking the entire repo for you?
Aditya
@ezioda004
Dec 07 2018 18:16
Ok but how'd you contribute by cloning?
Christopher McCormack
@cmccormack
Dec 07 2018 18:16
@ehutchllew cloning is just copying it locally
DMZ
@DMZ011
Dec 07 2018 18:16
i think if u clone it, and push it to their repo
Aditya
@ezioda004
Dec 07 2018 18:16
You cant push the changes to the original repo if you dont have write access which you wont
Christopher McCormack
@cmccormack
Dec 07 2018 18:16
unless you have permissions to the repo you need to fork it
DMZ
@DMZ011
Dec 07 2018 18:17
it'll be a pull request, without having to fork it, right?
Aditya
@ezioda004
Dec 07 2018 18:17
Cant make a PR without a fork
DMZ
@DMZ011
Dec 07 2018 18:17
so if u clone it, and push?
ehutchllew
@ehutchllew
Dec 07 2018 18:17
yeah you just submit a PR
Christopher McCormack
@cmccormack
Dec 07 2018 18:17
you fork theirs, then clone your fork
DMZ
@DMZ011
Dec 07 2018 18:17
ok
ehutchllew
@ehutchllew
Dec 07 2018 18:17
eh okay
Pagnito
@Pagnito
Dec 07 2018 18:19
@cmccormack hey do u know how to query firebaste realtime databse?
Christopher McCormack
@cmccormack
Dec 07 2018 18:19
@Pagnito i've not used firebase
Pagnito
@Pagnito
Dec 07 2018 18:19
shucks
Christopher McCormack
@cmccormack
Dec 07 2018 18:21
You can do a pull request against your own repo if you want though, via github
or whatever you're using
but you don't really need to do that, you can just merge a branch
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 18:22
@ezioda004 thanks i just got confused cause i saw that W matches everything except numbers and letters :/
DMZ
@DMZ011
Dec 07 2018 18:22
aha
Aditya
@ezioda004
Dec 07 2018 18:22
@thodorisanta I promise thats the only "gotcha" with regex :D
Otherwise its consistent
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 18:23
@ezioda004 haha
Lucci Paula
@luccipaula
Dec 07 2018 18:44
Does anyone know what this style of navbar is called? When you click on the link and then the dropdown menu rolls out (at 900px width and below)? http://www.sezia.co/about
Zaza
@ForkInSpace
Dec 07 2018 19:05
shot in the dark...
responsive navbar ? :P
@luccipaula
Jason Luboff
@JLuboff
Dec 07 2018 19:09
Looks like a Modal to me..
Lucci Paula
@luccipaula
Dec 07 2018 19:11
@ForkInSpace Haha true but I didn't know what the rolling motion was called
@JLuboff I've seen that term before but didn't know what it meant hehe
It's like the menu is already there but the amount of it that's shown increases and decreases slowly
Christopher McCormack
@cmccormack
Dec 07 2018 19:15
Are we seeing different things? all I see is a simple Modal
Lucci Paula
@luccipaula
Dec 07 2018 19:15
@cmccormack Are you seeing it at <900px width?
Christopher McCormack
@cmccormack
Dec 07 2018 19:16
yes
Lucci Paula
@luccipaula
Dec 07 2018 19:17
I'm just trying to figure out how to do that collapsing animation
Christopher McCormack
@cmccormack
Dec 07 2018 19:17
what browser?
Lucci Paula
@luccipaula
Dec 07 2018 19:17
I'm in Firefox
Aditya
@ezioda004
Dec 07 2018 19:17
All I see is a regular fadein, fadeout with a modal
Lucci Paula
@luccipaula
Dec 07 2018 19:18
Maybe I'm just terrible at describing things
Christopher McCormack
@cmccormack
Dec 07 2018 19:18
@ezioda004 same
Jason Luboff
@JLuboff
Dec 07 2018 19:20
I agree. Fadein / Fadeout with modal
(in FF)
Lucci Paula
@luccipaula
Dec 07 2018 19:20
It's okay, I found it. It's just called "collapsing navbar" hehe
Aditya
@ezioda004
Dec 07 2018 19:20
Same on firefox
Christopher McCormack
@cmccormack
Dec 07 2018 19:21
I still don't see any kind of rolling animation
Found it here under "Collapsing the Navigation"
Christopher McCormack
@cmccormack
Dec 07 2018 19:22
Are you just referring to the menu items being removed and the Menu button replacing them?
Lucci Paula
@luccipaula
Dec 07 2018 19:23
@cmccormack I was more referring to how the links appear when you click on the menu :p
Instead of appearing and disappearing abruptly it's more fluid
Jason Luboff
@JLuboff
Dec 07 2018 19:23
The example you gave on w3 is not the same thing that I see on that original page.
Lucci Paula
@luccipaula
Dec 07 2018 19:24
@JLuboff Really? The only difference I see is that on the w3 example it pushes the content down
But the animation is the same
Aditya
@ezioda004
Dec 07 2018 19:25
I see no animation, just the navbar changing from row to column in w3's example
Lucci Paula
@luccipaula
Dec 07 2018 19:27
It's fine guys I found what I needed lol :thumbsup:
Christopher McCormack
@cmccormack
Dec 07 2018 19:35
is $ special in a JS object? For some reason I cannot access the property...
console.log(JSON.stringify(response))
console.log(response['$'])
> {"response":{"$":{"status":"error","code":"400"},"result":[{"msg":["Illegal parameter [request]"]}]}}
> undefined
Aditya
@ezioda004
Dec 07 2018 19:36
No its a valid identifier
Try response.$
Christopher McCormack
@cmccormack
Dec 07 2018 19:36
did
same problem
Aditya
@ezioda004
Dec 07 2018 19:37
const x = {$: 1};
x.$; // 1
x['$']; // 1
Can you just log response?
Christopher McCormack
@cmccormack
Dec 07 2018 19:38
ohh it's because I am idiot
I was using response as my variable name as well so needed response.response lol
Chris
@crokita
Dec 07 2018 19:38
response.response.$? ah, yeah lol
Aditya
@ezioda004
Dec 07 2018 19:39
Ohh, missed that
Christopher McCormack
@cmccormack
Dec 07 2018 19:41
dangit even the simple things still cause a stumble
Jason Luboff
@JLuboff
Dec 07 2018 19:42
It happens on the daily to me :)
Jason Luboff
@JLuboff
Dec 07 2018 19:56
Hmm...not sure how I feel about this.. I have a map within a map within a map Some inception shit right there
Aditya
@ezioda004
Dec 07 2018 19:58
Perhaps using recursion in that case would be more elegant?
Jason Luboff
@JLuboff
Dec 07 2018 19:59
....I'm awful at recursion..like...I never use it awful
steps.map(({ hazardAndControls }, index) =>
          hazardAndControls.map(({ hazardID, controlIDs }) =>
            controlIDs.map(id =>
              insert.hazardAndControls(
                Number(stepIDArray[index].jobStepID),
                Number(hazardID),
                Number(id)
              )
            )
          )
        )
I'm sure I could refactor it some..but this was the quick and dirty
Christopher McCormack
@cmccormack
Dec 07 2018 20:02
I think that looks fine
what is insert?
Jason Luboff
@JLuboff
Dec 07 2018 20:04
Exactly what it sounds like! :) It's Database insert
all my insert methods are in my insert file
Aditya
@ezioda004
Dec 07 2018 20:05
I find it a bit confusing that both array and method name is same hazardAndControls
Jason Luboff
@JLuboff
Dec 07 2018 20:06
Thats a fair critique
Aditya
@ezioda004
Dec 07 2018 20:06
Its not a good variable name day it seems :P
Jason Luboff
@JLuboff
Dec 07 2018 20:07
I guess to me it makes sense since I know they are two seperate things but I can see where it would be confusing to someone else looking at it
Aditya
@ezioda004
Dec 07 2018 20:08
Yeah, then again I'm also bad at naming variables 🙈
Jason Luboff
@JLuboff
Dec 07 2018 20:08
I've gotten better I think since I started with React...but.. I do have a tendency to have fairly long variable names :shrug:
Christopher McCormack
@cmccormack
Dec 07 2018 20:08
@ezioda004 I fixed that with the super hero destructure man!
    const {response} = await api(url.getFullUrl(), options)
    const {$: {status, code=400}, result} = response
Aditya
@ezioda004
Dec 07 2018 20:10
I swear this code would've tripped me up 6 months ago
Jason Luboff
@JLuboff
Dec 07 2018 20:11
First line making a call to api which returns an object with key response?
Second line...more complex destructure lol
Christopher McCormack
@cmccormack
Dec 07 2018 20:14
@JLuboff yup
second line destructures $ and result from response, then status and code from $, adding a default value for code in case it is undefined
Jason Luboff
@JLuboff
Dec 07 2018 20:15
Ya see exactly what I said
Christopher McCormack
@cmccormack
Dec 07 2018 20:15
I love me some difficult-to-refactor code
const {response: {$: {status, code=400}, result}} = await api(url.getFullUrl(), options)
would probably work as well
but at a certain point you got to cut off that nesting for readability
Kaz Baig
@kbaig
Dec 07 2018 20:17
Hey friendos
Christopher McCormack
@cmccormack
Dec 07 2018 20:18
@kbaig hey! what's up?
Jason Luboff
@JLuboff
Dec 07 2018 20:18
Hey man
Aditya
@ezioda004
Dec 07 2018 20:18
Doesnt look that bad, but a linter would probably add new lines in that destructuring
Jason Luboff
@JLuboff
Dec 07 2018 20:18
@ezioda004 Renamed my insert method to be less confusing :)
Well... slightly less confusing
Kaz Baig
@kbaig
Dec 07 2018 20:18
A while ago I was asking if there was a way to have the mongoose schema shape my data the way i want it rather than having to map over it within the route middleware
Aditya
@ezioda004
Dec 07 2018 20:18
@JLuboff Awesome lol
Kaz Baig
@kbaig
Dec 07 2018 20:19
Just wanted to let you know I found a diff approach that was also satisfying
I reshaped the data in the validation/sanitation middleware
Jason Luboff
@JLuboff
Dec 07 2018 20:19
[
 [
  [
   {},
   {}
  ]
 ],
 [
  [
   {},
   {}
  ],
  [
   {},
   {}
  ]
 ],
 [
  [
   {},
   {}
  ],
  [
   {},
   {}
  ],
  []
 ]
]
[
 [
  [
   {}
  ]
 ],
 [
  [],
  []
 ],
 [
  [],
  [],
  [
   {},
   {}
  ]
 ]
]
Isn't it beautiful
Christopher McCormack
@cmccormack
Dec 07 2018 20:20
@kbaig this was for the default values?
Kaz Baig
@kbaig
Dec 07 2018 20:20
@cmccormack Yeah
Christopher McCormack
@cmccormack
Dec 07 2018 20:20
very nice!
are you using express-validator?
Kaz Baig
@kbaig
Dec 07 2018 20:20
Yes I am
Made a lot of progress since then I think
Christopher McCormack
@cmccormack
Dec 07 2018 20:21
it grows and grows
Kaz Baig
@kbaig
Dec 07 2018 20:21
But I feel like I need to add the ability to edit polls, even if it's not in the user stories. Feels incomplete without it
Is it weird that it's taken me a month + to do my first full stack app?
Christopher McCormack
@cmccormack
Dec 07 2018 20:22
no it took me a few months to do the voting app
like 4
edit polls how?
like remove entries?
Jason Luboff
@JLuboff
Dec 07 2018 20:23
I think voting app took me about a month... but I also used a template engine and.. there's probably a ton of things I did wrong or would do much differently now
Kaz Baig
@kbaig
Dec 07 2018 20:23
Okay great! I had to learn a lot of stuff in the process. Auth, jwt, express-validator, react router etc
Christopher McCormack
@cmccormack
Dec 07 2018 20:23
yup same @kbaig
lots of little hills to climb
Kaz Baig
@kbaig
Dec 07 2018 20:24
@cmccormack I already have the ability to remove polls, but I want to add the ability to rename polls, and rename/delete options
Christopher McCormack
@cmccormack
Dec 07 2018 20:25
@kbaig that would introduce bias
Kaz Baig
@kbaig
Dec 07 2018 20:25
You mean by changing names after people have voted?
Christopher McCormack
@cmccormack
Dec 07 2018 20:25
I could make a poll that says "Do you like X" and if I don't like that results change the name to "Do you hate X"
yeah
Kaz Baig
@kbaig
Dec 07 2018 20:26
That would indeed be pretty troll
Christopher McCormack
@cmccormack
Dec 07 2018 20:26
haha sure would be
@kbaig Do you hate programming?
Kaz Baig
@kbaig
Dec 07 2018 20:26
For sure! Why do you ask
GOT EM
Christopher McCormack
@cmccormack
Dec 07 2018 20:26
lol
Kaz Baig
@kbaig
Dec 07 2018 20:27
I feel really stupid for not seeing that lmao
Christopher McCormack
@cmccormack
Dec 07 2018 20:27
I figured you would haha
not feel stupid, see it
Kaz Baig
@kbaig
Dec 07 2018 20:27
:smile:
Pagnito
@Pagnito
Dec 07 2018 20:33
how is this possible, im using firebase serve, i built a new bundle, with a changed request url, yet its serving a bundle that shouldnt even by in the build directory wit the old request url
Brad
@bradtaniguchi
Dec 07 2018 20:51
Where's the meme of the Alien guy with the hair, I need him to say "caching"
Pagnito
@Pagnito
Dec 07 2018 20:52
lol
yea i just figured that out
is it worth to turn of caching?
in the code
im guessin it is with a service worker, but if i dont use it, wouldnt having cache be nice for faster loads
Brad
@bradtaniguchi
Dec 07 2018 21:26
@Pagnito service worker is great for local caching, but like any cache you gotta use it right
Pagnito
@Pagnito
Dec 07 2018 21:26
yea i gotta understand how the built in cache works
i just saw a video yesterday that i think mentioned it and it said its on some remote local cdn server
Jason Luboff
@JLuboff
Dec 07 2018 21:32
@Pagnito All your troubles with firebase...make me never want to use it :smile:
Pagnito
@Pagnito
Dec 07 2018 21:32
lmao @JLuboff
i think once i figure it out, its simple, im kind of starting to like it, except i dont wanna use firebase on the front end
firebase.js bloats up my bundle od
Brad
@bradtaniguchi
Dec 07 2018 21:36
The two things about firebase is 1. the api is "observable based", and 2. you have to design the database around firebase otherwise you end up paying for stupid wasted queries
Jason Luboff
@JLuboff
Dec 07 2018 21:37
So..what exactly IS firebase
Brad
@bradtaniguchi
Dec 07 2018 21:37
@JLuboff Its basically a backend as a service
Jason Luboff
@JLuboff
Dec 07 2018 21:37
So would it replace node/express?
Brad
@bradtaniguchi
Dec 07 2018 21:38
@JLuboff Yup, it handles that with its basic API's for most use-cases, any edge-cases (like exports) are supported through firebase cloud functions, which are serverless express apps more or less
Also gotta mention its a real-time database too, so think socketio for all the api calls. So doing a chat app (like gitter) can be done pretty quickly out of the box
Jason Luboff
@JLuboff
Dec 07 2018 21:41
Oh..hmm
Interesting
Keegan
@Keggatron
Dec 07 2018 21:47
So say I have an array of position objects that I would like to add to. However I'd like to add to the end of specific positions. Here's an example of what I mean:
positions: [
      {
        id: 1,
        description: 'Position 1',
        employee: {
          firstName: 'Jan',
        }
      },
      {
        id: 1,
        description: 'Position 1',
        employee: {
          firstName: 'Greg',
        }
      },
      {
        id: 2,
        description: 'Position 2',
        employee: {
          firstName: 'Doug',
        }
      },
      {
        id: 3,
        description: 'Position 3',
        employee: {
          firstName: 'Jen',
        }
      }
    ]
so say I had
{
        id: 1,
        description: 'Position 1',
        employee: {
          firstName: 'Roger',
        }
      },
Christopher McCormack
@cmccormack
Dec 07 2018 21:48
@Keggatron push it as-is to the array then sort the array by position (id or description), or iterate over the array and splice in where needed
Keegan
@Keggatron
Dec 07 2018 21:49
I would like to add that to the array, but have it right after
{
        id: 1,
        description: 'Position 1',
        employee: {
          firstName: 'Greg',
        }
      },
Christopher McCormack
@cmccormack
Dec 07 2018 21:49
the former only works if it doesn't matter the order of the objects that all have the same position
Keegan
@Keggatron
Dec 07 2018 21:49
yes what's the easiest way to add it to the last value with description Position 1
Christopher McCormack
@cmccormack
Dec 07 2018 21:50
that's what I just answered
Keegan
@Keggatron
Dec 07 2018 21:50
sorry the thing is I'm using different descriptions, I don't actually want it to be alphabetically
Christopher McCormack
@cmccormack
Dec 07 2018 21:51
sort can be given a callback so you can sort it however you want
Jason Luboff
@JLuboff
Dec 07 2018 21:51
Perhaps find lastIndexOf where id matches, than splice in there
Keegan
@Keggatron
Dec 07 2018 21:51
nice @JLuboff that's what I'm looking for, that might work, thanks
Christopher McCormack
@cmccormack
Dec 07 2018 21:52
that's what I said! haha
Jason Luboff
@JLuboff
Dec 07 2018 21:52
@cmccormack I mean...you sort of said that...but.. not exactly!
Christopher McCormack
@cmccormack
Dec 07 2018 21:52
that was basically the second option, indexOf is still an iteration of sorts
not sure how you intend to use indexOf without making a new temporary data structure just to use that method though
Adel
@AdelMahjoub
Dec 07 2018 21:54
  const left = positions.filter(e => e.id <= emp.id);
  const right = positions.filter(e => e.id > emp.id);

  positions = [... left, emp, ...right]
Christopher McCormack
@cmccormack
Dec 07 2018 21:55
@AdelMahjoub nice
Adel
@AdelMahjoub
Dec 07 2018 21:55
@cmccormack thanks, :smile:
Christopher McCormack
@cmccormack
Dec 07 2018 21:55
maybe more work than needed as it has to iterate over the whole thing twice though
but if small enough it's easy
Adel
@AdelMahjoub
Dec 07 2018 21:56
yes
Jason Luboff
@JLuboff
Dec 07 2018 21:56
Lol.. I was looking at <= emp.id and I was like "What is this backwards arrow function magic?!" than realized.. its a comparison in the callback... :joy:
Adel
@AdelMahjoub
Dec 07 2018 21:56
:laughing:
Christopher McCormack
@cmccormack
Dec 07 2018 21:56
I think finding the index then combining is probably fastest
@JLuboff lol
Adel
@AdelMahjoub
Dec 07 2018 21:58
the indexOf and slice is the best I think
Jason Luboff
@JLuboff
Dec 07 2018 21:58
Damn.. just recieved 6 of these EliteDesk 800 G4 Tower Core i7-8700 3.2GHz / 16GB / 256GB SSD better than my workstation for users who (besides two) don't need that sort of power
Adel
@AdelMahjoub
Dec 07 2018 22:00
a gtx 1060 inside ?
Jason Luboff
@JLuboff
Dec 07 2018 22:01
Nah...all using onboard graphics I believe
Brad
@bradtaniguchi
Dec 07 2018 22:01
@JLuboff I can take any extras off your hands :smile: I wont mind the burden :P
Jason Luboff
@JLuboff
Dec 07 2018 22:02
lol Several of these individuals are also getting Surface Pros
Adel
@AdelMahjoub
Dec 07 2018 22:02
slice one of them with your workstation
surface pros for commercials
what do you do with the previous stations ?
alpox
@alpox
Dec 07 2018 22:07
@JLuboff Niice :) but could use a bit more GB
SSD
Adel
@AdelMahjoub
Dec 07 2018 22:11
@alpox I just learned that better use a lot of tables with few columns and forbid null values, than few tables with more columns and nullable values, from a data modeling expert, is that always true ?
Lucci Paula
@luccipaula
Dec 07 2018 22:11
Quick question: if I completed some legacy projects last year and submitted them along with recent projects to claim a certificate, will I be able to redeem it? Should I go back and redo the older projects?
Adel
@AdelMahjoub
Dec 07 2018 22:11
fewer indexes and smaller size, leads to more perf
or is it @JLuboff the sql expert ?
@luccipaula I think you can redeem legacy projects
Lucci Paula
@luccipaula
Dec 07 2018 22:17
@AdelMahjoub Thanks I hope so hehe
Pagnito
@Pagnito
Dec 07 2018 22:18
hey anyone know how i can config a fascebook passport strategy to redirect the user back to the url he was on when he clicked the log in btn, currently i have i to redirect to '/', but i dont like it because it interrupts the flow, my auth is in the header, and i want it to be very simple process without interrupting the user flow
alpox
@alpox
Dec 07 2018 22:18
@AdelMahjoub I'm no expert. I believe it depends on the case - too many tables is not good either as a lot of joins can get quite complicated when the system grows too big
Pagnito
@Pagnito
Dec 07 2018 22:18
but if i dont i give it redirect on succes, it just stays idle on callback url
alpox
@alpox
Dec 07 2018 22:19
But in general I would say you're right
Jason Luboff
@JLuboff
Dec 07 2018 22:21
@AdelMahjoub Two of the users have older (4+ year old) laptops. The other couple have new (less than a year old) laptops. So the old ones will either be kept for checkout laptops or e-waste. The new ones will be reissued.
In regards to SQL... it is generally better to have less wide tables but in regards to null values...a null value (of a datatype that is variable) takes literally no space but there is some overhead. I think its more a matter of choosing the correct datatype's for your table
@alpox I agree... my 256 GB SSD is practically full (only 10% free space)...and I need to be able to store more.. :(
Kaz Baig
@kbaig
Dec 07 2018 22:36
:wave:
Could I get a bit of advice on modals/flash messages in react?
Right now I've got
const body = document.body;
const messageDuration = 2000;

class FlashMessage extends Component {
    constructor () {
        super();

        this.state = { mounted: true };
    }

    componentDidMount () {
        setTimeout(() => this.setState({ mounted: false }), messageDuration);
    }

    render () {
        return this.state.mounted && createPortal(
            <div className='FlashMessage'>{ this.props.children }</div>,
            body
        );
    }
}
The problem is every time I want to reuse this component, it's going to be appended to my react tree
I'm trying to find a way to remove the component from the tree when the timeout ends
Kaz Baig
@kbaig
Dec 07 2018 22:42
It could just be that I'm thinking about this wrong and it's not going to be stacking FlashMessages in the tree
Perhaps it's just better to manage the timeout in the parent that's rendering the message?
Pagnito
@Pagnito
Dec 07 2018 22:59
hey anyone used a compression package for gzip ?
Pagnito
@Pagnito
Dec 07 2018 23:11
awkjbaskjdbalkdbaslkjdnasd
cant figure out why compression isnt working with firebase
Norvin Burrus
@ndburrus
Dec 07 2018 23:20
@Pagnito this may be helpful :sparkles:
Spyrantis Theodoros
@thodorisanta
Dec 07 2018 23:53
lets say i have an array str = ["a", "b" , "c" , "d"]; whats the easiest way to remove the first letter "a" and place it at the end of the array?
Jason Luboff
@JLuboff
Dec 07 2018 23:57
There is several ways. You could use indexOf to find the first occurance, than remove it with slice than add it to the end with splice or push