jeudi 1 juin 2017

Unable to find session with IF asp.net C#

I have a database with a entry called Sally which is also link with asp login . When Sally logs I coded that it will gave a session["name"] which is Sally's database column name. When Sally logs in I made it so that "Label" will display the session's value (Sally) which it works. However, when pressing the "sally button" (to see if session is sally) it does not work. I assume its my code that is wrong but l cant find a solution. example of my "sally button code".

if (Convert.ToString(Session["group"]) == "Sally")
    {
        Label1.Text = "isSally";
    }
    else
    {
        Label1.Text = "notSally";
    }

It will always show "notSally" even thought the label will say sally once she logs in. I made another button which will change the label to see if the session["name"] is null, it works as when sally logs in it shows that there a session. Sorry for bad english. Sample of what it looks like

Excel VBA - Take only the numeric value in a cell

I have an IF function in VBA that has a mathematical formula in it:- (Cells(i3, 10).Value > 30)

The issue i'm having is that the values in column 10 are all alphanumeric. For example they're all " 1 - Hard", "2 - Moderate", "3 - Easy".

Is there anyway to make VBA only look at the number so when it's testing if the value is more than 30, it actually works?

Thanks

JS "If & else" does not respond properly

I am trying to make a site which will display various sentences depending on the variable "d". The plan is if "d" is exactly 0, the first line will be displayed, as well as the value of d will be displayed in the paragraph with a class of "text".

This is the code

    <!doctype HTML>
<html>

<head>
  <link href="main.css" rel="stylesheet" />
  <meta charset="utf-8">
  <link href="http://ift.tt/1qQRi4V" rel="stylesheet">
</head>

<body class="Ubuntu">
<nav>
  <div>
    <h1>Beregn antal diskriminanter</h1>
  </div>
</nav>

<div align="center" class="main_container">
  <table>
    <form method="POST" name="diskriminant" action="diskriminant.html">
  <tr>
    <td>
      <p> Indtast a </p>
    </td>
    <td>
      <input type="number" name="numA" size="6" class="input-form"/></p>
    </td>
  </tr>

  <tr>
    <td>
      <p> Indtast b </p>
    </td>
    <td>
      <input type="number" name="numB" size="6" class="input-form"/></p>
    </td>
  </tr>
  <tr>
    <td>
      <p> Indtast c </p>
    </td>
    <td>
        <input type="number" name="numC" size="6" class="input-form"/></p>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center">
            <p><input type="button"  name="knap" value="Beregn" onkeydown="enter()" onclick="beregner()"class="button Ubuntu"/></p>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center">
            <p id="text" class="align"></p> <br> <p id="result" class="align"></p>
    </td>
  </tr>
    </form>
  </table>
</div>
<footer>
</footer>
<script>
    function beregner() {
        var a;
        var b;
        var c;
        var d;
        var res;

        a=document.diskriminant.numA.value;
        b=document.diskriminant.numB.value;
        c=document.diskriminant.numC.value;

        d=Math.pow(( +b),2)-4*a*c;


        if (d = 0) {
          res = "Der er ingen nulpunkter";
        }
        else if (d < 0) {
            res ="Der er et nulpunkt";
          }
        else {
            res ="Der er to nulpunkter";
          }


          document.getElementById('text').innerHTML=+d;
          document.getElementById('result').innerHTML=res;


    }
</script>

</body>
</html>

Extracting keywords from parsed files in JAVA

I'm a new to javaparser and I'm trying to look for ways on how one can improve overall code coverage of a class. From a very basic perspective I'm trying to parse the class and look for conditional statements (like if else if switch etc.) and try-catch clauses. Imo,if test-cases for all such possible branches are provided then it'll help increase the code coverage.

Question: 1.How can I look for keywords like "else-if" by parsing the file

2.What classes must I use?

I found the Statement class and created a mock method to check for if statements in a class

public void visit(IfStmt n,Void arg) 
            {
                System.out.println("Found an if statement " + n.getClass() + " @ " + n.getBeginLine());
            }

3.How can I search for operators like "&&" and "||" ?

4.Any tips on how I might go about increasing the code coverage?

Compare Array to String in bash

Please let me have this clear, dont comment or post negatively if you're not willing to help. I have this pure bash script that finds out all IPs on the computer/laptop/server and saves the IPs in an array, also it saves a list of those IPs in a file in the /tmp/ folder for temporary use.

what i'm trying to do is:

a user runs the shell, it'll prompt him/her to enter the public (real) IP address used for internet connection, then it verifies this IP by pinging it to check if its reachable. then if its reachable the script continues and if its not it'll re-ask him/her to enter his/her real (public) IP again.

now i know that pinging any IP from the list will be reachable and the script will run no matter whether he/she entered any of the listed IPs, and i'm working on how to ping it from outside the network to check if its reachable or not. but my question is how can i achieve that? ---> how can i compare the array to the user's input?

here's my script thats getting stuck at the "Please Type Your Public......" question no matter what IP i entered from the list, i know its because of the while or a missing "break".

#!/bin/bash

##--------------START Temp Variables-------------##
KEY_USER="${KEY_USER:-$(whoami)}"

ifconfig | grep Bcast > /tmp/ip1
cat /tmp/ip1 | awk '{ print $2 }' > /tmp/ip2
rm /tmp/ip1
sed -i 's/addr://' /tmp/ip2
#ips=$(cat /tmp/ip2)
howmanyips=$(grep -c "." /tmp/ip2)
for (( i=$howmanyips; i>0; i-- ))
do  
   head -$i /tmp/ip2|tail -1 > /tmp/$i
done

ipcheck=0
intip=0
##---------------END Temp Variables--------------##

##---------------START Main Script---------------##
code...
code...
code...
code...
##---------------START Prompt Loop---------------##
while true; do
echo -e "\e[33;44m***** CHOOSE YOUR VALID PUBLIC IP *****\e[0m"
    cat /tmp/ip2
    read -p "Please Type Your Public IP (that has internet access) from above:" uip
readarray -t ips < <(exec ifconfig | awk '/Bcast/ { gsub(/addr:/, "", $2); print $2 }')
 for ip in "${ips[@]}"; do
  if [ $uip == $ip ]; then
   ipcheck=$ip
   intip=$i
   ping -c 1 $ip > /tmp/ipnetcheck
   ipnetcheck=$(grep -ic "0%" /tmp/ipnetcheck)
   if [ $ipnetcheck = 1 ]; then
      break
      else
      exit 130
   fi
   else
   break
  fi
 done
done

thats it, i would really appreciate anyone's help, and thanks in-forward.

if statement return false for no reason

Can anyone please tell me why this block of code is not working?

It's driving me crazy now. The if statement shows that both entries are Equal and it refuses to accept it as true for no reason.

if (isStoragePermissionGranted()) { File sdcard = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); for (File f:sdcard.listFiles()) { if (f.isFile()){ String name = f.getName(); // String[] splited = name.split("."); StringTokenizer string = new StringTokenizer(name,"."); String frst = string.nextToken(); String scnd = string.nextToken().toLowerCase(); // String scnd=splited[1]; String jpg ="jpg"; if (scnd==jpg) { files.add(f); fileNames.add(name); }

Count combinations in indicators

I am trying to figure out a more efficient way of calculating the number of correct combinations within the indicators.

Here is my data:

head(data)
   email_flag home_number_flag mobile_flag
1:  incorrect        incorrect     correct
2:  incorrect        incorrect   incorrect
3:  incorrect        incorrect   incorrect
4:  incorrect        incorrect   incorrect
5:  incorrect        incorrect   incorrect
6:  incorrect        incorrect   incorrect

My current approach with an ifelse statement:

data <- mutate(data, number_of_correct_flags =
    +                            ifelse(email_flag == "correct" & mobile_flag == "correct", 2, 
    +                            ifelse(email_flag != "correct" & mobile_flag == "correct", 1, 
    +                            ifelse(email_flag == "correct" & mobile_flag != "correct", 1,
    +                            ifelse(email_flag != "correct" & mobile_flag != "correct", 0,
    +                                                        
    +                            ifelse(home_number_flag == "correct" & mobile_flag == "correct", 2, 
    +                            ifelse(home_number_flag != "correct" & mobile_flag == "correct", 1, 
    +                            ifelse(home_number_flag == "correct" & mobile_flag != "correct", 1,
    +                            ifelse(home_number_flag != "correct" & mobile_flag != "correct", 0, 
    +                                                                                    
    +                            ifelse(email_flag == "correct" & mobile_flag == "correct", 2, 
    +                            ifelse(email_flag != "correct" & mobile_flag == "correct", 1, 
    +                            ifelse(email_flag == "correct" & mobile_flag != "correct", 1,
    +                            ifelse(email_flag != "correct" & mobile_flag != "correct", 0, 
    +                                   
    +                            ifelse(email_flag == "correct" & mobile_flag == "correct" & home_number_flag == "correct", 3, 
    +                            ifelse(email_flag != "correct" & mobile_flag != "correct" & home_number_flag != "correct", 0, "check")))))))))))))))

Result:

head(data)
      email_flag home_number_flag mobile_flag number_of_correct_flags
    1  incorrect        incorrect     correct                       1
    2  incorrect        incorrect   incorrect                       0
    3  incorrect        incorrect   incorrect                       0
    4  incorrect        incorrect   incorrect                       0
    5  incorrect        incorrect   incorrect                       0
    6  incorrect        incorrect   incorrect                       0

Obviouslly, this becomes problematic as the number of indicators grows.

Any thoughts on a more efficient approach?