问:
Organise my mutual recursive types
Is it possible to have mutual recursive types ([<Struct>]) spread across different files? The types are directly under a namespace.

My solution is to put them in one big file and use type ... and ...  and ... etc construction. Is it the only way?

答:
You can use a technique called untying the recursive knot where you parameterize one over the other.

So this:

```<code>type a = B of b
and b = A of a
</code>```

becomes:

```<code>type 'b a = B of 'b
type b = A of b a
</code>```

Title: Organise my mutual recursive types

Body:
You can use a technique called untying the recursive knot where you parameterize one over the other.

So this:

type a = B of b
and b = A of a

becomes:

type 'b a = B of 'b
type b = A of b a


来源: stackexchange

问:
Fe and first difference in a regression table
I am doing an analysis in Stata and I have a lot of different panel regressions (within, first-difference and random trend) and to see the results properly, I am using eststo and esttab.

My problem now is that to get the difference for first difference and the double difference for the random trend, I use d.varname and d.d.varname.
Stata then thinks that the differences are new variables and puts them in their own rows which becomes very difficult to read.

Has anyone an idea how I can get a regression table in which Stata sees varname, d.varname and d.d.varname as the same variable?

My regression looks like this:

```<code> foreach v in a aa aaa aaaa{
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year, fe cluster(xy)
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year if c>d, fe cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year, cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year if c>d, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year if c>d, cluster(xy)
 esttab using output.tex, wide
 }
</code>```

In my table I then get my estimates for

```<code> b
 b1
 b2
 b3
 b4
 b5
 d.b1
 d.d.b1
 d.b2
 d.d.b2
 and so on..
</code>```

答:
It actually works just using the esttab command. One example:

```<code>esttab ,compress nogaps booktabs drop( _cons) ///
 indicate("State specific effects = var_dummy_*") ///
rename(    D.b b D2.b b D.b2 b2 D2.b b2 )   ///
</code>```

The rename gets the job done. The rest is included to show more possibilities.

ContentLicense: CC BY-SA 3.0

Body:
I am doing an analysis in Stata and I have a lot of different panel regressions (within, first-difference and random trend) and to see the results properly, I am using eststo and esttab.

My problem now is that to get the difference for first difference and the double difference for the random trend, I use d.varname and d.d.varname.
Stata then thinks that the differences are new variables and puts them in their own rows which becomes very difficult to read.

Has anyone an idea how I can get a regression table in which Stata sees varname, d.varname and d.d.varname as the same variable?

My regression looks like this:

 foreach v in a aa aaa aaaa{
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year, fe cluster(xy)
 qui eststo: xtreg `v' b b1 b2 b3 b4 b5 i.year if c>d, fe cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year, cluster(xy)
 qui eststo: reg d.`v' d.b d.b1 d.b2 d.b3 d.b4 d.b5 i.year if c>d, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year, cluster(xy)
 qui eststo: reg d.d.`v' d.d.b d.d.b1 d.d.b2 d.d.b3 d.d.b4 d.d.b5 i.year if c>d, cluster(xy)
 esttab using output.tex, wide
 }

In my table I then get my estimates for

 b
 b1
 b2
 b3
 b4
 b5
 d.b1
 d.d.b1
 d.b2
 d.d.b2
 and so on..

Body:
It actually works just using the esttab command. One example:

esttab ,compress nogaps booktabs drop( _cons) ///
 indicate("State specific effects = var_dummy_*") ///
rename(    D.b b D2.b b D.b2 b2 D2.b b2 )   ///

The rename gets the job done. The rest is included to show more possibilities.


问:
Node.js: how to limit the HTTP request size and upload file size?
I'm using Node.js and express.

I would like to limit the HTTP request size. Let's say, if someone sends me a HTTP request more than 2 MB then I stop the request right away. I looked at the code and I think if I change the core, I can do it. However, is there a way to set a max_request_size or soemthing like that?

It is kind of related to my second question. I'm using express to get an uploaded file from req.files. Is there a way to stop writing the file to the /tmp folder (which is the default upload behavior) as soon as the file size exceeds a certain file size?

答:
Answer for Question 1:

To limit the HTTP request size and upload file size we need to set the body-parser limit.

```<code>app.use(bodyParser.urlencoded({limit: '50mb',extended: true}));
app.use(bodyParser.json({limit: '50mb'}));
</code>```

bodyParser.urlencoded

The files from the front end comes as urlencoded bodies.

Returns middleware that only parses urlencoded bodies. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).

bodyParser.json

Returns middleware that only parses json. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body).

Note:
By default the input limit for body parser is 100kb

Answer for Question 2:

To change the default upload directory we can use the following.

```<code>app.set('uploadDir', './files');  // Sets the upload Directory to files folder in your project.
</code>```

Other Implementation

While including the bodyParser into the app we can mention the upload directory.

```<code>app.use(express.bodyParser({uploadDir:'./files', keepExtensions: true}));
</code>```

Reference:

https://github.com/expressjs/body-parser#limit

https://github.com/expressjs/body-parser#bodyparserjsonoptions

https://github.com/expressjs/body-parser#bodyparserurlencodedoptions

Issues: https://github.com/expressjs/express/issues/1684

Hope this helps!

Body:
Answer for Question 1:

To limit the HTTP request size and upload file size we need to set the body-parser limit.

app.use(bodyParser.urlencoded({limit: '50mb',extended: true}));
app.use(bodyParser.json({limit: '50mb'}));

bodyParser.urlencoded

The files from the front end comes as urlencoded bodies.

Returns middleware that only parses urlencoded bodies. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).

bodyParser.json

Returns middleware that only parses json. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body).

Note:
By default the input limit for body parser is 100kb

Answer for Question 2:

To change the default upload directory we can use the following.

app.set('uploadDir', './files');  // Sets the upload Directory to files folder in your project.

Other Implementation

While including the bodyParser into the app we can mention the upload directory.

app.use(express.bodyParser({uploadDir:'./files', keepExtensions: true}));

Reference:

https://github.com/expressjs/body-parser#limit

https://github.com/expressjs/body-parser#bodyparserjsonoptions

https://github.com/expressjs/body-parser#bodyparserurlencodedoptions

Issues: https://github.com/expressjs/express/issues/1684

Hope this helps!


问:
Qt QItemDelegate Commit data and close Editor on mouse leave the view widget (listView)
I had a problem with calling off the editor of my listView, when mouse left it. I have managed to solve my problem. It was not obvious to me, so I've decided to post my solution:

In delegate header file Ive created a editor widget pointer, and in constructor, I gave him the value Q_NULLPTR.

```<code>//in header file of Delegate
mutable QWidget *myCustomWidget;

//in the source file of Delegate
MyItemDelegate::MyItemDelegate(QObject *parent) : QStyledItemDelegate(parent),
  myCustomWidget(Q_NULLPTR)
{
}
</code>```

then in createEditor:

```<code>QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
myCustomWidget= new KontaktForm(parent);
myCustomWidget->autoFillBackground();

return myCustomWidget;
}
</code>```

in MyListView header file I've created a signal saveToModelFromEditor(); and emited the signal in

```<code>void MyListView::leaveEvent(QEvent *event)
{
emit saveToModelFromEditor();

QListView::leaveEvent(event);
}
</code>```

The function to commitData to the model and close the editor, if someone wants it to close:

```<code>void MyItemDelegate::commitAndSaveData()
{
if(kontaktForm!=Q_NULLPTR){

// after testing the UI I've decided, that the editor should remain open, and just commit data

emit commitData(kontaktForm);

//    emit closeEditor(kontaktForm);
}
}
</code>```

Finally I've used signal and slot mechanism to connect signal from listView to slot in the editor

```<code>   connect(treeView,SIGNAL(saveToModelFromEditor()),itemDelegate,SLOT(commitAndSaveData()));
</code>```

I had help from a different comunity (VoidRealms facebook group).

Hope this helps someone here.

答:
In delegate header file Ive created a editor widget pointer, and in constructor, I gave him the value Q_NULLPTR.

```<code> //in header file of Delegate
 mutable QWidget *myCustomWidget;

 //in the source file of Delegate
 MyItemDelegate::MyItemDelegate(QObject *parent) : QStyledItemDelegate(parent),
   myCustomWidget(Q_NULLPTR)
 {
 }
</code>```

then in createEditor:

```<code> QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
 {
 myCustomWidget= new KontaktForm(parent);
 myCustomWidget->autoFillBackground();

 return myCustomWidget;
 }
</code>```

in MyListView header file I've created a signal saveToModelFromEditor(); and emited the signal in

```<code> void MyListView::leaveEvent(QEvent *event)
 {
 emit saveToModelFromEditor();

 QListView::leaveEvent(event);
 }
</code>```

The function to commitData to the model and close the editor, if someone wants it to close:

```<code> void MyItemDelegate::commitAndSaveData()
 {
 if(kontaktForm!=Q_NULLPTR){

 // after testing the UI I've decided, that the editor should remain open, and just commit data

 emit commitData(kontaktForm);

 //    emit closeEditor(kontaktForm);
 }
 }
</code>```

Finally I've used signal and slot mechanism to connect signal from listView to slot in the editor

```<code>    connect(treeView,SIGNAL(saveToModelFromEditor()),itemDelegate,SLOT(commitAndSaveData()));
</code>```

I had help from a different comunity (VoidRealms facebook group).

Hope this helps someone here.

Body:
I had a problem with calling off the editor of my listView, when mouse left it. I have managed to solve my problem. It was not obvious to me, so I've decided to post my solution:

In delegate header file Ive created a editor widget pointer, and in constructor, I gave him the value Q_NULLPTR.

//in header file of Delegate
mutable QWidget *myCustomWidget;

//in the source file of Delegate
MyItemDelegate::MyItemDelegate(QObject *parent) : QStyledItemDelegate(parent),
  myCustomWidget(Q_NULLPTR)
{
}

then in createEditor:

QWidget *MyItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
myCustomWidget= new KontaktForm(parent);
myCustomWidget->autoFillBackground();

return myCustomWidget;
}

in MyListView header file I've created a signal saveToModelFromEditor(); and emited the signal in

void MyListView::leaveEvent(QEvent *event)
{
emit saveToModelFromEditor();

QListView::leaveEvent(event);
}

The function to commitData to the model and close the editor, if someone wants it to close:

void MyItemDelegate::commitAndSaveData()
{
if(kontaktForm!=Q_NULLPTR){

// after testing the UI I've decided, that the editor should remain open, and just commit data

emit commitData(kontaktForm);

//    emit closeEditor(kontaktForm);
}
}

Finally I've used signal and slot mechanism to connect signal from listView to slot in the editor

   connect(treeView,SIGNAL(saveToModelFromEditor()),itemDelegate,SLOT(commitAndSaveData()));

I had help from a different comunity (VoidRealms facebook group).

Hope this helps someone here.


问:
Sybase *= to Ansi Standard with 2 different outer tables for same inner table
I am trying to migrate some legacy procedural code. I am having trouble figuring out the ANSI standard syntax to produce the same results.

Below is one of the many combinations I have tried.  What is the inner table for the second join, is it the output from the first join or is it the source table.

Please help I have a lot of code to change.

Original SQL Statement

```<code>select * from
JT1 a, JT2 b, JT3 c
where a.ID *= b.ID
  and c.JOB *= b.JOB
</code>```

My Conversion

```<code>select *
from JT1 a
 left outer join JT2 b
 on a.ID = b.ID
 right outer join JT3 c
 on c.JOB = b.JOB
</code>```

Below is the SQL table definitions and sample data.

```<code>Create table JT1 (
 ID   int(4)   not null,
 NAME char(20) not null)

Create table JT2 (
  ID  int(4)   not null,
  JOB char(20) not null)

Create table JT3 (
  JOB  char(20) not null,
  DUTY char(20) not null)

INSERT INTO dbo.JT1 VALUES(10, "Saunders")
INSERT INTO dbo.JT1 VALUES(20, "Pernal")
INSERT INTO dbo.JT1 VALUES(30, "Marenghi")
INSERT INTO dbo.JT2 VALUES(20, "Sales")
INSERT INTO dbo.JT2 VALUES(30, "Clerk")
INSERT INTO dbo.JT2 VALUES(30, "Mgr")
INSERT INTO dbo.JT2 VALUES(40, "Sales")
INSERT INTO dbo.JT2 VALUES(50, "Mgr")
INSERT INTO dbo.JT3 VALUES("Mgr","Evaluate")
INSERT INTO dbo.JT3 VALUES("Mgr","Reports")
INSERT INTO dbo.JT3 VALUES("Mgr","Meeting")
INSERT INTO dbo.JT3 VALUES("Clerk","Stocking")
INSERT INTO dbo.JT3 VALUES("Clerk","Customer Request")
</code>```

答:
how to create query...

Sample table : Transact

```
Entry    Date       PartyIdno  Catage    Credit/Debit  Amount
------   ---------- ---------- --------- ------------  --------
     1   02-01-2016          1   Receipt       C          8,200
     1   02-01-2016          5   Payment       D          8,200
     2   14-02-2016          1     Sales       D         11,200
     2   14-02-2016          4     Sales       C          6,500
     2   14-02-2016          2     Sales       C          4,700

Output
------

Entry  Date       PartyIdno                     Debit   Credit   Balance
-----  ------     ----------                    ------  -------  -----------
                             SubId  SubAmount
                             -----  ---------
  1   02-01-2016      1                                  8,200    8,200 Cr
      02-01-2016               5     8,200 Dr
  2   14-02-2016      1                         11,200            3,000 Dr
      14-02-2016               4     6,500 Cr
      14-02-2016               2     4,700 Cr
```

SQL Statement :

```
GLOBALSSS.Open_DB_Connection()

Dim cmd As New Sql Command("Select T1.ENTRY,COALESCE(T1.PARTYIDNO,T2.PARTYIDNO) AS Colour FROM TRANSACT T1 FULL OUTER JOIN (SELECT PARTYIDNO  FROM TRANSACT WHERE ENTRY=1) T2  ON 1 = 0 WHERE T1.PARTYIDNO=1 OR T2.PARTYIDNO-1  ", Connection)

Dim da As New SqlDataAdapter(cmd)

Dim dt As New DataTable

da.Fill(dt)

DataGridView1.DataSource = dt

GLOBALSSS.Close_DB_Connection()
```

Body:
I am trying to migrate some legacy procedural code. I am having trouble figuring out the ANSI standard syntax to produce the same results.

Below is one of the many combinations I have tried.  What is the inner table for the second join, is it the output from the first join or is it the source table.

Please help I have a lot of code to change.

Original SQL Statement

select * from
JT1 a, JT2 b, JT3 c
where a.ID *= b.ID
  and c.JOB *= b.JOB

My Conversion

select *
from JT1 a
 left outer join JT2 b
 on a.ID = b.ID
 right outer join JT3 c
 on c.JOB = b.JOB

Below is the SQL table definitions and sample data.

Create table JT1 (
 ID   int(4)   not null,
 NAME char(20) not null)

Create table JT2 (
  ID  int(4)   not null,
  JOB char(20) not null)

Create table JT3 (
  JOB  char(20) not null,
  DUTY char(20) not null)

INSERT INTO dbo.JT1 VALUES(10, "Saunders")
INSERT INTO dbo.JT1 VALUES(20, "Pernal")
INSERT INTO dbo.JT1 VALUES(30, "Marenghi")
INSERT INTO dbo.JT2 VALUES(20, "Sales")
INSERT INTO dbo.JT2 VALUES(30, "Clerk")
INSERT INTO dbo.JT2 VALUES(30, "Mgr")
INSERT INTO dbo.JT2 VALUES(40, "Sales")
INSERT INTO dbo.JT2 VALUES(50, "Mgr")
INSERT INTO dbo.JT3 VALUES("Mgr","Evaluate")
INSERT INTO dbo.JT3 VALUES("Mgr","Reports")
INSERT INTO dbo.JT3 VALUES("Mgr","Meeting")
INSERT INTO dbo.JT3 VALUES("Clerk","Stocking")
INSERT INTO dbo.JT3 VALUES("Clerk","Customer Request")

Body:
how to create query...

Sample table : Transact

Entry    Date       PartyIdno  Catage    Credit/Debit  Amount
------   ---------- ---------- --------- ------------  --------
     1   02-01-2016          1   Receipt       C          8,200
     1   02-01-2016          5   Payment       D          8,200
     2   14-02-2016          1     Sales       D         11,200
     2   14-02-2016          4     Sales       C          6,500
     2   14-02-2016          2     Sales       C          4,700

Output
------

Entry  Date       PartyIdno                     Debit   Credit   Balance
-----  ------     ----------                    ------  -------  -----------
                             SubId  SubAmount
                             -----  ---------
  1   02-01-2016      1                                  8,200    8,200 Cr
      02-01-2016               5     8,200 Dr
  2   14-02-2016      1                         11,200            3,000 Dr
      14-02-2016               4     6,500 Cr
      14-02-2016               2     4,700 Cr

SQL Statement :

GLOBALSSS.Open_DB_Connection()

Dim cmd As New Sql Command("Select T1.ENTRY,COALESCE(T1.PARTYIDNO,T2.PARTYIDNO) AS Colour FROM TRANSACT T1 FULL OUTER JOIN (SELECT PARTYIDNO  FROM TRANSACT WHERE ENTRY=1) T2  ON 1 = 0 WHERE T1.PARTYIDNO=1 OR T2.PARTYIDNO-1  ", Connection)

Dim da As New SqlDataAdapter(cmd)

Dim dt As New DataTable

da.Fill(dt)

DataGridView1.DataSource = dt

GLOBALSSS.Close_DB_Connection()


问:
When to use ContextCompat class
I want to know when to use ContextCompact class in an application. Basically what is it used for and when to use it? I have read developers site, it says ContextCompact is a "helper for accessing features in Context". But what does this line mean?

答:
ContextCompat is a class for replacing some work with base context.

For example if you used before something like

```<code>getContext().getColor(R.color.black);
</code>```

Now its deprecated since android 6.0 (API 22+) so you should use:

```<code>getContext().getColor(R.color.black,theme);
</code>```

or use ContextCompat which fill theme automatically depends on your Context's theme:

```<code>ContextCompat.getColor(getContext(),R.color.black)
</code>```

Same thing with getDrawable

Also ContextCompat contains other methods for functional of API 22+ such as checking permissions or adding multiple activity to stack

ContentLicense: CC BY-SA 4.0

Title: When to use ContextCompat class

Body:
ContextCompat is a class for replacing some work with base context.

For example if you used before something like

getContext().getColor(R.color.black);

Now its deprecated since android 6.0 (API 22+) so you should use:

getContext().getColor(R.color.black,theme);

or use ContextCompat which fill theme automatically depends on your Context's theme:

ContextCompat.getColor(getContext(),R.color.black)

Same thing with getDrawable

Also ContextCompat contains other methods for functional of API 22+ such as checking permissions or adding multiple activity to stack


问:
Using getSimpleName() vs getName() for acquiring logger
I've seen code that uses log4j, which acquires logger for a given Logger using

```<code>static public Logger getLogger(String name)
</code>```

and

```<code>static public Logger getLogger(Class clazz)
</code>```

with the former api passed explicitly with getSimpleName(), while the latter uses getName() on the passed Class. Is there a difference between these two? Would it affect if I configure various packages to log at different level in log4j.properties file?

答:
I prefer using the full name (Class.getName()). When packages are organized correctly, this allows tuning log4j to handle differently log messages originating from different parts of the java packages tree.

For example, you can easily configure all classes in packages starting with "com.mycompany.infra" to use a specific appender, and log only messages of level WARN or above.

Body:
I've seen code that uses log4j, which acquires logger for a given Logger using

static public Logger getLogger(String name)

and

static public Logger getLogger(Class clazz)

with the former api passed explicitly with getSimpleName(), while the latter uses getName() on the passed Class. Is there a difference between these two? Would it affect if I configure various packages to log at different level in log4j.properties file?

ContentLicense: CC BY-SA 2.5


问:
Execute MapReduce job only on a part of a HDFS file
I have a big file in HDFS (~20Gb) on which I usually execute a MapReduce job. Around 170 mappers are created. The InputFormat used is a FileInputFormat.

Now I would like to execute the MapReduce job only on a part of the file (for example, the first 40Mb of the file).

Is there a simple way to perform this?

Thanks for your help.

答:
Hello all,

Finally, I found a solution consisting of deriving the FileInputFormat class and overriding the getSplits method in order to get only the splits corresponding to the wanted part of the HDFS file.

In this method, I call the super class to get the splits generated by the InputFileFormat class. Thanks to the configuration of the job, I manage to get some information like the beginning of the HDFS file and the end of the HDFS file I wanted to read. Finally, the beginning and the end of all splits get from the getSPlits method of the super class are compared to the previous information and returned if they match the the wanted part of the HDFS file.


问:
Adding HTTPS to Azure VM mapped through CNAME
I intend to buy a wildcard SSL certificate for mydomain.com. From my ISP I map test.mydomain.com - using CNAME setting - to an Azure VM (not a simple web app) running a webserver (e.g. blahblah-vm.cloudapp.net) where I have opened port 80 and 443.

Now, my client connects to https://test.mydomain.com. Will there be any issues? Do I need to somehow prepare the VM with the mydomain.com SSL certificate or will it just work thanks to the CNAME mapping?

答:
Does your VM have a static Public IP address? If yes, you could use A Records.  Also, we can use CNAME map the Azure VM's  FQDN.

Now, my client connects to https://test.mydomain.com. Will there be
  any issues?

Before you connect to https://test.mydomain.com, we should install SSL certificate on your PC first.

Do I need to somehow prepare the VM with the mydomain.com SSL
  certificate or will it just work thanks to the CNAME mapping?

There is no need to prepare something except install SSL certificate.

Update:

If your VM is windows, and use IIS to deploy your web server, we can use SSL certificate here:


问:
Start Activity from within ArrayAdapter
I have a custom adapter that extends ArrayAdapter. I want to go to MapActivity when the EMAIL is clicked. If I remove the intent part a toast appears with the correct position of the item clicked. However, if I add the startActivity function, the app crashes (no toast). I removed the irrelevant code such as getting distance and setters.getters. Any help or pointer would be appreciated!

ArrayAdapter code

```<code>import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.auth.FirebaseAuth;

import java.util.ArrayList;
import java.util.List;

public class TrackAdapter extends ArrayAdapter{

    private Context c;
    //ArrayLists to save items

    public TrackAdapter(Context context, int resource)
    {
        super(context, resource);
        this.c = context;
    }

    public void add(/*items to be added*/)
    {
       //add to ArrayLists and super.add()
    }

    static class RowHolder
    {
        TextView EMAIL;
        TextView DISTANCE;
    }

    @Override
    public int getCount()
    {
        return this.email.size();
    }

    @Override
    public Object getItem(int position)
    {
        return this.email.get(position);
    }

    /*other setters and getters*/

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row;
        row = convertView;
        RowHolder holder;

        final int currentPosition = position;

        if (convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.track_item, parent, false);

            holder = new RowHolder();

            holder.EMAIL = (TextView) row.findViewById(R.id.track_item_text);
            holder.DISTANCE = (TextView) row.findViewById(R.id.track_item_distance);

            holder.EMAIL.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    Toast.makeText(c, "item at position " + currentPosition, Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(c, MapActivity.class);
                    c.startActivity(intent);
                }
            });

            row.setTag(holder);
        }
        else
        {
            holder = (RowHolder) row.getTag();
        }

        String EM = (String) getItem(position);
        holder.EMAIL.setText(EM);

        //calculate and display distance

        return row;

    }
}
</code>```

I also tried replacing c with c.getApplicationContext() and v.getContext(), which also doesn't work.

EDIT- I ran the app on an emulator, and it goes to the MapActivity. However, when  ran on an android device connected by USB, the app crashes

EDIT2 - Here is the crash report

```<code>--------- beginning of crash
03-29 03:23:42.036 7768-7768/com.example.*******
E/AndroidRuntime: FATAL EXCEPTION: main

                                                                                android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:672)
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:659)
                                                                                at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
                                                                                at com.example.ankit.findyourfellow.TrackAdapter$1.onClick(TrackAdapter.java:127)
                                                                                at android.view.View.performClick(View.java:5204)
                                                                                at android.view.View$PerformClick.run(View.java:21153)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
</code>```

答:
add following code to your adapter class

```<code>ClickListener mClickListener;
public void setClickListener(ClickListener clickListener) {
        this.mClickListener = clickListener;
    }

    public interface ClickListener {
        void onItemClick();
    }
</code>```

Now in Activity class add this where you setting adapter :

```<code>mAdapter.setClickListener(new TrackAdapter.ClickListener() {

            @Override
            public void onItemClick() {
                 Intent intent = new Intent(YourActivity.this, MapActivity.class);
                 startActivity(intent);
            }
}
</code>```

Than onClick method of your adapter class call following  :

```<code>if (mClickListener != null ) {
                             mClickListener.onItemClick();
                        }
</code>```

Title: Start Activity from within ArrayAdapter

Body:
I have a custom adapter that extends ArrayAdapter. I want to go to MapActivity when the EMAIL is clicked. If I remove the intent part a toast appears with the correct position of the item clicked. However, if I add the startActivity function, the app crashes (no toast). I removed the irrelevant code such as getting distance and setters.getters. Any help or pointer would be appreciated!

ArrayAdapter code

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.auth.FirebaseAuth;

import java.util.ArrayList;
import java.util.List;

public class TrackAdapter extends ArrayAdapter{

    private Context c;
    //ArrayLists to save items

    public TrackAdapter(Context context, int resource)
    {
        super(context, resource);
        this.c = context;
    }

    public void add(/*items to be added*/)
    {
       //add to ArrayLists and super.add()
    }

    static class RowHolder
    {
        TextView EMAIL;
        TextView DISTANCE;
    }

    @Override
    public int getCount()
    {
        return this.email.size();
    }

    @Override
    public Object getItem(int position)
    {
        return this.email.get(position);
    }

    /*other setters and getters*/

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row;
        row = convertView;
        RowHolder holder;

        final int currentPosition = position;

        if (convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.track_item, parent, false);

            holder = new RowHolder();

            holder.EMAIL = (TextView) row.findViewById(R.id.track_item_text);
            holder.DISTANCE = (TextView) row.findViewById(R.id.track_item_distance);

            holder.EMAIL.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    Toast.makeText(c, "item at position " + currentPosition, Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(c, MapActivity.class);
                    c.startActivity(intent);
                }
            });

            row.setTag(holder);
        }
        else
        {
            holder = (RowHolder) row.getTag();
        }

        String EM = (String) getItem(position);
        holder.EMAIL.setText(EM);

        //calculate and display distance

        return row;

    }
}

I also tried replacing c with c.getApplicationContext() and v.getContext(), which also doesn't work.

EDIT- I ran the app on an emulator, and it goes to the MapActivity. However, when  ran on an android device connected by USB, the app crashes

EDIT2 - Here is the crash report

--------- beginning of crash
03-29 03:23:42.036 7768-7768/com.example.*******
E/AndroidRuntime: FATAL EXCEPTION: main

                                                                                android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:672)
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:659)
                                                                                at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
                                                                                at com.example.ankit.findyourfellow.TrackAdapter$1.onClick(TrackAdapter.java:127)
                                                                                at android.view.View.performClick(View.java:5204)
                                                                                at android.view.View$PerformClick.run(View.java:21153)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Body:
add following code to your adapter class

ClickListener mClickListener;
public void setClickListener(ClickListener clickListener) {
        this.mClickListener = clickListener;
    }

    public interface ClickListener {
        void onItemClick();
    }

Now in Activity class add this where you setting adapter :

mAdapter.setClickListener(new TrackAdapter.ClickListener() {

            @Override
            public void onItemClick() {
                 Intent intent = new Intent(YourActivity.this, MapActivity.class);
                 startActivity(intent);
            }
}

Than onClick method of your adapter class call following  :

if (mClickListener != null ) {
                             mClickListener.onItemClick();
                        }


问:
how to make a row maintain its position of entry even though its primary key id number is less than the earlier row entered

Please guys, my primary key id is auto generated from my java code. Because of that, some of the id numbers of the new row to be inserted is less than the older rows already inserted in the database . My question is: Is it possible to make the database maintain  each rows in the order by which they where inserted even though the new rows have lesser id numbers as compared to the older ones? . i use Mysql in phpmyadmin. Thanks

答:
I don't know if there is any way to create non-clustered primary keys in mySql.

But in MS Sql Server there is way to create non-clustered primary key as below

ALTER TABLE my_table DROP CONSTRAINT pk_my_table;

ALTER TABLE my_table ADD CONSTRAINT pk_my_table PRIMARY KEY
  NONCLUSTERED (id);

or

If you are not concerned with actually keeping your java generated id as primary key.

And you want to maintain natural ordering of rows, create a separate column (with auto-generated sequence) and make it primary key.


问:
How do I pass a string parameter to Powershell for ConvertFrom-StringData from command line?
I'm having trouble running powershell with a script that should use a variable number of parameters.

The script file looks like this:

```<code>param( [string]$paramString )

$params = ConvertFrom-StringData $paramString
$params
</code>```

Running the script directly in powershell yields the expected result:

```<code>[PS] C:\some\path>.\test.ps1 "a=foo `n b=bar `n c=moo"

Name                           Value
----                           -----
c                              moo
a                              foo
b                              bar
</code>```

Calling powershell from the command line with the same script and parameters shows this:

```<code>C:\some\path>powershell -nologo -file ./test.ps1 "a=foo `n b=bar `n c=moo"

Name                           Value
----                           -----
a                              foo `n b=bar `n c=moo
</code>```

It seems like the passed string is in some format so the ConvertFrom-StringData function is unable to parse it anymore.

答:
Use single quote to pass parameters to powershell with script like this:</p>

```<code>C:\some\path>powershell .\test.ps1 'a=foo' 'b=bar' 'c=moo'
</code>```

Body:
I'm having trouble running powershell with a script that should use a variable number of parameters.

The script file looks like this:

param( [string]$paramString )

$params = ConvertFrom-StringData $paramString
$params

Running the script directly in powershell yields the expected result:

[PS] C:\some\path>.\test.ps1 "a=foo `n b=bar `n c=moo"

Name                           Value
----                           -----
c                              moo
a                              foo
b                              bar

Calling powershell from the command line with the same script and parameters shows this:

C:\some\path>powershell -nologo -file ./test.ps1 "a=foo `n b=bar `n c=moo"

Name                           Value
----                           -----
a                              foo `n b=bar `n c=moo

It seems like the passed string is in some format so the ConvertFrom-StringData function is unable to parse it anymore.

Body:
Use single quote to pass parameters to powershell with script like this:

C:\some\path>powershell .\test.ps1 'a=foo' 'b=bar' 'c=moo'


问:
How to hide config files from direct access?
I am using Laravel for web app. Uploaded everything on production and found out that some of the files can be directly accessed by url - for example http://example.com/composer.json </p>

<p>How to avoid that direct access? </p>

答:
With Apache, you can create .htaccess file in the root directory of Laravel project to rewrite all requests to public/ directory.</p>

```<code><IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
</code>```

Body:
I am using Laravel for web app. Uploaded everything on production and found out that some of the files can be directly accessed by url - for example http://example.com/composer.json

How to avoid that direct access?

Body:
With Apache, you can create .htaccess file in the root directory of Laravel project to rewrite all requests to public/ directory.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


问:
XCode/Swift 3: How to shift storyboard elements down/up without messing up existing constraints?
XCode/Swift 3

I've placed several elements (e.g. labels, text Fields) on my story board, and I've properly set all constraints.

Now I've decided that all content needs to shift down about five pixels. I can press the COMMAND + A keys to select all and then press the down arrow five times on my keyboard to shift everything. However, that messes up all of my existing constraints!

How can I shift everything down five pixels and preserve my constraints?

I'm very new to iOS programming, so thanks for your patience for what must be a very easy question for some of you!

答:
after you shifted down all your items (like you've done)

there is a button with which you can update all constraints


问:
Sorting two arrays (values,keys), then sorting the keys
I have what seems to be a simple problem but I can't figure it out so far.

Say I have two arrays:

```<code>int[] values = {10,20,20,10,30};
int[] keys = {1,2,3,4,5};

Array.Sort(values,keys);
</code>```

Then the arrays would look like this:

```<code>values = {10,10,20,20,30};
keys = {4,1,2,3,5};
</code>```

Now, what I want to do is make it so that the keys are also sorted in second priority so the key array to look like this:

```<code>keys = {1,4,2,3,5};
</code>```

Notice the 1 and 4 values are switched and the order of the value array has not changed.

答: By converting this to a sort on an array of value pairs you can supply your own comparator and make the sort work pretty much any way you like.  (It seems awful risky to use two separate arrays.)  See the fourth method at http://msdn.microsoft.com/en-us/library/system.array.sort.aspx.  </p>

Body:
I have what seems to be a simple problem but I can't figure it out so far.

Say I have two arrays:

int[] values = {10,20,20,10,30};
int[] keys = {1,2,3,4,5};

Array.Sort(values,keys);

Then the arrays would look like this:

values = {10,10,20,20,30};
keys = {4,1,2,3,5};

Now, what I want to do is make it so that the keys are also sorted in second priority so the key array to look like this:

keys = {1,4,2,3,5};

Notice the 1 and 4 values are switched and the order of the value array has not changed.


答:
Don't worry about it, First you have shifted all these downs now on storyboard left side there is a Document Outline Bar, on that your storyboard has a yellow arrow, click that and you will see all the shifted objects are presents with their properties. Click them one by one and and select

Update Constraints

This will set your constraints as you updated.

Title: XCode/Swift 3: How to shift storyboard elements down/up without messing up existing constraints?

Body:
XCode/Swift 3

I've placed several elements (e.g. labels, text Fields) on my story board, and I've properly set all constraints.

Now I've decided that all content needs to shift down about five pixels. I can press the COMMAND + A keys to select all and then press the down arrow five times on my keyboard to shift everything. However, that messes up all of my existing constraints!

How can I shift everything down five pixels and preserve my constraints?

I'm very new to iOS programming, so thanks for your patience for what must be a very easy question for some of you!


问:
Laravel 4.2 on MAMP 4 - PHP 7.1.0 - Mcrypt PHP extension required
I've recently installed MAMP 4 running PHP 7.1.0 in order to run Craft 3. Now my Laravel 4.2 installations all come up with a message saying Mcrypt PHP extension required.

Does anyone know how to get it working using this installation of MAMP with this PHP version?

Everything I've looked at is related to older versions running php 5.x.

When I run which php I get /Applications/MAMP/bin/php/php7.1.0/bin/php

My .bash_profile says;

```<code>alias phpmamp='/Applications/MAMP/bin/php/php7.1.0/bin/php'
export PATH=/Applications/MAMP/bin/php/php7.1.0/bin:$PATH
</code>```

答:
I had the same issue when trying to install OpenCart using the same PHP version.

I fixed it by using this in my .bash_profile :

```<code>export PATH=/Applications/MAMP/bin/php/php7.1.0/bin:$PATH
</code>```

And by making sure that in my php.ini located in /Applications/MAMP/bin/php/php7.1.0/conf/ :

The line 'extension=mcrypt.so' is present and is not commented (no ; at the beginning, if there is one just remove it)

Every link to 'no-debug-no-zts-xxxxxxxx' is using the exact same name than the directory located in /Applications/MAMP/bin/php/php7.1.0/lib/php/extensions/.

For exemple, mine is :

/Applications/MAMP/bin/php/php7.1.0/lib/php/extensions/no-debug-non-zts-20160303/, I suppose it depends on the PHP version.

There should be three links like this, one at the beginning of the file and two at the end.

I hope it helps someone.

Body:
I've recently installed MAMP 4 running PHP 7.1.0 in order to run Craft 3. Now my Laravel 4.2 installations all come up with a message saying Mcrypt PHP extension required.

Does anyone know how to get it working using this installation of MAMP with this PHP version?

Everything I've looked at is related to older versions running php 5.x.

When I run which php I get /Applications/MAMP/bin/php/php7.1.0/bin/php

My .bash_profile says;

alias phpmamp='/Applications/MAMP/bin/php/php7.1.0/bin/php'
export PATH=/Applications/MAMP/bin/php/php7.1.0/bin:$PATH

Body:
I had the same issue when trying to install OpenCart using the same PHP version.

I fixed it by using this in my .bash_profile :

export PATH=/Applications/MAMP/bin/php/php7.1.0/bin:$PATH

And by making sure that in my php.ini located in /Applications/MAMP/bin/php/php7.1.0/conf/ :

The line 'extension=mcrypt.so' is present and is not commented (no ; at the beginning, if there is one just remove it)

Every link to 'no-debug-no-zts-xxxxxxxx' is using the exact same name than the directory located in /Applications/MAMP/bin/php/php7.1.0/lib/php/extensions/.

For exemple, mine is :

/Applications/MAMP/bin/php/php7.1.0/lib/php/extensions/no-debug-non-zts-20160303/, I suppose it depends on the PHP version.

There should be three links like this, one at the beginning of the file and two at the end.

I hope it helps someone.


问:
SED expression for turning Yeseva+one, Yrsa, ... into yeseva-one, yrsa,
I have a comma separated list of fonts like this:

```<code>Yeseva+one, Yrsa, ...
</code>```

I need a SED expression, or similar, to turn the + into a dash and lowercase all capitals.

Update

Just wanted to say thanks for all the great help with this and if anyone needs google fonts as CSS variables / properties they are all available here (MIT License):
https://github.com/superfly-css/superfly-css-variables-fonts/blob/master/src/main/css/index.css

I'll also be providing utilities for using google fonts here:
https://github.com/superfly-css/superfly-css-utilities-fonts

答:
With Bash:

```<code>a="Yeseva+One, Yrsa, Courier+New, Alegreya+Sans+SC" ; a="${a,,}";a="${a//+/-}";echo "$a"
#Output
yeseva-one, yrsa, courier-new, alegreya-sans-sc
</code>```

With Sed

```<code>b="Yeseva+One, Yrsa, Courier+New, Alegreya+Sans+SC"
sed 's/.*/\L&/g; s/+/-/g' <<<"$b"
#Output
yeseva-one, yrsa, courier-new, alegreya-sans-sc
</code>```

Body:
I have a comma separated list of fonts like this:

Yeseva+one, Yrsa, ...

I need a SED expression, or similar, to turn the + into a dash and lowercase all capitals.

Update

Just wanted to say thanks for all the great help with this and if anyone needs google fonts as CSS variables / properties they are all available here (MIT License):
https://github.com/superfly-css/superfly-css-variables-fonts/blob/master/src/main/css/index.css

I'll also be providing utilities for using google fonts here:
https://github.com/superfly-css/superfly-css-utilities-fonts

Body:
With Bash:

a="Yeseva+One, Yrsa, Courier+New, Alegreya+Sans+SC" ; a="${a,,}";a="${a//+/-}";echo "$a"
#Output
yeseva-one, yrsa, courier-new, alegreya-sans-sc

With Sed

b="Yeseva+One, Yrsa, Courier+New, Alegreya+Sans+SC"
sed 's/.*/\L&/g; s/+/-/g' <<<"$b"
#Output
yeseva-one, yrsa, courier-new, alegreya-sans-sc


问:
Intrepret bytecode with subprocess.call argument
I have a program that take one argument.

I need to call this program in my python script and I need to pass the argument in bytecode format (like \x42\x43).

Directly in bash, I can do like this and it does work:

./myprogram $'\x42\x43'

But with subprocess.call it doesn't work:

subprocess.call(["myprogram", "$'\x42\x43'"])

Bytes are not intrepreted.

I try to call my program with /bin/bash but my program returns a segfault!

答:
Thanks @acw1668

This works well:
subprocess.call(["myprogram", b"\x42\x43"])

But if yours bytecodes are in a variable, you need to do this manipulation:

```<code># If you're string is unicode type
mystring = mystring.decode('unicode_escape')
# I choose latin1, because some of my bytecode are bigger than 128
mystring = mystring.encode('latin1')
</code>```

And my bytecodes are correctly interpreted:
subprocess.call(["myprogram", mystring])

Body:
Thanks @acw1668

This works well:
subprocess.call(["myprogram", b"\x42\x43"])

But if yours bytecodes are in a variable, you need to do this manipulation:

# If you're string is unicode type
mystring = mystring.decode('unicode_escape')
# I choose latin1, because some of my bytecode are bigger than 128
mystring = mystring.encode('latin1')

And my bytecodes are correctly interpreted:
subprocess.call(["myprogram", mystring])


问:
pandas read_table gives single column with JSON data
I am using pandas to deal with a larger file, and I have used the get_chunk method, but the does not load properly.

What I tried

```<code>def load_data():
    reader = pd.read_table('/Users/fiz/Desktop/xad', iterator=True,encoding='utf-8')
    loop = True
    chunkSize = 10000
    chunks = []
    while loop:
       try:
          chunk = reader.get_chunk(chunkSize)
          chunks.append(chunk)
          print(chunk)

       except StopIteration:
          loop = False
          print("Iteration is stopped.")
    df = pd.concat(chunks, ignore_index=True)
</code>```

Gives:

```<code>{"_index":"pos_journals-2017.03.24","_type":"pos_journals","_id":"AVr_peEqanqtRFPuszUt","_score":null,"_source": {"message":"Chk 4040                   Gst 0\r\n1005 Yangshuying          PCWS02\r\nCE:   1005 CC:      0 TC:      0\r\nTrn 8704          24Mar'17 17:28\r\n--------------------------------\r\n    To Go       \r\n      SR:6010381353541922\r\n           SR:ONLINE\r\n  1 Mocha Ice V         37.00\r\n    Cash               102.00\r\n    Subtotal            37.00\r\n    Paid                37.00\r\n    Change Due          65.00\r\n================================","@version":"1","@timestamp":"2017-03-24T09:28:56.787Z","type":"pos_journals","count":1,"beat":{"hostname":"S24376","name":"S24376"},"source":"d:\\MICROS\\Res\\Pos\\Journals\\POS02.txt","offset":40621,"input_type":"log","fields":null,"host":"S24376","tags":["beats_input_codec_plain_applied"]},"fields":{"@timestamp":[1490347736787]},"highlight":{"message":["Chk 4040                   Gst 0\r\n1005 Yangshuying          PCWS02\r\nCE:   1005 CC:      0 TC:      0\r\nTrn 8704          24Mar'17 17:28\r\n--------------------------------\r\n    To Go       \r\n      SR:6010381353541922\r\n           SR:ONLINE\r\n  1 Mocha Ice V         37.00\r\n    @kibana-highlighted-field@Cash@/kibana-highlighted-field@               102.00\r\n    Subtotal            37.00\r\n    Paid                37.00\r\n    Change Due          65.00\r\n================================"]},"sort":[1490347736787]}

 0   {"_index":"pos_journals-2017.03.24","_type":"p...
 1   {"_index":"pos_journals-2017.03.24","_type":"p...
 2   {"_index":"pos_journals-2017.03.24","_type":"p...
 3   {"_index":"pos_journals-2017.03.24","_type":"p...
</code>```

Desired output

enter image description here

答:
It seems your data file is JSON.

Try the pandas.read_json method

It also looks like the data is in the 'records' orientation, so something like:

```<code>pd.read_json('/Users/fiz/Desktop/xad', orient='records', encoding='utf-8')
</code>```

May be a good place to start.

Sadly the read_json method does not seem to support chunking.

Body:
I am using pandas to deal with a larger file, and I have used the get_chunk method, but the does not load properly.

What I tried

def load_data():
    reader = pd.read_table('/Users/fiz/Desktop/xad', iterator=True,encoding='utf-8')
    loop = True
    chunkSize = 10000
    chunks = []
    while loop:
       try:
          chunk = reader.get_chunk(chunkSize)
          chunks.append(chunk)
          print(chunk)

       except StopIteration:
          loop = False
          print("Iteration is stopped.")
    df = pd.concat(chunks, ignore_index=True)

Gives:

{"_index":"pos_journals-2017.03.24","_type":"pos_journals","_id":"AVr_peEqanqtRFPuszUt","_score":null,"_source": {"message":"Chk 4040                   Gst 0\r\n1005 Yangshuying          PCWS02\r\nCE:   1005 CC:      0 TC:      0\r\nTrn 8704          24Mar'17 17:28\r\n--------------------------------\r\n    To Go       \r\n      SR:6010381353541922\r\n           SR:ONLINE\r\n  1 Mocha Ice V         37.00\r\n    Cash               102.00\r\n    Subtotal            37.00\r\n    Paid                37.00\r\n    Change Due          65.00\r\n================================","@version":"1","@timestamp":"2017-03-24T09:28:56.787Z","type":"pos_journals","count":1,"beat":{"hostname":"S24376","name":"S24376"},"source":"d:\\MICROS\\Res\\Pos\\Journals\\POS02.txt","offset":40621,"input_type":"log","fields":null,"host":"S24376","tags":["beats_input_codec_plain_applied"]},"fields":{"@timestamp":[1490347736787]},"highlight":{"message":["Chk 4040                   Gst 0\r\n1005 Yangshuying          PCWS02\r\nCE:   1005 CC:      0 TC:      0\r\nTrn 8704          24Mar'17 17:28\r\n--------------------------------\r\n    To Go       \r\n      SR:6010381353541922\r\n           SR:ONLINE\r\n  1 Mocha Ice V         37.00\r\n    @kibana-highlighted-field@Cash@/kibana-highlighted-field@               102.00\r\n    Subtotal            37.00\r\n    Paid                37.00\r\n    Change Due          65.00\r\n================================"]},"sort":[1490347736787]}

 0   {"_index":"pos_journals-2017.03.24","_type":"p...
 1   {"_index":"pos_journals-2017.03.24","_type":"p...
 2   {"_index":"pos_journals-2017.03.24","_type":"p...
 3   {"_index":"pos_journals-2017.03.24","_type":"p...

Desired output

enter image description here

Body:
It seems your data file is JSON.

Try the pandas.read_json method

It also looks like the data is in the 'records' orientation, so something like:

pd.read_json('/Users/fiz/Desktop/xad', orient='records', encoding='utf-8')

May be a good place to start.

Sadly the read_json method does not seem to support chunking.


问:
Using mongo gems in Rails 5 -- should it be this hard?
Am I missing something incredibly obvious?

I generate a new rails 5 application, and per the mongo doc, added the gem to the Gemfile:

```<code>gem 'mongo', '~> 2.4'
</code>```

bundle install installs the gem (and gem dependencies) fine, but when I just try to bring up a rails console:

```<code>$ rails c
Could not find bson-4.2.1 in any of the sources
Run `bundle install` to install missing gems.
</code>```

Are there some further installation instructions buried somewhere?

FWIW, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]

and

```<code>$ rails -v
Rails 5.0.2
</code>```

答:
Try these gems by replacing them in gem file .It works for me with Rails 5</p>

```<code>gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git'
gem 'bson_ext'
</code>```

Body:
Am I missing something incredibly obvious?

I generate a new rails 5 application, and per the mongo doc, added the gem to the Gemfile:

gem 'mongo', '~> 2.4'

bundle install installs the gem (and gem dependencies) fine, but when I just try to bring up a rails console:

$ rails c
Could not find bson-4.2.1 in any of the sources
Run `bundle install` to install missing gems.

Are there some further installation instructions buried somewhere?

FWIW, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]

and

$ rails -v
Rails 5.0.2

Body:
Try these gems by replacing them in gem file .It works for me with Rails 5

gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git'
gem 'bson_ext'


问:
Drupal stripping my closing div tags from a JavaScript variable
I'm trying to style a Google Maps InfoWindow. For each of my map markers I have a window that works perfectly on a local site and in a JSFiddle. However, when I add the code to a Drupal block, it strips the closing div tags.

I've tried this way:

```<code>`var message =
"<div class='window-container'>" +
  "<div class='window-content'>" +
    "<div class='window-header'>" +
      "<div class='window-title'>" + name + "</div>" +
      "<div class='window-subtitle'>" + org + "</div>" +
    "</div>" +
    "<div class='window-body'>" + summary + "...</div>" +
  "</div>" +
"</div>";`
</code>```

And this way:

```<code>`var message =
'<div class="window-container">\
  <div class="window-content">\
    <div class="window-header">\
      <div class="window-title">' +name+ '</div>\
      <div class="window-subtitle">' +org+ '</div>\
    </div>\
    <div class="window-body">' +summary+ '</div>\
  </div>\
</div>';`
</code>```

And this way with a Babel compiler:

```<code>`var message = '
  <div class="window-container">
    <div class="window-content">
      <div class="window-header">
        <div class="window-title">${name}</div>
        <div class="window-subtitle">${org}</div>
      </div>
      <div class="window-body">${summary}</div>
    </div>
  </div>'`
</code>```

And on the page, in my console, it always comes out like this!

```<code>`var message =
"<div class='window-container'>" +
  "<div class='window-content'>" +
    "<div class='window-header'>" +
      "<div class='window-title'>" + name + "" +
      "<div class='window-subtitle'>" + org + "" +
    "" +
    "<div class='window-body'>" + summary + "..." +
  "" +
"";`
</code>```

It removes all the closing div tags! Why?

答:
If you paste your code into ckeditor or other filters you'll have some trouble like that.

So it's recommanded to create a custom block programmatically, like explained here :
https://www.drupal.org/docs/creating-custom-modules/creating-custom-blocks/create-a-custom-block

Body:
I'm trying to style a Google Maps InfoWindow. For each of my map markers I have a window that works perfectly on a local site and in a JSFiddle. However, when I add the code to a Drupal block, it strips the closing div tags.

I've tried this way:

`var message =
"
" +
  "
" +
    "
" +
      "
" + name + "
" +
      "
" + org + "
" +
    "
" +
    "
" + summary + "...
" +
  "
" +
"
";`

And this way:

`var message =
'
\

\

\

' +name+ '
\

' +org+ '
\

\

' +summary+ '
\

\

';`

And this way with a Babel compiler:

`var message = '

${name}

${org}

${summary}

'`

And on the page, in my console, it always comes out like this!

`var message =
"
" +
  "
" +
    "
" +
      "
" + name + "" +
      "
" + org + "" +
    "" +
    "
" + summary + "..." +
  "" +
"";`

It removes all the closing div tags! Why?


问:
Get RGB of JPG in Android
first of all thank for your time. I have a jar library which would be included as library in my Android Application.
This jar, among other things, is able to get the RGB values from a jpg image. This works perfectly in my java application but when I runs it in my Android application it does not work because the class ImageIO.read(File file) (Bufferedimage) does not implemented in Android.
I read something about using Bitmap class but i do not find out anything about it.

Could you help me with this method you find here below?

```<code>public static int[][][] getImageRgb(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
int[][][] rgb = new int[height][width][3];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int pixel = image.getRGB(j, i);
rgb[i][j] = getPixelRgb(pixel); }
}
return rgb;
}
</code>```

Where getPixelRgb is a function aims this:

```<code>public static int[] getPixelRgb(int pixel) {
        // int alpha = (pixel >> 24) & 0xff;
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        return new int[]{red, green, blue};
}
</code>```

I really I do not know how to transform this methods for Android.

I look forward to hearing from you.
Thank a lot.

答:
What you need is in the official docs:

int getPixel (int x, int y)

Returns the Color at the specified location.

You can create a Bitmap from a resource in res/drawable folder or if you're downloading the image, you need to first save it to the device storage.

Title: Get RGB of JPG in Android

Body:
first of all thank for your time. I have a jar library which would be included as library in my Android Application.
This jar, among other things, is able to get the RGB values from a jpg image. This works perfectly in my java application but when I runs it in my Android application it does not work because the class ImageIO.read(File file) (Bufferedimage) does not implemented in Android.
I read something about using Bitmap class but i do not find out anything about it.

Could you help me with this method you find here below?

public static int[][][] getImageRgb(BufferedImage image) {
int width = image.getWidth();
int height = image.getHeight();
int[][][] rgb = new int[height][width][3];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int pixel = image.getRGB(j, i);
rgb[i][j] = getPixelRgb(pixel); }
}
return rgb;
}

Where getPixelRgb is a function aims this:

public static int[] getPixelRgb(int pixel) {
        // int alpha = (pixel >> 24) & 0xff;
        int red = (pixel >> 16) & 0xff;
        int green = (pixel >> 8) & 0xff;
        int blue = (pixel) & 0xff;
        return new int[]{red, green, blue};
}

I really I do not know how to transform this methods for Android.

I look forward to hearing from you.
Thank a lot.


答:
Add flag Intent.FLAG_ACTIVITY_NEW_TASK to your intent.

Use intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) before starting MapActivity.

Try this:

```<code> Intent intent = new Intent(c, MapActivity.class);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 c.startActivity(intent);
</code>```

Title: Start Activity from within ArrayAdapter

Body:
I have a custom adapter that extends ArrayAdapter. I want to go to MapActivity when the EMAIL is clicked. If I remove the intent part a toast appears with the correct position of the item clicked. However, if I add the startActivity function, the app crashes (no toast). I removed the irrelevant code such as getting distance and setters.getters. Any help or pointer would be appreciated!

ArrayAdapter code

import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.maps.model.LatLng;
import com.google.firebase.auth.FirebaseAuth;

import java.util.ArrayList;
import java.util.List;

public class TrackAdapter extends ArrayAdapter{

    private Context c;
    //ArrayLists to save items

    public TrackAdapter(Context context, int resource)
    {
        super(context, resource);
        this.c = context;
    }

    public void add(/*items to be added*/)
    {
       //add to ArrayLists and super.add()
    }

    static class RowHolder
    {
        TextView EMAIL;
        TextView DISTANCE;
    }

    @Override
    public int getCount()
    {
        return this.email.size();
    }

    @Override
    public Object getItem(int position)
    {
        return this.email.get(position);
    }

    /*other setters and getters*/

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row;
        row = convertView;
        RowHolder holder;

        final int currentPosition = position;

        if (convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.track_item, parent, false);

            holder = new RowHolder();

            holder.EMAIL = (TextView) row.findViewById(R.id.track_item_text);
            holder.DISTANCE = (TextView) row.findViewById(R.id.track_item_distance);

            holder.EMAIL.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    Toast.makeText(c, "item at position " + currentPosition, Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(c, MapActivity.class);
                    c.startActivity(intent);
                }
            });

            row.setTag(holder);
        }
        else
        {
            holder = (RowHolder) row.getTag();
        }

        String EM = (String) getItem(position);
        holder.EMAIL.setText(EM);

        //calculate and display distance

        return row;

    }
}

I also tried replacing c with c.getApplicationContext() and v.getContext(), which also doesn't work.

EDIT- I ran the app on an emulator, and it goes to the MapActivity. However, when  ran on an android device connected by USB, the app crashes

EDIT2 - Here is the crash report

--------- beginning of crash
03-29 03:23:42.036 7768-7768/com.example.*******
E/AndroidRuntime: FATAL EXCEPTION: main

                                                                                android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:672)
                                                                                at android.app.ContextImpl.startActivity(ContextImpl.java:659)
                                                                                at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
                                                                                at com.example.ankit.findyourfellow.TrackAdapter$1.onClick(TrackAdapter.java:127)
                                                                                at android.view.View.performClick(View.java:5204)
                                                                                at android.view.View$PerformClick.run(View.java:21153)
                                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Body:
Add flag Intent.FLAG_ACTIVITY_NEW_TASK to your intent.

Use intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) before starting MapActivity.

Try this:

 Intent intent = new Intent(c, MapActivity.class);
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 c.startActivity(intent);


问:
how to write a function in bash_profile
how can we write a simple regular function which i can put in my bashprofile
which can be used to secure console to any host i want.

but my secure console has to go through a jump host. that is the issue.

```<code>function func_name () {
 ssh jumphostname;
 sc $hostname # from jump host secure console to another host given as input from terminal
}
</code>```

this function only making to login in to jump host but not to secureconsole in to another host from there.

-bash-4.1$func_name host.me.com
should give me console to host.me.com via jumphost

is function for this not possible?
do i have to write a script?

答:
Below link would help you to go ahead

```<code>ssh username@host_address "command to execute"
</code>```

For example output:

```<code>arul@OA2:~/work/images$ ssh arul@localhost echo "hai"
arul@localhost's password:
hai
arul@OA2:~/work/images$
</code>```

ssh arul@localhost command will login and "echo hai" command printed in currently logged in prompt"

Citation: https://www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/

Title: how to write a function in bash_profile

Body:
how can we write a simple regular function which i can put in my bashprofile
which can be used to secure console to any host i want.

but my secure console has to go through a jump host. that is the issue.

function func_name () {
 ssh jumphostname;
 sc $hostname # from jump host secure console to another host given as input from terminal
}

this function only making to login in to jump host but not to secureconsole in to another host from there.

-bash-4.1$func_name host.me.com
should give me console to host.me.com via jumphost

is function for this not possible?
do i have to write a script?

Body:
Below link would help you to go ahead

ssh username@host_address "command to execute"

For example output:

arul@OA2:~/work/images$ ssh arul@localhost echo "hai"
arul@localhost's password:
hai
arul@OA2:~/work/images$

ssh arul@localhost command will login and "echo hai" command printed in currently logged in prompt"

Citation: https://www.cyberciti.biz/faq/unix-linux-execute-command-using-ssh/


问:
Nested tabs in bootstrap
I have nested tabs in Bootstrap, and here is the code: http://jsfiddle.net/RLdYC/

$("ul.nav-tabs a").click(function (e) {
  e.preventDefault();
  $(this).tab('show');
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="tabbable boxed parentTabs">
    <ul class="nav nav-tabs">
        <li class="active">Tab 1
        </li>
        <li>Tab 2
        </li>
    </ul>
    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade active in" id="set1">
            <div class="tabbable">
                <ul class="nav nav-tabs">
                    <li class="active">Tab 1.1
                    </li>
                    <li>Tab 1.2
                    </li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="sub11">
                        <p>Tab 1.1</p>
                    </div>
                    <div class="tab-pane fade" id="sub12">
                        <p>Tab 1.2</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="set2">
            <div class="tabbable">
                <ul class="nav nav-tabs">
                    <li class="active">Tab 2.1
                    </li>
                    <li>Tab 2.2
                    </li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="sub21">
                        <p>Tab 2.1</p>
                    </div>
                    <div class="tab-pane fade" id="sub22">
                        <p>Tab 2.2</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div></code>```

The problem is, as soon as you click on a different tab on the top row, the actual content of the nested tab below will become hidden. I need the content of the first subtab to be shown.

I tried to trigger the click() function on the first subtab, but it didn't help. Can you please write the code that I need to fix this?

答:
Try using this:</p>

```<code><div class="row">
        <div class="col-md-12">
         <!-- Custom Tabs -->
          <div class="nav-tabs-custom">
          <ul class="nav nav-tabs">
        <li class="active"><a href="#set1">New</a>
        </li>
        <li><a href="#set2">Confirmed</a>
        </li>
    </ul>
    <div class="tab-content">

        <div class="tab-pane fade active in" id="set1">

            <div class="tabbable">
                 <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Web Design and Development</a></li>
              <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Domain Registration</a></li>
              <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Cloud Computing Services</a></li>
              <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Android application Development</a></li>
              <li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Web Hosting</a></li>
              <li class=""><a href="#tab_6" data-toggle="tab" aria-expanded="false">SEO and Online Marketing</a></li>
              <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
                <b>Web Deign and development hires:</b>

                <table class="table" id="webdesignTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_2">
              <b>Domain Registration</b>

              <table class="table" id="domainregistrationTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_3">
               <b>Cloud Computing</b>

              <table class="table" id="cloudcomputingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_4">
               <b>Android application Development</b>

              <table class="table" id="androidappTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_5">
               <b>Web Hosting</b>

              <table class="table" id="webhostingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_6">
               <b>SEO and Online Marketing</b>

              <table class="table" id="seoTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
            </div>

        </div>

        <div class="tab-pane fade" id="set2">
            <div class="tabbable">
                   <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Web Design and Development</a></li>
              <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Domain Registration</a></li>
              <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Cloud Computing Services</a></li>
              <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Android application Development</a></li>
              <li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Web Hosting</a></li>
              <li class=""><a href="#tab_6" data-toggle="tab" aria-expanded="false">SEO and Online Marketing</a></li>
              <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
                <b>Web Deign and development hires:</b>

                <table class="table" id="webdesignTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_2">
              <b>Domain Registration</b>

              <table class="table" id="domainregistrationTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_3">
               <b>Cloud Computing</b>

              <table class="table" id="cloudcomputingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_4">
               <b>Android application Development</b>

              <table class="table" id="androidappTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_5">
               <b>Web Hosting</b>

              <table class="table" id="webhostingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_6">
               <b>SEO and Online Marketing</b>

              <table class="table" id="seoTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
            </div>
        </div>

    </div>
          </div>
        </div>
        </div>
</code>```

Title: Nested tabs in bootstrap

Body:
I have nested tabs in Bootstrap, and here is the code: http://jsfiddle.net/RLdYC/

$("ul.nav-tabs a").click(function (e) {
  e.preventDefault();
  $(this).tab('show');
});

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

Tab 1

Tab 2

Tab 1.1

Tab 1.2

Tab 1.1

Tab 1.2

Tab 2.1

Tab 2.2

Tab 2.1

Tab 2.2

The problem is, as soon as you click on a different tab on the top row, the actual content of the nested tab below will become hidden. I need the content of the first subtab to be shown.

I tried to trigger the click() function on the first subtab, but it didn't help. Can you please write the code that I need to fix this?

Body:
Try using this:

<div class="row">
        <div class="col-md-12">
         <!-- Custom Tabs -->
          <div class="nav-tabs-custom">
          <ul class="nav nav-tabs">
        <li class="active"><a href="#set1">New</a>
        </li>
        <li><a href="#set2">Confirmed</a>
        </li>
    </ul>
    <div class="tab-content">

        <div class="tab-pane fade active in" id="set1">

            <div class="tabbable">
                 <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Web Design and Development</a></li>
              <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Domain Registration</a></li>
              <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Cloud Computing Services</a></li>
              <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Android application Development</a></li>
              <li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Web Hosting</a></li>
              <li class=""><a href="#tab_6" data-toggle="tab" aria-expanded="false">SEO and Online Marketing</a></li>
              <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
                <b>Web Deign and development hires:</b>

                <table class="table" id="webdesignTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_2">
              <b>Domain Registration</b>

              <table class="table" id="domainregistrationTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_3">
               <b>Cloud Computing</b>

              <table class="table" id="cloudcomputingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_4">
               <b>Android application Development</b>

              <table class="table" id="androidappTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_5">
               <b>Web Hosting</b>

              <table class="table" id="webhostingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_6">
               <b>SEO and Online Marketing</b>

              <table class="table" id="seoTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
            </div>

        </div>

        <div class="tab-pane fade" id="set2">
            <div class="tabbable">
                   <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">Web Design and Development</a></li>
              <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">Domain Registration</a></li>
              <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">Cloud Computing Services</a></li>
              <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">Android application Development</a></li>
              <li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="false">Web Hosting</a></li>
              <li class=""><a href="#tab_6" data-toggle="tab" aria-expanded="false">SEO and Online Marketing</a></li>
              <li class="pull-right"><a href="#" class="text-muted"><i class="fa fa-gear"></i></a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
                <b>Web Deign and development hires:</b>

                <table class="table" id="webdesignTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_2">
              <b>Domain Registration</b>

              <table class="table" id="domainregistrationTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>

              </div>
              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_3">
               <b>Cloud Computing</b>

              <table class="table" id="cloudcomputingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_4">
               <b>Android application Development</b>

              <table class="table" id="androidappTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_5">
               <b>Web Hosting</b>

              <table class="table" id="webhostingTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->

              <!-- /.tab-pane -->
              <div class="tab-pane" id="tab_6">
               <b>SEO and Online Marketing</b>

              <table class="table" id="seoTable">
                    <thead>
                        <tr>
                            <th>S.no</th>
                            <th>Order By</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Message</th>
                            <th>Date</th>
                            <th>Status</th>
                            <th>Options</th>
                        </tr>
                    </thead>
                </table>
              </div>
              <!-- /.tab-pane -->
            </div>
            <!-- /.tab-content -->
            </div>
        </div>

    </div>
          </div>
        </div>
        </div>


问:
How usable is Qt without its preprocessing step?
I think it's unreasonable for a library to require preprocessing of my source code with a special tool. That said, several people have recommended the Qt library to me for cross platform GUI development.

How usable is Qt without the preprocessing step?

EDIT: Okay people, I'm not meaning this question as a rip on Qt -- too many Qt fanboys are treating it as if it is. I don't want to discuss the merits of the fact that Qt came up with this preprocessing tool. I understand why the tool is there, and I understand why there are large parts of Qt's design that are built upon the idea of preprocessing.

I've never used Qt, ergo I am in no position to rip on it. But I would much rather pay in writing a small amount of boilerplate myself and not depend on ripping apart my entire build process. I won't use Flex and Bison in my current project for the same reason; if I won't use those tools, I'm definitely not going to use another kind of preprocessing.

So, please don't take me as ripping on Qt. I cannot comment on how nice or not nice it is; I have not used it. I just want to know if it is possible to use it without moc.

答:
I'm currently in the position of needing to find alternatives to MOC. So far I use GLib for text translation and I'm in the middle of reengineering a signals/slots library I found on the web (sigslot) using C++ templates and C macros combined. The boring and exhausting part is redoing the GUI for my app and replacing normal Qt widgets with my own widgets (i.e. QPushButton -> MyPushButton) through widget promotion (a feature of Qt Designer). This way I can have my widgets emit templated signals instead of Qt's. There's a catch, tho. My "modified" widget classes MUST be run through the preprocessor, but that's a once-in-a-lifetime step. After that, I can move on.

I can afford to do all of this only because I have already written an Application Framework library with its own event loop (well, it's a wrapper that piggybacks on Qt's event loop code), multithreading and string classes, etc. My project will only need Qt to display the nice and nifty widgets.

But if you don't have these tools at your disposal - which I'm sure you don't - trust me, trying to get rid of Qt's preprocessor is going to be a royal pain in the arse.

Here's my message to you: If you can use QMake or moc, just use them.