问:
How could i make a div with rounded borders and make the fa icons inside it centered?
So i want a div with rounded borders (to make a circle) and inside that i want my fa icons which would be aligned to the middle.

So basically i want a Circle containing an fa icon in the middle just to make it simple.

.normal-page {
  padding-top: 30px;
}

body .normal-page {
  z-index: 998;
  position: relative;
  padding-bottom: 10px;
  background: url(../images/tpbg.jpg) top center no-repeat #141416;
  border: 1px solid #000;
  border-top: 0;
  min-height: 500px;
}

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.vote-container {
  text-align: center;
  padding-left: 30px;
  padding-right: 30px;
  color: #fff;
}

.vote-fa {
  color: #ff8800;
  margin-bottom: 20px;
}

.vote-container a {
  cursor: pointer;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="normal-page">
  <div class="container">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <i class="fa fa-handshake-o fa-3x vote-fa" aria-hidden="true"></i>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
    </div>
  </div>
</div></code>```

答:
You need to wrap your icons with a div tag

Here you can go with this code.

It may helpful to you.

.normal-page {
  padding-top: 30px;
}

body .normal-page {
  z-index: 998;
  position: relative;
  padding-bottom: 10px;
  background: url(../images/tpbg.jpg) top center no-repeat #141416;
  border: 1px solid #000;
  border-top: 0;
  min-height: 500px;
}

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.vote-container {
  text-align: center;
  padding-left: 30px;
  padding-right: 30px;
  color: #fff;
}

.vote-fa {
  color: #ff8800;
  margin-bottom: 20px;
}

.vote-container a {
  cursor: pointer;
}

.vote-container .icons {
 border-radius: 50%;
 height: 65px;
 width: 65px;
 border: 2px solid #fff;
 line-height: 60px;
 margin-bottom: 10px;
}
.vote-container .icons i {
line-height: 60px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="normal-page">
  <div class="container">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <div class="icons">
          <i class="fa fa-handshake-o fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          Click here to vote!
        </div>
      </div>
    </div>
  </div>
</div></code>```

Body:
So i want a div with rounded borders (to make a circle) and inside that i want my fa icons which would be aligned to the middle.

So basically i want a Circle containing an fa icon in the middle just to make it simple.

.normal-page {
  padding-top: 30px;
}

body .normal-page {
  z-index: 998;
  position: relative;
  padding-bottom: 10px;
  background: url(../images/tpbg.jpg) top center no-repeat #141416;
  border: 1px solid #000;
  border-top: 0;
  min-height: 500px;
}

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.vote-container {
  text-align: center;
  padding-left: 30px;
  padding-right: 30px;
  color: #fff;
}

.vote-fa {
  color: #ff8800;
  margin-bottom: 20px;
}

.vote-container a {
  cursor: pointer;
}

<link href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.

          Click here to vote!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.

          Click here to vote!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.

          Click here to vote!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.

          Click here to vote!

Body:
You need to wrap your icons with a div tag

Here you can go with this code.

It may helpful to you.

.normal-page {
  padding-top: 30px;
}

body .normal-page {
  z-index: 998;
  position: relative;
  padding-bottom: 10px;
  background: url(../images/tpbg.jpg) top center no-repeat #141416;
  border: 1px solid #000;
  border-top: 0;
  min-height: 500px;
}

.container {
  padding-right: 15px;
  padding-left: 15px;
  margin-right: auto;
  margin-left: auto;
}

.vote-container {
  text-align: center;
  padding-left: 30px;
  padding-right: 30px;
  color: #fff;
}

.vote-fa {
  color: #ff8800;
  margin-bottom: 20px;
}

.vote-container a {
  cursor: pointer;
}

.vote-container .icons {
 border-radius: 50%;
 height: 65px;
 width: 65px;
 border: 2px solid #fff;
 line-height: 60px;
 margin-bottom: 10px;
}
.vote-container .icons i {
line-height: 60px;
}

<link href="https://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="normal-page">
  <div class="container">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
          <div class="icons">
          <i class="fa fa-handshake-o fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          <a href="#">Click here to vote!</a>
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          <a href="#">Click here to vote!</a>
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          <a href="#">Click here to vote!</a>
        </div>
      </div>
      <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
        <div class="vote-container">
        <div class="icons">
          <i class="fa fa-superpowers fa-3x vote-fa" aria-hidden="true"></i>
          </div>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu risus vitae metus rhoncus tincidunt eu a lorem.</p><br>
          <a href="#">Click here to vote!</a>
        </div>
      </div>
    </div>
  </div>
</div>


来源: stackexchange

问:
How can I disable the Close button of a waitbar in MATLAB?
I want to create a waitbar that should be processed without any interruption. How can I achieve this?

I have tried setting

```<code>h=waitbar(0,'please wait','CreateCancelBtn','setappdata(gcbf,''Cancel'',0)');
</code>```

This disables the Close button on the waitbar, but it also shows me a Cancel button too. I don't want that button.

答:
When you use the CreateCancelBtn option of waitbar, it creates a Cancel button, takes the string you supply, and then sets that string to be both the Callback of the Cancel button (i.e. the thing that happens when you press the button) and the CloseRequestFcn of the figure window (i.e. the thing that happens when you click the Close button on the window frame).

You can avoid this by just directly setting the CloseRequestFcn of the figure window yourself:

```<code>h = waitbar(0,'Please Wait...');
h.CloseRequestFcn = '';
</code>```

The Close button is now disabled.

Bear in mind that the CloseRequestFcn is also what gets executed when you call close(h), so you now won't be able to close it with close(h). You can either call delete(h) instead, or you can make sure that before you call close(h) you reset the CloseRequestFcn back to the default, which is the buit-in function closereq (type edit closereq to see what this does, it basically just calls delete anyway).

Hope that helps!

ContentLicense: CC BY-SA 3.0

Body:
I want to create a waitbar that should be processed without any interruption. How can I achieve this?

I have tried setting

h=waitbar(0,'please wait','CreateCancelBtn','setappdata(gcbf,''Cancel'',0)');

This disables the Close button on the waitbar, but it also shows me a Cancel button too. I don't want that button.

Body:
When you use the CreateCancelBtn option of waitbar, it creates a Cancel button, takes the string you supply, and then sets that string to be both the Callback of the Cancel button (i.e. the thing that happens when you press the button) and the CloseRequestFcn of the figure window (i.e. the thing that happens when you click the Close button on the window frame).

You can avoid this by just directly setting the CloseRequestFcn of the figure window yourself:

h = waitbar(0,'Please Wait...');
h.CloseRequestFcn = '';

The Close button is now disabled.

Bear in mind that the CloseRequestFcn is also what gets executed when you call close(h), so you now won't be able to close it with close(h). You can either call delete(h) instead, or you can make sure that before you call close(h) you reset the CloseRequestFcn back to the default, which is the buit-in function closereq (type edit closereq to see what this does, it basically just calls delete anyway).

Hope that helps!


问:
How to for loop in userDefaults swift
I am saving data into userDeafults using 2 textfield as String, String but I want to know how to retrieve all the data to display either using loop or function </p>

```<code>    let save = UserDefaults.standard

    let heading = headingText.text
    let description = desxriptionTexr.text
    save.set(description, forKey: heading!)
</code>```

答:
If you have multiple Strings, simply save value as array</p>

```<code>UserDefaults.standard.set(YourStringArray, forKey: "stringArr")

let arr = UserDefaults.standard.stringArray(forKey: "stringArr")

for s in arr! {
    //do stuff
}
</code>```

Title: How to for loop in userDefaults swift

Body:
I am saving data into userDeafults using 2 textfield as String, String but I want to know how to retrieve all the data to display either using loop or function

    let save = UserDefaults.standard

    let heading = headingText.text
    let description = desxriptionTexr.text
    save.set(description, forKey: heading!)

Body:
If you have multiple Strings, simply save value as array

UserDefaults.standard.set(YourStringArray, forKey: "stringArr")

let arr = UserDefaults.standard.stringArray(forKey: "stringArr")

for s in arr! {
    //do stuff
}


问:
Data binding only working when using as syntax in select ng-options
I have the following Angular controller from the book AngularJS in Action:

```<code>angular.module('Angello.Storyboard')
    .controller('StoryboardCtrl', function() {
        var storyboard = this;

        storyboard.currentStory = null;
        storyboard.editedStory = {};

        storyboard.setCurrentStory = function(story) {
            storyboard.currentStory = story;
            storyboard.editedStory = angular.copy(storyboard.currentStory);
        };

        storyboard.stories = [
            {
                "assignee": "1",
                "criteria": "It tests!",
                "description": "This is a test",
                "id": "1",
                "reporter": "2",
                "status": "To Do",
                "title": "First Story",
                "type": "Spike"
            },
            {
                "assignee": "2",
                "criteria": "It works!",
                "description": "testing something",
                "id": "2",
                "reporter": "1",
                "status": "Code Review",
                "title": "Second Story",
                "type": "Enhancement"
            }
        ];

        storyboard.types = [
            {name: "Spike"},
            {name: "Enhancement"}
        ];

        storyboard.users = [
            {id: "1", name: "User1"},
            {id: "2", name: "User2"}
        ];

        storyboard.statuses = [
            {name: 'To Do'},
            {name: 'In Progress'},
            {name: 'Code Review'},
            {name: 'QA Review'},
            {name: 'Verified'}
        ];
    });
</code>```

And the following HTML template:

```<code><div class="list-area">
    <div class="list-wrapper">
        <ul class="list" ng-repeat="status in storyboard.statuses">
            <h3 class="status">{{status.name}}</h3>
            <hr/>
            <li class="story" ng-repeat="story in storyboard.stories | filter: {status:status.name}" ng-click="storyboard.setCurrentStory(story)">
                <article>
                    <div>
                        <button type="button" class="close">×</button>
                        <p class="title">{{story.title}}</p>
                    </div>
                    <div class="type-bar {{story.type}}"></div>
                    <div>
                        <p>{{story.description}}</p>
                    </div>
                </article>
            </li>
        </ul>
    </div>
</div>

<div class="details">
    <h3>Card Details</h3>
    <form name="storyboard.detailsForm">
        <div class="form-group">
            <div class="controls">
                <label class="control-label" for="inputTitle">Title</label>
                <input type="text" id="inputTitle" name="inputTitle" placeholder="Title"
                        ng-model="storyboard.editedStory.title" ng-required="true"
                        ng-minlength="3" ng-maxlength="30" class="form-control">

                <label class="control-label" for="inputStatus">Status</label>
                <select id="inputStatus" name="inputStatus"
                        ng-model="storyboard.editedStory.status"
                        ng-options="status.name as status.name for status in storyboard.statuses"
                        class="form-control">
                    <option value="">Please select...</option>
                </select>

                <label class="control-label" for="inputReporter">Reporter</label>
                <select id="inputReporter" name="inputReporter"
                        ng-model="storyboard.editedStory.reporter" ng-required="true"
                        ng-options="user.id as user.name for user in storyboard.users"
                        class="form-control">
                    <option value="">Please select...</option>
                </select>

                <label class="control-label" for="inputType">Type</label>
                <select id="inputType" name="inputType"
                        ng-model="storyboard.editedStory.type" ng-required="true"
                        ng-options="type.name as type.name for type in storyboard.types"
                        class="form-control">
                    <option value="" disabled selected>Please select...</option>
                </select>
            </div>
        </div>
    </form>
    <div ng-if="storyboard.currentStory">
        <button class="btn btn-default ng-click="storyboard.updateCancel()">Cancel</button>
        <button class="btn pull-right btn-default" ng-disabled="!storyboard.detailsForm.$valid" ng-click="storyboard.updateStory()">Update Story</button>
    </div>
</div>
</code>```

When I using the code like this, all works fine and if I want to display on of my story (from the stories array in the storyboard) in the storyboard.detailsForm, this works find and the select elements are populated with the values from the card that I've selected.

However, when I change the ng-options in the select element like that
(use type.name for type ... instead of type.name as type.name for ...):

```<code><select id="inputType" name="inputType"
        ng-model="storyboard.editedStory.type" ng-required="true"
        ng-options="type.name for type in storyboard.types"
        class="form-control">
        <option value="" disabled selected>Please select...</option>
</select>
</code>```

Then, populating the values does not work anymore, and 'Please select' is the displayed value in the select control. I don't understand why this is like that and can't find an explanation neither in the book or online.

答:
ng-options syntax can be understood as value as text for item in items.

If you don't use as part(lead to text for item in items, value part is missing), then item itself(object) will be bind to option(confirm by the below example), finally the empty option is setted to be selected for angular can't match any options with the value bind to ng-model.

angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $scope.default1 = 1;
    $scope.default2 = 1;
    $scope.data = [
      {
        id: 1,
        name: 'name1'
      },{
        id: 2,
        name: 'name2'
      },{
        id: 3,
        name: 'name3'
      }
    ];
  });```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="app" ng-controller="myCtrl">
  <h4>Change options to see what is binded to options</h4>
  <select id="inputType" name="inputType"
    ng-model="default1" ng-required="true"
    ng-options="item.id as item.name for item in data"
    class="form-control">
    <option value="" disabled selected>Please select...</option>
  </select>
  {{default1}}<br>
  <select id="inputType2" name="inputType2"
    ng-model="default2" ng-required="true"
    ng-options="item.id for item in data"
    class="form-control">
    <option value="" disabled selected>Please select...</option>
  </select>
  {{default2}}
</div></code>```

Body:
I have the following Angular controller from the book AngularJS in Action:

angular.module('Angello.Storyboard')
    .controller('StoryboardCtrl', function() {
        var storyboard = this;

        storyboard.currentStory = null;
        storyboard.editedStory = {};

        storyboard.setCurrentStory = function(story) {
            storyboard.currentStory = story;
            storyboard.editedStory = angular.copy(storyboard.currentStory);
        };

        storyboard.stories = [
            {
                "assignee": "1",
                "criteria": "It tests!",
                "description": "This is a test",
                "id": "1",
                "reporter": "2",
                "status": "To Do",
                "title": "First Story",
                "type": "Spike"
            },
            {
                "assignee": "2",
                "criteria": "It works!",
                "description": "testing something",
                "id": "2",
                "reporter": "1",
                "status": "Code Review",
                "title": "Second Story",
                "type": "Enhancement"
            }
        ];

        storyboard.types = [
            {name: "Spike"},
            {name: "Enhancement"}
        ];

        storyboard.users = [
            {id: "1", name: "User1"},
            {id: "2", name: "User2"}
        ];

        storyboard.statuses = [
            {name: 'To Do'},
            {name: 'In Progress'},
            {name: 'Code Review'},
            {name: 'QA Review'},
            {name: 'Verified'}
        ];
    });

And the following HTML template:

{{status.name}}

                        <button type="button" class="close">×</button>

{{story.title}}

{{story.description}}

Card Details

    <form name="storyboard.detailsForm">

                Title
                <input type="text" id="inputTitle" name="inputTitle" placeholder="Title"
                        ng-model="storyboard.editedStory.title" ng-required="true"
                        ng-minlength="3" ng-maxlength="30" class="form-control">

                Status
                <select id="inputStatus" name="inputStatus"
                        ng-model="storyboard.editedStory.status"
                        ng-options="status.name as status.name for status in storyboard.statuses"
                        class="form-control">
                    <option value="">Please select...</option>
                </select>

                Reporter
                <select id="inputReporter" name="inputReporter"
                        ng-model="storyboard.editedStory.reporter" ng-required="true"
                        ng-options="user.id as user.name for user in storyboard.users"
                        class="form-control">
                    <option value="">Please select...</option>
                </select>

                Type
                <select id="inputType" name="inputType"
                        ng-model="storyboard.editedStory.type" ng-required="true"
                        ng-options="type.name as type.name for type in storyboard.types"
                        class="form-control">
                    <option value="" disabled selected>Please select...</option>
                </select>

    </form>

        <button class="btn btn-default ng-click="storyboard.updateCancel()">Cancel</button>
        <button class="btn pull-right btn-default" ng-disabled="!storyboard.detailsForm.$valid" ng-click="storyboard.updateStory()">Update Story</button>

When I using the code like this, all works fine and if I want to display on of my story (from the stories array in the storyboard) in the storyboard.detailsForm, this works find and the select elements are populated with the values from the card that I've selected.

However, when I change the ng-options in the select element like that
(use type.name for type ... instead of type.name as type.name for ...):

<select id="inputType" name="inputType"
        ng-model="storyboard.editedStory.type" ng-required="true"
        ng-options="type.name for type in storyboard.types"
        class="form-control">
        <option value="" disabled selected>Please select...</option>
</select>

Then, populating the values does not work anymore, and 'Please select' is the displayed value in the select control. I don't understand why this is like that and can't find an explanation neither in the book or online.

Body:
ng-options syntax can be understood as value as text for item in items.

If you don't use as part(lead to text for item in items, value part is missing), then item itself(object) will be bind to option(confirm by the below example), finally the empty option is setted to be selected for angular can't match any options with the value bind to ng-model.

angular.module("app", [])
  .controller("myCtrl", function($scope) {
    $scope.default1 = 1;
    $scope.default2 = 1;
    $scope.data = [
      {
        id: 1,
        name: 'name1'
      },{
        id: 2,
        name: 'name2'
      },{
        id: 3,
        name: 'name3'
      }
    ];
  });

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="app" ng-controller="myCtrl">
  <h4>Change options to see what is binded to options</h4>
  <select id="inputType" name="inputType"
    ng-model="default1" ng-required="true"
    ng-options="item.id as item.name for item in data"
    class="form-control">
    <option value="" disabled selected>Please select...</option>
  </select>
  {{default1}}<br>
  <select id="inputType2" name="inputType2"
    ng-model="default2" ng-required="true"
    ng-options="item.id for item in data"
    class="form-control">
    <option value="" disabled selected>Please select...</option>
  </select>
  {{default2}}
</div>


问:
DateTime.ParseExact returns wrong date for the 'dd/MM/yyyy h:mm tt' format
I need to convert datetime from MM/dd/yyyy h:mm:ss tt format to the dd/MM/yyyy h:mm:ss tt

My code

```<code> var date = ((DateTime)model.WorkshopDate).ToString("dd/MM/yyyy h:mm:ss tt");

 var resultDate = DateTime.ParseExact(date, "dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
</code>```

In result date = 25/12/2017 12:00:00 AM

But resultDate = 12/25/2017 12:00:00 AM .

How can i parse it right?

答:
You are looking at the object in the debugger which is a datetime object and not a display version of your date.

Example:

```<code>var theDate = DateTime.UtcNow;

var date = theDate.ToString( "dd/MM/yyyy h:mm:ss tt" );
var resultDate = DateTime.ParseExact( date, "dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture );

Console.WriteLine(date == resultDate.ToString("dd/MM/yyyy h:mm:ss tt"));//Returns true
</code>```

As you see they are the same dates so just .ToString() it to whatever format you need when displaying.

Body:
I need to convert datetime from MM/dd/yyyy h:mm:ss tt format to the dd/MM/yyyy h:mm:ss tt

My code

 var date = ((DateTime)model.WorkshopDate).ToString("dd/MM/yyyy h:mm:ss tt");

 var resultDate = DateTime.ParseExact(date, "dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);

In result date = 25/12/2017 12:00:00 AM

But resultDate = 12/25/2017 12:00:00 AM .

How can i parse it right?

Body:
You are looking at the object in the debugger which is a datetime object and not a display version of your date.

Example:

var theDate = DateTime.UtcNow;

var date = theDate.ToString( "dd/MM/yyyy h:mm:ss tt" );
var resultDate = DateTime.ParseExact( date, "dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture );

Console.WriteLine(date == resultDate.ToString("dd/MM/yyyy h:mm:ss tt"));//Returns true

As you see they are the same dates so just .ToString() it to whatever format you need when displaying.


问:
How can I write SQL Query?
I need a request that displays the name and surname of the clients with the smallest credit limit - among married women who do not live in Japan, Brazil or Italy.

Diagram:

答:
select top 1 * from Customers C

Inner Join

(
select MIn(cust_credit_limit) from Customers C1

Inner Join Countries CT on C1.Country_id = C1.Country_id

where CT.Country_Name  Not in ('Japan', 'Brazil','Italy')

)
 C2 on C2.cust_credit_limit = C.cust_credit_limit

Title: How can I write SQL Query?


问:
ADFS 4.0: Received invalid Client credentials
Any ideas why this can happen?
Our IT had ADFS updated from version 3 to version 4.
After the update our ASP.NET Core application gets following error:

Error Code:

```<code>"Unhandled remote failure. (OAuth token endpoint failure: Status: BadRequest;
Body: {\"error\":\"invalid_client\",\"error_description\":\"MSIS9623: Received invalid Client credentials. The OAuth client is not configured to authenticate using passed in client credentials.\"};)"
</code>```

The request:

```<code> https://.../adfs/oauth2/authorize?client_id=d...4c&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44377%2F&state=CfDJ8...Og&resource=https%3A%2F%2Flocalhost%3A44377&redirect_url=https%3A%2F%2Flocalhost%3A44377
</code>```

I tried also tried:

"grant_type"="authorization_code"

Someone an idea what the "client credentials" means in this context?

答:
ADFS 4.0 throws an error if "client_secret" was sent. ADFS 3.0 has ignored that value.

The  UseOAuthAuthentication sends always an "client_secret". My dirty solution is to intercept the http request and remove the "client_secret". If someone has a better solution...

```<code> if (securityService.IsOAuthEnabled)
 {

     HttpClientHandler clientHandler = new HttpClientHandlerInterceptor(){};
     var options = securityService.GetOAuthOptions();
     options.BackchannelHttpHandler = clientHandler;
     app.UseOAuthAuthentication(options);
 }
</code>```

HttpClientHandlerInterceptor:

```<code> public class HttpClientHandlerInterceptor : HttpClientHandler
 {
     protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     {
         if (request.Content is FormUrlEncodedContent)
         {
             var x = ((FormUrlEncodedContent) request.Content).ReadAsStringAsync().Result;
             var contenttype = request.Content.Headers.ContentType.MediaType;
             x = x.Replace("client_secret=will+be+ignored&", "");
             request.Content = new StringContent(x, Encoding.UTF8, contenttype);
         }
         return base.SendAsync(request, cancellationToken);
     }
 }
</code>```

Body:
Any ideas why this can happen?
Our IT had ADFS updated from version 3 to version 4.
After the update our ASP.NET Core application gets following error:

Error Code:

"Unhandled remote failure. (OAuth token endpoint failure: Status: BadRequest;
Body: {\"error\":\"invalid_client\",\"error_description\":\"MSIS9623: Received invalid Client credentials. The OAuth client is not configured to authenticate using passed in client credentials.\"};)"

The request:

 https://.../adfs/oauth2/authorize?client_id=d...4c&scope=&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A44377%2F&state=CfDJ8...Og&resource=https%3A%2F%2Flocalhost%3A44377&redirect_url=https%3A%2F%2Flocalhost%3A44377

I tried also tried:

"grant_type"="authorization_code"

Someone an idea what the "client credentials" means in this context?

Body:
ADFS 4.0 throws an error if "client_secret" was sent. ADFS 3.0 has ignored that value.

The  UseOAuthAuthentication sends always an "client_secret". My dirty solution is to intercept the http request and remove the "client_secret". If someone has a better solution...

 if (securityService.IsOAuthEnabled)
 {

     HttpClientHandler clientHandler = new HttpClientHandlerInterceptor(){};
     var options = securityService.GetOAuthOptions();
     options.BackchannelHttpHandler = clientHandler;
     app.UseOAuthAuthentication(options);
 }

HttpClientHandlerInterceptor:

 public class HttpClientHandlerInterceptor : HttpClientHandler
 {
     protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     {
         if (request.Content is FormUrlEncodedContent)
         {
             var x = ((FormUrlEncodedContent) request.Content).ReadAsStringAsync().Result;
             var contenttype = request.Content.Headers.ContentType.MediaType;
             x = x.Replace("client_secret=will+be+ignored&", "");
             request.Content = new StringContent(x, Encoding.UTF8, contenttype);
         }
         return base.SendAsync(request, cancellationToken);
     }
 }


问:
For R data.table, how to use uniqueN() in order count unique/distinct values in multiple columns?
Let's say we have the following R data.table (though a dataframe is fine in principle as well):

```<code>library(data.table)
new_dt = as.data.table(readcsv(...))
head(new_dt)
    name order_no  overlimit
1    Amy       32  TRUE
2   Jack       14  TRUE
3   Jack       16  TRUE
4   Dave       11  FALSE
5    Amy       22  TRUE
6   Jack       16  TRUE
7    Tom       19  FALSE
8  Larry       22  FALSE
9    Tom       89  FALSE
10  Dave       81  TRUE
11  Jack       67  TRUE
12   Tom       60  TRUE
13   Amy       23  FALSE
14  Jack       16  TRUE
</code>```

For this task, the values of order_no is irrelevant---I would like to count the unique number of rows for name and overlimit:

```<code>name    overlimit  distinct_groups
Amy     TRUE       2
Amy     FALSE      1
Jack    TRUE       4
Jack    FALSE      0
Dave    TRUE       1
Dave    FALSE      1
...
</code>```

Does one simply include more columns in the by argument?

答:
If the request is to have the adjacent elements in 'overlimit' as a separate group, then we can use rleid to create the group

```<code>dt[, .(overlimit = overlimit[1], distinct_group = uniqueN(order_no)),
     .(name, grp = rleid(overlimit))][, grp := NULL][]
</code>```

If it is a simple grouping and wants only combinations

```<code>dt[, .(distinct_group = .N), by = .(name, overlimit)
  ][CJ(name = dt$name, overlimit = dt$overlimit, unique = TRUE),
      on = .(name, overlimit)][is.na(distinct_group), distinct_group := 0][]
</code>```

Body:
Let's say we have the following R data.table (though a dataframe is fine in principle as well):

library(data.table)
new_dt = as.data.table(readcsv(...))
head(new_dt)
    name order_no  overlimit
1    Amy       32  TRUE
2   Jack       14  TRUE
3   Jack       16  TRUE
4   Dave       11  FALSE
5    Amy       22  TRUE
6   Jack       16  TRUE
7    Tom       19  FALSE
8  Larry       22  FALSE
9    Tom       89  FALSE
10  Dave       81  TRUE
11  Jack       67  TRUE
12   Tom       60  TRUE
13   Amy       23  FALSE
14  Jack       16  TRUE

For this task, the values of order_no is irrelevant---I would like to count the unique number of rows for name and overlimit:

name    overlimit  distinct_groups
Amy     TRUE       2
Amy     FALSE      1
Jack    TRUE       4
Jack    FALSE      0
Dave    TRUE       1
Dave    FALSE      1
...

Does one simply include more columns in the by argument?

Body:
If the request is to have the adjacent elements in 'overlimit' as a separate group, then we can use rleid to create the group

dt[, .(overlimit = overlimit[1], distinct_group = uniqueN(order_no)),
     .(name, grp = rleid(overlimit))][, grp := NULL][]

If it is a simple grouping and wants only combinations

dt[, .(distinct_group = .N), by = .(name, overlimit)
  ][CJ(name = dt$name, overlimit = dt$overlimit, unique = TRUE),
      on = .(name, overlimit)][is.na(distinct_group), distinct_group := 0][]


问:
How to setup WOW.js in Angular 2 and 4?
I am trying to get WOW.js working in my Angular project but it is not working yet. I am not using webpack so I think the next thread is not answering my question: How to use WOW.js in Angular 2 Webpack?.

The steps that I took until now:

I installed the wow.js module.

npm install wowjs

I added the wowjs files to '.angular-cli.json'.

"styles": [
    "../node_modules/wowjs/css/libs/animate.css" ],

"scripts": [
"../node_modules/wowjs/dist/wow.js"
]

3.Then I added a wow effect to one of my headers.

```<code><h1 class="wow slideInLeft" data-wow-duration="2s">Wow effect!</h1>
</code>```

And the next thing I did was rebuilding and serving my project.

ng build

ng serve

There is no wow effect yet. Does somebody know what I have to do yet?

答:
You will need to initialise WOW for your component.

In the component where you plan on using WOW, import the script

```<code> import { WOW } from 'wowjs/dist/wow.min';
</code>```

then  in your class with the Angular method ngAfterViewInit

```<code> class ngAfterViewInit(){

   new WOW().init();
 }
</code>```

Title: How to setup WOW.js in Angular 2 and 4?

Body:
I am trying to get WOW.js working in my Angular project but it is not working yet. I am not using webpack so I think the next thread is not answering my question: How to use WOW.js in Angular 2 Webpack?.

The steps that I took until now:

I installed the wow.js module.

npm install wowjs

I added the wowjs files to '.angular-cli.json'.

"styles": [
    "../node_modules/wowjs/css/libs/animate.css" ],

"scripts": [
"../node_modules/wowjs/dist/wow.js"
]

3.Then I added a wow effect to one of my headers.

Wow effect!

And the next thing I did was rebuilding and serving my project.

ng build

ng serve

There is no wow effect yet. Does somebody know what I have to do yet?

Body:
You will need to initialise WOW for your component.

In the component where you plan on using WOW, import the script

 import { WOW } from 'wowjs/dist/wow.min';

then  in your class with the Angular method ngAfterViewInit

 class ngAfterViewInit(){

   new WOW().init();
 }


问:
How to define Specific Bucket Only Allow S3 Full Access Policy to that bucket only?
I have created below S3 policy for a user-name - john under account : 416XXXXXX, so that he is only allowed to use consolek S3 folder.

But this is giving following error :
This policy contains the following error: Has prohibited field Principal For more information about the IAM policy grammar, see AWS IAM Policies.

What exactly I am missing here ?

```<code>{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1487252735934",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::john",
      "Principal": {
        "AWS": [
          "arn:aws:iam::416XXXXXX:user/karthik"
        ]
      }
    }
  ]
}
</code>```

答: IAM policy does not have Principle section. You can create resource-based policy at http://awspolicygen.s3.amazonaws.com/policygen.html.</p>

Body:
I have created below S3 policy for a user-name - john under account : 416XXXXXX, so that he is only allowed to use consolek S3 folder.

But this is giving following error :
This policy contains the following error: Has prohibited field Principal For more information about the IAM policy grammar, see AWS IAM Policies.

What exactly I am missing here ?

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1487252735934",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::john",
      "Principal": {
        "AWS": [
          "arn:aws:iam::416XXXXXX:user/karthik"
        ]
      }
    }
  ]
}


问:
Lucene index updation and performance
I am working on a job portal site and have been using Lucene for job search functionality.
Users will be posting a number jobs on our site on a daily basis.We need to make sure that new job posted is searchable on the site as soon as possible.
In this context, how do I update Lucene index when a new job is posted or when an existing job is edited?
Can lucene index updating and search work in parallel?

Also,can I know any tips/best practices with respect to Lucene indexing,optimizing,performance etc?

Appreciate ur help!

Thanks!

答: I have used Lucene.Net on a web site similar to what you are doing. Yes, you can do live indexes, updating to keep everything up to date? What platform are you using Lucene on, .NET, Java?</p>

ContentLicense: CC BY-SA 2.5

Title: Lucene index updation and performance

OwnerDisplayName: Craig


问:
Python regex matching problem
I have been parsing a GraphViz file for a specific identifer using Regex. Here is the typical content from this file:

```<code>node10 [label="second-messenger-mediated signaling\nGO:0019932", fontname=Courier, ...];

node11 [label="inositol phosphate-mediated signaling\nGO:0048016", fontname=Courier, ...];

node12 [label="activation of phospholipase C activity by G-protein coupled receptor protein signaling pathway coupled to IP3 second messenger\n\

GO:0007200", fontname=Courier, ...];

node13 [label="G-protein coupled receptor protein signaling pathway\nGO:0007186", fontname=Courier, ...];

node14 [label="activation of phospholipase C activity\nGO:0007202", fontname=Courier, ...];

node15 [label="elevation of cytosolic calcium ion concentration involved in G-protein signaling coupled to IP3 second messenger\nGO:0051482", fontname=Courier, pos="798,1162", width="9.56", height="0.50"];
</code>```

Since I am only interested in the nodeid, label and the GO identifier I have used the following regex to match each line:

```<code>(node\d*)\s\[label=\"([\w\s-]*).*(GO:\d*)
</code>```

I know that it's neither terribly elegant nor very efficient but it got the job done except for the line with node12. I have tried using re.DOTALL and re.MULTILINE but to no avail.

Can anyone help me spot the missing piece of the puzzle to make the regex also work with node12 ?

**EDIT:

Here [1] is a link to the file that contains one of those lines.

[1] http://amigo.geneontology.org/cgi-bin/amigo/term-details.cgi?session_id=7924amigo1292519756&term=GO:0051482&format=dot

答: if you match each line, then node 12 will be splitted in 2 lines...you should read the all file or iter between one node and one other...</p>

Title: Python regex matching problem

Body:
I have been parsing a GraphViz file for a specific identifer using Regex. Here is the typical content from this file:

node10 [label="second-messenger-mediated signaling\nGO:0019932", fontname=Courier, ...];

node11 [label="inositol phosphate-mediated signaling\nGO:0048016", fontname=Courier, ...];

node12 [label="activation of phospholipase C activity by G-protein coupled receptor protein signaling pathway coupled to IP3 second messenger\n\

GO:0007200", fontname=Courier, ...];

node13 [label="G-protein coupled receptor protein signaling pathway\nGO:0007186", fontname=Courier, ...];

node14 [label="activation of phospholipase C activity\nGO:0007202", fontname=Courier, ...];

node15 [label="elevation of cytosolic calcium ion concentration involved in G-protein signaling coupled to IP3 second messenger\nGO:0051482", fontname=Courier, pos="798,1162", width="9.56", height="0.50"];

Since I am only interested in the nodeid, label and the GO identifier I have used the following regex to match each line:

(node\d*)\s\[label=\"([\w\s-]*).*(GO:\d*)

I know that it's neither terribly elegant nor very efficient but it got the job done except for the line with node12. I have tried using re.DOTALL and re.MULTILINE but to no avail.

Can anyone help me spot the missing piece of the puzzle to make the regex also work with node12 ?

**EDIT:

Here [1] is a link to the file that contains one of those lines.

[1] http://amigo.geneontology.org/cgi-bin/amigo/term-details.cgi?session_id=7924amigo1292519756&term=GO:0051482&format=dot


问:
Take input in an infinte loop in c
I am writing a C program to blink LED for Raspberry Pi. Its like (i) Blink LED (2) Stop blinking it.

Now while the LED is blinking, if I press 2 it should stop blinking. How to do it ?

If I include scanf inside the code will stop blinking.

```<code>while(1)
{
 printf("Enter a command \n 1.Blink Led\n 2. Stop blinking\n");
 scanf("%d",&choice);
if(choice==1)
    for (;;)
    {
        digitalWrite (LED, HIGH) ;  // On
        delay (500) ;               // mS
        digitalWrite (LED, LOW) ;   // Off
        delay (500) ;
        // If i press 2 the led should stop blinking
  }

else if(choice==2){
 digitalWrite (LED, LOW) ;
}
</code>```

答:
Use poll:

```<code>#include <stdio.h>
#include <unistd.h>
#include <poll.h>
int main()
{
    struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
    unsigned char c, blink=1, on =1, q=1;
    while(q) {
      if( poll(&mypoll, 1, 500) ) {
        c=getchar();
        switch(c) {
          case '1':
              blink = 1;
              break;
          case '2':
              blink =0;
              break;
          case 'q':
              q= 0;
              break;
       }
   }
   else{
    if (blink) {
       if (on)
          on =0;
       else
         on =1;
     }
     printf("%u\n",on);
    }
  }
  return 0;
}
</code>```

replace the on parameter with the led functions.

Title: Take input in an infinte loop in c

Body:
I am writing a C program to blink LED for Raspberry Pi. Its like (i) Blink LED (2) Stop blinking it.

Now while the LED is blinking, if I press 2 it should stop blinking. How to do it ?

If I include scanf inside the code will stop blinking.

while(1)
{
 printf("Enter a command \n 1.Blink Led\n 2. Stop blinking\n");
 scanf("%d",&choice);
if(choice==1)
    for (;;)
    {
        digitalWrite (LED, HIGH) ;  // On
        delay (500) ;               // mS
        digitalWrite (LED, LOW) ;   // Off
        delay (500) ;
        // If i press 2 the led should stop blinking
  }

else if(choice==2){
 digitalWrite (LED, LOW) ;
}

Body:
Use poll:

#include <stdio.h>
#include <unistd.h>
#include <poll.h>
int main()
{
    struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
    unsigned char c, blink=1, on =1, q=1;
    while(q) {
      if( poll(&mypoll, 1, 500) ) {
        c=getchar();
        switch(c) {
          case '1':
              blink = 1;
              break;
          case '2':
              blink =0;
              break;
          case 'q':
              q= 0;
              break;
       }
   }
   else{
    if (blink) {
       if (on)
          on =0;
       else
         on =1;
     }
     printf("%u\n",on);
    }
  }
  return 0;
}

replace the on parameter with the led functions.


问:
Why is my DialogFragment not showing the custom layout?
I want to show a DialogFragment with no title, buttons, etc.(i.e, none of what is included in a typical Dialog) but just a ProgressBar spinner on a plain background. For a rough idea, the background's width matches that of the parent and spinner lies at the center of it. For this, I have a custom layout as follows:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <View
        android:id="@+id/search_progress_alpha_indicator"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline2"
        android:background="#00ffffff"/>

    <ProgressBar
        android:id="@+id/search_tutors_progress_bar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline2"
        app:layout_constraintGuide_percent="0.20"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="126dp"
        tools:layout_editor_absoluteX="0dp" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline3"
        app:layout_constraintGuide_percent="0.80"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="378dp"
        tools:layout_editor_absoluteX="0dp" />

</android.support.constraint.ConstraintLayout>
</code>```

Here, View is the background on top of which the ProgressBar is supposed to spin.

But when I inflate this layout in the DialogFragment, it shows something completely different:

Here is the DialogFragment code:

```<code>public static class SearchIndicatorDialogFragment extends DialogFragment{

        public static String FRAGMENT_TAG = "searchIndDiaFragTag";

        private View alphaSearchIndicator;
        private ProgressBar progressBar;

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }

        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

            View dialogRootView = inflater.inflate(R.layout.fragment_search_dialog, container, false);

            // Obtain the ProgressBar
            progressBar = (ProgressBar) dialogRootView.findViewById(R.id.search_tutors_progress_bar);

            // Obtain the Alpha search indicator
            alphaSearchIndicator = dialogRootView.findViewById(R.id.search_progress_alpha_indicator);

            return dialogRootView;
        }

        @Override
        public void onStop() {

            progressBar.setVisibility(View.GONE);

            alphaSearchIndicator.setBackgroundColor(0x00ffffff);

            super.onStop();
        }

        @Override
        public void onResume() {
            progressBar.setVisibility(View.VISIBLE);

            alphaSearchIndicator.setBackgroundColor(0xA6ffffff);

            super.onResume();
        }

    }
</code>```

Why is it not showing my custom layout as intended?

EDIT: As an additional note, The problem in my case is that the background View is supposed to be occupying 60% area of screen(height wise) and for this I have constrained it in between the Guidelines. This is something, I am unable to achieve with other answers to similar questions regarding DialogFragment. Moreover, I would like to know, why does a DialogFragment doesn't display the correct by default in general?

答:
Try this:</p>

```<code>    AlertDialog builder = new AlertDialog.Builder(this).create();
    builder.setView(progressbar_id);
    Window window = builder.getWindow();
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    builder.show();
</code>```

Body:
I want to show a DialogFragment with no title, buttons, etc.(i.e, none of what is included in a typical Dialog) but just a ProgressBar spinner on a plain background. For a rough idea, the background's width matches that of the parent and spinner lies at the center of it. For this, I have a custom layout as follows:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <View
        android:id="@+id/search_progress_alpha_indicator"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline3"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline2"
        android:background="#00ffffff"/>

    <ProgressBar
        android:id="@+id/search_tutors_progress_bar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:visibility="gone"/>

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline2"
        app:layout_constraintGuide_percent="0.20"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="126dp"
        tools:layout_editor_absoluteX="0dp" />

    <android.support.constraint.Guideline
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/guideline3"
        app:layout_constraintGuide_percent="0.80"
        android:orientation="horizontal"
        tools:layout_editor_absoluteY="378dp"
        tools:layout_editor_absoluteX="0dp" />

</android.support.constraint.ConstraintLayout>

Here, View is the background on top of which the ProgressBar is supposed to spin.

But when I inflate this layout in the DialogFragment, it shows something completely different:

Here is the DialogFragment code:

public static class SearchIndicatorDialogFragment extends DialogFragment{

        public static String FRAGMENT_TAG = "searchIndDiaFragTag";

        private View alphaSearchIndicator;
        private ProgressBar progressBar;

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }

        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

            View dialogRootView = inflater.inflate(R.layout.fragment_search_dialog, container, false);

            // Obtain the ProgressBar
            progressBar = (ProgressBar) dialogRootView.findViewById(R.id.search_tutors_progress_bar);

            // Obtain the Alpha search indicator
            alphaSearchIndicator = dialogRootView.findViewById(R.id.search_progress_alpha_indicator);

            return dialogRootView;
        }

        @Override
        public void onStop() {

            progressBar.setVisibility(View.GONE);

            alphaSearchIndicator.setBackgroundColor(0x00ffffff);

            super.onStop();
        }

        @Override
        public void onResume() {
            progressBar.setVisibility(View.VISIBLE);

            alphaSearchIndicator.setBackgroundColor(0xA6ffffff);

            super.onResume();
        }

    }

Why is it not showing my custom layout as intended?

EDIT: As an additional note, The problem in my case is that the background View is supposed to be occupying 60% area of screen(height wise) and for this I have constrained it in between the Guidelines. This is something, I am unable to achieve with other answers to similar questions regarding DialogFragment. Moreover, I would like to know, why does a DialogFragment doesn't display the correct by default in general?

Body:
Try this:

    AlertDialog builder = new AlertDialog.Builder(this).create();
    builder.setView(progressbar_id);
    Window window = builder.getWindow();
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    builder.show();


问:
NSData vs NSValue ? how to encapsulate a C-structure in sendMIDISysExEvent:(NSData *)midiData
I'm trying work out the way to use sendMIDISysExEvent:(NSData *)midiData as a way to retune a handful of MIDI notes in a music app. I'd like the ViewController to send a MIDI message to the Synth class to change the tuning of 10 notes. The standard MIDI System Exclusive message format for retuning one note looks like this

```<code>                 F0 7F <device ID> 08 02 tt ll [kk xx yy zz] F7.
</code>```

legend: tt ll [kk xx yy zz] (NB -slightly different to MIDI 1.0 Detailed Specification 4.2, p.49)

With typedef struct it would be possible to use a single float instead of a uint8_t to represent tuning frequency, e.g.

PlayViewController.h

```<code>    typedef struct
    {
    uint8_t SYSEX_SysexHeader;                // oxF0h;     // System Exclusive Header
    uint8_t SYSEX_UniversalRealTimeHeader;    // ox7Fh;     // Universal RealTime Header
    uint8_t SYSEX_myPhone;                    // ox00h;     // ID of target device (e.g. iPhone)
    uint8_t SYSEX_subID1;                     // ox08h;     // sub-ID #1 (MIDI Tuning Standard)
    uint8_t SYSEX_subID2;                     // ox02h;     // sub-ID #2 (note change)
    uint8_t SYSEX_tuningProgramNumber;        // ox0h;      // tuning program number (0 -127)
    uint8_t SYSEX_numberOfKeys;               // ox10h;     // number of changes

    uint8_t SYSEX_key0;
    float   TUNING_pitch_0;

    uint8_t SYSEX_key1;
    float   TUNING_pitch_1;

    uint8_t SYSEX_key2;
    float   TUNING_pitch_2;

    uint8_t SYSEX_key3;
    float   TUNING_pitch_3;

    uint8_t SYSEX_key4;
    float   TUNING_pitch_4;

    uint8_t SYSEX_key5;
    float   TUNING_pitch_5;

    uint8_t SYSEX_key6;
    float   TUNING_pitch_6;

    uint8_t SYSEX_key7;
    float   TUNING_pitch_7;

    uint8_t SYSEX_key8;
    float   TUNING_pitch_8;

    uint8_t SYSEX_key9;
    float   TUNING_pitch_9;

    uint8_t eox;                                // OxF7h;       //

    }
    TuneEvent;
</code>```

and still in .h

```<code>    typedef NS_ENUM(NSInteger, SYSEX)
    {
    SYSEX_SysexHeader               = 240,
    SYSEX_UniversalRealTimeHeader   = 127,
    SYSEX_myPhone                   = 0,
    SYSEX_subID1                    = 8,
    SYSEX_subID2                    = 2,
    SYSEX_tuningProgramNumber       = 0,
    SYSEX_numberOfKeysToBeChanged   = 1,
    SYSEX_key0                      = 61,
    SYSEX_key1                      = 62,
    SYSEX_key2                      = 63,
    SYSEX_key3                      = 64,
    SYSEX_key4                      = 65,
    SYSEX_key5                      = 66,
    SYSEX_key6                      = 67,
    SYSEX_key7                      = 68,
    SYSEX_key8                      = 69,
    SYSEX_key9                      = 70,
    SYSEX_eox                       = 247
    };

    typedef NS_ENUM(NSInteger, TUNING)
    {
    TUNING_pitch0,
    TUNING_pitch1,
    TUNING_pitch2,
    TUNING_pitch3,
    TUNING_pitch4,
    TUNING_pitch5,
    TUNING_pitch6,
    TUNING_pitch7,
    TUNING_pitch8,
    TUNING_pitch9
    };

    float TUNING_float(TUNING micro);
</code>```

and finally for the floating point values ... (thanks to this answer)

PlayViewController.m

```<code>    float TUNING_float(TUNING micro)
    {
    switch (micro)
        {
        case TUNING_pitch0:
            return  579.4618f;
        case TUNING_pitch1:
            return  607.0552f;
        case TUNING_pitch2:
            return  662.2421f;
        case TUNING_pitch3:
            return  708.2311f;
        case TUNING_pitch4:
            return  772.6157f;
        case TUNING_pitch5:
            return  809.4070f;
        case TUNING_pitch6:
            return  882.9894f;
        case TUNING_pitch7:
            return  910.5828f;
        case TUNING_pitch8:
            return  993.3631f;
        case TUNING_pitch9:
            return  1030.1540f;
        default:
            return   0.0f;
        }
    }
</code>```

However when I read this answer I began to ask how I might go about preparing a MIDI data packet based on NSData that sendMIDISysExEvent:(NSData *)midiData will send. And this answer recommends NSValue as the better way to encapsulate a C-structure like the one I'm trying to create so I'm confused. If that really is the case, I'm puzzled why Apple would introduce a method like sendMIDISysExEvent:(NSData *)midiData.

My question is: based on the message format (outlined in my code above), how would I prepare midiData in order to send it using this method ?

CONCLUSION

In response to the accepted answer, length of "raw binary data", defined in terms of number of bytes rather than type of data, explains the salient difference between NSData and NSValue. This would also suggest sendMIDISysExEvent:(NSData *)midiData was only designed to handle bytes of data i.e. uint8_t and not float. In other words, the sensible option is to express frequency values using bytes as per the following extract from the MIDI Tuning Standard

```<code>    yy = MSB of fractional part (1/128 semitone = 100/128 cents = .78125 cent units)
    zz = LSB of fractional part (1/16384 semitone = 100/16384 cents = .0061 cent units)
</code>```

答:
Both NSData and NSValue are wrappers around "raw binary data", yet with a different intent and with a different way in defining the length of the binary data.

NSValue targets in boxing scalar types like int, float (but also a struct), and the interface of NSValue is designed to pass the length of the "data" by means of the type. Hence, it is not possible to encapsulate objects of variable length (like VLA or C-strings) within an NSValue, since the size of the data cannot be derived from the type information (cf. NSValue):

The type you specify must be of constant length. You cannot store C
  strings, variable-length arrays and structures, and other data types
  of indeterminate length in an NSValue—you should use NSString or
  NSData objects for these types.

NSData is meant as a box for arbitrary byte buffers. So it has an interface through which you can define the length of the "raw binary data" in terms of bytes (and not in terms of a type).

Concerning your question, as the MIDI-interface in sendMIDISysExEvent:(NSData *)midiData expects an NSData-object, the only (meaningful) way is to pass your object as an NSData-object.

Hope it helps.

Body:
I'm trying work out the way to use sendMIDISysExEvent:(NSData *)midiData as a way to retune a handful of MIDI notes in a music app. I'd like the ViewController to send a MIDI message to the Synth class to change the tuning of 10 notes. The standard MIDI System Exclusive message format for retuning one note looks like this

                 F0 7F <device ID> 08 02 tt ll [kk xx yy zz] F7.

legend: tt ll [kk xx yy zz] (NB -slightly different to MIDI 1.0 Detailed Specification 4.2, p.49)

With typedef struct it would be possible to use a single float instead of a uint8_t to represent tuning frequency, e.g.

PlayViewController.h

    typedef struct
    {
    uint8_t SYSEX_SysexHeader;                // oxF0h;     // System Exclusive Header
    uint8_t SYSEX_UniversalRealTimeHeader;    // ox7Fh;     // Universal RealTime Header
    uint8_t SYSEX_myPhone;                    // ox00h;     // ID of target device (e.g. iPhone)
    uint8_t SYSEX_subID1;                     // ox08h;     // sub-ID #1 (MIDI Tuning Standard)
    uint8_t SYSEX_subID2;                     // ox02h;     // sub-ID #2 (note change)
    uint8_t SYSEX_tuningProgramNumber;        // ox0h;      // tuning program number (0 -127)
    uint8_t SYSEX_numberOfKeys;               // ox10h;     // number of changes

    uint8_t SYSEX_key0;
    float   TUNING_pitch_0;

    uint8_t SYSEX_key1;
    float   TUNING_pitch_1;

    uint8_t SYSEX_key2;
    float   TUNING_pitch_2;

    uint8_t SYSEX_key3;
    float   TUNING_pitch_3;

    uint8_t SYSEX_key4;
    float   TUNING_pitch_4;

    uint8_t SYSEX_key5;
    float   TUNING_pitch_5;

    uint8_t SYSEX_key6;
    float   TUNING_pitch_6;

    uint8_t SYSEX_key7;
    float   TUNING_pitch_7;

    uint8_t SYSEX_key8;
    float   TUNING_pitch_8;

    uint8_t SYSEX_key9;
    float   TUNING_pitch_9;

    uint8_t eox;                                // OxF7h;       //

    }
    TuneEvent;

and still in .h

    typedef NS_ENUM(NSInteger, SYSEX)
    {
    SYSEX_SysexHeader               = 240,
    SYSEX_UniversalRealTimeHeader   = 127,
    SYSEX_myPhone                   = 0,
    SYSEX_subID1                    = 8,
    SYSEX_subID2                    = 2,
    SYSEX_tuningProgramNumber       = 0,
    SYSEX_numberOfKeysToBeChanged   = 1,
    SYSEX_key0                      = 61,
    SYSEX_key1                      = 62,
    SYSEX_key2                      = 63,
    SYSEX_key3                      = 64,
    SYSEX_key4                      = 65,
    SYSEX_key5                      = 66,
    SYSEX_key6                      = 67,
    SYSEX_key7                      = 68,
    SYSEX_key8                      = 69,
    SYSEX_key9                      = 70,
    SYSEX_eox                       = 247
    };

    typedef NS_ENUM(NSInteger, TUNING)
    {
    TUNING_pitch0,
    TUNING_pitch1,
    TUNING_pitch2,
    TUNING_pitch3,
    TUNING_pitch4,
    TUNING_pitch5,
    TUNING_pitch6,
    TUNING_pitch7,
    TUNING_pitch8,
    TUNING_pitch9
    };

    float TUNING_float(TUNING micro);

and finally for the floating point values ... (thanks to this answer)

PlayViewController.m

    float TUNING_float(TUNING micro)
    {
    switch (micro)
        {
        case TUNING_pitch0:
            return  579.4618f;
        case TUNING_pitch1:
            return  607.0552f;
        case TUNING_pitch2:
            return  662.2421f;
        case TUNING_pitch3:
            return  708.2311f;
        case TUNING_pitch4:
            return  772.6157f;
        case TUNING_pitch5:
            return  809.4070f;
        case TUNING_pitch6:
            return  882.9894f;
        case TUNING_pitch7:
            return  910.5828f;
        case TUNING_pitch8:
            return  993.3631f;
        case TUNING_pitch9:
            return  1030.1540f;
        default:
            return   0.0f;
        }
    }

However when I read this answer I began to ask how I might go about preparing a MIDI data packet based on NSData that sendMIDISysExEvent:(NSData *)midiData will send. And this answer recommends NSValue as the better way to encapsulate a C-structure like the one I'm trying to create so I'm confused. If that really is the case, I'm puzzled why Apple would introduce a method like sendMIDISysExEvent:(NSData *)midiData.

My question is: based on the message format (outlined in my code above), how would I prepare midiData in order to send it using this method ?

CONCLUSION

In response to the accepted answer, length of "raw binary data", defined in terms of number of bytes rather than type of data, explains the salient difference between NSData and NSValue. This would also suggest sendMIDISysExEvent:(NSData *)midiData was only designed to handle bytes of data i.e. uint8_t and not float. In other words, the sensible option is to express frequency values using bytes as per the following extract from the MIDI Tuning Standard

    yy = MSB of fractional part (1/128 semitone = 100/128 cents = .78125 cent units)
    zz = LSB of fractional part (1/16384 semitone = 100/16384 cents = .0061 cent units)


问:
Check if a hive table is partitioned on a given column
I have a list of hive tables , of which some are partitioned. Given a column I need to check if a particular table is partitioned on that column or not.
I have searched and found that desc formatted tablename would result in all the details of the table.
Since I have to iterate over all the tables and get the list , desc formatted would not help.
Is there any other way this can be done.

答:
You can connect directly to metastore and query it:

```<code>metastore=# select d."NAME" as DATABASE,
  t."TBL_NAME" as TABLE,
  p."PKEY_NAME" as PARTITION_KEY
  from "PARTITION_KEYS" p
  join "TBLS" t on p."TBL_ID"=t."TBL_ID"
  join "DBS" d on t."DB_ID"=d."DB_ID";

 database |    table    | partition_key
----------+-------------+---------------
 default  | src_union_1 | ds
 default  | cbo_t1      | dt
 default  | cbo_t2      | dt
</code>```

The exact syntax of querying your metastore depends on your particular choice of metastore (in my case is a PostgreSQL one).

Body:
You can connect directly to metastore and query it:

metastore=# select d."NAME" as DATABASE,
  t."TBL_NAME" as TABLE,
  p."PKEY_NAME" as PARTITION_KEY
  from "PARTITION_KEYS" p
  join "TBLS" t on p."TBL_ID"=t."TBL_ID"
  join "DBS" d on t."DB_ID"=d."DB_ID";

 database |    table    | partition_key
----------+-------------+---------------
 default  | src_union_1 | ds
 default  | cbo_t1      | dt
 default  | cbo_t2      | dt

The exact syntax of querying your metastore depends on your particular choice of metastore (in my case is a PostgreSQL one).


问:
Copy all styles from one element to another
How can i get every styles (even inherited) from an element A to an element B ? in javascript or using jquery.

let's tell i have an element
...
 and i append new element
 which would look like the same, except content.

答:
If you don't care about IE, then you can do this:

var p = document.getElementById("your_p_id");
var div = document.createElement("div");
div.innerHTML = "your div content";
div.style.cssText = document.defaultView.getComputedStyle(p, "").cssText;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#your_p_id {
  color: #123124;
  background-color: #decbda;
}</code>```

<textArea id="your_p_id">Hello world!</textArea>```

This works for inline, embedded, and inherited styles.

EDIT: And by "don't care about IE," I of course meant "don't care about anything except Webkit."

UPDATE: This works in the current versions of Chrome(19), Safari(5), Firefox(12), and IE(9). It also works in older versions of some, such as IE8.

Body:
If you don't care about IE, then you can do this:

var p = document.getElementById("your_p_id");
var div = document.createElement("div");
div.innerHTML = "your div content";
div.style.cssText = document.defaultView.getComputedStyle(p, "").cssText;

#your_p_id {
  color: #123124;
  background-color: #decbda;
}

<textArea id="your_p_id">Hello world!</textArea>

This works for inline, embedded, and inherited styles.

EDIT: And by "don't care about IE," I of course meant "don't care about anything except Webkit."

UPDATE: This works in the current versions of Chrome(19), Safari(5), Firefox(12), and IE(9). It also works in older versions of some, such as IE8.

ContentLicense: CC BY-SA 4.0


问:
Purpose of char a[0] in converting integer to string using itoa()
I have this code,

```<code>char a[0];
cout << "What is a? " << a << endl;
char *word = itoa(123,a,10);
string yr = string(word);
</code>```

but i have trouble comprehending the array a[0]. I tried to change its value and see if there is any changes, but it seems to make no differences at all.

example, even if a change a[0] to a[1], or any other integer, the output still make no difference

```<code>char a[1];
cout << "What is a? " << a << endl;
char *word = itoa(123,a,10);
string yr = string(word);
</code>```

What is its purpose here?

答:
What is its purpose here?

A zero-length array is an array with no elements in it.

You can't [legally] print or modify its contents, because it doesn't have any.

There are arcane reasons to want to use one, but speaking generally it has no purpose for you. It's not even allowed by the standard (although compilers tend to support it for those arcane reasons).

even if a change a[0] to a[1], or any other integer, the output still make no difference

Well, if you have an array with n elements in it, and you write more than n elements' worth of data to it, that's a "buffer overrun" and has undefined behaviour. It could appear to work as you overwrite somebody else's memory, or your program could crash, or your dog could suddenly turn into a zombie and eat you alive. Best avoided tbh.

Body:
I have this code,

char a[0];
cout << "What is a? " << a << endl;
char *word = itoa(123,a,10);
string yr = string(word);

but i have trouble comprehending the array a[0]. I tried to change its value and see if there is any changes, but it seems to make no differences at all.

example, even if a change a[0] to a[1], or any other integer, the output still make no difference

char a[1];
cout << "What is a? " << a << endl;
char *word = itoa(123,a,10);
string yr = string(word);

What is its purpose here?


问:
How can I create a BehaviorSubject that subscribes to an observable?
I have a function which should return a BehaviorSubject. The subject is meant to return the most current version of a Profile

(user)Profile is just a POJO that contains references to three members:

- a User,

- that User's MeasurementList,

- and a Deadline.

Two of these properties is obtained via a retrofit call, and one of them is already held in a class variable.

Whenever the observable emits a new measurement list or deadline, the BehaviorSubject should emit a new updated Profile.

Here is a (hopefully helpful) diagram of what should be happening

This is what I have so far

```<code> public BehaviorSubject<Profile> observeProfile() {

        if (profileBS == null) {

            profileBS = BehaviorSubject.create();

            Observable o = Observable.combineLatest(
                    Observable.just(userAccount),
                    observeMeasurements(),
                    observeDeadline(),
                    Profile::new
            );

            profileBS.subscribeTo(o); //subscribeTo does not exist, but this is what I am trying to figure out how to do.

        }
        return profileBS;
    }
</code>```

Can anyone help me to create this BehaviorSubject properly?

Thanks.

答:
Subject implements the Observer interface so you can do the following

```<code>public BehaviorSubject<Profile> observeProfile() {

        if (profileBS == null) {

            profileBS = BehaviorSubject.create();

            Observable o = Observable.combineLatest(
                    Observable.just(userAccount),
                    observeMeasurements(),
                    observeDeadline(),
                    Profile::new
            );

            // Note the following returns a subscription. If you want to prevent leaks you need some way of unsubscribing.
            o.subscribe(profileBS);

        }
        return profileBS;
}
</code>```

Note that you should come up with a way of handling the resulting subscription.

Body:
I have a function which should return a BehaviorSubject. The subject is meant to return the most current version of a Profile

(user)Profile is just a POJO that contains references to three members:

- a User,

- that User's MeasurementList,

- and a Deadline.

Two of these properties is obtained via a retrofit call, and one of them is already held in a class variable.

Whenever the observable emits a new measurement list or deadline, the BehaviorSubject should emit a new updated Profile.

Here is a (hopefully helpful) diagram of what should be happening

This is what I have so far

 public BehaviorSubject<Profile> observeProfile() {

        if (profileBS == null) {

            profileBS = BehaviorSubject.create();

            Observable o = Observable.combineLatest(
                    Observable.just(userAccount),
                    observeMeasurements(),
                    observeDeadline(),
                    Profile::new
            );

            profileBS.subscribeTo(o); //subscribeTo does not exist, but this is what I am trying to figure out how to do.

        }
        return profileBS;
    }

Can anyone help me to create this BehaviorSubject properly?

Thanks.

Body:
Subject implements the Observer interface so you can do the following

public BehaviorSubject<Profile> observeProfile() {

        if (profileBS == null) {

            profileBS = BehaviorSubject.create();

            Observable o = Observable.combineLatest(
                    Observable.just(userAccount),
                    observeMeasurements(),
                    observeDeadline(),
                    Profile::new
            );

            // Note the following returns a subscription. If you want to prevent leaks you need some way of unsubscribing.
            o.subscribe(profileBS);

        }
        return profileBS;
}

Note that you should come up with a way of handling the resulting subscription.


问:
Get city place id from Google Places API
My app has a search for cities, but when the user enters the full address, he gets placeId that is more specific than a city -- for an address, or a business. I want the placeId for the city to store in my database.

I'm using Geocomplete http://ubilabs.github.io/geocomplete/

```<code>$('input[name="address"]').geocomplete().bind('geocode:result', function(event, result){
    console.log(result.place_id)
});
</code>```

I need to get place_id city from place_id address and check validity in PHP.

答:
You can avoid results that represent full addresses by using types to (regions) or (cities), see details here.

Whether to use one or the other will depend on which countries you want results from, because sometimes cities can be administrative_area1 (e.g. Tokyo), see the note in the Place Autocomplete Address Form example.

Body:
My app has a search for cities, but when the user enters the full address, he gets placeId that is more specific than a city -- for an address, or a business. I want the placeId for the city to store in my database.

I'm using Geocomplete http://ubilabs.github.io/geocomplete/

$('input[name="address"]').geocomplete().bind('geocode:result', function(event, result){
    console.log(result.place_id)
});

I need to get place_id city from place_id address and check validity in PHP.


问:
c# doing a custom sort on a datatable
i have data in a datatable that needs to be sorted on the first column this way:

```<code>A02 BLANK0010
D02 BLANK0007
B04 BLANK0011
G05 BLANK0012
C06 BLANK0014
E08 BLANK0013
F10 BLANK0016
H12 BLANK0015
B02 G112486
C02 G125259
E02 G125257
F02 G112492
G02 G125095
H02 G112489
A03 G125090
B03 G112499
C03 G125256
D03 G002007
E03 G112494
F03 G002005
G03 G112495
H03 G002008
A04 G115717
</code>```

if i do a regular sort, it will just sort like this: A02, A03, A04. but i need A02, B02, C02... etc

how can i do this>? here my code so far:

DataView view = dt.DefaultView;
        view.Sort = "position";

答:
Maybe need refactorings but solves the problem.

```<code>//group by the rows by splitting values of column
var groupBy = table.AsEnumerable()
                .GroupBy(o =>
                    Regex.Replace(o["position"].ToString(), @"[0-9]", ""));

 var dataRows = Sort(groupBy);
</code>```

And Here is the Sort Method:

```<code>//yield the first row of each group
private static IEnumerable<DataRow> Sort(IEnumerable<IGrouping<string, DataRow>> groupByCollection)
{
    //sort each character group(e.g. A,B) by integer part of their values
    var groupings =
        groupByCollection.Select(
            o =>
            new
                {
                    o.Key,
                    Value = o.OrderBy(a => Regex.Replace(a["position"].ToString(), "[a-z]", "", RegexOptions.IgnoreCase)).ToArray()
                }).ToArray();

    int i = 0, j;
    for (j = 0; j < groupings[i].Value.Length; j++,i=0)
        for (i = 0; i < groupings.Length; i++)
        {
            yield return groupings[i].Value[j];
        }
}
</code>```

Title: c# doing a custom sort on a datatable

Body:
i have data in a datatable that needs to be sorted on the first column this way:

A02 BLANK0010
D02 BLANK0007
B04 BLANK0011
G05 BLANK0012
C06 BLANK0014
E08 BLANK0013
F10 BLANK0016
H12 BLANK0015
B02 G112486
C02 G125259
E02 G125257
F02 G112492
G02 G125095
H02 G112489
A03 G125090
B03 G112499
C03 G125256
D03 G002007
E03 G112494
F03 G002005
G03 G112495
H03 G002008
A04 G115717

if i do a regular sort, it will just sort like this: A02, A03, A04. but i need A02, B02, C02... etc

how can i do this>? here my code so far:

DataView view = dt.DefaultView;
        view.Sort = "position";

Body:
Maybe need refactorings but solves the problem.

//group by the rows by splitting values of column
var groupBy = table.AsEnumerable()
                .GroupBy(o =>
                    Regex.Replace(o["position"].ToString(), @"[0-9]", ""));

 var dataRows = Sort(groupBy);

And Here is the Sort Method:

//yield the first row of each group
private static IEnumerable<DataRow> Sort(IEnumerable<IGrouping<string, DataRow>> groupByCollection)
{
    //sort each character group(e.g. A,B) by integer part of their values
    var groupings =
        groupByCollection.Select(
            o =>
            new
                {
                    o.Key,
                    Value = o.OrderBy(a => Regex.Replace(a["position"].ToString(), "[a-z]", "", RegexOptions.IgnoreCase)).ToArray()
                }).ToArray();

    int i = 0, j;
    for (j = 0; j < groupings[i].Value.Length; j++,i=0)
        for (i = 0; i < groupings.Length; i++)
        {
            yield return groupings[i].Value[j];
        }
}


问:
Woocommerce specific banner product category and childs
I've searched a lot and I did not find any specific to this, or at least, my development skills are yet not great, if someone can help I appreciate.

My goal is to show a text on each product that is inside the category X or sub-category of that same X.

For example:
Fruits
-Bananas

If the bellow product is inside Bananas it will show the code too because belongs to Fruits.

```<code>add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){

    if ( is_product_category(array(140,20)) )
        $post_excerpt = $post_excerpt. '<br><div class="product-message"><p>' . __( "Whats the measure? <a href='/#right-measure' target='_blank'>Check</a>.", "woocommerce" ) . '</p></div>';

    return $post_excerpt;
}
</code>```

I know my code is not good because each time the client add a sub-category I have to fix it...

答:
I managed doing this:

```<code>add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;

if ( in_array( 'piercings', $categories ) || in_array( 'piercings-en', $categories ) ) {
  $post_excerpt = $post_excerpt. '<br><div class="product-message"><p>' . __( "Bla bla bla", "woocommerce" ) . '</p></div>';
}

return $post_excerpt;
}
</code>```

Hope this helps someone

Body:
I've searched a lot and I did not find any specific to this, or at least, my development skills are yet not great, if someone can help I appreciate.

My goal is to show a text on each product that is inside the category X or sub-category of that same X.

For example:
Fruits
-Bananas

If the bellow product is inside Bananas it will show the code too because belongs to Fruits.

add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){

    if ( is_product_category(array(140,20)) )
        $post_excerpt = $post_excerpt. '

' . __( "Whats the measure? Check.", "woocommerce" ) . '

';

    return $post_excerpt;
}

I know my code is not good because each time the client add a sub-category I have to fix it...

Body:
I managed doing this:

add_filter( 'woocommerce_short_description', 'single_product_short_description', 10, 1 );
function single_product_short_description( $post_excerpt ){
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;

if ( in_array( 'piercings', $categories ) || in_array( 'piercings-en', $categories ) ) {
  $post_excerpt = $post_excerpt. '<br><div class="product-message"><p>' . __( "Bla bla bla", "woocommerce" ) . '</p></div>';
}

return $post_excerpt;
}

Hope this helps someone


问:
HTML - change image inside frame and keep frame size intact
My main goal is to have a simple frame (as you can see) with few text lines and images. The thing I want to do, is make this frame flexible. By that I mean - if I change picture inside of it (bigger -> smaller) the frame should change. It should stay fixed.

Online editor: https://www.bootply.com/Y09Zn1wir3#

HTML:

```<code><div class="col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="first-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>

<div class="col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="second-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>
</code>```

CSS:

```<code>/* CSS used here will be applied after bootstrap.css */
.single-image{
    border: 1px solid orange;
    width: 100%;
    text-align: center;
    margin: 0px 0px 15px 0px;
    float: right;
}

.name{
    padding: 20px 0px 0px 0px;
    color: black;
    height: 75px;
    font-size: 18px;
}

.img-wrap{
    padding-bottom: 50px;
    padding-top: 25px;
}

.first-image{
    width: 200px;
}

.second-image{
    width: 150px;
}

.extra-info{
    border-top: 1px solid orange;
}

.bottom-text{
    padding-top: 15px;
    height: 50px;
    letter-spacing: 0.1em;
}
</code>```

I tried to add height property to such as:

.single-image{
    ...
    height: 405px;
}

Result: https://www.codeply.com/go/2s2hH3nbju

But it doesn't look correct, as bottom text floats somewhere up.
I need a solution for different type of image sizes. Any ideas?

答:
Try using flex

.single-image{
    border: 1px solid orange;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
}

.name{
    padding: 20px 0px 0px 0px;
    color: black;
    height: 75px;
    font-size: 18px;
}

.img-wrap{
    padding-bottom: 50px;
    padding-top: 25px;
}

.first-image{
    width: 200px;
}

.second-image{
    width: 150px;
}

.extra-info{
    border-top: 1px solid orange;
    align-self: bottom;
}

.bottom-text{
    padding-top: 15px;
    height: 50px;
    letter-spacing: 0.1em;
}

.images-wrap{
display: flex;
}

.single-image-wrap {
    height: 100%;
    margin-bottom: 15px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <div class="row images-wrap">
  <div class="col-xs-6 col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="first-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>

<div class="col-xs-6 col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="second-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>
  </div></code>```

Body:
My main goal is to have a simple frame (as you can see) with few text lines and images. The thing I want to do, is make this frame flexible. By that I mean - if I change picture inside of it (bigger -> smaller) the frame should change. It should stay fixed.

Online editor: https://www.bootply.com/Y09Zn1wir3#

HTML:

NAME

ABC

NAME

ABC

CSS:

/* CSS used here will be applied after bootstrap.css */
.single-image{
    border: 1px solid orange;
    width: 100%;
    text-align: center;
    margin: 0px 0px 15px 0px;
    float: right;
}

.name{
    padding: 20px 0px 0px 0px;
    color: black;
    height: 75px;
    font-size: 18px;
}

.img-wrap{
    padding-bottom: 50px;
    padding-top: 25px;
}

.first-image{
    width: 200px;
}

.second-image{
    width: 150px;
}

.extra-info{
    border-top: 1px solid orange;
}

.bottom-text{
    padding-top: 15px;
    height: 50px;
    letter-spacing: 0.1em;
}

I tried to add height property to such as:

.single-image{
    ...
    height: 405px;
}

Result: https://www.codeply.com/go/2s2hH3nbju

But it doesn't look correct, as bottom text floats somewhere up.
I need a solution for different type of image sizes. Any ideas?

Body:
Try using flex

.single-image{
    border: 1px solid orange;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
}

.name{
    padding: 20px 0px 0px 0px;
    color: black;
    height: 75px;
    font-size: 18px;
}

.img-wrap{
    padding-bottom: 50px;
    padding-top: 25px;
}

.first-image{
    width: 200px;
}

.second-image{
    width: 150px;
}

.extra-info{
    border-top: 1px solid orange;
    align-self: bottom;
}

.bottom-text{
    padding-top: 15px;
    height: 50px;
    letter-spacing: 0.1em;
}

.images-wrap{
display: flex;
}

.single-image-wrap {
    height: 100%;
    margin-bottom: 15px;
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <div class="row images-wrap">
  <div class="col-xs-6 col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="first-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>

<div class="col-xs-6 col-md-4">
  <div class="single-image-wrap">
    <div class="single-image">
      <div class="name">NAME</div>
      <div class="img-wrap">
        <img src="https://cdn.pixabay.com/photo/2013/07/12/14/07/basketball-147794_960_720.png" class="second-image">
      </div>
      <div class="extra-info">
        <div class="bottom-text">ABC</div>
      </div>
    </div>
  </div>
</div>
  </div>


问:
Uncaught (in promise) error in Chrome originating from Facebook scripts
My site is loading and one it's finished, I get the following error in the console.

```<code>Uncaught (in promise) ▶ j ▶ __proto__: Error
</code>```

The error is from:

```<code>https://www.facebook.com/sw?s=push
</code>```

I have facebook like share button, Facebook page like widget on my site. I also have Facebook login but my own implementation not the standard Facebook login button and it's only initiated when a user clicks a link.

The Chrome dev tool is open when I see this, obviously.

In Firefox it says uncaught exception: undefined but without any indication of where the error is originating from.

Any idea how to solve this?

My site running under HTTPS. ASP.NET 4.5 / C# / jQuery / Windows 2012 RC Server.

答: just unchecked Enable Browser Link in Visual Studio by following image:

Body:
My site is loading and one it's finished, I get the following error in the console.

Uncaught (in promise) ▶ j ▶ __proto__: Error

The error is from:

https://www.facebook.com/sw?s=push

I have facebook like share button, Facebook page like widget on my site. I also have Facebook login but my own implementation not the standard Facebook login button and it's only initiated when a user clicks a link.

The Chrome dev tool is open when I see this, obviously.

In Firefox it says uncaught exception: undefined but without any indication of where the error is originating from.

Any idea how to solve this?

My site running under HTTPS. ASP.NET 4.5 / C# / jQuery / Windows 2012 RC Server.


问:
Build once, deploy many, with Angular-CLI
I'm using angular-cli (beta 26). For local development it's great, but I'm struggling to see how it can fit into a more serious "build once, deploy many" type of pipeline?

I'm using the built-in concept of an environment to store environment specific information, e.g. connection strings. But I'm required to specify the environment at build time, by using ng build --environment=xyz. This basically means I have to do a fresh build for every deployment. Idealy I'd like to select my environment at runtime (much like can be done with ASP.NET Core for example).

Am I missing something here? Is there another way to solve this problem?

答:
This was quite thoroughly discussed in the https://github.com/angular/angular-cli/issues/3855#issuecomment-274803729. Probably you know the answer already, but since it's not linked here I'm posting so anyone can see it.

Basically angular-cli environments are designed to be build-connected, so we have to custom-load e.g. a json file with runtime config.