mercredi 25 décembre 2019

javascript if or statements [closed]

I have the following code:

if (insurance != ("amica" || "travelers" || "national general" || "infinity" || "cincinatti")) {
    amount = "$200";
} else {
    amount = "$300";
}

I'm trying to have my web page display you get $200 if it's not one of the five company above.

Unfortunately, I can't seem to get it to work. I've written it several different ways I started if (insurance === "amica || insurance === "travelers || ... but nothing seems to work.

What am I doing wrong?

cat a file into an array and read it through if statement in bash

I am trying to make a script in bash that scans my network for alive IPs and then it does port scan and grep services (ssh etc) and products (OpenSSH) and versions then stores them to name.txt,product.txt,version.txt OR to an array. Then, here comes my problem, i want it to take first line from all three files and check them against my arrays, if first line in name.txt = ssh_NameDataBase[] and first line in product.txt = ssh_VulnsDataBase[] and first line in version.txt then echo "vulnerable". the code below works but it prints about 24 times. I REALLY would appreciate your help

ssh_NameDataBase=('ssh' '')
ssh_VulnsDataBase=('OpenSSH' 'OpenSSH')
ssh_VersionDataBase=('2.9p2' '3.9p2')

cat $ips/$ips.xml | grep -oP 'name="\K[^"]+' > $ips/name.txt
cat $ips/$ips.xml | grep -oP 'product="\K[^"]+' > $ips/product.txt
cat $ips/$ips.xml | grep -oP 'version="\K[^"]+' > $ips/version.txt

my problem starts here

for name in $(cat $ips/name.txt)
do
    for product in $(cat $ips/product.txt)
    do
        for version in $(cat $ips/version.txt)
        do
            for ssh in "${ssh_VulnsDataBase[@]}"
            do
                if [ "$product" = "$ssh" ]
                then
                    if [ "$version" = "${ssh_VersionDataBase=[@]}" ]
                    then
                        echo "$ips is vulnerable to $product $version you need to upgrade"
                    fi
                fi
            done
        done
    done
done

How can i pad 0's to the left?

In this example i want to make it so where the enters any number between this range. If the user enters the number 2 for example, the account number would be like something like this 00000002, where it adds the 0's automatically. Is this possible to do at all in this scenario?

System.out.println("What is your 8 digit Account Number?"); //Enter Account Number.
AccountNumber = ask.nextInt();  //user is asked for an input for the account number. I want input to fall within that range

if (AccountNumber > 00000000 && AccountNumber < 99999999) {   
}       
else  {
 System.out.println("Invalid Account Number \n"); 

 System.out.println("Re-Enter Account Number");
 AccountNumber = ask.nextInt(); 
}

fit a number into the range if if chained

I have a total variable and I have a range of 250 out of 250 I need to know in which range is the variable, but in a range of 15250 would have to do more than 61 if chained, has another way to eliminate this repetition of ifs? Thanks for the help. example

 public void ValidTravel(int Traveled)
 {
    int total = 15250
    int range = 250   

     if (Traveled>= 1 && Traveled<= 250)
        {                
           return 250;
        }

     if (Traveled>= 251 && Traveled<= 500)
        {                
           return 500;
        }

     if (Traveled>= 501 && Traveled<= 750)
        {                
           return 750;
        }

     if (Traveled>= 751 && Traveled<= 1000)
        {                
           return 1000;
        }

}

how to improve my code iteration through two different data frame with 100K rows to decrease processing speed in python?

Could you please take a look at my code and give me some advice how I might improve my code so it takes less time to process? Main purpose is to look at each row (ID) at test table and find same ID at list table, if it's match then look at time difference between the two identical ID and label them as if it takes less than 1 hours (3600s) or not. Thanks in advance

test.csv has two col (ID, time) and 100K rows list.csv has tow col (ID, time) and 40k rows

sample data: ID Time 83d-36615fa05fb0 2019-12-11 10:41:48

a = -1
for row_index,row in test.iterrows():
   a = a + 1

   for row_index2,row2 in list.iterrows():

       if row['ID'] == row2['ID']:
           time_difference = row['Time'] - row2['Time']
           time_difference = time_difference.total_seconds() 

           if time_difference < 3601 and time_difference > 0:
               test.loc[a, 'result'] = "short waiting time"

Considering three numbers, nr_1, nr_2, and nr_3. How can write a program such that nr_1 has the largest value and nr_3 the smallest

The three numbers are variables and can have any value. The program should just assign the largest of the number to nr_1 and smallest to nr_3

How to clean up some of the script in a two input file while loop?

This is my script.

while read lineA; do
  while read lineB; do
    if [[ ${lineA##*/} == ${lineB##*/} ]]; then
      printf "${lineA##*/} and ${lineB##*/} match\n"
    else
      printf "${lineA##*/} and ${lineB##*/} don't match\n"
      printf "$lineA\n" >> file2 # Add Line if Not in file2
    fi
  done < file2
done < file

The script endless runs and in file2 adds endless lines.

It is reading right. I was trying to get line 1 in file to read through each line in file2 adding only new lines to file2 if not in file2. Repeating line 2 in file through each line in file2 adding only new lines to file2. Reading all lines in file till done. What can I do to correct this?

Hoping for: Script

Hoping for: Script

Checking 'Bull.txt' in file2

Fox.txt don't match

Zebra.txt don't match

Adding Bull.txt to file2

Checking 'Cat.txt' in file2

Fox.txt don't match

Zebra.txt don't match

Cat.txt is a match

Not Adding Cat.txt to file2

And Than: checking file2

Fox.Fox.txt

Zebra.Zebra.txt

Bull.Bull.txt

Cat.Cat.txt

only