samedi 2 janvier 2016

How to write condition if the column is not null in mysql

enter image description here

I need to eliminate the rows, if the enrollDate and cancelDate is same. So i wrote the query as follows SELECT a.id, a.clientId, a.enrollDate, a.cancelDate FROM gap_borrower a WHERE STR_TO_DATE( a.loanEndDate, '%Y-%m-%d' ) >= STR_TO_DATE( '2015-12-31', '%Y-%m-%d' ) AND FIND_IN_SET( a.status, 'A,C' ) AND STR_TO_DATE( a.enrollDate, '%Y-%m-%d' ) <> STR_TO_DATE( a.cancelDate, '%Y-%m-%d' )

But if cancelDate is Null, it didn't display as different.(Only need to eliminate the id=8551 in the above figure. This is my problem) So i wrote another query using if condition

SELECT a.id, a.clientId, a.enrollDate, a.cancelDate FROM gap_borrower a WHERE STR_TO_DATE( a.`loanEndDate` ,  '%Y-%m-%d' ) >= STR_TO_DATE(  '2015-12-31',  '%Y-%m-%d' ) AND FIND_IN_SET( a.status,  'A,C' ) AND (CASE WHEN a.cancelDate IS NOT NULL THEN (STR_TO_DATE( a.`enrollDate` ,  '%Y-%m-%d' ) <> STR_TO_DATE(  a.cancelDAte,  '%Y-%m-%d' )) END  ) 

Its also fails.Please guide me to fix this

vendredi 1 janvier 2016

Detecting result of a logical OR in JS conditional

Is there a good way to detect which half of a logical or within a conditional is true?

// foo would return true or false    
if (thing1 === "3" || thing2 === foo()) {

     // do something if thing1 is 3
     // do something different if thing2 is true


};

Or should I just use two nested if blocks?

Loop with if statements is not working properly in C

So im basically trying to do a loop with some if statements in it, and the problem with the loop is that the user is going to enter a choice, either H or S. However, when the user enter S, the program goes straight to the H statement and goes through that and after it, it goes to the other statement. Let me show you with the code:

int decision(struct CardDeck *deck) {
char choice;
printf("Value is %d\n", deck->ValueOfSecondPlayer);
while (deck->ValueOfSecondPlayer <= 21) 
{
    if (deck->ValueOfSecondPlayer == 21) {
        printf("Blackjack!");
    }
    if (deck->ValueOfSecondPlayer > 21) {
        printf("Sorry, you lose");
    }
    if (deck->ValueOfSecondPlayer < 21) {
        printf("Would you like to hit or stand?\n");
        scanf("%c", &choice);
    }
    if (choice == 'H' || choice == 'h'); {
        printf("You wish to hit, heres your card\n");
        deck->ValueOfSecondPlayer += printCards(deck);
        printf("Your total is now %d\n", deck->ValueOfSecondPlayer);
    }
    if (choice == 'S' || choice == 's') {
        printf("You wished to stay\n");
        break;
    }
}

}

So the output im getting when i enter S is:

Value is 18
Would you like to hit or stand?
S
You wish to hit, heres your card
Jack of Clubs
Your total is now 28
You wished to stay
Pess any key to continue . . .

And when i enter H the program runs like this:

Value is 16
Would you like to hit or stand?
h
You wish to hit, heres your card
4 of Clubs
Your total is now 20
Would you like to hit or stand?
You wish to hit, heres your card
2 of Spades
Your total is now 22
Press any key to continue . . .

So my problem here is that the program goes into the choice H and h even though i use S or s. I dont know if im dumb or something, but if anyone can tell me what im doing wrong and how to fix the problem i would be greatful!

Thanks!

Not working if statements in Python

I have a problem with my if statements. It involves looking for a pair of strings and collecting the times and then subtracting them, but I don't get why it doesn't work, and with a small loop inside to count the difference and if it's less it prints it out:


fh = open('Perfe.txt')
R=0
Z=0
for line in fh:
    line=line.rstrip()
    if not 'Service Permission' in line :
        continue
    Y=line.split()
    Time1=float(Y[1])

    elif not 'Assignment Finished' in line :
        continue
    U=line2.split()
    Time2=float(U[1])
    R=R+1
        if (Time2-Time1) <= 3:
            print 'time of Request setup end',Time2-Time1
        else:
            continue 
print R


and the Data is


Time               
A1 139.637737000 Service Permission 

Time          
B1 141.167620000 Assignment Finished

Time               
A1 159.897737000 Service Permission


Targeting group of buttons in quiz, rather than all quiz questions on click

Goal

I have a quiz that has 25 questions, each question has 4 possible answers .quiz__response. When a button is clicked, I'm looking to do the following, but only on the answers related to that specific question, right now it is applying the following to all the questions.

When a button is clicked ...

  • addClass(".is--unclickable") to those four answers
  • .show() .fa-check if the answer is true, .fa-times if the answer is false
  • addClass(".is--true") to change background to green if the answer is correct and addClass(".is--false") to change background to red for the remaining three answers

JSFiddle: http://ift.tt/1mVxeAz

scripts.js

$(function(){

    /*-------------------------------------
    QUIZ
    --------------------------------------*/

    function showScoreBox() {
        var scrollDepth = $(window).scrollTop();
        var divPosition = $(".quiz__header").offset().top - 45;
        var windowWidth = $(window).width();
        // console.log(windowWidth);

        if (scrollDepth > divPosition && (windowWidth > 768)) {
            $(".quiz__score").show();
            $(".quiz__score--mobile").hide();
        } else {
            $(".quiz__score").hide();
            $(".quiz__score--mobile").show();
        }
    } showScoreBox();

    $(window).on("scroll", function(){
        showScoreBox();
    });

    $(window).on("resize", function(){
        showScoreBox();
    });

    var score = 0;

    $(".quiz__response").on("click", function(){
        $(".quiz__response").addClass("is--unclickable");
        $(".quiz__info").show("quiz__info");  // Show extra info
        console.log("Clicked");

        if ($(this).hasClass("answer--true")) {
            $(this).addClass("is--true");
            $(".fa-check").show();

            // Update score
            score++
            $(".quiz__correct").html(score);
            $(".quiz__correct--mobile").html(score);
        } else {
            $(this).addClass("is--false");
            $(".fa-times").show();
        }
    });

    /*-------------------------------------
    RESET
    --------------------------------------*/

    function resetQuiz() {
      $(".quiz__response").removeClass("answer--true answer--false");
      var score = 0
      $(".quiz__correct").html(score);
      $(".quiz__correct--mobile").html(score);
    }

    $(".button__reset").on("click", function(){
     resetQuiz();
    });

    /*-------------------------------------
    CONFETTI
    --------------------------------------*/

    function rainConfetti() {

        if (score === 25) {
            canvas.show()
        }
    }

    /*-------------------------------------
    SMOOTH SCROLL
    --------------------------------------*/

    $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: target.offset().top
                }, 1000);
                return false;
            }
        }
    });
});

index.html (Quiz snippet)

  <link rel="stylesheet" href="http://ift.tt/1PinXyn">

  <div class="quiz">
            <div class="quiz__score">
                <p><span class="quiz__correct">0</span> / 25</p>
            </div>

            <h2 class="quiz__header" id="top">Take the quiz</h2>
            <p class="credit">How well have you been paying attention to what's been happening in southwestern Manitoba in 2015? Take our 25-question quiz to test your local news knowledge.</p>

            <div class="quiz__questions">
            <!-- <canvas id="confetti"></canvas> -->
                <!-- Question -->
                <div class="quiz__question question-1 question__sports">
                    <div class="wrapper">
                        <!-- <img src="http://ift.tt/1vRdcHq" alt="" class="quiz__image"> -->
                    </div>
                    <h3>Question #1</h3>
                    <p class="quiz__description">What Brandon Wheat King, who was drafted by the New York Islanders, lost his desire to play hockey and walked away from the team prior to this season starting?</p>
                    <div class="quiz__responses">
                        <button class="quiz__response answer--false">Kale Clague <i class="fa fa-times"></i></button>
                        <button class="quiz__response answer--false">Macoy Erkamps <i class="fa fa-times"></i></button>
                        <button class="quiz__response answer--true">Ryan Pilon <i class="fa fa-check"></i></button>
                        <button class="quiz__response answer--false">Colin Cloutier <i class="fa fa-times"></i></button>


                        <!-- The six­-foot-­two, 212­pound rearguard had 11 goals and 41 assists in 68 regular­ season games, with a goal and 11 assists in 19 playoff contests last season, paired mainly with Russian Ivan Provorov. In 193 regular­season games with Brandon and the Lethbridge,Hurricanes, Pilon has 23 goals, 93 assists and 116 penalty minutes. -->

                    </div> <!-- .responses -->
                </div> <!-- .question -->

                <!-- Question -->
                <div class="quiz__question question-2 question__sports">
                    <div class="wrapper">
                        <!-- <img src="http://ift.tt/1vRdcHq" alt="" class="quiz__image"> -->
                    </div>
                    <h3>Question #2</h3>
                    <p class="quiz__description">Which former Brandon skip refused to talk to the local media after losing his fifth provincial men’s curling championship game in six years at Westman Place?</p>
                    <div class="quiz__responses">
                        <button class="quiz__response answer--false">Russ Howard <i class="fa fa-times"></i></button>
                        <button class="quiz__response answer--false">Kerry Burtnyk <i class="fa fa-times"></i></button>
                        <button class="quiz__response answer--true">Mike McEwen <i class="fa fa-check"></i></button>
                        <button class="quiz__response answer--false">Braden Calvert <i class="fa fa-times"></i></button>
                    </div> <!-- .responses -->
                </div> <!-- .question -->

                <!-- McEwen’s Winnipeg based team of B.J. Neufeld, Matt Wozniak and Denni Neufeld lost to Ried Carruthers 5­3 at the Safeway Championship hosted by Brandon. -->
        </div> <!-- quiz -->

Exception Handling in If statement?

I'm struggling to create a very simple app. There are Product Names with matching Product Numbers. User enters a Number and the corresponding Name appears.

editTextField1 = the number user types

button1 = the search button

editTextField2 = the product name appears

Now my code is working but there is only one problem, when the user doesn't enter anything and clicks on button1 the app crashes. So I need some sort of exception handler maybe? Im struggling to get my head around it. I know how I'm coding, by declaring loads of variables, is long-winded lol.

public class MainActivity extends AppCompatActivity {

private Button button1;
private EditText editText1;
private EditText editText2;
private int a = 123;
private String b = "TV";
private int c  = 333;
private String d = "Radio";



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button1 = (Button) findViewById(R.id.button1);
    editText1 = (EditText) findViewById(R.id.editText1);
    editText2 = (EditText) findViewById(R.id.editText2);

    View.OnClickListener myOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            double pNumber = Double.parseDouble(editText1.getText().toString());
            if(pNumber == a){
                editText2.setText(b);
            }
           else if (pNumber == c){
                editText2.setText(d);
            }
            else
                editText2.setText("Invalid Product Number");
            }


    };

    button1.setOnClickListener(myOnClickListener);

Unable to enter if statement after raw_input

Whenever I call a function within a while loop in my project it will do absolute nothing according to the function just being called and will just continue to refresh the loop like nothing happened.

Here is a simple example I wrote demonstrating the problem. By running the code you will be shown a menu and you will need to enter a choice from the menu. When doing so a few "if" statements will check which option you chose and call and execute the code below them if the choice doesn't belong to any of the statements the menu will just refresh:

#!/usr/bin/env python

import os
import time

def test():
    x = True
    while True:
        if not x:
            print "You need to type 1\n"
        choice = raw_input("type 1 here: ")
        if choice == 1:
            print 'Works!\n'
            time.sleep(5)
            break
        else:
            x = False

def test2():
    print "Test123\n"

try:
    while True:
        os.system("clear")

        menu_choice = raw_input("Enter Choice: ")

        if menu_choice == 1:
            test()

        if menu_choice == 2:
            test2()

        if menu_choice == 3:
            os.system("python")

except:
    pass