问:
Javascript - How to have a variable that combined a letter and a number call another variable
I am currently making a STEM Math Game. I made a function call onLoad() that gets 20 different random numbers that do not repeat and set them as variables. Now I'm trying to take that number and add Q to the front of it because I have different variables named Q1, Q2, etc. But when I try to console.log the variable X that combined the two all it displays is Q1 instead of the string in the variable Q1. Any help will be appreciated!

//Questions - Answers
var Q1 = "5 x 107 = ?";
//var A1 = "A: 50,000,000";
var A1 = "<button id='answerButton' type='button' class='reg'>A: 50,000,000</button> <button id='answerButton' type='button' class='reg'>B: 0.0000005</button>

<button id='answerButton' type='button' class='reg'>C: 5,000,000</button><button id='answerButton' type='button' class='reg'>D: 500,000</button>";
var Q2 = "3.868 x 109 = ?";
var A2 = "B: 3,868,000,000";
var Q3 = "What is the answer for 20000000 × 3.5 × 1000000 in scientific notation?";
var A3 = "A: 7 × 1013";
var Q4 = "123,000 = ?";
var A4 = "B: 1.23 x 105";
var Q5 = "0.00123 x 105 = ?";
var A5 = "A: 12.3 x 101";
var Q6 = "0.0686 x 100 = ?";
var A6 = "C: 0.0686";
var Q7 = "2.26 x 105 = ?";
var A7 = "B: 226,000";
var Q8 = "0.0002395 = ?";
var A8 = "C: 2.395 x 10-4";
var Q9 = "731,000 = ?";
var A9 = "A: 7.31 x 105";
var Q10 = "0.00018 = ?";
var A10 = "B: 1.8 x 10-4";

var Q11 = "2x = 54";
var A11 = "D: x = 27";
var Q12 = "x = 81";
var A12 = "A: x = 81";
var Q13 = "4x+8=7.2+5x";
var A13 = "C: x = 0.800";
var Q14 = "4(0.5f−0.25)=6+f";
var A14 = "C: f = 7";
var Q15 = "2+6g=11−3g";
var A15 = "B: g = 1";
var Q16 = "−11f=7(1−2f)+5";
var A16 = "A: f = 4";
var Q17 = "0.5s+1=7+4.5s";
var A17 = "B: s = -1.5";
var Q18 = "2(x+3) = 16";
var A18 = "D: x = 5";
var Q19 = "21+3j = 6";
var A19 = "C: j = -5";
var Q20 = "4(x-1) = -16";
var A20 = "A: x = -3";

var Q21 = "A company charges a flat fee of 1500 dollars to rent a yacht. In addition, renters must pay 100 dollars per hour. Which equation shows the cost C to rent a yacht for h hours?";
var A21 = "C: C = 100h + 1500";
var Q22 = "What is the equation of a line that has a slope of 3/5 and a y-intercept of 2?";
var A22 = "A: 5y - 3x = 10";
var Q23 = "Make an equation for sixteen more than a number is 9.";
var A23 = "C: 16 + x = 9";
var Q24 = "There are b boys in the class.  This is three more than four times the number of girls. How many girls are in the class?";
var A24 = "B: b = 3 + 4g";
var Q25 = "The sum of two numbers is 84, and one of them is 12 more than the other. What is the equation?";
var A25 = "D: x + 12 + x = 84";
var Q26 = "Anton's birthday party costs $2 for every guest he invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A26 = "A: y = 2x";
var Q27 = "Allie jars 6 liters of jam every day. Write an equation that shows the relationship between the days x and the jam made y.";
var A27 = "C: y = 6x";
var Q28 = "Gabe can grow 8 flowers with every seed packet. Write an equation that shows the relationship between the number of seed packets x and the total number of flowers y.";
var A28 = "B: y = 8x";
var Q29 = "Bella's retirement party costs $6, plus an additional $1 for each guest she invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A29 = "C: y = x + 6";
var Q30 = "Cole has already taken 4 pictures at home, and he expects to take 1 picture during every day of vacation. Write an equation that shows the relationship between the days of vacation x and the total number of pictures taken y.";
var A30 = "C: y = x + 4";

//Question Numbers
var N1 = Math.floor(Math.random() * 30) + 1;
var N2 = 0;
var N3 = 0;
var N4 = 0;
var N5 = 0;
var N6 = 0;
var N7 = 0;
var N8 = 0;
var N9 = 0;
var N10 = 0;
var N11 = 0;
var N12 = 0;
var N13 = 0;
var N14 = 0;
var N15 = 0;
var N16 = 0;
var N17 = 0;
var N18 = 0;
var N19 = 0;
var N20 = 0;

//On Game Load
function onLoad() {
 do {
  N2 = Math.floor(Math.random() * 30) + 1;
 } while(N2 === N1);

 do {
  N3 = Math.floor(Math.random() * 30) + 1;
 } while(N3 === N1 || N3 === N2);

 do {
  N4 = Math.floor(Math.random() * 30) + 1;
 } while(N4 === N1 || N4 === N2 || N4 === N3);

 do {
  N5 = Math.floor(Math.random() * 30) + 1;
 } while(N5 === N1 || N5 === N2 || N5 === N3 || N5 === N4);

 do {
  N6 = Math.floor(Math.random() * 30) + 1;
 } while(N6 === N1 || N6 === N2 || N6 === N3 || N6 === N4 || N6 === N5);

 do {
  N7 = Math.floor(Math.random() * 30) + 1;
 } while(N7 === N1 || N7 === N2 || N7 === N3 || N7 === N4 || N7 === N5 || N7 === N6);

 do {
  N8 = Math.floor(Math.random() * 30) + 1;
 } while(N8 === N1 || N8 === N2 || N8 === N3 || N8 === N4 || N8 === N5 || N8 === N6 || N8 === N7);

 do {
  N9 = Math.floor(Math.random() * 30) + 1;
 } while(N9 === N1 || N9 === N2 || N9 === N3 || N9 === N4 || N9 === N5 || N9 === N6 || N9 === N7 || N9 === N8);

 do {
  N10 = Math.floor(Math.random() * 30) + 1;
 } while(N10 === N1 || N10 === N2 || N10 === N3 || N10 === N4 || N10 === N5 || N10 === N6 || N10 === N7 || N10 === N8 || N10 === N9);

 do {
  N11 = Math.floor(Math.random() * 30) + 1;
 } while(N11 === N1 || N11 === N2 || N11 === N3 || N11 === N4 || N11 === N5 || N11 === N6 || N11 === N7 || N11 === N8 || N11 === N9 || N11 === N10);

 do {
  N12 = Math.floor(Math.random() * 30) + 1;
 } while(N12 === N1 || N12 === N2 || N12 === N3 || N12 === N4 || N12 === N5 || N12 === N6 || N12 === N7 || N12 === N8 || N12 === N9 || N12 === N10 || N12 === N11);

 do {
  N13 = Math.floor(Math.random() * 30) + 1;
 } while(N13 === N1 || N13 === N2 || N13 === N3 || N13 === N4 || N13 === N5 || N13 === N6 || N13 === N7 || N13 === N8 || N13 === N9 || N13 === N10 || N13 === N11 || N13 === N12);

 do {
  N14 = Math.floor(Math.random() * 30) + 1;
 } while(N14 === N1 || N14 === N2 || N14 === N3 || N14 === N4 || N14 === N5 || N14 === N6 || N14 === N7 || N14 === N8 || N14 === N9 || N14 === N10 || N14 === N11 || N14 === N12 || N14 === N13);

 do {
  N15 = Math.floor(Math.random() * 30) + 1;
 } while(N15 === N1 || N15 === N2 || N15 === N3 || N15 === N4 || N15 === N5 || N15 === N6 || N15 === N7 || N15 === N8 || N15 === N9 || N15 === N10 || N15 === N11 || N15 === N12 || N15 === N13 || N15 === N14);

 do {
  N16 = Math.floor(Math.random() * 30) + 1;
 } while(N16 === N1 || N16 === N2 || N16 === N3 || N16 === N4 || N16 === N5 || N16 === N6 || N16 === N7 || N16 === N8 || N16 === N9 || N16 === N10 || N16 === N11 || N16 === N12 || N16 === N13 || N16 === N14 || N16 === N15);

 do {
  N17 = Math.floor(Math.random() * 30) + 1;
 } while(N17 === N1 || N17 === N2 || N17 === N3 || N17 === N4 || N17 === N5 || N17 === N6 || N17 === N7 || N17 === N8 || N17 === N9 || N17 === N10 || N17 === N11 || N17 === N12 || N17 === N13 || N17 === N14 || N17 === N15 || N17 === N16);

 do {
  N18 = Math.floor(Math.random() * 30) + 1;
 } while(N18 === N1 || N18 === N2 || N18 === N3 || N18 === N4 || N18 === N5 || N18 === N6 || N18 === N7 || N18 === N8 || N18 === N9 || N18 === N10 || N18 === N11 || N18 === N12 || N18 === N13 || N18 === N14 || N18 === N15 || N18 === N16 || N18 === N17);

 do {
  N19 = Math.floor(Math.random() * 30) + 1;
 } while(N19 === N1 || N19 === N2 || N19 === N3 || N19 === N4 || N19 === N5 || N19 === N6 || N19 === N7 || N19 === N8 || N19 === N9 || N19 === N10 || N19 === N11 || N19 === N12 || N19 === N13 || N19 === N14 || N19 === N15 || N19 === N16 || N19 === N17 || N19 === N18);

 do {
  N20 = Math.floor(Math.random() * 30) + 1;
 } while(N20 === N1 || N20 === N2 || N20 === N3 || N20 === N4 || N20 === N5 || N20 === N6 || N20 === N7 || N20 === N8 || N20 === N9 || N20 === N10 || N20 === N11 || N20 === N12 || N20 === N13 || N20 === N14 || N20 === N15 || N20 === N16 || N20 === N17 || N20 === N18 || N20 === N19);

 questions();
}

function questions() {
 var Q = "Q";

 var x1 = Q.concat(N1);
 //var x1 = Q + N1;
 var y1 = document.getElementById("Q1");
 y1.innerHTML = x1;
 var z1 = document.getElementById("1").getElementsByClassName("answers");
 z1.innerHTML = A1;

 console.log(x1);
}```

答:
What you are looking for is called an "array".

```<code>var questions = [
    {
      question: "5 x 10<sup>7</sup> = ?",
      answer: "Find a calculator."
    },
    // ...
];
</code>```

Then:

```<code>questions.sort(function() {return Math.random()-0.5;});
// imperfect shuffle, you'll need more code for a good one but this works decently
</code>```

And:

```<code>console.log(questions[0].question);
console.log(questions[0].answer);
</code>```

Body:
What you are looking for is called an "array".

var questions = [
    {
      question: "5 x 10<sup>7</sup> = ?",
      answer: "Find a calculator."
    },
    // ...
];

Then:

questions.sort(function() {return Math.random()-0.5;});
// imperfect shuffle, you'll need more code for a good one but this works decently

And:

console.log(questions[0].question);
console.log(questions[0].answer);


来源: stackexchange

问:
Format output in python
I have the following function which transforms list of numbers:

```<code>import numpy as np
from math import *

def walsh_transform(x):
    if len(x) > 3:
        n = len(x)
        m = trunc(log(n, 2))
        x = x[0:2 ** m]
        h2 = [[1, 1], [1, -1]]
        for i in range(m - 1):
            if i == 0:
                h = np.kron(h2, h2)
            else:
                h = np.kron(h, h2)

        return np.dot(h, x) / 2. ** m

arr = [1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0]

print(walsh_transform(arr))
</code>```

It returns output [ 0.625 -0.125 -0.125  0.125  0.625 -0.125 -0.125  0.125]

How can I make it return output [0.625, -0.125, -0.125,  0.125,  0.625, -0.125, -0.125,  0.125] ? I.e. comma-separated values?

答: You could use return [z for z in np.dot(h, x) / 2. ** m] instead of return np.dot(h, x) / 2. ** m

ContentLicense: CC BY-SA 3.0

Title: Format output in python

Body:
I have the following function which transforms list of numbers:

import numpy as np
from math import *

def walsh_transform(x):
    if len(x) > 3:
        n = len(x)
        m = trunc(log(n, 2))
        x = x[0:2 ** m]
        h2 = [[1, 1], [1, -1]]
        for i in range(m - 1):
            if i == 0:
                h = np.kron(h2, h2)
            else:
                h = np.kron(h, h2)

        return np.dot(h, x) / 2. ** m

arr = [1.0, 1.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0]

print(walsh_transform(arr))

It returns output [ 0.625 -0.125 -0.125  0.125  0.625 -0.125 -0.125  0.125]

How can I make it return output [0.625, -0.125, -0.125,  0.125,  0.625, -0.125, -0.125,  0.125] ? I.e. comma-separated values?


Title: Format output in python

Body:
Try using repr

print(repr(walsh_transform(arr))) # output = [0.625, -0.125, -0.125, 0.125, 0.625, -0.125, -0.125, 0.125]

Alternatively, you can cast it to a list:

print(list(walsh_transform(arr))) # output = [0.625, -0.125, -0.125, 0.125, 0.625, -0.125, -0.125, 0.125]


问:
Expandable Listview error inflating class TextView
I am using material design tablayout in my main activity where i have scrollable tabs and in my very first fragment i am using expandable listview.

Here is my fragment code

```<code>public class House_Hold_List_Fragment extends Fragment {
    ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<HouseHoldList_Model> listDataHeader;
    HashMap<HouseHoldList_Model, List<String>> listDataChild;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.house_hold_list_fragment, container, false);
        setHasOptionsMenu(true);
        expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
        listDataHeader = new ArrayList<HouseHoldList_Model>();
        listDataChild = new HashMap<HouseHoldList_Model, List<String>>();
        loadModel();
        // preparing list data
        prepareListData();

        listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);

        // setting list adapter
        expListView.setAdapter(listAdapter);
        return view;
    }

    public void prepareListData(){
        List<String> top250 = new ArrayList<String>();
        top250.add("The Shawshank Redemption");
        top250.add("The Godfather");
        top250.add("The Godfather: Part II");
        top250.add("Pulp Fiction");
        top250.add("The Good, the Bad and the Ugly");
        top250.add("The Dark Knight");
        top250.add("12 Angry Men");

        List<String> nowShowing = new ArrayList<String>();
        nowShowing.add("The Conjuring");
        nowShowing.add("Despicable Me 2");
        nowShowing.add("Turbo");
        nowShowing.add("Grown Ups 2");
        nowShowing.add("Red 2");
        nowShowing.add("The Wolverine");

        List<String> comingSoon = new ArrayList<String>();
        comingSoon.add("2 Guns");
        comingSoon.add("The Smurfs 2");
        comingSoon.add("The Spectacular Now");
        comingSoon.add("The Canyons");
        comingSoon.add("Europa Report");

        listDataChild.put((HouseHoldList_Model)listDataHeader.get(0), top250); // Header, Child data
        listDataChild.put(listDataHeader.get(1), nowShowing);
        listDataChild.put(listDataHeader.get(2), comingSoon);

    }

    public void loadModel(){
        listDataHeader.add(new HouseHoldList_Model("A"));
        listDataHeader.add(new HouseHoldList_Model("B"));
        listDataHeader.add(new HouseHoldList_Model("C"));
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        //super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.search:
                //do something
                Log.e("search clicked","sd");
                return true;

            case R.id.action_settings:
                //do something
                Log.e("search clicked","sd");
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
</code>```

and here is my model class code where i am just adding name

```<code>public class HouseHoldList_Model {
    String name;

    public HouseHoldList_Model(){
    }

    public HouseHoldList_Model(String name){
        this.name=name;
    }
}
</code>```

and here is my ExpandableListAdapter class code

```<code>public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<HouseHoldList_Model> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<HouseHoldList_Model
            , List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<HouseHoldList_Model> listDataHeader,
                                 HashMap<HouseHoldList_Model, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.house_holld_list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.house_hold_list_item);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        HouseHoldList_Model model = (HouseHoldList_Model) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.house_hold_list_row, null);
        }
        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.house_hold_name);
        lblListHeader.setText(model.name);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
</code>```

my house_hold_list_row is a custom layout for row where i have different fields like name,address etc but at the time i am just displaying only name.
here my logcat.

```<code>11-13 18:03:05.565 6756-6756/com.zaigham.lhw_diary E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.zaigham.lhw_diary, PID: 6756
                                                                     android.view.InflateException: Binary XML file line #0: Error inflating class TextView
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                         at com.zaigham.lhw_diary.HouseHoldList.ExpandableListAdapter.getGroupView(ExpandableListAdapter.java:86)
</code>```

Here is my house_hold_list_row

```<code><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:layout_centerInParent="true"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="3">
            <TextView
                android:id="@+id/house_hold_number"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="1"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
                android:padding="8dp"
                android:gravity="center"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:textColor="@color/white"
                android:background="@drawable/hh_count_round"
                android:layout_weight=".5"/>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_weight="2.2"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/house_hold_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textSize="18dp"
                    android:textColor="@color/blacktext"
                    android:text="Muhammad Ramza"/>
                <TextView
                    android:id="@+id/house_hold_address"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Main double road g-11"
                    android:textColor="@color/blacktext"/>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Family Members"
                        android:textColor="@color/blacktext" />
                    <TextView
                        android:id="@+id/house_hold_fm_number"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="10"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/hh_fm_count_round"
                        android:textColor="@color/white"/>
                </LinearLayout>
            </LinearLayout>
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:src="@drawable/down"
                android:layout_marginRight="5dp"
                android:layout_gravity="center"
                android:layout_weight=".3"/>

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>
</code>```

答:
```<code>This will work
    @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                                 View convertView, ViewGroup parent) {
            HouseHoldList_Model model = (HouseHoldList_Model) getGroup(groupPosition);
            if (convertView == null) {
                LayoutInflater infalInflater = (LayoutInflater) this._context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = infalInflater.inflate(R.layout.house_hold_list_row, null);
    TextView lblListHeader = (TextView) convertView
                    .findViewById(R.id.house_hold_name);
            }

            lblListHeader.setText(model.name);

            return convertView;
        }
</code>```

Body:
I am using material design tablayout in my main activity where i have scrollable tabs and in my very first fragment i am using expandable listview.

Here is my fragment code

public class House_Hold_List_Fragment extends Fragment {
    ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<HouseHoldList_Model> listDataHeader;
    HashMap<HouseHoldList_Model, List<String>> listDataChild;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.house_hold_list_fragment, container, false);
        setHasOptionsMenu(true);
        expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
        listDataHeader = new ArrayList<HouseHoldList_Model>();
        listDataChild = new HashMap<HouseHoldList_Model, List<String>>();
        loadModel();
        // preparing list data
        prepareListData();

        listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);

        // setting list adapter
        expListView.setAdapter(listAdapter);
        return view;
    }

    public void prepareListData(){
        List<String> top250 = new ArrayList<String>();
        top250.add("The Shawshank Redemption");
        top250.add("The Godfather");
        top250.add("The Godfather: Part II");
        top250.add("Pulp Fiction");
        top250.add("The Good, the Bad and the Ugly");
        top250.add("The Dark Knight");
        top250.add("12 Angry Men");

        List<String> nowShowing = new ArrayList<String>();
        nowShowing.add("The Conjuring");
        nowShowing.add("Despicable Me 2");
        nowShowing.add("Turbo");
        nowShowing.add("Grown Ups 2");
        nowShowing.add("Red 2");
        nowShowing.add("The Wolverine");

        List<String> comingSoon = new ArrayList<String>();
        comingSoon.add("2 Guns");
        comingSoon.add("The Smurfs 2");
        comingSoon.add("The Spectacular Now");
        comingSoon.add("The Canyons");
        comingSoon.add("Europa Report");

        listDataChild.put((HouseHoldList_Model)listDataHeader.get(0), top250); // Header, Child data
        listDataChild.put(listDataHeader.get(1), nowShowing);
        listDataChild.put(listDataHeader.get(2), comingSoon);

    }

    public void loadModel(){
        listDataHeader.add(new HouseHoldList_Model("A"));
        listDataHeader.add(new HouseHoldList_Model("B"));
        listDataHeader.add(new HouseHoldList_Model("C"));
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // TODO Auto-generated method stub
        //super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.menu, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.search:
                //do something
                Log.e("search clicked","sd");
                return true;

            case R.id.action_settings:
                //do something
                Log.e("search clicked","sd");
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

and here is my model class code where i am just adding name

public class HouseHoldList_Model {
    String name;

    public HouseHoldList_Model(){
    }

    public HouseHoldList_Model(String name){
        this.name=name;
    }
}

and here is my ExpandableListAdapter class code

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<HouseHoldList_Model> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<HouseHoldList_Model
            , List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<HouseHoldList_Model> listDataHeader,
                                 HashMap<HouseHoldList_Model, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.house_holld_list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.house_hold_list_item);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        HouseHoldList_Model model = (HouseHoldList_Model) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.house_hold_list_row, null);
        }
        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.house_hold_name);
        lblListHeader.setText(model.name);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}

my house_hold_list_row is a custom layout for row where i have different fields like name,address etc but at the time i am just displaying only name.
here my logcat.

11-13 18:03:05.565 6756-6756/com.zaigham.lhw_diary E/AndroidRuntime: FATAL EXCEPTION: main
                                                                     Process: com.zaigham.lhw_diary, PID: 6756
                                                                     android.view.InflateException: Binary XML file line #0: Error inflating class TextView
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
                                                                         at com.zaigham.lhw_diary.HouseHoldList.ExpandableListAdapter.getGroupView(ExpandableListAdapter.java:86)

Here is my house_hold_list_row

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:layout_centerInParent="true"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="5dp"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="3">
            <TextView
                android:id="@+id/house_hold_number"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="1"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
                android:padding="8dp"
                android:gravity="center"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:textColor="@color/white"
                android:background="@drawable/hh_count_round"
                android:layout_weight=".5"/>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_weight="2.2"
                android:orientation="vertical">
                <TextView
                    android:id="@+id/house_hold_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textSize="18dp"
                    android:textColor="@color/blacktext"
                    android:text="Muhammad Ramza"/>
                <TextView
                    android:id="@+id/house_hold_address"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Main double road g-11"
                    android:textColor="@color/blacktext"/>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Family Members"
                        android:textColor="@color/blacktext" />
                    <TextView
                        android:id="@+id/house_hold_fm_number"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="10"
                        android:layout_marginLeft="10dp"
                        android:background="@drawable/hh_fm_count_round"
                        android:textColor="@color/white"/>
                </LinearLayout>
            </LinearLayout>
            <ImageView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:src="@drawable/down"
                android:layout_marginRight="5dp"
                android:layout_gravity="center"
                android:layout_weight=".3"/>

        </LinearLayout>

    </LinearLayout>

</RelativeLayout>


问:
XSLT append URL from relative to absolute
In my XML document, I am pulling the content of a <TextBlock> that contains images. The XML shows:

```<code><img src="/templates_soft/images/facebook.png" alt="twitter" />
</code>```

When I view the page, the image doesn't show up because it is not at the same path as the original page.

I need to add the rest of the URL for the images to display. Something like http://www.mypage.com/ so that the image displays from http://www.mypage.com/templates_soft/images/facebook.png

Is there a way to do this?

答: If you go with XSLT, you simply create an XML that contains the entire URL as you desire, you then tag the XSLT up so it contains the "pointers" to the original fields in the XML file. If you are binding to a control, like a Grid, you can row bind and add the information at that point, if it is easier for you to do than XSLT.</p>

ContentLicense: CC BY-SA 4.0

Body:
In my XML document, I am pulling the content of a <TextBlock> that contains images. The XML shows:

When I view the page, the image doesn't show up because it is not at the same path as the original page.

I need to add the rest of the URL for the images to display. Something like http://www.mypage.com/ so that the image displays from http://www.mypage.com/templates_soft/images/facebook.png

Is there a way to do this?


问:
NodeJS : Right-To-Left Language Console Log (Arabic)
I have the following tiny nodejs script which just console logs an arabic verb:

```<code>var verb = "كتب";
console.log(verb);
</code>```

However, the console log gives me: output: بتك
- which is the verb, but inverted. (So instead of getting abc I get cba).

I guess that this is because nodejs does not know that I am using a right-to-left language, such as Arabic. However, I was not able to find anything online, on how to fix this? Is there some setting I don't know of?

PS: What's interesting is also, that while the letters are inverted, their their form is basically correct - so the first letter, although displayed at the end, still has the correct form of a first letter in Arabic (in Arabic, letters take on different forms, depending on the position in the word)

答:
Although i am not sure why it is doing that (i cant reproduce it in chrome console).

You could try reverse the string before output like so:

```<code>var verb = "كتب";
console.log(verb.split("").reverse().join(""));
</code>```

Body:
I have the following tiny nodejs script which just console logs an arabic verb:

var verb = "كتب";
console.log(verb);

However, the console log gives me: output: بتك
- which is the verb, but inverted. (So instead of getting abc I get cba).

I guess that this is because nodejs does not know that I am using a right-to-left language, such as Arabic. However, I was not able to find anything online, on how to fix this? Is there some setting I don't know of?

PS: What's interesting is also, that while the letters are inverted, their their form is basically correct - so the first letter, although displayed at the end, still has the correct form of a first letter in Arabic (in Arabic, letters take on different forms, depending on the position in the word)

Body:
Although i am not sure why it is doing that (i cant reproduce it in chrome console).

You could try reverse the string before output like so:

var verb = "كتب";
console.log(verb.split("").reverse().join(""));


问:
Get count of child in firebase when view controller is showing
I have a collection view with a list of matches cell and a button to add new matches.
I'd like to have the same numbers of cell as per matches (IE: 10 matches, 10 cells) . I want the list every time the view appears.

```<code>var countOfMatches = [DataSnapshot]()
viewWillAppear {
      ref.child("matches").observe(.childAdded, with: { (snapshot) in

        self.countOfMatches = [DataSnapshot]()

        for item in snapshot.children {
            self.countOfMatches.append(item as! DataSnapshot)
        }

    })}
</code>```

and in the collection view

```<code>return countOfMatches.count
</code>```

Why my cells are not showing? I can see the results created under /matches in Firebase DB but not the cells

答:
You should use .value instead of .childAdded.

Also you should reload the tableView.reloadData() method.

Body:
I have a collection view with a list of matches cell and a button to add new matches.
I'd like to have the same numbers of cell as per matches (IE: 10 matches, 10 cells) . I want the list every time the view appears.

var countOfMatches = [DataSnapshot]()
viewWillAppear {
      ref.child("matches").observe(.childAdded, with: { (snapshot) in

        self.countOfMatches = [DataSnapshot]()

        for item in snapshot.children {
            self.countOfMatches.append(item as! DataSnapshot)
        }

    })}

and in the collection view

return countOfMatches.count

Why my cells are not showing? I can see the results created under /matches in Firebase DB but not the cells


问:
Static files in ExpressJS cannot be loaded via Nginx
In short, Nginx and Node JS are both running on the same server 10.0.0.120. I can access a Node app via http://10.0.0.120:3000, all stylesheets are loaded properly.

I want the Node app to be accessed via 10.0.0.120/abc/ so I had the following Nginx setup in /etc/nginx/sites-available/default

```<code>location /abc/ {
  proxy_pass http://localhost:3000/;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
</code>```

}

Now that 10.0.0.120/abc/ can reach the Node app but returns without stylesheet loaded because the relative path maps into 10.0.0.120/stylesheets, which obviously does not exist.

On the NodeJS side, I simply used the Express template,in which public folder is used for serving static files.

```<code>app.use(express.static(path.join(__dirname, 'public')));
</code>```

The Node directory tree is shown below

```<code>Node App
|
|── public
|   ├── images
|   ├── javascripts
│   │   ├── bootstrap.js
│   │   ├── bootstrap.min.js
│   │   └── jquery.min.js
│   └── stylesheets
│       ├── animate.css
│       ├── bootstrap.css
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
</code>```

How should I change the Nginx setting to fix the issue?

答:
It's better to serve static files directly by nginx, its more efficient and you can easily manage cache there</p>

```<code>server {

       listen YOUR_APP_PORT;
       server_name YOUR_SERVER_NAME;

       location /abc/ {
          YOUR_STANDARD_ROUTING_CONFIGURATION
       }

       location ~^\/(images|stylesheets|fonts|javascripts) {
           expires 1M;
           access_log off;
           add_header Cache-Control "public";
           add_header Access-Control-Allow-Origin *;
           add_header Access-Control-Allow-Methods GET;
           add_header Access-Control-Allow-Headers X-Requested-With,content-type;
           add_header Access-Control-Allow-Credentials true;
           root YOUR_APPLICATION_PATH/public;
       }

}
</code>```

Body:
In short, Nginx and Node JS are both running on the same server 10.0.0.120. I can access a Node app via http://10.0.0.120:3000, all stylesheets are loaded properly.

I want the Node app to be accessed via 10.0.0.120/abc/ so I had the following Nginx setup in /etc/nginx/sites-available/default

location /abc/ {
  proxy_pass http://localhost:3000/;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

Now that 10.0.0.120/abc/ can reach the Node app but returns without stylesheet loaded because the relative path maps into 10.0.0.120/stylesheets, which obviously does not exist.

On the NodeJS side, I simply used the Express template,in which public folder is used for serving static files.

app.use(express.static(path.join(__dirname, 'public')));

The Node directory tree is shown below

Node App
|
|── public
|   ├── images
|   ├── javascripts
│   │   ├── bootstrap.js
│   │   ├── bootstrap.min.js
│   │   └── jquery.min.js
│   └── stylesheets
│       ├── animate.css
│       ├── bootstrap.css
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js

How should I change the Nginx setting to fix the issue?

Body:
It's better to serve static files directly by nginx, its more efficient and you can easily manage cache there

server {

       listen YOUR_APP_PORT;
       server_name YOUR_SERVER_NAME;

       location /abc/ {
          YOUR_STANDARD_ROUTING_CONFIGURATION
       }

       location ~^\/(images|stylesheets|fonts|javascripts) {
           expires 1M;
           access_log off;
           add_header Cache-Control "public";
           add_header Access-Control-Allow-Origin *;
           add_header Access-Control-Allow-Methods GET;
           add_header Access-Control-Allow-Headers X-Requested-With,content-type;
           add_header Access-Control-Allow-Credentials true;
           root YOUR_APPLICATION_PATH/public;
       }

}


问:
Deserialization error in XML document(1,1)
I have an XML file that I deserialize, the funny part is the XML file is the was serialized
using the following code:

```<code>enter code here
var serializer = new XmlSerializer(typeof(CommonMessage));
var writer = new StreamWriter("OutPut.txt");
serializer.Serialize(writer, commonMessage);
writer.Close();
</code>```

And i m trying to deserialized it again to check if the output match the input.
anyhow here is my code to deserialize:

```<code>var serializer = new XmlSerializer(typeof(CommonMessage));
var reader = new StringReader(InputFileName);
CommonMessage commonMessage = (CommonMessage)serializer.Deserialize(reader);
</code>```

答: Replace StringReader with StreamReader and it will work fine. StringReader reads value from the string (which is file name in your case).</p>

ContentLicense: CC BY-SA 2.5

Body:
I have an XML file that I deserialize, the funny part is the XML file is the was serialized
using the following code:

enter code here
var serializer = new XmlSerializer(typeof(CommonMessage));
var writer = new StreamWriter("OutPut.txt");
serializer.Serialize(writer, commonMessage);
writer.Close();

And i m trying to deserialized it again to check if the output match the input.
anyhow here is my code to deserialize:

var serializer = new XmlSerializer(typeof(CommonMessage));
var reader = new StringReader(InputFileName);
CommonMessage commonMessage = (CommonMessage)serializer.Deserialize(reader);


答:
All you have to do is replace the whitespace with commas. </p>

<p>re.sub function should work too. </p>

Title: Format output in python

Body:
All you have to do is replace the whitespace with commas.

re.sub function should work too.


问:
how to count up variables in java
my problem is the following: I want to set all panes white, just like this:

```<code>    paneVfeld1.setStyle("-fx-background-color: white");
    paneVfeld2.setStyle("-fx-background-color: white");
    paneVfeld3.setStyle("-fx-background-color: white");
    paneVfeld4.setStyle("-fx-background-color: white");
    paneVfeld5.setStyle("-fx-background-color: white");
    paneVfeld6.setStyle("-fx-background-color: white");
    paneVfeld7.setStyle("-fx-background-color: white");
    paneVfeld8.setStyle("-fx-background-color: white");
    paneVfeld9.setStyle("-fx-background-color: white");
    paneVfeld10.setStyle("-fx-background-color: white");
</code>```

But i seriously can´t do this for all my 42 panes, how can i shorten that, with an Array?, anything else?, thx for the help :)

答:
There is no separate CSS class for a Pane, but you might create one.
You still have to add the style to every class.

This allows adding more styles and for instance offering a "dark" theme.

```<code>.paperpane {
    -fx-background-color: white;
}
</code>```

So the hard way:

```<code>Pane[] panes = new Pane[] { paneVfeld1, paneVfeld2, ... };
for (Pane pane : panes) {
   pane.getStyleClass().add("paperpane");
}
</code>```

or make an artifical base class derived from Pane that in the constructor sets it to white (ugly though, as restrictive and abuse of inheritance).

To do a bulk change, if all those panes are children of one container, you could iterate over its children.

However the regular numbered names seem to indicate, you could better create an array or list of panes:

```<code>Pane[] vFelder = new Pane[10];
for (int i = 0; i < vFelder.length; ++i) ...
</code>```

Title: how to count up variables in java

Body:
my problem is the following: I want to set all panes white, just like this:

    paneVfeld1.setStyle("-fx-background-color: white");
    paneVfeld2.setStyle("-fx-background-color: white");
    paneVfeld3.setStyle("-fx-background-color: white");
    paneVfeld4.setStyle("-fx-background-color: white");
    paneVfeld5.setStyle("-fx-background-color: white");
    paneVfeld6.setStyle("-fx-background-color: white");
    paneVfeld7.setStyle("-fx-background-color: white");
    paneVfeld8.setStyle("-fx-background-color: white");
    paneVfeld9.setStyle("-fx-background-color: white");
    paneVfeld10.setStyle("-fx-background-color: white");

But i seriously can´t do this for all my 42 panes, how can i shorten that, with an Array?, anything else?, thx for the help :)

Body:
There is no separate CSS class for a Pane, but you might create one.
You still have to add the style to every class.

This allows adding more styles and for instance offering a "dark" theme.

.paperpane {
    -fx-background-color: white;
}

So the hard way:

Pane[] panes = new Pane[] { paneVfeld1, paneVfeld2, ... };
for (Pane pane : panes) {
   pane.getStyleClass().add("paperpane");
}

or make an artifical base class derived from Pane that in the constructor sets it to white (ugly though, as restrictive and abuse of inheritance).

To do a bulk change, if all those panes are children of one container, you could iterate over its children.

However the regular numbered names seem to indicate, you could better create an array or list of panes:

Pane[] vFelder = new Pane[10];
for (int i = 0; i < vFelder.length; ++i) ...


答:
Just cast the end result to a list, since lists print out in the format you want.</p>

```<code>print(list(walsh_transform(arr)))
</code>```

Title: Format output in python

Body:
Just cast the end result to a list, since lists print out in the format you want.

print(list(walsh_transform(arr)))


问:
Create Objects of inner Component of Object of outer Component
Is it possible to do something like this:

```<code>import QtQuick 2.7
import QtQuick.Window 2.2

Window{
    id: root_
    visible: true
    width: 300
    height: 300

    Component {
        id:compouter

        Column{
            anchors.fill: parent

            Component {
                id: compinner

                Rectangle {
                    width:parent.width
                    height:parent.height/2
                }
            }
        }
    }

    Component.onCompleted: {

        var c = compouter.createObject(this)
        //var d = c.compinner.createObject(c, {"color": "green"})
        //var e = c.compinner.createObject(c, {"color": "red"})
    }
}
</code>```

That is, I want to create multiple Objects inside the outer object (after the outer object was created). However this isn't possible, as I get the error:
TypeError: Cannot call method 'createObject' of undefined

Is there any workaround for this? Is it maybe only possible to instantiate all inner objects during the instantiation of the outer object?

答:
The ids are out of the scope for your function call.

You can either add a function to your outer component, that creates your objects:

```<code>Component {
    id:compouter

    Column{
        anchors.fill: parent

        function createCompinner(arg) { compinner.createObject(this, arg) }

        Component {
            id: compinner

            Rectangle {
                width:parent.width
                height:parent.height/2
            }
        }
    }
}
</code>```

or you expose the inner Component as a property:

```<code>Component {
    id:compouter

    Column{
        property alias compinner: compinnerComponent
        anchors.fill: parent

        Component {
            id: compinnerComponent

            Rectangle {
                width:parent.width
                height:parent.height/2
            }
        }
    }
}
</code>```

and access it like that.

Body:
Is it possible to do something like this:

import QtQuick 2.7
import QtQuick.Window 2.2

Window{
    id: root_
    visible: true
    width: 300
    height: 300

    Component {
        id:compouter

        Column{
            anchors.fill: parent

            Component {
                id: compinner

                Rectangle {
                    width:parent.width
                    height:parent.height/2
                }
            }
        }
    }

    Component.onCompleted: {

        var c = compouter.createObject(this)
        //var d = c.compinner.createObject(c, {"color": "green"})
        //var e = c.compinner.createObject(c, {"color": "red"})
    }
}

That is, I want to create multiple Objects inside the outer object (after the outer object was created). However this isn't possible, as I get the error:
TypeError: Cannot call method 'createObject' of undefined

Is there any workaround for this? Is it maybe only possible to instantiate all inner objects during the instantiation of the outer object?

Body:
The ids are out of the scope for your function call.

You can either add a function to your outer component, that creates your objects:

Component {
    id:compouter

    Column{
        anchors.fill: parent

        function createCompinner(arg) { compinner.createObject(this, arg) }

        Component {
            id: compinner

            Rectangle {
                width:parent.width
                height:parent.height/2
            }
        }
    }
}

or you expose the inner Component as a property:

Component {
    id:compouter

    Column{
        property alias compinner: compinnerComponent
        anchors.fill: parent

        Component {
            id: compinnerComponent

            Rectangle {
                width:parent.width
                height:parent.height/2
            }
        }
    }
}

and access it like that.


问:
Style disabled button with CSS
I'm trying to change the style of a button with an embedded image as seen in the following Fiddle:

http://jsfiddle.net/krishnathota/xzBaZ/1/

In the example there are no images, I'm afraid.

I'm trying to:

Change the background-color of the button when it is disabled

Change the image in the button when it is disabled

Disable the hover effect when disabled

When you click on the image in the button and drag it, the image can be seen separately; I want to avoid that

The text on the button can be selected. I want to avoid that, too.

I tried doing in button[disabled]. But some effects could not be disabled. like
top: 1px; position: relative; and image.

答:
By CSS:

```<code>.disable{
   cursor: not-allowed;
   pointer-events: none;
}
</code>```

Them you can add any decoration to that button.
For change the status you can use jquery

```<code>$("#id").toggleClass('disable');
</code>```

Title: Style disabled button with CSS

Body:
By CSS:

.disable{
   cursor: not-allowed;
   pointer-events: none;
}

Them you can add any decoration to that button.
For change the status you can use jquery

$("#id").toggleClass('disable');


问:
swift - Add blur to UIView in order to "blur" the Controller below? Read before
I know that this question could appears a duplicate, but please read before downvote!

I have this ReachabilityViewController with a UIView named pickerView in it, as you can see in this picture below

My desired result is this:

but I get this instead:

This is my class of the viewController:

```<code>import UIKit

class ReachabilityViewController: UIViewController {

    //MARK: pickerView outlets and actions
    @IBOutlet weak var pickerView: UIView!
    @IBOutlet weak var saveButton: UIButton!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var startEndLabel: UILabel!
    @IBOutlet weak var timePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerView.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

}

// MARK: - Table view data source
extension ReachabilityViewController: UITableViewDelegate, UITableViewDataSource {

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        self.view.addSubview(pickerView)
        pickerView.alpha = 0.0
        UIView.animate(withDuration: 0.3) {
            self.pickerView.alpha = 1.0
        }
    }
}
</code>```

how to get the effect I want?
I already set pickerView backgroundColor as clear.

答:
this is what I've done

```<code>class ViewController: UIViewController,UIPickerViewDataSource, UIPickerViewDelegate {

var pickerDataSource = ["White", "Red", "Green", "Blue"];
@IBOutlet var pickerView: UIPickerView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.regular)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = view.bounds
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    self.pickerView.delegate = self
    self.pickerView.dataSource = self
    self.view.addSubview(blurEffectView)
    self.view.bringSubview(toFront: self.pickerView)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return pickerDataSource.count;
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
    return pickerDataSource[row]
}
</code>```

}

Body:
I know that this question could appears a duplicate, but please read before downvote!

I have this ReachabilityViewController with a UIView named pickerView in it, as you can see in this picture below

My desired result is this:

but I get this instead:

This is my class of the viewController:

import UIKit

class ReachabilityViewController: UIViewController {

    //MARK: pickerView outlets and actions
    @IBOutlet weak var pickerView: UIView!
    @IBOutlet weak var saveButton: UIButton!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var startEndLabel: UILabel!
    @IBOutlet weak var timePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()
        pickerView.frame = CGRect(x: 0.0, y: 0.0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

}

// MARK: - Table view data source
extension ReachabilityViewController: UITableViewDelegate, UITableViewDataSource {

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        self.view.addSubview(pickerView)
        pickerView.alpha = 0.0
        UIView.animate(withDuration: 0.3) {
            self.pickerView.alpha = 1.0
        }
    }
}

how to get the effect I want?
I already set pickerView backgroundColor as clear.

Body:
this is what I've done

class ViewController: UIViewController,UIPickerViewDataSource, UIPickerViewDelegate {

var pickerDataSource = ["White", "Red", "Green", "Blue"];
@IBOutlet var pickerView: UIPickerView!
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.regular)
    let blurEffectView = UIVisualEffectView(effect: blurEffect)
    blurEffectView.frame = view.bounds
    blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    self.pickerView.delegate = self
    self.pickerView.dataSource = self
    self.view.addSubview(blurEffectView)
    self.view.bringSubview(toFront: self.pickerView)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return pickerDataSource.count;
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
    return pickerDataSource[row]
}

}


问:
Opinions on Uptrends vs Dynatrace Keynote for Website Monitoring?
Any suggestions on what would be a better fit for a retail website monitoring would be great. Thanks in advance.  </p>

答:
As per Gartner you need to cover 4 important dimensions in order to cover Digital Experience fully.

Availability - can use both solutions for that

Errors - This is a case where you should look for Real User Monitoring solutions because you won't be able to configure all your real users environments in any of the solutions. Also think about tracking down server side errors which leads you to full APM solutions that also cover the server side

Performance - In an modern environment you need a mix of clean room/baseline (Synthetic) data points and real life (Real User Monitoring) data points.

Business Results - is only achievable via Real User Monitoring

If you only want to cover Availability you can use both but if you need to cover any of the other - Dynatrace is the more complete solution that gives you more head room for the future.


答:
The value of x1 is a literal string e.g. "Q2". The javascript interpreter will never see this as a variable because it is a string. You need to restructure your application, instead of using so many variables, build an object.

```<code>var Q = {
    'Q1': 'string',
    'Q2': 'string',
}
</code>```

etc, etc. Then you can say  Q[x1] and you will get the value of the corresponding property. That is the only way I can think to accomplish what you're looking for.

Title: Javascript - How to have a variable that combined a letter and a number call another variable

Body:
I am currently making a STEM Math Game. I made a function call onLoad() that gets 20 different random numbers that do not repeat and set them as variables. Now I'm trying to take that number and add Q to the front of it because I have different variables named Q1, Q2, etc. But when I try to console.log the variable X that combined the two all it displays is Q1 instead of the string in the variable Q1. Any help will be appreciated!

//Questions - Answers
var Q1 = "5 x 107 = ?";
//var A1 = "A: 50,000,000";
var A1 = "<button id='answerButton' type='button' class='reg'>A: 50,000,000</button> <button id='answerButton' type='button' class='reg'>B: 0.0000005</button>

<button id='answerButton' type='button' class='reg'>C: 5,000,000</button><button id='answerButton' type='button' class='reg'>D: 500,000</button>";
var Q2 = "3.868 x 109 = ?";
var A2 = "B: 3,868,000,000";
var Q3 = "What is the answer for 20000000 × 3.5 × 1000000 in scientific notation?";
var A3 = "A: 7 × 1013";
var Q4 = "123,000 = ?";
var A4 = "B: 1.23 x 105";
var Q5 = "0.00123 x 105 = ?";
var A5 = "A: 12.3 x 101";
var Q6 = "0.0686 x 100 = ?";
var A6 = "C: 0.0686";
var Q7 = "2.26 x 105 = ?";
var A7 = "B: 226,000";
var Q8 = "0.0002395 = ?";
var A8 = "C: 2.395 x 10-4";
var Q9 = "731,000 = ?";
var A9 = "A: 7.31 x 105";
var Q10 = "0.00018 = ?";
var A10 = "B: 1.8 x 10-4";

var Q11 = "2x = 54";
var A11 = "D: x = 27";
var Q12 = "x = 81";
var A12 = "A: x = 81";
var Q13 = "4x+8=7.2+5x";
var A13 = "C: x = 0.800";
var Q14 = "4(0.5f−0.25)=6+f";
var A14 = "C: f = 7";
var Q15 = "2+6g=11−3g";
var A15 = "B: g = 1";
var Q16 = "−11f=7(1−2f)+5";
var A16 = "A: f = 4";
var Q17 = "0.5s+1=7+4.5s";
var A17 = "B: s = -1.5";
var Q18 = "2(x+3) = 16";
var A18 = "D: x = 5";
var Q19 = "21+3j = 6";
var A19 = "C: j = -5";
var Q20 = "4(x-1) = -16";
var A20 = "A: x = -3";

var Q21 = "A company charges a flat fee of 1500 dollars to rent a yacht. In addition, renters must pay 100 dollars per hour. Which equation shows the cost C to rent a yacht for h hours?";
var A21 = "C: C = 100h + 1500";
var Q22 = "What is the equation of a line that has a slope of 3/5 and a y-intercept of 2?";
var A22 = "A: 5y - 3x = 10";
var Q23 = "Make an equation for sixteen more than a number is 9.";
var A23 = "C: 16 + x = 9";
var Q24 = "There are b boys in the class.  This is three more than four times the number of girls. How many girls are in the class?";
var A24 = "B: b = 3 + 4g";
var Q25 = "The sum of two numbers is 84, and one of them is 12 more than the other. What is the equation?";
var A25 = "D: x + 12 + x = 84";
var Q26 = "Anton's birthday party costs $2 for every guest he invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A26 = "A: y = 2x";
var Q27 = "Allie jars 6 liters of jam every day. Write an equation that shows the relationship between the days x and the jam made y.";
var A27 = "C: y = 6x";
var Q28 = "Gabe can grow 8 flowers with every seed packet. Write an equation that shows the relationship between the number of seed packets x and the total number of flowers y.";
var A28 = "B: y = 8x";
var Q29 = "Bella's retirement party costs $6, plus an additional $1 for each guest she invites. Write an equation that shows the relationship between the guests x and the cost y.";
var A29 = "C: y = x + 6";
var Q30 = "Cole has already taken 4 pictures at home, and he expects to take 1 picture during every day of vacation. Write an equation that shows the relationship between the days of vacation x and the total number of pictures taken y.";
var A30 = "C: y = x + 4";

//Question Numbers
var N1 = Math.floor(Math.random() * 30) + 1;
var N2 = 0;
var N3 = 0;
var N4 = 0;
var N5 = 0;
var N6 = 0;
var N7 = 0;
var N8 = 0;
var N9 = 0;
var N10 = 0;
var N11 = 0;
var N12 = 0;
var N13 = 0;
var N14 = 0;
var N15 = 0;
var N16 = 0;
var N17 = 0;
var N18 = 0;
var N19 = 0;
var N20 = 0;

//On Game Load
function onLoad() {
 do {
  N2 = Math.floor(Math.random() * 30) + 1;
 } while(N2 === N1);

 do {
  N3 = Math.floor(Math.random() * 30) + 1;
 } while(N3 === N1 || N3 === N2);

 do {
  N4 = Math.floor(Math.random() * 30) + 1;
 } while(N4 === N1 || N4 === N2 || N4 === N3);

 do {
  N5 = Math.floor(Math.random() * 30) + 1;
 } while(N5 === N1 || N5 === N2 || N5 === N3 || N5 === N4);

 do {
  N6 = Math.floor(Math.random() * 30) + 1;
 } while(N6 === N1 || N6 === N2 || N6 === N3 || N6 === N4 || N6 === N5);

 do {
  N7 = Math.floor(Math.random() * 30) + 1;
 } while(N7 === N1 || N7 === N2 || N7 === N3 || N7 === N4 || N7 === N5 || N7 === N6);

 do {
  N8 = Math.floor(Math.random() * 30) + 1;
 } while(N8 === N1 || N8 === N2 || N8 === N3 || N8 === N4 || N8 === N5 || N8 === N6 || N8 === N7);

 do {
  N9 = Math.floor(Math.random() * 30) + 1;
 } while(N9 === N1 || N9 === N2 || N9 === N3 || N9 === N4 || N9 === N5 || N9 === N6 || N9 === N7 || N9 === N8);

 do {
  N10 = Math.floor(Math.random() * 30) + 1;
 } while(N10 === N1 || N10 === N2 || N10 === N3 || N10 === N4 || N10 === N5 || N10 === N6 || N10 === N7 || N10 === N8 || N10 === N9);

 do {
  N11 = Math.floor(Math.random() * 30) + 1;
 } while(N11 === N1 || N11 === N2 || N11 === N3 || N11 === N4 || N11 === N5 || N11 === N6 || N11 === N7 || N11 === N8 || N11 === N9 || N11 === N10);

 do {
  N12 = Math.floor(Math.random() * 30) + 1;
 } while(N12 === N1 || N12 === N2 || N12 === N3 || N12 === N4 || N12 === N5 || N12 === N6 || N12 === N7 || N12 === N8 || N12 === N9 || N12 === N10 || N12 === N11);

 do {
  N13 = Math.floor(Math.random() * 30) + 1;
 } while(N13 === N1 || N13 === N2 || N13 === N3 || N13 === N4 || N13 === N5 || N13 === N6 || N13 === N7 || N13 === N8 || N13 === N9 || N13 === N10 || N13 === N11 || N13 === N12);

 do {
  N14 = Math.floor(Math.random() * 30) + 1;
 } while(N14 === N1 || N14 === N2 || N14 === N3 || N14 === N4 || N14 === N5 || N14 === N6 || N14 === N7 || N14 === N8 || N14 === N9 || N14 === N10 || N14 === N11 || N14 === N12 || N14 === N13);

 do {
  N15 = Math.floor(Math.random() * 30) + 1;
 } while(N15 === N1 || N15 === N2 || N15 === N3 || N15 === N4 || N15 === N5 || N15 === N6 || N15 === N7 || N15 === N8 || N15 === N9 || N15 === N10 || N15 === N11 || N15 === N12 || N15 === N13 || N15 === N14);

 do {
  N16 = Math.floor(Math.random() * 30) + 1;
 } while(N16 === N1 || N16 === N2 || N16 === N3 || N16 === N4 || N16 === N5 || N16 === N6 || N16 === N7 || N16 === N8 || N16 === N9 || N16 === N10 || N16 === N11 || N16 === N12 || N16 === N13 || N16 === N14 || N16 === N15);

 do {
  N17 = Math.floor(Math.random() * 30) + 1;
 } while(N17 === N1 || N17 === N2 || N17 === N3 || N17 === N4 || N17 === N5 || N17 === N6 || N17 === N7 || N17 === N8 || N17 === N9 || N17 === N10 || N17 === N11 || N17 === N12 || N17 === N13 || N17 === N14 || N17 === N15 || N17 === N16);

 do {
  N18 = Math.floor(Math.random() * 30) + 1;
 } while(N18 === N1 || N18 === N2 || N18 === N3 || N18 === N4 || N18 === N5 || N18 === N6 || N18 === N7 || N18 === N8 || N18 === N9 || N18 === N10 || N18 === N11 || N18 === N12 || N18 === N13 || N18 === N14 || N18 === N15 || N18 === N16 || N18 === N17);

 do {
  N19 = Math.floor(Math.random() * 30) + 1;
 } while(N19 === N1 || N19 === N2 || N19 === N3 || N19 === N4 || N19 === N5 || N19 === N6 || N19 === N7 || N19 === N8 || N19 === N9 || N19 === N10 || N19 === N11 || N19 === N12 || N19 === N13 || N19 === N14 || N19 === N15 || N19 === N16 || N19 === N17 || N19 === N18);

 do {
  N20 = Math.floor(Math.random() * 30) + 1;
 } while(N20 === N1 || N20 === N2 || N20 === N3 || N20 === N4 || N20 === N5 || N20 === N6 || N20 === N7 || N20 === N8 || N20 === N9 || N20 === N10 || N20 === N11 || N20 === N12 || N20 === N13 || N20 === N14 || N20 === N15 || N20 === N16 || N20 === N17 || N20 === N18 || N20 === N19);

 questions();
}

function questions() {
 var Q = "Q";

 var x1 = Q.concat(N1);
 //var x1 = Q + N1;
 var y1 = document.getElementById("Q1");
 y1.innerHTML = x1;
 var z1 = document.getElementById("1").getElementsByClassName("answers");
 z1.innerHTML = A1;

 console.log(x1);
}

Body:
The value of x1 is a literal string e.g. "Q2". The javascript interpreter will never see this as a variable because it is a string. You need to restructure your application, instead of using so many variables, build an object.

var Q = {
    'Q1': 'string',
    'Q2': 'string',
}

etc, etc. Then you can say  Q[x1] and you will get the value of the corresponding property. That is the only way I can think to accomplish what you're looking for.


问:
Build on openshift with a Jenkins pipeline referring to a git branch
I have the following structure:

a git(gitlab) repository where I have 2 branch (dev and master) (more are there but I'm interested only in this two for the build)

configurated gitLab that makes a webhook when push/merge action are maded on this project. The webhook points on a pipeline

a openshift container that has a pod with jenkins installed

2 pipeline defined in the openshift jenkins project, one to build the dev branch and one to build the master branch. The pieline are written in groovy, and made some git, maven and oc commands

Versions:

gitlab 10.1

openshift 3.4

Jenkins 2.19.3

What I'm able to do:
make a push on dev/master that start the 2 pipelines and builds the two branches. There starts two build because I don't know how to filter out that a push/merge event is made on dev or master.
I want to do this because:

on the build there are some integration tests that use a DB and If the pipeline starts simultaneously then they make some disaster on the test-db

and there is no reason that the two pipelines starts, when the branch that they represent are not involved. Only the pipeline with the correct branch has to start

I saw two option to resolve this.
On Gitlab there are no possibility to drive the webhook event on a defined branch. (or is there and I don't know how?)
On the pipeline I could write some code to check on witch branch there is made a push/merge. But I don't know how exactly make this check.

Are there other options?
If possible I don't want to change the workflow, but I'm open to hear any good Idea.

If I'm missing some relevant information please ask me. I don't publish any code because the context are very big, and principally I only need the right direction or some ideas how to solve this.

答:
So At the end I found a way by myself.

I think it's not elegant but at the moment it solves my problem.

All I do is to check with git in the pipeline the hash of the last Merge and the last hash of the branch in this way:

```<code>def lastMerge = sh(returnStdout: true, script: 'git show :/^Merge --pretty=format:"%H"').trim()
def hash = sh(returnStdout: true, script: 'git log -1 origin/master --pretty=format:"%H"').trim()
if(lastMerge==hash){
    doTheJob()
}
</code>```

If there are better solutions, I'm open to hear it.

Body:
So At the end I found a way by myself.

I think it's not elegant but at the moment it solves my problem.

All I do is to check with git in the pipeline the hash of the last Merge and the last hash of the branch in this way:

def lastMerge = sh(returnStdout: true, script: 'git show :/^Merge --pretty=format:"%H"').trim()
def hash = sh(returnStdout: true, script: 'git log -1 origin/master --pretty=format:"%H"').trim()
if(lastMerge==hash){
    doTheJob()
}

If there are better solutions, I'm open to hear it.


问:
Memory leaks caused due to CoreFoundation Framework
I am developing an iPhone application which mainly makes use of the Address Book and database. After fetching about 3000 contacts from the address book, I am attaching string tags to the contacts (5 for each). I am saving my tags in the database.

For Load testing purpose i have added 10,000 tags to the App. But during the load testing of my application, I observed some memory leaks which were not related to the Application code but represents a set of Instruction sets. Also Instruments showed Foundation as the  responsible library for the Leak (Extensive use of NSString,NSDictionary,NSArray which belongs to the Foundation framework). My application crashes after 10 - 15 mins of usage.The Crash report mentions, application crashed due to low memory.

Memory profiling using CLANG shows zero leaks. How do i solve these memory leaks?
Are these leaks the real culprit behind the crash? Are there any other tools available to check memory leaks?

答:
Try to do some issues in u code:
1. Please avoid hide declaration like

```<code>NSString *string = [dictionary valueForKey:[dictionary2 valueForKey:@"something"]]
</code>```

Correct code is:

```<code>NSString *key = [dictionary2 valueForKey:@"something"];
NSString *string = [dictionary valueForKey:key];
key = nil;
</code>```

Try to avoid declaration with autorelease and local declaration like:

NSArray *array = [NSArray array];

If u do this, make sure that u have:

```<code>NSArray *array = [NSArray array];
.... some code where array is using;
array = nil;
</code>```

Better idea is alloc and release immediately when u don't need object and put it to nil.
3. Check if u using correct setters. Probably better idea is avoid to using it, at my experience, deallocate class start leaks for getters and setters, which was using before.

If u post some part of u code, where u seen most leaks (instruments give u possibility to click on leaked objects and see volume of leaks in programming code) community can suggest more.

Body:
Try to do some issues in u code:
1. Please avoid hide declaration like

NSString *string = [dictionary valueForKey:[dictionary2 valueForKey:@"something"]]

Correct code is:

NSString *key = [dictionary2 valueForKey:@"something"];
NSString *string = [dictionary valueForKey:key];
key = nil;

Try to avoid declaration with autorelease and local declaration like:

NSArray *array = [NSArray array];

If u do this, make sure that u have:

NSArray *array = [NSArray array];
.... some code where array is using;
array = nil;

Better idea is alloc and release immediately when u don't need object and put it to nil.
3. Check if u using correct setters. Probably better idea is avoid to using it, at my experience, deallocate class start leaks for getters and setters, which was using before.

If u post some part of u code, where u seen most leaks (instruments give u possibility to click on leaked objects and see volume of leaks in programming code) community can suggest more.


问:
Is the CAP theorem a red herring?
I am told that I have to give up transactional guarantees in large distributed systems because the CAP theorem says I can't have it.

I think this is wrong for the following reasons:

Internet routing is amazingly reliable.

The CAP theorem only applies to network partitions where two groups of live machines can't communicate.

Almost all real network partitions consist of catastrophic failures or cases where one of the partitions is very small and the other is very large and the small one can just shut down.

Machine failures by themselves do not constitute a network partition.

Therefore, I can assume that for practical purposes I can have transactional behavior provided I attempt to guarantee that small partitions detect that they are disconnected and shut down or operate in some sort of degraded mode until the connection is repaired.

Corrections? Comments? Flames?

References:

For an overview of CAP Theorem see this article by Julian Browne here

CAP Theorem on wikipedia

答:
I recommend you read this paper: Brewer's Conjeture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services.pdf

After read it I understood two things.

First, the Brewer's conjecture is about any web service, not just about them that are distributed. Then, in this context, it makes sense that you can choose two of the three properties. For example, let's ignore partition-tolerant. From my point of view, in this case you have 2 options:

Use a single machine: Then there is not network, then I have not worry about partition-tolerant, but the availability of the entire system depends on the fact that the single machine must be online.

Use multiple machines, but whitout replication: Just use each machine for processing/storing data that do not have a strong functional relationship. If some machine crashes, the rest of data is available and consistent.

Maybe, you can think that there is a third option: Use multiple machines and replication and do not care about partition-tolerant. Let's suppose this! In this case, if some machine or connection among machines crash there is no manner of guaranteeing consistency or availability because the system will not have processes to recover its right data state. Here, notice that adding replication meanings to increase partition-tolerant.

Then, the second thing that understood is:

In distributed systems, where we use several machines for spreading the computation and the storage of data, the partition-tolerant is an intrisic property to them. We use a group of machines as if them were one to increase processing and storage resources and availability for clients, not CAP avalability. Therefore, a way to increase availability for clients is to support partition-tolerant: an intrisic property of distributed systems.

As a summary, the CAP theorem applied to distributed systems most say the following: Under partition-tolerant, it is impossible to guarantee consistency and availability at the same time.

Title: Is the CAP theorem a red herring?


问:
Slow code in "inner joins" lists in python
I have seen several posts about lists in python here, but I don't find a correct answer to my question; because it is about optimize a code.

I have a python code to compare two lists. It has to find the same code, and modifying the value of the second positions. It finally works perfectly, but it takes a lot of time. In SQL this query take 2 minuts, no more...., however, here, I spend 15 minutes.... so I don't understand if it is problem of memory or bad code written.

I have two lists.
The first one [code, points]. The second [code, license]
If the first value(code) in the first list, match with the first value of the second list(code); it has to update the second value  of the first list (points) if the license is equal to 'THIS', for example:

```<code>itemswithscore = [5675, 0], [6676, 0], [9898, 0], [4545, 0]
itemswithlicense = [9999, 'ATR'], [9191, 'OPOP'], [9898, 'THIS'], [2222, 'PLPL']

for sublist1 in itemswithscore:
    for sublist2 in itemswithlicense:
        if sublist1[0] == sublist2[0]: #this is the "inner join" :)
            if sublist2[1] == 'THIS': #It has to be license 'THIS'
                sublist1[1] += 50 #I add 50 to the score value
</code>```

Finally, I have this list updated in the code 9868:

```<code>itemswithscore = [5675, 0], [6676, 0], [9898, 50], [4545, 0]
</code>```

It is true that the two lists have 80.000 values everyone.. :(

Thanks in advance!!!

答:
I'm pretty sure the slowness is mostly due to the looping itself, which is not very fast in Python. You can speed up the code somewhat by caching variables, like so:

```<code>for sublist1 in itemswithscore:
    a = sublist1[0]  # Save to variable to avoid repeated list-lookup
    for sublist2 in itemswithlicense:
        if a == sublist2[0]:
            if sublist2[1] == 'THIS':
                sublist1[1] += 50
</code>```

Also, if you happen to know that 'THIS' does not occur in itemswithlicense more than once, you should insert a break after you update sublist1[1].

Let me know how much of a different this make.

Body:
I have seen several posts about lists in python here, but I don't find a correct answer to my question; because it is about optimize a code.

I have a python code to compare two lists. It has to find the same code, and modifying the value of the second positions. It finally works perfectly, but it takes a lot of time. In SQL this query take 2 minuts, no more...., however, here, I spend 15 minutes.... so I don't understand if it is problem of memory or bad code written.

I have two lists.
The first one [code, points]. The second [code, license]
If the first value(code) in the first list, match with the first value of the second list(code); it has to update the second value  of the first list (points) if the license is equal to 'THIS', for example:

itemswithscore = [5675, 0], [6676, 0], [9898, 0], [4545, 0]
itemswithlicense = [9999, 'ATR'], [9191, 'OPOP'], [9898, 'THIS'], [2222, 'PLPL']

for sublist1 in itemswithscore:
    for sublist2 in itemswithlicense:
        if sublist1[0] == sublist2[0]: #this is the "inner join" :)
            if sublist2[1] == 'THIS': #It has to be license 'THIS'
                sublist1[1] += 50 #I add 50 to the score value

Finally, I have this list updated in the code 9868:

itemswithscore = [5675, 0], [6676, 0], [9898, 50], [4545, 0]

It is true that the two lists have 80.000 values everyone.. :(

Thanks in advance!!!

Body:
I'm pretty sure the slowness is mostly due to the looping itself, which is not very fast in Python. You can speed up the code somewhat by caching variables, like so:

for sublist1 in itemswithscore:
    a = sublist1[0]  # Save to variable to avoid repeated list-lookup
    for sublist2 in itemswithlicense:
        if a == sublist2[0]:
            if sublist2[1] == 'THIS':
                sublist1[1] += 50

Also, if you happen to know that 'THIS' does not occur in itemswithlicense more than once, you should insert a break after you update sublist1[1].

Let me know how much of a different this make.


问:
Sorting Server Side with AJAX, headers not working properly
I've got a problem:

Not all headers work to sort the table, and some of them partially work, I.E.: Marca and Modelo work perfectly but idTipoDeVehiculo just works once and idAuto and FechaDeLanzamiento never work.

Okay, this is my index.php:

index.php

And this is the order-column.php:

order-column.php

Here is the AJAX, but I don't think the problem lies in there:

```<code>function orderColumn(column_name, column_order) {
  $.ajax({
    url: "order-column.php",
    data: 'orderby=' + column_name + '&order=' + column_order,
    type: "POST",
    success: function(data) {
      $('#demo-order-list').html(data);
    }
  });
}
</code>```

I'm not allowed to use any plugins and forced to use AJAX.

Anyways, I tried everything and I'm completely lost, I hope someone can help me.

答:
The problem is, that you did not declared your variables. See this:

```<code>if($orderBy == "idAuto" and $order == "desc") {
    $idAutoNextOrder = "asc";
}
</code>```

If the $orderBy not idAuto or $order is not desc, your $idAutoNextOrder won't created but later you reference to it.

```<code>$idAutoNextOrder = "desc"; //<----Init here
if($orderBy == "idAuto" and $order == "desc") {
    //change if need
    $idAutoNextOrder = "asc";
}
</code>```

Body:
I've got a problem:

Not all headers work to sort the table, and some of them partially work, I.E.: Marca and Modelo work perfectly but idTipoDeVehiculo just works once and idAuto and FechaDeLanzamiento never work.

Okay, this is my index.php:

index.php

And this is the order-column.php:

order-column.php

Here is the AJAX, but I don't think the problem lies in there:

function orderColumn(column_name, column_order) {
  $.ajax({
    url: "order-column.php",
    data: 'orderby=' + column_name + '&order=' + column_order,
    type: "POST",
    success: function(data) {
      $('#demo-order-list').html(data);
    }
  });
}

I'm not allowed to use any plugins and forced to use AJAX.

Anyways, I tried everything and I'm completely lost, I hope someone can help me.

Body:
The problem is, that you did not declared your variables. See this:

if($orderBy == "idAuto" and $order == "desc") {
    $idAutoNextOrder = "asc";
}

If the $orderBy not idAuto or $order is not desc, your $idAutoNextOrder won't created but later you reference to it.

$idAutoNextOrder = "desc"; //<----Init here
if($orderBy == "idAuto" and $order == "desc") {
    //change if need
    $idAutoNextOrder = "asc";
}


问:
Add css to button
how could add css style to this button.
Button html:

```<code><html>
    <body>
        <button onclick="myFunction()">Player</button>
        <script>
            function myFunction() {
                alert('what ever');
            }
        </script>
    </body>
</html>
</code>```

CSS i want to add

```<code><style>
.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
</style>
</code>```

If there is answered question, please send link. Thank you

答:
Instead of declaring class button i.e(.button) you can apply style to all button elements.

Demo- https://jsfiddle.net/akshay193sw/bxm8wdqk/ Refer link

Title: Add css to button

Body:
how could add css style to this button.
Button html:

        <button onclick="myFunction()">Player</button>

CSS i want to add

If there is answered question, please send link. Thank you


问:
Is it possible to have a QWidget without a display?
I have a console-only win32 application (which can be launched as a windows service) where I want to create QWidget objects and interact with them.

These QWidget will not be rendered locally (because there is no display) but I need to access painting operations (to create screenshot of them for example) and I need to intercept mouse and keyboard operations.

The aim of the service is to provide a display of the widget to a remote application. So the image, mouse and keyboard are meant to be redirected over the network.

Is it possible to have QWidget objects in a console application? What is the preferred method to intercept painting, mouse and keyboard operations in that case?

If this is possible, is it still possible with QAxWidget objects?

答:
You can create a QApplication without a Gui using one of the provided constructors:

```<code>QApplication::QApplication(int&, char**, bool GuiEnabled)
</code>```

In order to do GUI operations you'll still need a GUI available. For example, on Linux it will still require that X be running and available. I believe there are certain restrictions on what can and can't happen but can't find the blog post on http://labs.qt.nokia.com that provides details.

Body:
You can create a QApplication without a Gui using one of the provided constructors:

QApplication::QApplication(int&, char**, bool GuiEnabled)

In order to do GUI operations you'll still need a GUI available. For example, on Linux it will still require that X be running and available. I believe there are certain restrictions on what can and can't happen but can't find the blog post on http://labs.qt.nokia.com that provides details.