samedi 1 avril 2017

Clearing Cells If Specific Text is found

I have created a task list. in this task list you can insert you progress. each row is a task and there is 25 rows. in the third column is the progress cell which if this cell has "complete" in it I would like to either automatically of by pushing a button clear content in a range of A:F of each row. So to further explain if I have 5 rows that have complete in them and you then push a clear button it will only clear the content in those five rows and only the cells in columns A:F. I have been able to clear content in one row with a button but not been able to insert the If statement of having "complete" in the cell. Could anyone help. I have this so far but it is currently giving me an error.

function clearRange() {
//replace 'Sheet1' with your actual sheet name
var sheet = SpreadsheetApp.getActive().getSheetByName('TaskList');
if(cellcontent === "Complete"){
sheet.getRange('A26:F26').clearContent();
}
}

[Java]Program not outputting in correct format -- drawing an arrow with asterisks based on user input

So I'm trying to understand why this code isn't outputting in the correct asterisk arrow format that is asked of me. Here's the prompt for this program:

This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width.

(1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight.

(2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base.

(3) Modify the given program to use a loop to output an arrow head of width arrowHeadWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow head.

(4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width.

Example output for arrowBaseHeight = 5, arrowBaseWidth = 2, and arrowHeadWidth = 4:

Enter arrow base height: 5
Enter arrow base width: 2
Enter arrow head width: 4

**
**
**
**
**
****
***
**
*

If you have any suggestion as to how I could be going about this in a better way, then that would be greatly appreciated. I included the for for if else for for statements as a precaution to try to stop user input for the arrow head width if it's less than or equal to the arrow base width, and this is basically where my problem lies. If you notice that I've done the rest or any else of the program wrong, then please tell me, as I'd like to learn how to go about this the correct way.

import java.util.Scanner;

public class DrawHalfArrow {
   public static void main(String[] args) {
      Scanner scnr = new Scanner(System.in);
      int arrowBaseHeight = 0;
      int arrowBaseWidth  = 0;
      int arrowHeadWidth = 0;
      int j;
      int i;

  System.out.println("Enter arrow base height: ");
  arrowBaseHeight = scnr.nextInt();

  System.out.println("Enter arrow base width: ");
  arrowBaseWidth = scnr.nextInt();

  System.out.println("Enter arrow head width: ");
  arrowHeadWidth = scnr.nextInt();


  for (i = 0; i < arrowHeadWidth; i++) {
  for (j = arrowHeadWidth; j>i; j--) {
  }

      if (arrowHeadWidth <= arrowBaseWidth) {

         System.out.println("Please enter an arrow head width that is greater than the arrow base width.");
         arrowHeadWidth = scnr.nextInt();
      }else {
          for ( i = 0; i < arrowBaseHeight; i++) {
          for ( j = 0; j < arrowBaseWidth; j++) {
          System.out.print("*");
          }
          System.out.println();
          }
         System.out.print("*");
      }
  }
  System.out.println();

  return;
  }
}

How to stop "if(isset($_POST['form-submit']))" from redirecting after clicking Submit?

I have a serious problem about Password Recovery Program these days. While I was programing an if(isset($_POST['pass-submit'])) on reset.php?recoverykey=6602f445b4736ef3363a31e05750022d. When someone clicks Submit button of the form, it should stay at the same page for processing, i.e. on reset.php?recoverykey=6602f445b4736ef3363a31e05750022d. But instead it takes us to reset.php where no code would work because the variable recoverykey is empty. I want it to stay where it was even after clicking the Submit button so that PHP can check whether the Password and Confirm Password fields where same or incorrect according to the program.

Here's all my code in reset.php:

<?php
    ob_start();
    session_start();
?>
<!DOCTYPE html>
            <head>
                <meta name="robots" content="noindex" />
                <link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" />
                <title>Reset Password</title>
            </head>
<?php
    include('db-config.php');
    function show_change_pass_form(){
        ?>
                <form class="iqform" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
                    <h3>Change your Password</h3>
                    <label><span class="text-danger"><?php echo $passError ?></span><input type="password" placeholder="New Password" name="new-pass" required /></label>
                    <label><span class="text-danger"><?php echo $Con_passError; ?></span><input type="password" placeholder="Confirm Password" name="confirm-new-pass" required /></label>
                    <input type="submit" value="Change Password" name="pass-submit" />
                </form>
        <?php
    }
    $recovery_code = $_GET['recoverykey'];
    if(empty($recovery_code)){
        echo 'Looks like you landed elsewhere.';
    }
    $sql = "SELECT * FROM RegisteredMembers WHERE RecoveryCode='$recovery_code'";
    $result = mysql_query($sql);
    if($result){
        $count = mysql_num_rows($result);
        if($count==1){

            if( isset($_POST['pass-submit']) ){

                $pass = $_POST['new-pass'];
                $Con_pass = $_POST['confirm-new-pass'];

                    // Confirmation
                        if($pass==$Con_pass){
                            $sql1 = "UPDATE RegisteredMembers SET password = '$pass' WHERE RecoveryCode = '$recovery_code'";
                            $output = mysql_query($sql1);
                            echo $output;
                            $error = false;
                            $passError = "Password successfully changed. Feel free to Log In.";
                        } else if(!($pass==$Con_pass)){
                            $error = true;
                            $Con_passError = "The Password isn't matching. Be sure you remember the New Password.";
                        } else if(empty($pass)){
                            $error = true;
                            $passError = "Please do not keep the password empty.";
                        } else if(empty($Con_pass)){
                            $error = true;
                            $Con_passError = "Please do not keep this field empty.";
                        }
            }
            show_change_pass_form();

        } else if($count==0) {
            echo "No such recovery code, please don't try Spamming around!";
        }
    }
?>
<?php ob_end_flush(); ?>

Here's my code in forget.php (I added it though its not much necessary):

<?php

    ob_start();
    session_start();
    include('db-config.php');

    if(isset($_POST['forgot-submit'])){
        $recovery_user = $_POST['forgot-email'];
        $query = "SELECT * FROM RegisteredMembers WHERE userEmail='$recovery_user'";
        $output = mysql_query($query);
        $count = mysql_num_rows($output);
        $row = mysql_fetch_array($output);
        if($count==1){
            $error = false;

            // Mail the Recovery link
            $recovery_code = md5(uniqid(rand()));
            $mTo = $recovery_user;
            $mFrom = 'From: '.$website_details['name'].' Team '.'<'.$website_details['email'].'>';
            $mSubject = $website_details['name']." Account recovery Mail";
                // Message
                $mMsg[0] = "Hi ".$row['fname'].", \r\n";
                $mMsg[1] = "This is the password recovery email which you have requested just few minutes before. <b>(If you havn't requested, you may kindly ingnore this Email)</b>";
                $mMsg[2] = "Here's your <a href='$web_path/reset.php?recoverykey=$recovery_code'>Password Recovery Link</a>. Clicking it would allow you to change your existing password into a new one.";
                $mFinMsg = $mMsg[0].$mMsg[1].$mMsg[2];
            $sendRecMail = mail( $mTo , $mSubject , $mFinMsg , $mFrom );

            // Add recovery code to Database
            $mysql = "UPDATE RegisteredMembers SET RecoveryCode='$recovery_code' WHERE userEmail='$recovery_user'";
            $result = mysql_query($mysql);
            if($result){
                $error = false;
                $forgotEmailMsg = "Thanks, Check your Email for recovering your password.";
            } else{
                echo "Looks like there's a Disturbance and Load on server. Try again later.";
            }
        } else if(strlen($recovery_user)==0){
            $error = true;
            $forgotEmailMsg = "Please do not leave this field empty.";
        } else{
            $error = true;
            $forgotEmailMsg = "No such Email found in Database.";
        }
    }

?>
<!DOCTYPE html>
<html>
    <head>
        <meta name="robots" content="noindex" />
        <link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" />
        <title>Password Recovery</title>
    </head>
    <body>
        <form class="iqform" method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" autocomplete="off">
            <h3>Password Recovery</h3>
            <label><span class="text-danger"><?php echo $forgotEmailMsg; ?></span><input type="email" placeholder="Your registered Email" name="forgot-email" required /></label>
            <input type="submit" value="Next" name="forgot-submit" />
        </form>
    </body>
</html>
<?php ob_end_flush(); ?>

Forget.php is all okay but may be you can refer something from it.

Thanks in advance to the Stack Community. Hats off to everyone.

assigning a case number as an if else elif statement

If the user inputs no when the program asks if the problem matches the one displayed by the system, the data should be allocated a case number and stored to be sent to a technician. I tried using the elif However the case number appears when i run the program not when the user replies no to the question.

def question():
  description = input('Please describe the problem with your device: ')
  words = {''.join(filter(str.isalpha, word))
             for word in description.lower().split()}
  for problem, keywords, steps in PROBLEMS:
    if words & keywords:
      print('This may be what you are experiencing:')
      print(problem)
      if get_response:
        print('Does this match your problem? ')
      ans=input()
      if ans== "yes":
        print('Please follow the solution given')
        print('After this, your problem should be solved.')
        print('If it does not, please take it to a professional.')
        break
      elif ans=="no":
        case_number()

import random       
def case_number():
  import random
case_number = random.randint(1, 10000)
print('Your case number is:')
print(case_number)

error when using wc -c with file names

I am running this code, that sorts files in the desired folders. If a file name has 13 chars it should run the first statement, else the second.

for i in *.png; do if [ "$($i | wc -c)" -eq 13 ]; then
    echo cp $i $HOME/Desktop/final/pos_${i:0:1}/${i:0:3}.jpg
else
    echo cp $i $HOME/Desktop/final/pos_${i:0:1}/${i:0:4}.jpg
fi;
done

the problem is, that [ "$($i | wc -c)" -eq 13 ] is always 0, but clearly, file names have some length. What is the correct way of evaluating wc -c in an if statement?

How to create a new variable after comparing values from multiple columns in R?

I have this data frame, q17, below. My goal is replacing "contacts" following these rules:

if any values in q17a, q17d, q17f, q17g <5 then contacts is 1

if any values in q17a, q17d, q17f, q17g ==5 then contacts is 0

if any values in q17a, q17d, q17f, q17g ==8 or 9 then contacts is 99

if any values in q17a, q17d, q17f, q17g ==NA then contacts is 99

q17[1:50,]

   q17a q17d q17f q17g contacts
1     2    5    2   NA       NA
2     5    5    5   NA       NA
3     1    5    5   NA       NA
4     4   NA    5   NA       NA
5     1    5    5    5       NA
6     3    5   NA   NA       NA
7     4    5    5   NA       NA
8     5    5    1   NA       NA
9     4    5   NA   NA       NA
10    4    5    4   NA       NA
11    1    5    5    5       NA
12    3    5    5   NA       NA
13    4    4    3    4       NA
14    5   NA    5   NA       NA
15    5    5    5    5       NA
16    5   NA    4   NA       NA
17    1    5   NA   NA       NA
18    4    5    3   NA       NA
19    4    5    4   NA       NA
20    3    5    5   NA       NA
21    5    5    4   NA       NA
22    4    5    2   NA       NA
23    4   NA    3   NA       NA
24    5   NA   NA   NA       NA
25    2    5    5   NA       NA
26    2    5    4    5       NA
27    3   NA    3   NA       NA
28    1   NA    1   NA       NA
29    5    5    5   NA       NA
30    2    5    5   NA       NA
31    5    5   NA   NA       NA
32    2    5    4   NA       NA
33    4    4    3    3       NA
34    5   NA    5   NA       NA
35    5    5    5    4       NA
36    5    5    4    4       NA
37    2    5    5    5       NA
38    4    5   NA   NA       NA
39    1    5    1   NA       NA
40    4    5    5    5       NA
41    3    5   NA   NA       NA
42    4    5    4   NA       NA
43    5   NA   NA   NA       NA
44    5    5   NA   NA       NA
45    2    5    3    3       NA
46    5    5    5   NA       NA
47    2    5    3    5       NA
48    3    5    5   NA       NA
49    5    5    5    5       NA
50    5    5   NA   NA       NA

I tried follwing for example, which is not efficient at all. Can somebody suggest a better way doing this?

d1$q17d <- ifelse(d1$q17d==1|d$q17d==2|d$q17d==3|d$q17d==4,1,d1$q17d)
d1$q17d <- ifelse(d1$q17d==5,0,d1$q17d)
d1$q17d <- ifelse(d1$q17d==8, d1$q17d)
d1$q17d <- ifelse(is.na(d1$q17d),99, d1$q17d)

d1$contacts <- ifelse(d1$q17d==1,1,d1$contacts)
d1$contacts

How to write if/else with boolean in Bash?

How can I write an if then statement to switch between these to variables as such:

if(switch){
  server_var_shortname=$server_shared_shortname
  server_var=$server_shared
  server_var_bare=$server_shared_bare
} else {
  server_var_shortname=$server_vps_shortname
  server_var=$server_vps
  server_var_bare=$server_vps_bare
}

I'm not familiar with bash syntax and basically just need an if/else statement on a Boolean. Also can I use true / false values as such? Also how do I do the else statement?

$switch=true;
if $switch
then
  server_var_shortname=$server_shared_shortname
  server_var=$server_shared
  server_var_bare=$server_shared_bare
fi