mercredi 1 février 2017

Shell command is not working

I use volnoti, a notification service, together with my i3 window manager, in my i3config file I tried to implement the commands for volnoti like this:

# Pulse Audio controls
# Increase sound volume
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 1 +5% && pkill -RTMIN+1 i3blocks && volnoti-show $(amixer -c 1 -M -D pulse get Master | grep -o '[0-9]*%' -m 1 | grep -o '[0-9]*')
# Decrease sound volume
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 1 -5% && pkill -RTMIN+1 i3blocks && volnoti-show $(amixer -c 1 -M -D pulse get Master | grep -o '[0-9]*%' -m 1 | grep -o '[0-9]*')
# Mute sound
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 1 toggle && pkill -RTMIN+1 i3blocks && if [[ -n $(amixer -c 1 -M -D pulse get Master | grep '\[off\]' -m 1) ]]; then volnoti-show -m; else volnoti-show $(amixer -c 1 -M -D pulse get Master | grep -o '[0-9]*%' -m 1 | grep -o '[0-9]*'); fi

Increasing and decreasing is shown without problems, but if I mute the sound i3 logs this error:

ERROR: Could not translate string to key symbol: "split+h"
[libi3] ERROR: Surface 0x555ee0dfd3b0 is not initialized, skipping drawing.
[libi3] ERROR: Surface 0x555ee0dfd3b0 is not initialized, skipping drawing.
[libi3] ERROR: Surface 0x555ee0dfd3b0 is not initialized, skipping drawing.
ERROR: Received ConfigureNotify for unknown window 0x00800000
ERROR: Received ExposeEvent for unknown window 0x00800000
ERROR: Received ConfigureNotify for unknown window 0x00800000
ERROR: Received ConfigureNotify for unknown window 0x00800003
ERROR: Received ConfigureNotify for unknown window 0x00800003
ERROR: Received ConfigureNotify for unknown window 0x00800006
ERROR: Received ConfigureNotify for unknown window 0x00800006
ERROR: Received ConfigureNotify for unknown window 0x00800009
ERROR: Received ConfigureNotify for unknown window 0x00800009
ERROR: Received ConfigureNotify for unknown window 0x0080000c
ERROR: Received ConfigureNotify for unknown window 0x0080000c
ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'debuglog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'sticky', 'split', 'floating', 'mark', 'unmark', 'resize', 'rename', 'nop', 'scratchpad', 'title_format', 'mode', 'bar'
ERROR: Your command: exec --no-startup-id pactl set-sink-mute 1 toggle && pkill -RTMIN+1 i3blocks && "if [[ -n $(amixer -c 1 -M -D pulse get Master | grep '\[off\]' -m 1) ]]; then volnoti-show -m; else volnoti-show $(amixer -c 1 -M -D pulse get Master | grep -o '[0-9]*%' -m 1 | grep -o '[0-9]*'); fi"
ERROR:                                                                                                                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I have to admit, it is not the most elegant solution. But it's working, except for the last line. If I execute the last part directly in a terminal, it's working fine and mute is detected properly:

if  [[ -n $(amixer -c 1 -M -D pulse get Master | grep '\[off\]' -m 1) ]]; then volnoti-show -m; else volnoti-show $(amixer -c 1 -M -D pulse get Master | grep -o '[0-9]*%' -m 1 | grep -o '[0-9]*'); fi

if function in unity not working c#

In my unity c# game for android I would like to see if the closest gameobject to the character is the one im looking for(left) and if the player of the game has not swiped left on the screen(swipeLeft) then I would like to change a value in my code called strike, but It is not working properly in game and Im not sure why.When Im in the game view the leftSwipe value does not work every time (It does when the if function is removed) and strike does not change at all.I would like to know how to fix this or is there is an alternative to this problem

Here is the if statement

if ((closestPlatform = left) && (leftSwipe = false)) { strike = 1; }

Here is the entire c# script



using UnityEngine;
using System.Collections;

public class SwipeChecker : MonoBehaviour
{

    public float maxTime;
    public float minSwipeDistance;

    float startTime;
    float endTime;

    Vector3 startPos;
    Vector3 endPos;

    float swipeDistance;
    float swipeTime;
    public float swipeScore;

    public GameObject left;
    public GameObject right;
    public GameObject up;
    public GameObject down;
    public GameObject swipeChecker;
    public GameObject[] platforms = new GameObject[5];

    public bool leftSwipe;
    public bool didntSwipe;

    public float strike;



    public GameObject closestPlatform;





    // Use this for initialization

    public GameObject FindClosestPlatform()
    {
        GameObject[] gos;
        GameObject[] gos2;
        GameObject[] gos3;
        GameObject[] gos4;
        gos = GameObject.FindGameObjectsWithTag("platform");

        GameObject closest = null;
        float distance = Mathf.Infinity;
        Vector3 position = transform.position;
        foreach (GameObject go in gos)

        {
            Vector3 diff = go.transform.position - position;
            float curDistance = diff.sqrMagnitude;
            if (curDistance < distance)
            {
                closest = go;
                distance = curDistance;
            }
        }
        return closest;
    }

public IEnumerator wait()
    {
        leftSwipe = true;
        yield return new WaitForSeconds(0.5f);
        leftSwipe = false;
    }



    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {



        closestPlatform = FindClosestPlatform();


        if ((closestPlatform = left) && (leftSwipe = false))
        {
            strike = 1;
        }


        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began)
            {
                startTime = Time.time;
                startPos = touch.position;
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                endTime = Time.time;
                endPos = touch.position;

                swipeDistance = (endPos - startPos).magnitude;
                swipeTime = endTime - startTime;

                if (swipeTime < maxTime && swipeDistance > minSwipeDistance)
                {
                    swipe();
                }
            }

        }

    }


    void swipe()
    {












            Vector2 distance = endPos - startPos;
            if (Mathf.Abs(distance.x) > Mathf.Abs(distance.y))
            {
                Debug.Log("Horizontal Swipe");
                if (distance.x > 0)
                {
                    Debug.Log("Right Swipe");
                }
                if (distance.x < 0)
                {
                    Debug.Log("Left Swipe");

                    StartCoroutine(wait());


                }

            }

            else if (Mathf.Abs(distance.x) < Mathf.Abs(distance.y))
            {
                Debug.Log("Vertical Swipe");
                if (distance.y > 0)
                {
                    Debug.Log("Up Swipe");
                }
                if (distance.y < 0)
                {
                    Debug.Log("Down Swipe");
                }
            }


        }




    }

Better way for nested if else

How can the nested if else can be done in a better way? I want to minimize code duplication for print "run dozer()"

print "some mechanical stuffs before this"
if a == 1:
    if b == 2:
        print "run car()"
    else:
        print "run dozer()"
else:
    print "run dozer()"
print "more mechanical stuffs after this"

Are all statements inside a switch without a case will be skipped?

I have this example which is about the use of switch and if:

int main(int argc, char** argv) {

    int i = 0, j = 1;

    switch(i){
        if (!i) // will not be evaluated!
            std::cout << "if(!i) : i = 0" << std::endl;

        if (1 == i) // no magic it will not be evaluated.
            std::cout << "i = 1" << std::endl;

        if (1 == j) // will not be evaluated!
            std::cout << "if(j == 1) : j = 1" << std::endl;

        for (int k(0); k < 3; k++) //  will not be evaluated!
            std::cout << "Ok!" << std::endl;

        while (1) //  will not be evaluated!
            std::cout << "Hi" << std::endl;

        case 0: // ok as we guess no magic
            std::cout << "(case 0) : i = 0" << std::endl;
        break;

        default: // now everything belongs to a `case` as we think it will be evaluated.
        if (1 == i)
            std::cout << "(default: if(i == 1)) : i = 1" << std::endl;
        if (1 == j) // ok
            std::cout << "(default: if(j == 1)) : j = 1" << std::endl;
    }


    std::cout << std::endl;
    std::cin.get();
    return 0;
}

  • So the program above uses ifs instead of cases the thing that matters why if inside a switch will not be evaluated?? Also why they are evaluated only in a case? Like in default:?

  • Does this mean that all statements will be skipped without a case? - If so why new C++ doesn't prevent that as long as they are redundant?

Testing a session variable for null or empty space

What I currently have is this:

if ((string)Session["PlanID"] == null)
{
   string PlanID = Request.QueryString["PlanID"];
   Session["PlanID"] = PlanID;
}

What I need is something like this:

if ((string)Session["PlanID"] == null) or if ((string)Session["PlanID"] == "")
{
   string PlanID = Request.QueryString["PlanID"];
   Session["PlanID"] = PlanID;
}

How would I do that?

Variable values are becoming null in the IF statement

I am trying to do a simple comparison using IF construct in bash scripting. Here is my code:

if [ ${ca} -eq ${cb} ] 
then
    echo "Compaction successful"
else
    echo "Compaction Unsuccessful"
fi  

The problem is when I put 'set -x' in the script, I notice that the above code shows up like this:

+ [[ '' == '' ]]
+ echo 'Compaction successful'
Compaction successful

Why are my variables not being substituted in the IF statement although there is data(number) in them?

Nested IF statement returning false, only on some cells. yet formula is the same

My formula is the same for all the cells yet some follow my IF formula while others return FALSE.

It returns the false on a few, not all, of the "Yes" responses

Formula: =IF(ISBLANK(B9),(IF(ISBLANK(C9),(IF(ISBLANK(D9),"No","Yes")))))

I have tried both copy/paste formula and manually typing the formula in the incorrect cells. Both return "FALSE"

Thanks in advance.