问:
How to show json inside another array in bootstrap table
I have to the below JSON data in a bootstrap table. I can show the one level data, but I don't know how to show array inside array data in bootstrap table.

```<code>[
    {
        "seriesName": "Indian Bank",
        "dataVlaues": {
            "11/12/2017": 50,
            "11/13/2017": 40,
            "11/14/2017": 60,
            "11/11/2017": 100
        }
    },
    {
        "seriesName": "Indian Bank1",
        "dataVlaues": {
            "11/18/2017": 12,
            "11/17/2017": 27,
            "11/16/2017": 30,
            "11/15/2017": 101
        }
    }
]
</code>```

答:
Please find working solution below, enjoy :)

angular.module('myApp', [])
  .controller('myCtrl', function($scope) {

    $scope.userTypes = [{
      "type": 'Parent',
      "options": {
        "option1": "11QWERT",
        "option2": "22QWERT"
      }
    }, {
      "type": 'Parent1',
      "options": {
        "option22": "11QWERT",
        "option222": "22QWERT"
      }
    }];
  })```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="myCtrl">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>Type</th>
          <th>Options</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat-start="user in userTypes">
          <td>{{user.type}}</td>
          <td>
            <button ng-click="showOptions = !showOptions" class="btn btn-xs btn-primary">
              Show
            </button>
          </td>
        </tr>
        <tr ng-repeat-end ng-if="showOptions">
          <td colspan="2">
            <table class="table table-bordered">
              <tbody>
                <tr ng-repeat="(key, val) in user.options">
                  <td>{{key}}</td>
                  <td>{{val}}</td>
                </tr>
              </tbody>
            </table>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div></code>```

Body:
I have to the below JSON data in a bootstrap table. I can show the one level data, but I don't know how to show array inside array data in bootstrap table.

[
    {
        "seriesName": "Indian Bank",
        "dataVlaues": {
            "11/12/2017": 50,
            "11/13/2017": 40,
            "11/14/2017": 60,
            "11/11/2017": 100
        }
    },
    {
        "seriesName": "Indian Bank1",
        "dataVlaues": {
            "11/18/2017": 12,
            "11/17/2017": 27,
            "11/16/2017": 30,
            "11/15/2017": 101
        }
    }
]

Body:
Please find working solution below, enjoy :)

angular.module('myApp', [])
  .controller('myCtrl', function($scope) {

    $scope.userTypes = [{
      "type": 'Parent',
      "options": {
        "option1": "11QWERT",
        "option2": "22QWERT"
      }
    }, {
      "type": 'Parent1',
      "options": {
        "option22": "11QWERT",
        "option222": "22QWERT"
      }
    }];
  })

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="myCtrl">
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>Type</th>
          <th>Options</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat-start="user in userTypes">
          <td>{{user.type}}</td>
          <td>
            <button ng-click="showOptions = !showOptions" class="btn btn-xs btn-primary">
              Show
            </button>
          </td>
        </tr>
        <tr ng-repeat-end ng-if="showOptions">
          <td colspan="2">
            <table class="table table-bordered">
              <tbody>
                <tr ng-repeat="(key, val) in user.options">
                  <td>{{key}}</td>
                  <td>{{val}}</td>
                </tr>
              </tbody>
            </table>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div>


来源: stackexchange

问:
How to improve captured image resolution with Camera2 API android?
I am using this project android-camera2-secret-picture-taker to capture image without open camera view, but the captured images is very bad like this

any help to make this better?

thanks

[Edit]

I tried other phones and it works fine, I take this bad images on Huawei Y6II only and I don't know why? the phone camera is 13 mpx and works fine with native camera app.

答:
This is a wildly blind guess, but hey, worth a try.

If you used some code snippet from the web which suggests to get a list of supported image sizes and just pick the first one - well this has backfired for me on Huawei devices (more than one model) because Huawei seems to provide the list in the ascending order of resolution (i.e. smallest-first), whereas most other devices I've seen does that in descending order (i.e. largest-first).

So if this is a resolution issue, it might be worth a check.

ContentLicense: CC BY-SA 3.0


问:
singleton with throwable initializer
I have a singleton:

```<code>public class Manager {
  static let shared = Manager()
  private init() {
    ...
  }
}
</code>```

Other class can access it by:

```<code>Manager.shared
</code>```

No problem here. Now, I start thinking, what if the private initializer is throwable?

```<code>public class Manager {
   // Compiler error: Call can throw, but erros cannot be thrown out of global variable initializer
   static let shared = Manager()

   // throwable initialier
   private init() throws {
     ...
   }
}
</code>```

How to resolve above error if I still want Manager to be singleton?

答:
One of the many possible solutions could be to let the shared variable be an Optional and call the initializer with the try? keyword.

Like this:

```<code>public class Manager {
   static let shared: Manager? = try? Manager()

   // throwable initialier
   private init() throws {
     ...
   }
}
</code>```

EDIT:
If you want to try to recreate the object if it failed the last time you called the init, you can write something like this.

```<code>public class Manager {
    static var shared: Manager? {
        get {
            if instance == nil {
                instance = try? Manager()
            }
            return instance
        }
    }

    static private var instance: Manager? = try? Manager()

    // throwable initialier
    private init() throws {
        ...
    }
}
</code>```

Title: singleton with throwable initializer

Body:
I have a singleton:

public class Manager {
  static let shared = Manager()
  private init() {
    ...
  }
}

Other class can access it by:

Manager.shared

No problem here. Now, I start thinking, what if the private initializer is throwable?

public class Manager {
   // Compiler error: Call can throw, but erros cannot be thrown out of global variable initializer
   static let shared = Manager()

   // throwable initialier
   private init() throws {
     ...
   }
}

How to resolve above error if I still want Manager to be singleton?

Body:
One of the many possible solutions could be to let the shared variable be an Optional and call the initializer with the try? keyword.

Like this:

public class Manager {
   static let shared: Manager? = try? Manager()

   // throwable initialier
   private init() throws {
     ...
   }
}

EDIT:
If you want to try to recreate the object if it failed the last time you called the init, you can write something like this.

public class Manager {
    static var shared: Manager? {
        get {
            if instance == nil {
                instance = try? Manager()
            }
            return instance
        }
    }

    static private var instance: Manager? = try? Manager()

    // throwable initialier
    private init() throws {
        ...
    }
}


问:
Check if key exists in an array and replace its value
CLIENT CODE

I am sending an id of a client from the client side using

```<code>var socket = io.connect('http://localhost:8080?token='+userID);
</code>```

and getting it on the server in my io.on('connection')
function using

SERVER CODE

```<code>let token = socket.handshake.query.token;
</code>```

so now I have the userID stored in the variable token.

Also I am getting the connected socket id and storing it like

```<code>var id = socket.id;
</code>```

Then I am storing the userID and the socketID in an array as key value pair.

```<code>var item = {};
item[token] = id;
</code>```

This is an array I am pushing it into(the array is declared outside the on connection function)

```<code>keyPairArray.push(item);
</code>```

So I am getting an array like this when two people are connected.

```<code>[ { '10': 'HvlunYNFCcF5vK0-AAAA' },
  { '1456': '17XF7mbh4vYr2WUSAAAB' } ]
</code>```

But when any user reloads the page the array gets like

```<code>[ { '10': 'HvlunYNFCcF5vK0-AAAA' },
  { '1456': '17XF7mbh4vYr2WUSAAAB' },
  { '1456': 'tIhvkxFbSSAQEckWAAAC' } ]
</code>```

Same user Id but different socket id's.

The socket id changes every time the user reloads the page or opens the page in another tab and the same UserID is appended into the array with a different socket id.

I don't want to insert the same user again. If the user reloads the page, I want it to check the userId which is the key in the array and replace the old socket id with the newly generated one.

This is the code that I tried with no luck

```<code>var checkKeyPair = keyPairArray.some(function(item){
    return item[token] === id;
});

if(checkKeyPair){
    console.log("Hello");
}else{
    keyPairArray.push(item);
    console.log(keyPairArray);
}
</code>```

答:
You can combine Array#some with Object.keys to check if there is an user with given userId, something like that:

const users = [{
    '10': 'HvlunYNFCcF5vK0-AAAA'
  },
  {
    '1456': '17XF7mbh4vYr2WUSAAAB'
  }
];

function checkIfUserExists(userId) {
  return users.some((user) => Object.keys(user).indexOf(userId) > -1)
}

console.log(checkIfUserExists('10'));
console.log(checkIfUserExists('11'));```

Body:
CLIENT CODE

I am sending an id of a client from the client side using

var socket = io.connect('http://localhost:8080?token='+userID);

and getting it on the server in my io.on('connection')
function using

SERVER CODE

let token = socket.handshake.query.token;

so now I have the userID stored in the variable token.

Also I am getting the connected socket id and storing it like

var id = socket.id;

Then I am storing the userID and the socketID in an array as key value pair.

var item = {};
item[token] = id;

This is an array I am pushing it into(the array is declared outside the on connection function)

keyPairArray.push(item);

So I am getting an array like this when two people are connected.

[ { '10': 'HvlunYNFCcF5vK0-AAAA' },
  { '1456': '17XF7mbh4vYr2WUSAAAB' } ]

But when any user reloads the page the array gets like

[ { '10': 'HvlunYNFCcF5vK0-AAAA' },
  { '1456': '17XF7mbh4vYr2WUSAAAB' },
  { '1456': 'tIhvkxFbSSAQEckWAAAC' } ]

Same user Id but different socket id's.

The socket id changes every time the user reloads the page or opens the page in another tab and the same UserID is appended into the array with a different socket id.

I don't want to insert the same user again. If the user reloads the page, I want it to check the userId which is the key in the array and replace the old socket id with the newly generated one.

This is the code that I tried with no luck

var checkKeyPair = keyPairArray.some(function(item){
    return item[token] === id;
});

if(checkKeyPair){
    console.log("Hello");
}else{
    keyPairArray.push(item);
    console.log(keyPairArray);
}


问:
How to bypass "Visual Studio Just-In-Time Debugger" prompt
Visual Studio Just-In-Time Debugger prompts to select "Possible Debuggers",

only "New instance of Microsoft Visual Studio 2010" is available,

I tick "Set the currently selected debugger as the default", click "Yes",

but, the dialog keeps being displayed every time.

I am debugging JavaScript in IE8 on Windows 7 x64.

How do I bypass this prompt?

These registry values do not solve the problem:

[HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]

"Auto"="1"

[HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]

"Auto"="1"

答:
Have you tried doing so directly from Visual Studio?

http://msdn.microsoft.com/en-us/library/5hs4b7a6.aspx

Scroll to "Enabling or disabling Just-In-Time debugging".

You can disable it only for Script if that's what you want.

Let me know how this works for you.

ContentLicense: CC BY-SA 2.5


问:
what are most commonly used JMeter listeners
I am using JMeter for load testing and using listeners for getting the response results but I am not sure which are the most commonly used listeners which will give data for analysis.

I know Table view and tree view but those basic ones, kindly advice which listeners should I use.

答:
While executing the test better to avoid adding the listeners, only thing you can add simple data writer alone from that listeners you can generate any type listeners as you need.

while making the script ready you can use any type of listeners that will no be any issues.


问:
how prevent the parent click event on change a checkbox
I have a checkbox inside a parent container which has a click event, whenever I try to click the checkbox parent click works first and following by the change event, I am using e.stopPropagation(); on both the parent and child events, but still, it's not working

```<code>// make the .parent react
 function grandParent(){
    alert('Grand Parent: You hit me, my child or my grand child, now deal with me!');
}

// make the .parent react
$('.parent').on('click', function(e){
    e.stopPropagation()
    alert('Parent : Don\'t you dare hitting me or my child, again!');
});

// make the child cry, when we hit him.
$('.child').on('click', function(e){
e.stopPropagation();
 alert('Child : waaaaaa waaaa waa huh huh waaa waaaa!');
});

$('.hello').on('change', function(e){
e.stopPropagation();
 alert('checkbox clicked');
});
</code>```

Fiddle example

答: You have to bind the click event on the checkbox and not the change event: http://jsfiddle.net/ohc8jt6w/

Body:
I have a checkbox inside a parent container which has a click event, whenever I try to click the checkbox parent click works first and following by the change event, I am using e.stopPropagation(); on both the parent and child events, but still, it's not working

// make the .parent react
 function grandParent(){
    alert('Grand Parent: You hit me, my child or my grand child, now deal with me!');
}

// make the .parent react
$('.parent').on('click', function(e){
    e.stopPropagation()
    alert('Parent : Don\'t you dare hitting me or my child, again!');
});

// make the child cry, when we hit him.
$('.child').on('click', function(e){
e.stopPropagation();
 alert('Child : waaaaaa waaaa waa huh huh waaa waaaa!');
});

$('.hello').on('change', function(e){
e.stopPropagation();
 alert('checkbox clicked');
});

Fiddle example


问:
Run parallel simulations in remote unix cluster from matlab
I want to run simulations in parallel in a remote Cluster calling them from matlab.

I manage to run them in my local Ubuntu machine using.

```<code>unix('parallel -j4 flow > /dev/null :::: Pool.txt');
</code>```

But when I want it to run it in a remote cluster I really did not mange to make the parallel command to work.

The first problem was to avoid entering the password.

For that I used the sshpass as this

```<code>unix('sshpass -p password ssh user@cluster.example.com')
</code>```

That get me in to the server but it does not continue to the next command line.

I try so many commands that I do not want to reference here.

But basically can some one that understands well the parallel GNU command usage tell me how can I connect to a cluster. and run the simulations there.  is it better just to make a script at the server and run it from matlab?

Any expert advice is highly appreciated.

答:
Your problem is not with GNU Parallel but with configuring ssh. First, you must get ssh set up, then the rest is easy.

So, on your local Ubuntu machine, you need to create your keys:

```<code>ssh-keygen -t rsa -b 2048
</code>```

That will make some files in $HOME/.ssh. You now need to copy the public part of those keys to each and every node of the remote cluster where you want to run your parallel jobs:

```<code>ssh-copy-id -i $HOME/.ssh/id_rsa.pub CLUSTERUSERNAME@NODE-0
...
ssh-copy-id -i $HOME/.ssh/id_rsa.pub CLUSTERUSERNAME@NODE-15
</code>```

e.g.

```<code>ssh-copy-id -i $HOME/.ssh/id_rsa.pub fred@192.168.0.100
</code>```

Now, test you can ssh into each node:

```<code>ssh fred@node2
</code>```

Then, on your local Ubuntu box, set up your config file for ssh, so it will be $HOME/.ssh/config

```<code>Host node0
Hostname 192.168.0.100
User fred

...
...

Host node15
Hostname 192.168.0.115
User fred
</code>```

Now you can just use:

```<code>ssh node0
</code>```

and it will know that means fred@192.168.0.100

Now GNU Parallel will work with:

```<code>parallel -S node0,node1,node2
</code>```

Body:
I want to run simulations in parallel in a remote Cluster calling them from matlab.

I manage to run them in my local Ubuntu machine using.

unix('parallel -j4 flow > /dev/null :::: Pool.txt');

But when I want it to run it in a remote cluster I really did not mange to make the parallel command to work.

The first problem was to avoid entering the password.

For that I used the sshpass as this

unix('sshpass -p password ssh user@cluster.example.com')

That get me in to the server but it does not continue to the next command line.

I try so many commands that I do not want to reference here.

But basically can some one that understands well the parallel GNU command usage tell me how can I connect to a cluster. and run the simulations there.  is it better just to make a script at the server and run it from matlab?

Any expert advice is highly appreciated.

Body:
Your problem is not with GNU Parallel but with configuring ssh. First, you must get ssh set up, then the rest is easy.

So, on your local Ubuntu machine, you need to create your keys:

ssh-keygen -t rsa -b 2048

That will make some files in $HOME/.ssh. You now need to copy the public part of those keys to each and every node of the remote cluster where you want to run your parallel jobs:

ssh-copy-id -i $HOME/.ssh/id_rsa.pub CLUSTERUSERNAME@NODE-0
...
ssh-copy-id -i $HOME/.ssh/id_rsa.pub CLUSTERUSERNAME@NODE-15

e.g.

ssh-copy-id -i $HOME/.ssh/id_rsa.pub fred@192.168.0.100

Now, test you can ssh into each node:

ssh fred@node2

Then, on your local Ubuntu box, set up your config file for ssh, so it will be $HOME/.ssh/config

Host node0
Hostname 192.168.0.100
User fred

...
...

Host node15
Hostname 192.168.0.115
User fred

Now you can just use:

ssh node0

and it will know that means fred@192.168.0.100

Now GNU Parallel will work with:

parallel -S node0,node1,node2


问:
Stack Size Estimation
In multi-threaded embedded software (written in C or C++), a thread must be given enough stack space in order to allow it to complete its operations without overflowing.  Correct sizing of the stack is critical in some real-time embedded environments, because (at least in some systems I've worked with), the operating system will NOT detect this for you.

Usually, the stack size for a new thread (other than the main thread) is designated at the time that thread is created (i.e. in an argument to pthread_create() or the like).  Often, these stack sizes are hard-coded to values that are known to be good at the time the code was originally written or tested.

However, future changes to the code often break the assumptions on which the hard-coded stack sizes were based, and one fateful day, your thread enters one of the deeper branches of its call graph and overflows the stack -- bringing down the whole system or silently corrupting memory.

I have personally seen this problem in the case where code executed in the thread declares struct instances on the stack.  When the struct is augmented to hold additional data, the stack size inflates accordingly, potentially allowing stack overflows to occur.  I imagine this could be a huge problem for established codebases where the full effects of adding fields to a structure cannot be known immediately (too many threads/functions to find all the places where that struct is used).

Since the usual response to "stack sizing" questions is "they're not portable", let's assume that the compiler, operating system, and processor are all known quantities for this investigation.  Let's also assume recursion isn't used, so we're not dealing with the possibility an "infinite recursion" scenario.

What are some reliable ways to estimate the necessary stack size for a thread?  I'd prefer methods that are offline (static analysis) and automatic, but all ideas are welcome.

答: Not 100% sure, but I think this may also be done. If you have a jtag port exposed, you can connect to Trace32 and check the maximum stack usage. Though for this, you will have to give an initial pretty big arbitrary stack size.</p>

Title: Stack Size Estimation


问:
Recursive binary tree search isn't returning True when the node has been found
myTree is a list of lists in python that represents a binary tree. For each list within the list, element 0 represents the pointer to the left child, element 1 represents the value of the node, and element 2 represents the pointer to the right child.

```<code>myTree = [[1,50,2],[3,27,4],[9,62,10],[5,12,6],[7,35,8],[-1,9,-1],[-1,14,-1],[-1,28,-1],[-1,41,-1],[11,59,12],[13,71,-1],[-1,52,-1],[-1,60,-1],[-1,68,-1]]

def findNode(item,comparingNode):
    #print (comparingNode)
    comparingNode = myTree[comparingNode]
    if item == comparingNode[1]:
        print(comparingNode[1])
        return True #This is where it is supposed to return True

    elif item > comparingNode[1]:
        if comparingNode[2] != -1:
            print(comparingNode[0],comparingNode[1],comparingNode[2],"comp1")
            return findNode(item,comparingNode[2])
        else:
            return False

    else:
        if comparingNode[0] != -1:
            print(comparingNode[0],comparingNode[1],comparingNode[2],"comp2")
            findNode(item,comparingNode[0])
        else:
            return False

    #print(comparingNode[1])

if findNode(9,0) == True:
    print("found")
</code>```

When run, It doesn't produce an error message, and the program completes. The search has clearly found node 9 because, when run, it prints out 9 at the end. However, The function doesn't return True even though the debugger says it's visited the source line (line 9).

答:
You just forgot a return:

```<code>if comparingNode[0] != -1:
    print(comparingNode[0],comparingNode[1],comparingNode[2],"comp2")
    **** findNode(item,comparingNode[0])
else:
    return False
</code>```

Another note: you can test without doing == True:

```<code>if findNode(9,0):
    print("found")
</code>```

Body:
myTree is a list of lists in python that represents a binary tree. For each list within the list, element 0 represents the pointer to the left child, element 1 represents the value of the node, and element 2 represents the pointer to the right child.

myTree = [[1,50,2],[3,27,4],[9,62,10],[5,12,6],[7,35,8],[-1,9,-1],[-1,14,-1],[-1,28,-1],[-1,41,-1],[11,59,12],[13,71,-1],[-1,52,-1],[-1,60,-1],[-1,68,-1]]

def findNode(item,comparingNode):
    #print (comparingNode)
    comparingNode = myTree[comparingNode]
    if item == comparingNode[1]:
        print(comparingNode[1])
        return True #This is where it is supposed to return True

    elif item > comparingNode[1]:
        if comparingNode[2] != -1:
            print(comparingNode[0],comparingNode[1],comparingNode[2],"comp1")
            return findNode(item,comparingNode[2])
        else:
            return False

    else:
        if comparingNode[0] != -1:
            print(comparingNode[0],comparingNode[1],comparingNode[2],"comp2")
            findNode(item,comparingNode[0])
        else:
            return False

    #print(comparingNode[1])

if findNode(9,0) == True:
    print("found")

When run, It doesn't produce an error message, and the program completes. The search has clearly found node 9 because, when run, it prints out 9 at the end. However, The function doesn't return True even though the debugger says it's visited the source line (line 9).

Body:
You just forgot a return:

if comparingNode[0] != -1:
    print(comparingNode[0],comparingNode[1],comparingNode[2],"comp2")
    **** findNode(item,comparingNode[0])
else:
    return False

Another note: you can test without doing == True:

if findNode(9,0):
    print("found")


问:
How to access model attribute in html page in Spring MVC?
I have Spring MVC project where the views are html pages. I am setting model attribute in my Controller method but unable to access it on html view page.

Here is my Controller method.

```<code>@RequestMapping(value = "/", method = RequestMethod.GET)
 public ModelAndView getData() {

  ModelAndView model =new ModelAndView();
  model.addObject("name", "Jack");
  model.setViewName("html/firstLayer.html");
  return model;

 }
</code>```

This is how i am accessing it in my html page

```<code><script type="text/javascript">
    var name1 ='${name}' ;
    console.log(name1);
 </script>
</code>```

But on console it is printing ${name}, it should print Jack.
Any help will be appreciated , Thanks.

答:
in html we can use model value. so when document is loaded then name will present as hidden field in page. and using javascript or jquery we can access it. Here is an example:</p>

```<code><input type="hidden" id="name" value='${name}'/>

<script type="text/javascript">
    var name"1 = $(#name).val();
    console.log(name1);
 </script>
</code>```

Body:
I have Spring MVC project where the views are html pages. I am setting model attribute in my Controller method but unable to access it on html view page.

Here is my Controller method.

@RequestMapping(value = "/", method = RequestMethod.GET)
 public ModelAndView getData() {

  ModelAndView model =new ModelAndView();
  model.addObject("name", "Jack");
  model.setViewName("html/firstLayer.html");
  return model;

 }

This is how i am accessing it in my html page

But on console it is printing ${name}, it should print Jack.
Any help will be appreciated , Thanks.

Body:
in html we can use model value. so when document is loaded then name will present as hidden field in page. and using javascript or jquery we can access it. Here is an example:

<input type="hidden" id="name" value='${name}'/>

<script type="text/javascript">
    var name"1 = $(#name).val();
    console.log(name1);
 </script>


问:
update action of a RESTful route in Rails (PATCH or PUT)
I am a newbie to Ruby on Rails.why is the update action of a RESTful route in Rails is mapped to two HTTP verbs i.e, PATCH and PUT?

```<code>   PATCH  /articles/:id(.:format)      articles#update
   PUT    /articles/:id(.:format)      articles#update
</code>```

Which Method among the two is called when I update a resource(general CRUD )?

答:
It's done to follow HTTP standard for request types.

How @Mikhail mentioned, conceptually:

PATCH is a proper request type, when you want to update only part of
your object

PUT is a standard way when you like fully overwrite your object with
new data

While in Rails both of this can be easily done with single update action and the difference is just in passed params, then Rails makes two routes to cover standards, but there is no real need in making 2 different controller action for that.

As I know Rails uses PUT as default, but you can use any of them. Just follow mentioned conceptual rule

Body:
I am a newbie to Ruby on Rails.why is the update action of a RESTful route in Rails is mapped to two HTTP verbs i.e, PATCH and PUT?

   PATCH  /articles/:id(.:format)      articles#update
   PUT    /articles/:id(.:format)      articles#update

Which Method among the two is called when I update a resource(general CRUD )?


问:
When I build Xamarin solution I see: "javac.exe" exited with code 2 error
I just created a new Xamarin solution in visual studio. Here is how the solution looks like:

And when I try to build, it shows the following error:

"javac.exe" exited with code 2.

Here is the error logs in output window:

1>------ Rebuild All started: Project: App2.Droid, Configuration:
  Debug Any CPU ------ 1>C:\Program Files
  (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(605,2):
  warning : Failed to get the Java SDK version. Found java version
  "9.0.1" 1>C:\Program Files
  (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(605,2):
  warning : Java(TM) SE Runtime Environment (build 9.0.1+11)
  1>C:\Program Files
  (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(605,2):
  warning : Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed
  mode) 1>C:\Program Files
  (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(605,2):
  warning :  but this does not seem to contain a valid version number.
  1>  App2.Droid -> C:\Users\abaig\documents\visual studio
  2015\Projects\App2\App2\App2.Droid\bin\Debug\App2.Droid.dll
  1>C:\Program Files
  (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1914,3):
  error MSB6006: "javac.exe" exited with code 2.
  ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Any Idea what could be wrong?

答: try to enable your multidex, go to yourandroidproject > rightclick > properties > Android options and click enable Multi-Dex</p>


问:
sed delete all occurences of pattern in each line
The following command doesn't repeat the process for each occurence in one line...

input_file.txt :

```<code><!--:nl-->hond <span>bob</span><!--:fr-->chien <span>bob</span><!--:nl-->kat<!--:fr-->chat
<!--:nl-->hond<!--:fr-->chien<!--:nl-->kat<!--:fr-->chat
</code>```

wrong sed command :

```<code>sed -e 's/\(\<\!--\:nl\--\>\).*\(\<\!--\:fr\--\>\)/\1\2/g' input_file.txt > output_file.txt
</code>```

current output_file.txt result :

```<code><!--:nl--><!--:fr-->chat
</code>```

desired output_file.txt result :

```<code>chien <span>bob</span>chat
chienchat
</code>```

[EDIT] hond, chien, kat and chat may have HTML tags around them that need to be kept...

答:
Following awk may also help you in same.

```<code>awk -F'<!--:nl-->|<!--:fr-->' '{print $3$5}'   Input_file
</code>```

Explanation: Simply making strings  OR  as field separators and then printing 3rd and 5th columns of the line(as per your output required).

Body:
The following command doesn't repeat the process for each occurence in one line...

input_file.txt :

hond bobchien bobkatchat
hondchienkatchat

wrong sed command :

sed -e 's/\(\<\!--\:nl\--\>\).*\(\<\!--\:fr\--\>\)/\1\2/g' input_file.txt > output_file.txt

current output_file.txt result :

chat

desired output_file.txt result :

chien bobchat
chienchat

[EDIT] hond, chien, kat and chat may have HTML tags around them that need to be kept...

Body:
Following awk may also help you in same.

awk -F'<!--:nl-->|<!--:fr-->' '{print $3$5}'   Input_file

Explanation: Simply making strings <!--:nl--> OR <!--:fr--> as field separators and then printing 3rd and 5th columns of the line(as per your output required).


问:
android.view.InflateException when extending AppCompatSpinner
I have successfully created custom views in the past extending LinearLayout or android.support.v7.widget.CardView, however I can't seem to get it working when extending from android.support.v7.widget.AppCompatSpinner. I don't see why it is a problem for this specific class so I must be overlooking something.

I have the following class CustomSpinner

```<code>public class CustomSpinner extends android.support.v7.widget.AppCompatSpinner {

    public CustomSpinner(Context context)
    {
       this(context, null);
    }

    public CustomSpinner(Context context, AttributeSet attrs)
    {
       super(context, attrs);
       init(context, attrs, 0);
    }

    public CustomSpinner(Context context, AttributeSet attrs, int defStyle)
    {
       super(context, attrs, defStyle);
       init(context, attrs, defStyle);
    }

    private void init(Context context, AttributeSet attrs, int defStyle)
    {
       LayoutInflater inflater = LayoutInflater.from(context);
       inflater.inflate(R.layout.view_custom_spinner, this);
    }
}
</code>```

And the R.layout.view_custom_spinner

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.AppCompatSpinner
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_custom_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="@dimen/minimum_clickable_area"
    android:gravity="center_vertical"/>
</code>```

And I use the custom component in another layout for 'MyFragment' like this (line #11 mentioned in the stacktrace):

```<code><my.custom.namespace.CustomSpinner
    android:id="@+id/view_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
</code>```

The strange thing is that when I extend the CustomSpinner class from LinearLayout everything is working fine and I don't get an InflateException.

I get the following stacktrace:

```<code>java.lang.RuntimeException: Unable to start activity ComponentInfo{my.custom.namespace.MyActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #11: Error inflating class my.custom.namespace.CustomSpinner
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3320)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #11: my.custom.namespace.CustomSpinner
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class my.custom.namespace.CustomSpinner
                                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: java.lang.reflect.InvocationTargetException
                                                                         at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:631)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file l
</code>```

答:
I don't get why you are inflating the layout of the spinner. The spinner has its own layout by itself, you don't need to create the xml with a spinner inside. For linear layout it makes sense to inflate your own layout beacause it's a ViewGroup and inside your custom view class you can bind the linear layout's children, but for the spinner simply work on the spinner layout elements, using your custom view attributes to edit the layout.
In summary, you can't add children to a spinner layout, so it doesn't make sense to inflate a custom xml for it. Simply remove
LayoutInflater inflater = LayoutInflater.from(context);
inflater.inflate(R.layout.view_custom_spinner, this);
from your code and you'll have a perfectly working class extending the spinner.

Body:
I have successfully created custom views in the past extending LinearLayout or android.support.v7.widget.CardView, however I can't seem to get it working when extending from android.support.v7.widget.AppCompatSpinner. I don't see why it is a problem for this specific class so I must be overlooking something.

I have the following class CustomSpinner

public class CustomSpinner extends android.support.v7.widget.AppCompatSpinner {

    public CustomSpinner(Context context)
    {
       this(context, null);
    }

    public CustomSpinner(Context context, AttributeSet attrs)
    {
       super(context, attrs);
       init(context, attrs, 0);
    }

    public CustomSpinner(Context context, AttributeSet attrs, int defStyle)
    {
       super(context, attrs, defStyle);
       init(context, attrs, defStyle);
    }

    private void init(Context context, AttributeSet attrs, int defStyle)
    {
       LayoutInflater inflater = LayoutInflater.from(context);
       inflater.inflate(R.layout.view_custom_spinner, this);
    }
}

And the R.layout.view_custom_spinner

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.AppCompatSpinner
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/view_custom_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="@dimen/minimum_clickable_area"
    android:gravity="center_vertical"/>

And I use the custom component in another layout for 'MyFragment' like this (line #11 mentioned in the stacktrace):

<my.custom.namespace.CustomSpinner
    android:id="@+id/view_spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

The strange thing is that when I extend the CustomSpinner class from LinearLayout everything is working fine and I don't get an InflateException.

I get the following stacktrace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{my.custom.namespace.MyActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #11: Error inflating class my.custom.namespace.CustomSpinner
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3320)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #11: my.custom.namespace.CustomSpinner
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class my.custom.namespace.CustomSpinner
                                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:657)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: java.lang.reflect.InvocationTargetException
                                                                         at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:631)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1001)
                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:843)
                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
                                                                         at my.custom.namespace.MyFragment.onCreateView(MyFragment.java:183)
                                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2261)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819)
                                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
                                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
                                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3231)
                                                                         at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3181)
                                                                         at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:192)
                                                                         at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:572)
                                                                         at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
                                                                         at my.custom.namespace.BaseActivity.onStart(BaseActivity.java:258)
                                                                         at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                                                                         at android.app.Activity.performStart(Activity.java:6943)
                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                                                                         at android.app.ActivityThread.access$1100(ActivityThread.java:229)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                         at android.os.Looper.loop(Looper.java:148)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:7407)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
                                                                      Caused by: android.view.InflateException: Binary XML file l


问:
CSS Computed width different from specified
As shown in this bin the width specified for the preview button is 120 px while the rendered width is always 132 px (on different screens).

.btn-grey{
    cursor: pointer;
    background: #f1f3f6;
    border: 1px solid #d7d9e1;
    box-shadow: 1px 1px 1px #fff inset;
    border-radius: 3px;
    color: #838AAB;
    display: inline-block;
    height: 30px;
    padding: 0 5px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
            <div style="display: flex; width: 60%; justify-content: center;">
                <input name="preview" class="btn-grey" value="Preview" style="flex-basis: 120px; width: 120px; height: 35px;max-width: 120px; max-height: 35px; margin : 5px 5px 5px 5px " title="preview"/>
                <input name="load" class="btn-grey" type="submit" value="Load " style="width: 120px; height: 35px;max-width: 120px; max-height: 35px;margin : 5px 5px 5px 5px "/>
            </div>

</body>
</html></code>```

答:
All you need is to add box-sizing: border-box to the input.

The reason is that an elements box-sizing defaults to content-box, which mean its padding/border by default adds to its set width, and with box-sizing: border-box it gets computed within it.

Src: https://drafts.csswg.org/css-box-3/#width-and-height

As a note, another option would be to use CSS Calc(), like this:

width: calc(wanted_width - left/right_padding - left/right_border)

Stack snippet

input {
  box-sizing:border-box
}

.btn-grey{
    cursor: pointer;
    background: #f1f3f6;
    border: 1px solid #d7d9e1;
    box-shadow: 1px 1px 1px #fff inset;
    border-radius: 3px;
    color: #838AAB;
    display: inline-block;
    height: 30px;
    padding: 0 5px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
            <div style="display: flex; width: 60%; justify-content: center;">
                <input name="preview" class="btn-grey" value="Preview" style="flex-basis: 120px; width: 120px; height: 35px;max-width: 120px; max-height: 35px; margin : 5px 5px 5px 5px " title="preview"/>
                <input name="load" class="btn-grey" type="submit" value="Load " style="width: 120px; height: 35px;max-width: 120px; max-height: 35px;margin : 5px 5px 5px 5px "/>
            </div>

</body>
</html></code>```

Body:
As shown in this bin the width specified for the preview button is 120 px while the rendered width is always 132 px (on different screens).

.btn-grey{
    cursor: pointer;
    background: #f1f3f6;
    border: 1px solid #d7d9e1;
    box-shadow: 1px 1px 1px #fff inset;
    border-radius: 3px;
    color: #838AAB;
    display: inline-block;
    height: 30px;
    padding: 0 5px;
}

<!DOCTYPE html>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>

                <input name="preview" class="btn-grey" value="Preview" style="flex-basis: 120px; width: 120px; height: 35px;max-width: 120px; max-height: 35px; margin : 5px 5px 5px 5px " title="preview"/>
                <input name="load" class="btn-grey" type="submit" value="Load " style="width: 120px; height: 35px;max-width: 120px; max-height: 35px;margin : 5px 5px 5px 5px "/>

Body:
All you need is to add box-sizing: border-box to the input.

The reason is that an elements box-sizing defaults to content-box, which mean its padding/border by default adds to its set width, and with box-sizing: border-box it gets computed within it.

Src: https://drafts.csswg.org/css-box-3/#width-and-height

As a note, another option would be to use CSS Calc(), like this:

width: calc(wanted_width - left/right_padding - left/right_border)

Stack snippet

input {
  box-sizing:border-box
}

.btn-grey{
    cursor: pointer;
    background: #f1f3f6;
    border: 1px solid #d7d9e1;
    box-shadow: 1px 1px 1px #fff inset;
    border-radius: 3px;
    color: #838AAB;
    display: inline-block;
    height: 30px;
    padding: 0 5px;
}

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
            <div style="display: flex; width: 60%; justify-content: center;">
                <input name="preview" class="btn-grey" value="Preview" style="flex-basis: 120px; width: 120px; height: 35px;max-width: 120px; max-height: 35px; margin : 5px 5px 5px 5px " title="preview"/>
                <input name="load" class="btn-grey" type="submit" value="Load " style="width: 120px; height: 35px;max-width: 120px; max-height: 35px;margin : 5px 5px 5px 5px "/>
            </div>

</body>
</html>


问:
How to mock `current_user` in flask templates?
I want to mock flask-login's current_user under the template rendering. This function return the current logged user.

Right now I'm mocking the  AnnonymousUserMixin from flask-login which is returned by default if the user is not authenticated. But this leads to all kind of juggles. If I could simply mock current_user I would be able to create a Mocked object for it to return.

Here a sample of what I'm using today:

```<code>import unnittest
from flask_login.mixins import AnonymousUserMixin

class TestFoo(unittest.TestCase):
    @patch.object(AnonymousUserMixin, 'is_admin', create=True,
                  return_value=False)
    @patch.object(AnonymousUserMixin, 'is_authenticated',  return_value=True)
    def test_user_restriction(self, *args):
        ...
</code>```

Regards,

答:
I found this tutorial  interesting in the section The Test.

It says this:

current_user needs to be accessed within the context of a request (it
  is a thread-local object, just like flask.request). When
  self.client.post completes the request and every thread-local object
  is torn down. We need to preserve the request context so we can test
  our integration with Flask-Login. Fortunately, Flask’s test_client is
  a context manager, which means that we can use it in a with a statement
  and it will keep the context around as long as we need it:

So in simple words, you can log in your user via post request and the current_user object will be available and then you can test everything you want in the code.

Here is an example:

```<code>with self.client:
    response = self.client.post(url_for('users.login'),
                                data={'email': 'joe@joes.com', 'password': '12345'})

    self.assert_redirects(response, url_for('index'))
    self.assertTrue(current_user.name == 'Joe')
    self.assertFalse(current_user.is_anonymous())
</code>```

Body:
I want to mock flask-login's current_user under the template rendering. This function return the current logged user.

Right now I'm mocking the  AnnonymousUserMixin from flask-login which is returned by default if the user is not authenticated. But this leads to all kind of juggles. If I could simply mock current_user I would be able to create a Mocked object for it to return.

Here a sample of what I'm using today:

import unnittest
from flask_login.mixins import AnonymousUserMixin

class TestFoo(unittest.TestCase):
    @patch.object(AnonymousUserMixin, 'is_admin', create=True,
                  return_value=False)
    @patch.object(AnonymousUserMixin, 'is_authenticated',  return_value=True)
    def test_user_restriction(self, *args):
        ...

Regards,

Body:
I found this tutorial  interesting in the section The Test.

It says this:

current_user needs to be accessed within the context of a request (it
  is a thread-local object, just like flask.request). When
  self.client.post completes the request and every thread-local object
  is torn down. We need to preserve the request context so we can test
  our integration with Flask-Login. Fortunately, Flask’s test_client is
  a context manager, which means that we can use it in a with a statement
  and it will keep the context around as long as we need it:

So in simple words, you can log in your user via post request and the current_user object will be available and then you can test everything you want in the code.

Here is an example:

with self.client:
    response = self.client.post(url_for('users.login'),
                                data={'email': 'joe@joes.com', 'password': '12345'})

    self.assert_redirects(response, url_for('index'))
    self.assertTrue(current_user.name == 'Joe')
    self.assertFalse(current_user.is_anonymous())

ContentLicense: CC BY-SA 4.0


问:
Creating comments in Cordova config.xml file
I'm trying to create comments in cordova's config.xml to explain what the various options included in there actually do, but every time I build the project the comments get stripped out.  Is there a way of making sure they stay?</p>

答:
Instead of adding a xml comment  you can try to add extra xml attribute to the xml tags.

The idea is to use an attribute that will be ignored by cordova but that should be kept when building.

(I have not checked if it's kept when adding plugins or other usages of the CLI)

ie:

```<code><platform comment="Settings for android platform" name="android">
    <preference comment="Set the minimum version of android for this app" name="android-minSdkVersion" value="16" />
</code>```

note that comment is not a cordova keyword and that you'll have the same result with any keyword that's unknown to Cordova.

Body:
Instead of adding a xml comment <!-- --> you can try to add extra xml attribute to the xml tags.

The idea is to use an attribute that will be ignored by cordova but that should be kept when building.

(I have not checked if it's kept when adding plugins or other usages of the CLI)

ie:

<platform comment="Settings for android platform" name="android">
    <preference comment="Set the minimum version of android for this app" name="android-minSdkVersion" value="16" />

note that comment is not a cordova keyword and that you'll have the same result with any keyword that's unknown to Cordova.


问:
Why isn't knownfolders works in winrt? Am I missing something?
I'm working on a UWP project with a background Task involved.  The background task needs to check a specific file on the document library.

This code works perfectly.

```<code>  try
    {
        StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
        SendToast(file.Path + file.Name + " - File Present");
    }
catch
    {
        SendToast("Not Found");
    }
</code>```

This one doesn't

```<code>  try
    {
        StorageFile file = await KnownFolders.DocumentsLibrary.GetFileAsync(fileName);
        SendToast(file.Path + file.Name + " - File Present");
    }
catch
    {
        SendToast("Not Found");
    }
</code>```

I have also add the document library capability in the Package.appxmanifest

```<code>  <Capabilities>
    <Capability Name="internetClient" />
    <uap:Capability Name="documentsLibrary" />
  </Capabilities>
</code>```

and this

```<code><uap:Extension Category="windows.fileTypeAssociation">
  <uap:FileTypeAssociation Name=".txt">
    <uap:DisplayName>Text</uap:DisplayName>
    <uap:SupportedFileTypes>
      <uap:FileType>.log</uap:FileType>
    </uap:SupportedFileTypes>
  </uap:FileTypeAssociation>
</uap:Extension>
</code>```

Am I missing something here?

答:
UWP apps run sandboxed and have very limited access to the file system, StorageItems(i.e. StorageFolder and StorageFile) are the canonical storage identifiers for Windows Store apps, not the path.

The data that are stored in our local folder (ApplicationData.Current.LocalFolder), we can use the path, but if you use the DocumentsLibrary,MusicLibrary, we can not use the path to access the file, it refers to a non file-system location and The DocumentsLibrary capability does not grant the app direct file system access. See File access permissions and Rob's blog to learn more about file access and using path in Windows store apps.

Body:
I'm working on a UWP project with a background Task involved.  The background task needs to check a specific file on the document library.

This code works perfectly.

  try
    {
        StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
        SendToast(file.Path + file.Name + " - File Present");
    }
catch
    {
        SendToast("Not Found");
    }

This one doesn't

  try
    {
        StorageFile file = await KnownFolders.DocumentsLibrary.GetFileAsync(fileName);
        SendToast(file.Path + file.Name + " - File Present");
    }
catch
    {
        SendToast("Not Found");
    }

I have also add the document library capability in the Package.appxmanifest

  <Capabilities>
    <Capability Name="internetClient" />
    <uap:Capability Name="documentsLibrary" />
  </Capabilities>

and this

<uap:Extension Category="windows.fileTypeAssociation">
  <uap:FileTypeAssociation Name=".txt">
    <uap:DisplayName>Text</uap:DisplayName>
    <uap:SupportedFileTypes>
      <uap:FileType>.log</uap:FileType>
    </uap:SupportedFileTypes>
  </uap:FileTypeAssociation>
</uap:Extension>

Am I missing something here?


问:
Android Twitter open source client
Where can I get the code of a Twitter client for Android? Possibly a recent one using the latest SDK. Thanks</p>

答: You can start here: Source Forge - Twitter for Android</p>

Title: Android Twitter open source client


问:
OrientDB - convert String to Link in queries
I have a map where the KEYS (although of type string) are meant to be LINKS (e.g. "#1:1", "#1:2") and I want to somehow be able to convert those string keys to LINKS and directly use them in queries.

E.g.

```<code>select  *  from  CONVERT_TO_LINK( myMap.keys()[0] )
</code>```

How can I do such a conversion?

Thanks

答: Why not using select  *  from myMap.keys()[0].convert('LINK') built-in method?

Body:
I have a map where the KEYS (although of type string) are meant to be LINKS (e.g. "#1:1", "#1:2") and I want to somehow be able to convert those string keys to LINKS and directly use them in queries.

E.g.

select  *  from  CONVERT_TO_LINK( myMap.keys()[0] )

How can I do such a conversion?

Thanks


问:
How to use nofollow link in script tag
This is my script code:

```

I want to make crawler not to follow or index example.com/js/infolinks_main.js.

How can I do this task? I have robots.txt in my root, but that URL is an external URL.

NB: I do not want to use iframe.

答:
rel=nofollow only applies to hyperlinks, there's no point in adding it to any other kind of element.

If your scripts create links, you could edit the script to ensure that they do so with a rel=nofollow attribute; but given that the google bot does not execute scripts when reading a page, there's no real point in doing so.

Title: How to use nofollow link in script tag

Body:
This is my script code:

I want to make crawler not to follow or index example.com/js/infolinks_main.js.

How can I do this task? I have robots.txt in my root, but that URL is an external URL.

NB: I do not want to use iframe.


问:
Create json array format in android
I want to create json request string. How can I do that? This is my following array:

```<code>[1,2,3,4,5];
</code>```

Now I want to create this type of json request:

```<code>{
    "contact_approve":[
    {
    "contact_id":1
    },
    {
    "contact_id":2
    },
    {
    "contact_id":3
    },
    {
    "contact_id":4
    },
    {
    "contact_id":5
    },
    ]

}
</code>```

Does anyone has the idea about how to create this type of json string?

答:
Try This

```<code>try{

JSONArray jarray=new JSonArray();

for(int i=0;i<array.size();i++){

JSONObject j=new JSONObject();
j.put("contact_id",array[i]);

jarray.put(j);

}
}catch(Exception e){

e.printStackStrace();

}
</code>```

Title: Create json array format in android

Body:
I want to create json request string. How can I do that? This is my following array:

[1,2,3,4,5];

Now I want to create this type of json request:

{
    "contact_approve":[
    {
    "contact_id":1
    },
    {
    "contact_id":2
    },
    {
    "contact_id":3
    },
    {
    "contact_id":4
    },
    {
    "contact_id":5
    },
    ]

}

Does anyone has the idea about how to create this type of json string?

Body:
Try This

try{

JSONArray jarray=new JSonArray();

for(int i=0;i<array.size();i++){

JSONObject j=new JSONObject();
j.put("contact_id",array[i]);

jarray.put(j);

}
}catch(Exception e){

e.printStackStrace();

}


问:
What is this JavaScript construct called
I've found a JavaScript arrow function that looks something like this:

```<code>([a,b,c]) => {
  a = 1;
  b = 2;
  c = 'x';
}
</code>```

How is this function invoked? Also, what is this construct called?

答:
This is an arrow function, which gets an array as a parameter and destruct the first 3 values into the corresponding parameters - a,b,c. But it must be assigned to a variable or be self invoked.

() => {} - Arrow function

[a,b,c] - Array destructuring

Example

const func = ([a,b,c]) => {
  console.log(a);
  console.log(b);
  console.log(c);
};

func([1,2,3,4]);```

Body:
I've found a JavaScript arrow function that looks something like this:

([a,b,c]) => {
  a = 1;
  b = 2;
  c = 'x';
}

How is this function invoked? Also, what is this construct called?


问:
Run docker run command in python script
I need to run following command inside python script to remove all exisiting docker services

```<code>import subprocess
bashCommand = "docker service rm $(docker service ls)"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE,  shell=True)
</code>```

This is not giving desired results. Services still exists after running this file.
I am using centos

答:
Have a look at this library :

You could loop all services through services.list() and rm them with service.remove()

Title: Run docker run command in python script

Body:
I need to run following command inside python script to remove all exisiting docker services

import subprocess
bashCommand = "docker service rm $(docker service ls)"
process = subprocess.Popen(bashCommand, stdout=subprocess.PIPE,  shell=True)

This is not giving desired results. Services still exists after running this file.
I am using centos


问:
Require following dll . for creating Windows application setup wizard
I want to create a setup wizard using C#.NET. I am not getting the following DLLs and would like help getting them:</p>

```<code>UtilityLibrary.Designers.dll
UtilityLibrary.Win32.WindowsAPI.dll
</code>```

答: First check your bin directory. if it is not there, than get a copy of ddl from GAC as described here</p>

Body:
I want to create a setup wizard using C#.NET. I am not getting the following DLLs and would like help getting them:

UtilityLibrary.Designers.dll
UtilityLibrary.Win32.WindowsAPI.dll


答:
```<code>([a, b, c]) => {}
</code>```

The first part is a destructuring assignment in the parameters, which takes an array as parameter and returns the variables with the values of the position.

The later assignment makes no sense with the given code.

Title: What is this JavaScript construct called

Body:
([a, b, c]) => {}

The first part is a destructuring assignment in the parameters, which takes an array as parameter and returns the variables with the values of the position.

The later assignment makes no sense with the given code.


问:
Href link to google map marker from outside the map
I have a website with google map embedded in it, and there is a div with a set of hrefs which I would like to point to certain coordinates on the map.

I have searched online but couldn't find much help.
I don't want to open the lat and long in another window using something like this - https://www.google.com/maps/?q=-15.623037,18.388672

If you see the image below, I want to have links in the div on the right(links will be fetched dynamically), and those links will point to the markers on the map and display an info window

Any help is appreciated thanks.

答:
When creating markers, add them

custom 'id'

data to be able to find them later:

```<code>var marker0 = createMarker({
    position: new google.maps.LatLng(33.808678, -117.918921),
    map: map,
    id: "m0",
    icon: "http://1.bp.blogspot.com/_GZzKwf6g1o8/S6xwK6CSghI/AAAAAAAAA98/_iA3r4Ehclk/s1600/marker-green.png"
  });
</code>```

Push all markers into array:

markers.push(marker0);

Generate links based on markers array and add

custom 'id'

to them:

```<code>function fillLinks(){
    var d1 = document.getElementById('markers_div');
    markers.forEach(function(marker) {
        d1.insertAdjacentHTML('beforeend', '<a href="#" onclick="linkClick(\''+marker["id"]+'\')">'+marker["id"]+'</a><br/>');
  });
}
</code>```

When clicking the link, use custom 'id' to center map based on lat and lng of marker:

```<code>function linkClick(markerId){
    for (let marker of markers) {
       if(marker['id'] == markerId){
          center(marker.getPosition().lat(), marker.getPosition().lng() );
          marker.info.open(map, marker);
       } else {
          marker.info.close(map, marker);
       }
    }
}

function center(lat, lng){
    map.setCenter({lat:lat, lng:lng});
}
</code>```

Working fiddle: http://jsfiddle.net/4mtyu/3315/

Body:
When creating markers, add them

custom 'id'

data to be able to find them later:

var marker0 = createMarker({
    position: new google.maps.LatLng(33.808678, -117.918921),
    map: map,
    id: "m0",
    icon: "http://1.bp.blogspot.com/_GZzKwf6g1o8/S6xwK6CSghI/AAAAAAAAA98/_iA3r4Ehclk/s1600/marker-green.png"
  });

Push all markers into array:

markers.push(marker0);

Generate links based on markers array and add

custom 'id'

to them:

function fillLinks(){
    var d1 = document.getElementById('markers_div');
    markers.forEach(function(marker) {
        d1.insertAdjacentHTML('beforeend', '<a href="#" onclick="linkClick(\''+marker["id"]+'\')">'+marker["id"]+'</a><br/>');
  });
}

When clicking the link, use custom 'id' to center map based on lat and lng of marker:

function linkClick(markerId){
    for (let marker of markers) {
       if(marker['id'] == markerId){
          center(marker.getPosition().lat(), marker.getPosition().lng() );
          marker.info.open(map, marker);
       } else {
          marker.info.close(map, marker);
       }
    }
}

function center(lat, lng){
    map.setCenter({lat:lat, lng:lng});
}

Working fiddle: http://jsfiddle.net/4mtyu/3315/