dimanche 27 novembre 2016

Redux select output

I m workin on admin panel with redux framework and I m trying to switch by three diffentes headers by a select input from the backend.

My options array

Redux::setSection($opt_name, array(
'title' => __('Header', 'redux-framework-demo'),
'id' => 'scegli_header',
'subsection' => true,
'fields' => array(
    array(
        'id' => 'header',
        'type' => 'select',
        'title' => __("Scegli il tuo header", 'redux-framework-demo'),
        'subtitle' => __("3 template diversi di header", 'redux-framework-demo'),
        'desc' => __('Basic media uploader with disabled URL input field.', 'redux-framework-demo'),
        //Must provide key => value pairs for multi checkbox options
        'options' => array(
            '1' => 'Hero header',
            '2' => 'Boxed header',
            '3' => 'Fluid header'
        ),
        'default'  => '2',

    ),
)));

Here my output

<?php


    if ($ascaro ['header'] = 1) {

        get_template_part('includes/header/hero-header');
    }
    elseif ($ascaro ['header'] = 2) {

        get_template_part('includes/header/boxed-header');
    } 

    else {

        get_template_part('includes/header/fluid-header');
    }
    ?>

what's wrong?

Issue in C# if statement

Hi i have the following part of code

string[] choices = new string[UserChoices.Count];  
int count1 = 0;
        for (int i = 0; i < UserChoices.Count; i++)
        {
            choices[i] = UserChoices[i];
            //MessageBox.Show(choices[i]);
            if (choices[i] == "1")
            {
                count1++;
            }        
        } 

I declare the array choices in which array i store the contains of a list with name UserChoices

So far so good but i have a problem with the if statement, for some reason when choices[i] is equal to "1" as a string the variable count1 does not increases.

I have checked every value of choices array through Message.Box and in some loops choices[i] is "1". I tried different ways to check equality such as .Equals, switch.

Any idea why my if statement does not goes true ?

map conditions to different actions (functional style)

I am looking for nice clean solution to map some conditions to different actions. Typical way is to use multiply if statements:

f1 = lambda x: print('f1(%s)' % x)
f2 = lambda x: print('f2(%s)' % x)
f3 = lambda x: print('f3(%s)' % x)


def non_functional_routing():
    for x in range(100):
        if 10>x>0:
            f1(x)
        if 20 > x >= 10:
            f2(x)
        if x >= 20:
            f3(x)

non_functional_routing()

But I think I can make it more expressive in functional style:

def func_routing():
    c1 = lambda x: 10>x>=0
    c2 = lambda x: 20 > x >= 10
    c3 = lambda x: x >= 20

    routes = ((c1,f1),(c2,f2),(c3,f3))

    for x in range(100):
        (r[1] for r in routes if r[0](x)).__iter__().__next__()(x)

func_routing()

How do you prefer to implement such a thing? any nice solutions (functional style is preferable)?

Loop JSON Data on PHP menu

I want to display our dispensary menu in categorical order. The code provided on the site was this:

<?php
            $menuItems = $client->menuItems();
            $menuItems = json_decode($menuItems, true);

            foreach($menuItems['menu_items'] as $item)
            {
               print($item['name']);
            }
            ?>

but it displays all our menu. I only want to display the menu that belongs to 'cannabis' category. Below is the json data:

{
  "menu_items": [
    {
      "on_hold":false,
      "price": {
        "ounce": 250.0,
        "quarter": 0.0,
        "eighth": 50.0,
        "gram": 20.0,
        "half": 0.0
      },
      "category": "Cannabis",
      "measurement": "grams",
      "sativa":0,
      "thc_percent":0,
      "cbn":0,
      "updated_at":"2010-12-22T23:29:02-07:00",
      "amount":3.0,
      "cbd":0,
      "genetics":"",
      "body_html":"",
      "created_at":"2010-08-09T15:58:08-07:00",
      "name":"Kush",
      "indica":0,
      "id":3654,
      "picture": {
        "original":"http://ift.tt/2fnAFke",
        "square":"http://ift.tt/2guLugk",
        "large":"http://ift.tt/2fnC7Tu",
        "small":"http://ift.tt/2guLwov",
        "medium":"http://ift.tt/2fnBx8B"
      }
    },
    {
      "on_hold":false,
      "price": {
        "ounce": 280.0,
        "quarter": 0.0,
        "eighth": 55.0,
        "gram": 25.0,
        "half": 0.0
      },
      "category": "Cannabis",
      "measurement": "grams",
      "sativa":0,
      "thc_percent":0,
      "cbn":0,
      "updated_at":"2010-12-22T23:29:02-07:00",
      "amount":3.0,
      "cbd":0,
      "genetics":"",
      "body_html":"",
      "created_at":"2010-08-09T15:58:08-07:00",
      "name":"Blueberry",
      "indica":0,
      "id":3654,
      "picture": {
        "original":"http://ift.tt/2fnAFke",
        "square":"http://ift.tt/2guLugk",
        "large":"http://ift.tt/2fnC7Tu",
        "small":"http://ift.tt/2guLwov",
        "medium":"http://ift.tt/2fnBx8B"
      }
    }
  ]
}

i'm using this wrapper http://ift.tt/2guDQCG.

CSS class as condition in if statement

This is again a pretty noobish question from me but I'm confused...

Is it possible to use a css class as a condition in an if statement ?

For example:

if (.css-class) {/*fire this code*/}  

Thanks in advance!

While / Do-While is not working in an if statement [duplicate]

This question already has an answer here:

Can someone help me with this please? I have a problem where when the user inputs a "Yes" the code doesn't begin from the start. Code is listed below.

    System.out.println("Press 1 to search a flight. Press 2 to exit");
        int option = Keyboard.readInt();
        if (option==1){
            String anotherFlightResult=null;
            String anotherFlight=null;
            while(anotherFlight=="No"){
            System.out.print("\u000C");
            System.out.println("Enter flight number to search: \t");
            String search = Keyboard.readString();
            System.out.print("\u000C");
            for(p=0; p<20; p++){
                if((search).equals(plane[p][0])){
                    System.out.println("Information about flight: "+plane[p][0]);
                    System.out.println("----------------------------------");
                    System.out.println("Flight Number: "+plane[p][0]);
                    System.out.println("Air Line: "+plane[p][1]);
                    System.out.println("To: "+plane[p][2]);
                    System.out.println("From: "+plane[p][3]);
                    System.out.println("Departure Time: "+plane[p][4]);
                    System.out.println("Estimated Time: "+plane[p][5]);
                    System.out.println("Status: "+plane[p][6]);
                    System.out.println("Distance: "+plane[p][7]+"km");
                }
            }
            System.out.println("");
            System.out.println("Do you want to search another flight?");
            anotherFlight = Keyboard.readString();
            if (anotherFlight=="No"){System.out.println("No");}else if (anotherFlight=="Yes"){System.out.println("Yes");}
             }
        }
        if (option==2){ System.out.print("\u000C");
            System.out.println("Program will now stop");
            System.exit(0);
        }

samedi 26 novembre 2016

How do I loop until one of two variables reaches zero

I want to first get a random number from 0-1, and then according to if that number is <= 0.6, I want it to add 1 to 2 and subtract 1 from 10. If it's > 0.6, I want it to add 1 to 10 and subtract 1 from 2. What is a code for making it keep adding/subtracting until one of the variables reaches 0?