Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 21 2018 17:11
    @MadLittleMods banned @OmarAlmaqtri
  • Jun 05 2018 23:13
    @MadLittleMods banned @LWSS
  • May 25 2018 16:50
    @MadLittleMods banned @TheRedstoneTaco
EuphoricPenguin
@EuphoricPenguin
VMs can be convenient, but it depends on what you want to do. If you need to flash stuff to boards/other hardware level stuff, the software can complicate things a great deal.
syedsimanta03
@syedsimanta03
@EuphoricPenguin I will then install linux on my HDD. So basically the HDD will be devided into 2 partitions. 300gb for linux development. 700gb for my necessary files
dimtabu
@taburetkin
Does anyone knows how to avoid this behavior?
https://s.codepen.io/dimatabu/debug/YzKpZGV/bZMQWELzJQYA - try it with chrome, its a codepen in debug mode
in codepen frame there is no such issue: https://codepen.io/dimatabu/pen/YzKpZGV
ns26
@ns26

Hey guys, looking for a JS medior/senior to give me some pointers on a script. The script is in a private/local (non-store) Chrome extension that highlights certain iframes with CSS in try/catches (to bypass some basic security issue). Usecase is an online CRM system called Exact.

Link to the main script here: https://pastebin.com/e3w8rXqX

What I'm trying to add is: if value 123 is found while highlighting ID list A then also highlight ID list B but only with a border-property. In the scenario where there is the same ID in list A & B it needs to properly apply both highlight functions.

I've tried all day yesterday to make it happen in numerous of ways but without any luck. I'm just a student that picked up a slightly overambitious internship project :p I can do basic debugging but I'm definitely a junior..

Mahi
@arbitrarymahi
HI
How do I wait till my XHR returns the response? Currently I get reuest.status = 0 and the code execution moves on but I want to wait until response is recieved.
Stephen James
@sjames1958gm
You don’t. Or at least shouldn’t. Use call back functions
Your in the browser should handle asynchronous behavior
Mahi
@arbitrarymahi
Actually i am calling an API but it has limit 10 fixed so i am using the XHR call inside a forloop but before i recieve the response the for loop iteration executed again and again
is that a good practice or else what should be the best solution in this case?
Stephen James
@sjames1958gm
You don’t want to have your js wait for responses as that will block your browser and is bad user experience. If they can run in parallel then you can assign a function to the onreadystatechange event property and handle each response as it occurs. This would be after the for loop completes. If you have specific code that should run after all the responses you would have to keep track of the responses and call that code from the code handling the last response.
Also, your code should not depend on the parallel responses coming back in the same order as you sent them.
If they cannot be parallel then each callback would invoke the next xhr request
Mahi
@arbitrarymahi
xhr.open(method, url, true);
xhr.onreadystatechange = function () {
// Begin accessing JSON data here
  var count = 0
  var data = JSON.parse(xhr.response)
  //var data = JSON.parse(xhr.responseText)
  if (request.status >= 200 && request.status < 400){
  console.log('data is: \n',data.records)}
else {
    console.log(request.status)
  }
  };
xhr.send()
I have written this code and it gets the response but due to some reason it is logging to the console twice.
Stephen James
@sjames1958gm
Is it hitting both console.log?
dimtabu
@taburetkin
if it logs twice then it means that onreadystatechange called two times
I just put my Node.js authentication boilerplate on Github. Check it out.
ptmhpp
@ptmhpp

Hi Guys…..
I have a javascript file and in that there are some functions defined in it.
How can i get all the function name defined in that particular js file in an array of string

for example js file looks something like this

function getabc1() {
//block of code
}
function getabc2() {
//block of code
}
function getabc3() {
//block of code
}

I need all the 3 functions name defined in this particular js file.
Only name of function
It will be great help if someone can help me on this.

dimtabu
@taburetkin
short: process the js file in some other runtme, read it as text and find something by pattern and store it somehow somewhere.
But i believe you are doing something certain and your question is partial.
I believe that there is more easy/better ways exists to achieve what you really want
alienroom
@alienroom
any 1 here doing stream in programming javascript? i would love to watch and learn i am level 5 of 10 in javascript thank you community.
Braulio
@bab2683
@lilalienx what do you mean you are level 5 of 10 in javascript?
alienroom
@alienroom
@bab2683 imagine 10 is top 5 is middle
Braulio
@bab2683
@lilalienx yeah but how can you tell what level are you? is there a scale or something?
EuphoricPenguin
@EuphoricPenguin
General syntax question: Is setting a variable using var foo = "bar"; and then later in the code reassigning the value without var: foo = "new value"; treated the same as using var for each value reassign?
EuphoricPenguin
@EuphoricPenguin
@bab2683 @lilalienx I don't think you could ever really measure where you are in JS. There's so many components: modern syntax usage, coding concept understanding, code structure and implementation, use of code modules strategically, etc...
You can get an idea in your head, but I always find more to learn. JS seems easy at first, but you can always learn more.
If you're still using for loops with arrays, for example, there's other options. for/in and for/of, plus forEach.
Braulio
@bab2683
@EuphoricPenguin that is what I was trying to say, you can't really declare you are "some level of javascript" because there is always something new to learn
dimtabu
@taburetkin
actually, its true for anything in the world
EuphoricPenguin
@EuphoricPenguin
General syntax question: Is setting a variable using var foo = "bar"; and then later in the code reassigning the value without var: foo = "new value"; treated the same as using var for each value reassign?
Still, about this ^
Is setting a variable as a property after declaring it by name to be a variable syntactically the same as using var for each value reassign?
dimtabu
@taburetkin
EuphoricPenguin
@EuphoricPenguin
@taburetkin I know how to use it, all I'm asking is if var is only used the first time for reassigning values.
dimtabu
@taburetkin
actually, links i give you completely answers your question, but to get the answer you have to read
EuphoricPenguin
@EuphoricPenguin
It looked like just scope.
EuphoricPenguin
@EuphoricPenguin
@taburetkin Saw an article here, so you don't use var to reassign. I never did, but for some reason I was worried lol.
EuphoricPenguin
@EuphoricPenguin
Oh, just saw this and was curious: What is the "?" operator? Is it shorthand, I've only seen it used a couple of times.
Tried to find it on MDN and Google, no luck.
Nvm, found it.
Assigns an optional value based on condition.
Nadia
@nadiaschutz
// how would you improve this code in node.js? any suggestions? thanks
const axios = require('axios')
const chalk = require('chalk');
const url = "http://api.genderize.io"
const names = [];
let params;

for (let j = 2; j < process.argv.length; j++) {
    if (isNaN(Number(process.argv[j]))) {
        names.push(process.argv[j]);
    }
}


if (names.length === 0) {
    console.log('Please provide names');
} else if (names.length === 1) {
    params = "?name=" + names;
} else {
    const result = [];
    for (let j = 0; j < names.length; j++) {
        (j === 0) ? params = "/?name[]=" + names[j] : result.push("&name[]=" + names[j]);
    };
    result.forEach(element => {
        params += element;
    });
}


axios({
    method: 'get',
    url: url + params,
    headers: {
        'Accept': 'application/json'
    },
}).then(res => {
    checkGender(res.data);
}).catch(err => {
    const log = chalk.red(err) // we set the color red here for errors.
    console.log(log)
})

const checkGender = (data) => {
    const result = [];
    females = [];
    males = [];
    data.forEach(name => {
        name.gender === 'female' ? females.push(name) : males.push(name)
    });
    result.push(females.sort(function (a, b) {
        return b.probability - a.probability;
    }));
    result.push(males.sort(function (a, b) {
        return a.probability - b.probability;
    }));

    console.log(result);
}
Nadia
@nadiaschutz
➜ node gender.js tom jack maria anna Alexis
[ [ { name: 'anna', gender: 'female', probability: 1, count: 4755 },
    { name: 'maria',
      gender: 'female',
      probability: 0.99,
      count: 8402 } ],
  [ { name: 'Alexis', gender: 'male', probability: 0.52, count: 1224 },
    { name: 'jack', gender: 'male', probability: 0.99, count: 1993 },
    { name: 'tom', gender: 'male', probability: 1, count: 3736 } ] ]
dimtabu
@taburetkin
@nadiaschutz
const checkGender = (data) => {
    let genders = { 
        male: [1, (a,b) => a.probability - b.probability], 
        female: [-1, (a,b) => b.probability - a.probability] 
    };
    data.sort((a,b) => {
       if (a.gender == b.gender) {
          return genders[a.gender][1](a,b);
       }
       return genders[a.gender][0] - genders[b.gender][0];
    });
    console.log(data);
}
Nadia
@nadiaschutz
const checkGender = (data) => {
    let females = (data.filter(item => { return item.gender === 'female' })).sort((a, b) => {
        return b.probability - a.probability;
    });
    let males = (data.filter(item => { return item.gender === 'male' })).sort((a, b) => { return a.probability - b.probability });
    let result = [...females, ...males];

    console.log(result);
}
dimtabu
@taburetkin
i belive you can sort in one go, like in my example
without creating three additional arrays.
Nadia
@nadiaschutz
@taburetkin could you please explain what does each step do?
dimtabu
@taburetkin
sure
Nadia
@nadiaschutz
можешь на русском если удобнее