问:
panda plot multiple lines base on a certain column
I have a dataframe like this

```<code>timestamp|type|value_1|value_2

t1|A|v1|v2

t2|B|v3|v4

t3|C|v5|v6

t4|A|v7|v8
</code>```

I would like to plot a graph with 6 lines each type and value
for example

```<code>type A - value_1
type A - value_2

type B - value_1
type B - value_2

type C - value_1
type C - value_2
</code>```

thanks,

it is like doing this

```<code>A = df[df["type"] == A]

A.plot(x="time", y=["value_1", "value_2"])
</code>```

do this for three types
and combine those 6 lines on the same graph

答:
As far as the plotting goes I recommend you check out:
MatPlotLib: Multiple datasets on the same scatter plot and Multiple data set plotting with matplotlib.pyplot.plot_date , as well as this tutorial.

For the selection of data to plot I recommend the section "selection by label" in the pandas docs. I suppose you could store the values from your corresponding columns / rows in some temporary variables x1 - xn and y1 - yn and then just plot all the pairs, which could look something like:

```<code>xs = sheet.loc[<appropriate labels>]
ys = sheet.loc[<appropriate labels>]
for i in range(len(xs)):
   plt.plot(xs[i],ys[i],<further arguments>)
plt.show()
</code>```

In your case, just accessing the 'values' label might not be sufficient, as only every n'th element of that column seams to belong to any given type. inthis question you can see how you can get a new list with only the appropriate values inside. Basically something like:

```<code>allXs = sheet.loc['v1']
xsTypeA = allXs[1::4]
...
</code>```

hope that helps.

Body:
I have a dataframe like this

timestamp|type|value_1|value_2

t1|A|v1|v2

t2|B|v3|v4

t3|C|v5|v6

t4|A|v7|v8

I would like to plot a graph with 6 lines each type and value
for example

type A - value_1
type A - value_2

type B - value_1
type B - value_2

type C - value_1
type C - value_2

thanks,

it is like doing this

A = df[df["type"] == A]

A.plot(x="time", y=["value_1", "value_2"])

do this for three types
and combine those 6 lines on the same graph

Body:
As far as the plotting goes I recommend you check out:
MatPlotLib: Multiple datasets on the same scatter plot and Multiple data set plotting with matplotlib.pyplot.plot_date , as well as this tutorial.

For the selection of data to plot I recommend the section "selection by label" in the pandas docs. I suppose you could store the values from your corresponding columns / rows in some temporary variables x1 - xn and y1 - yn and then just plot all the pairs, which could look something like:

xs = sheet.loc[<appropriate labels>]
ys = sheet.loc[<appropriate labels>]
for i in range(len(xs)):
   plt.plot(xs[i],ys[i],<further arguments>)
plt.show()

In your case, just accessing the 'values' label might not be sufficient, as only every n'th element of that column seams to belong to any given type. inthis question you can see how you can get a new list with only the appropriate values inside. Basically something like:

allXs = sheet.loc['v1']
xsTypeA = allXs[1::4]
...

hope that helps.


来源: stackexchange

问:
How to get timestamps correspond to the current days date? With Microsoft SQL
The number of rows in the A table, where the date value of the timestamps in the [time_created] and / or [time_updated] fields correspond to the current day's date

答:
You can use the CONVERT() function.

```<code>CONVERT(date, YOUR-COL-NAME-HERE)
</code>```

So if you are looking for rows with today's date, you should have something like:

```<code>WHERE CONVERT(date, YOUR-COL-NAME-HERE) = CONVERT(date, GETDATE())
</code>```

ContentLicense: CC BY-SA 3.0

Body:
You can use the CONVERT() function.

CONVERT(date, YOUR-COL-NAME-HERE)

So if you are looking for rows with today's date, you should have something like:

WHERE CONVERT(date, YOUR-COL-NAME-HERE) = CONVERT(date, GETDATE())


问:
Database configuration file for Sql server on windows
What is the configuration of database.yml file for sql server in windows.</p>

答:
```<code>development:
  adapter: sqlserver
  mode: odbc
  dsn: test_dj
  host: HOSTNAME\SQLEXPRESS
  database: test_dj
  username: guest
  password: guest
</code>```


问:
Since tvOS 10.2 the Apple TV displays a Airplay connection requires iOS 7.1 or later error
I have an Android app that can use AirPlay to play videos. Since my Apple TV 4 updated to tvOS 10.2 it has stopped working. I tried several other apps on Android and they all get the same error.

Does anyone know how to get around this issue?

Thanks.

答:
tvOS 10.2 introduced a new verification requirement for Airplay streaming devices.

You can find more information about this in the following article:

http://cordcuttersnews.com/apple-tv-tvos-10-2-update-breaks-third-party-airplay/


问:
Calculating Date Difference using date() method
I've been trying to execute the following piece of code to calculate the difference b/w the dates obtained using the PHP $date = date('Y-m-d H:i:s'); function.

```<code>$fine = mysqli_query($conn, "SELECT DATEDIFF(".$query_exec['Date_issued'].", ".$query_exec['Date_returned'].") AS days");
$fine = $fine*10;
</code>```

The value that $fine if returning is only 0 even if the difference b/w the dates is >0.

Plz help, thank you

答:
I suspect $query_exec['Date_issued'] and $query_exec['Date_returned'] contain something like 2017-03-01, 2017-03-30 that, when inserted in the SQL code above produces:

```<code>SELECT DATEDIFF(2017-03-30, 2017-03-01) AS DAYS
</code>```

There is no DATE value in this SQL. 2017-03-01 and 2017-03-30 are numeric expressions that evaluates to 2013 and 1984.

Enclose the values of $query_exec['Date_issued'] and $query_exec['Date_returned'] in quotes in the SQL:

```<code>$sql = sprintf("SELECT DATEDIFF('%s','%s') AS DAYS",
               $query_exec['Date_issued'], $query_exec['Date_returned']);
</code>```

I used sprintf() to make it more readable. You can use strings concatenation as well if you like it more.

Body:
I've been trying to execute the following piece of code to calculate the difference b/w the dates obtained using the PHP $date = date('Y-m-d H:i:s'); function.

$fine = mysqli_query($conn, "SELECT DATEDIFF(".$query_exec['Date_issued'].", ".$query_exec['Date_returned'].") AS days");
$fine = $fine*10;

The value that $fine if returning is only 0 even if the difference b/w the dates is >0.

Plz help, thank you

Body:
I suspect $query_exec['Date_issued'] and $query_exec['Date_returned'] contain something like 2017-03-01, 2017-03-30 that, when inserted in the SQL code above produces:

SELECT DATEDIFF(2017-03-30, 2017-03-01) AS DAYS

There is no DATE value in this SQL. 2017-03-01 and 2017-03-30 are numeric expressions that evaluates to 2013 and 1984.

Enclose the values of $query_exec['Date_issued'] and $query_exec['Date_returned'] in quotes in the SQL:

$sql = sprintf("SELECT DATEDIFF('%s','%s') AS DAYS",
               $query_exec['Date_issued'], $query_exec['Date_returned']);

I used sprintf() to make it more readable. You can use strings concatenation as well if you like it more.


问:
Getting the option text for selected option in select list angular js
My select list data looks like this

```<code>{
  123: 'abc',
  234: 'bcd',
  .
  .
}
</code>```

I am using ng-options in template to render this like

```<code><select ng-model="myOption" ng-option="key as value for (key, value) in data"></select>
</code>```

Now I want to get the option text for selected option in js controller

Is it possible?

PS- I can't change the data structure of data for select list,
so make it a object of objects as shown below is out of question

```<code>{
 {
   name: 'abc',
   value: 123
 },
 {
   name: 'bcd',
   value: 234
 }
}
</code>```

EDIT: I still want to be able to access the selected key i.e. 123 or 234

答:
you can use ng-change and implement a function to get the value by key

```<code><div>
    <select ng-model="myOption" ng-options="key as value for (key, value) in data" ng-change="getVal(myOption)"></select>

    {{selectVal}}
</div>

$scope.getVal = function(val){
    $scope.selectVal = $scope.data[val]
}
</code>```

not that its ng-options with s

demo

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.data = {
  123: 'abc',
  234: 'bcd',
}
$scope.getVal = function(val){
    $scope.selectVal = $scope.data[val]
}
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <select ng-model="myOption" ng-options="key as value for (key, value) in data" ng-change="getVal(myOption)"></select>
{{selectVal}}
</div></code>```

Body:
My select list data looks like this

{
  123: 'abc',
  234: 'bcd',
  .
  .
}

I am using ng-options in template to render this like

<select ng-model="myOption" ng-option="key as value for (key, value) in data"></select>

Now I want to get the option text for selected option in js controller

Is it possible?

PS- I can't change the data structure of data for select list,
so make it a object of objects as shown below is out of question

{
 {
   name: 'abc',
   value: 123
 },
 {
   name: 'bcd',
   value: 234
 }
}

EDIT: I still want to be able to access the selected key i.e. 123 or 234

Body:
you can use ng-change and implement a function to get the value by key

<div>
    <select ng-model="myOption" ng-options="key as value for (key, value) in data" ng-change="getVal(myOption)"></select>

    {{selectVal}}
</div>

$scope.getVal = function(val){
    $scope.selectVal = $scope.data[val]
}

not that its ng-options with s

demo

angular.module("app",[])
.controller("ctrl",function($scope){
$scope.data = {
  123: 'abc',
  234: 'bcd',
}
$scope.getVal = function(val){
    $scope.selectVal = $scope.data[val]
}
})

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
 <select ng-model="myOption" ng-options="key as value for (key, value) in data" ng-change="getVal(myOption)"></select>
{{selectVal}}
</div>


问:
Python Optimized Comparison Between List of Dict
I'm trying to see whether nodes reside within the volume of a sphere, and add the node id to a list. However, the efficiency of the algorithm is incredibly slow and I'm not sure how to improve it.

I have two lists. List A has the format [{'num': ID, 'x': VALUE, 'y': VALUE, 'z': VALUE] while List B has the format [{'x': VALUE, 'y': VALUE, 'z': VALUE, 'rad': VALUE}].

The size of both lists can run upwards of 100,000 items each.

My current code is posted below, but it's very inefficient.

```<code>    filteredList = []
    for i in range(len(sList)):

            minx = (sList[i]['x']) - (sList[i]['radius'])
            maxx = (sList[i]['x']) + (sList[i]['radius'])
            miny = (sList[i]['y']) - (sList[i]['radius'])
            maxy = (sList[i]['y']) + (sList[i]['radius'])
            minz = (sList[i]['z']) - (sList[i]['radius'])
            maxz = (sList[i]['z']) + (sList[i]['radius'])

            for j in range(len(nList)):
                    if minx <= nList[j]['x'] <= maxx:
                            if miny <= nList[j]['y'] <= maxy:
                                    if minz <= nList[j]['z'] <= maxz:
                                            tmpRad = findRadius(sList[i],nList[j])
                                            if tmpRad <= sList[i]['radius']:
                                                    filteredList.append(int(nList[j]['num']))
</code>```

I'm at a loss and appreciate any ideas.

Edit: Adding extra information about the data format.

List A (nList) -- defines nodes, with locations x,y,z, and identifier num

[{'y': 0.0, 'x': 0.0, 'num': 1.0, 'z': 0.0},

{'y': 0.0, 'x': 1.0, 'num': 2.0, 'z': 0.0},

{'y': 0.0, 'x': 2.0, 'num': 3.0, 'z': 0.0},

{'y': 0.0, 'x': 3.0, 'num': 4.0, 'z': 0.0},

{'y': 0.0, 'x': 4.0, 'num': 5.0, 'z': 0.0},

{'y': 0.0, 'x': 5.0, 'num': 6.0, 'z': 0.0},

{'y': 0.0, 'x': 6.0, 'num': 7.0, 'z': 0.0},

{'y': 0.0, 'x': 7.0, 'num': 8.0, 'z': 0.0},

{'y': 0.0, 'x': 8.0, 'num': 9.0, 'z': 0.0},

{'y': 0.0, 'x': 9.0, 'num': 10.0, 'z': 0.0}]

List B (sList) -- defines spheres using x,y,z, radius

[{'y': 18.0, 'x': 25.0, 'z': 26.0, 'radius': 0.0056470000000000001},

{'y': 29.0, 'x': 23.0, 'z': 45.0, 'radius': 0.0066280000000000002},

{'y': 46.0, 'x': 29.0, 'z': 13.0, 'radius': 0.014350999999999999},

{'y': 0.0, 'x': 20.0, 'z': 25.0, 'radius': 0.014866000000000001},

{'y': 27.0, 'x': 31.0, 'z': 18.0, 'radius': 0.018311999999999998},

{'y': 10.0, 'x': 36.0, 'z': 46.0, 'radius': 0.024702000000000002},

{'y': 27.0, 'x': 13.0, 'z': 48.0, 'radius': 0.027300999999999999},

{'y': 14.0, 'x': 1.0, 'z': 13.0, 'radius': 0.033889000000000002},

{'y': 31.0, 'x': 20.0, 'z': 11.0, 'radius': 0.034118999999999997},

{'y': 23.0, 'x': 28.0, 'z': 8.0, 'radius': 0.036683}]

答:
one we can remove from the sample

unless you need to iterate over a list by index, one shouldn't, also avoid using range, and merge ifs together

```<code>filteredList = []
for a in sList:

        minx = (a['x']) - (a['radius'])
        maxx = (a['x']) + (a['radius'])
        miny = (a['y']) - (a['radius'])
        maxy = (a['y']) + (a['radius'])
        minz = (a['z']) - (a['radius'])
        maxz = (a['z']) + (a['radius'])

        for b in nList:
                if minx <= b['x'] <= maxx and miny <= b['y'] <= maxy and minz <= b['z'] <= maxz:
                    tmpRad = findRadius(a,b)
                    if tmpRad <= a['radius']:
                        filteredList.append(int(b['num']))
</code>```

ContentLicense: CC BY-SA 2.5

Body:
I'm trying to see whether nodes reside within the volume of a sphere, and add the node id to a list. However, the efficiency of the algorithm is incredibly slow and I'm not sure how to improve it.

I have two lists. List A has the format [{'num': ID, 'x': VALUE, 'y': VALUE, 'z': VALUE] while List B has the format [{'x': VALUE, 'y': VALUE, 'z': VALUE, 'rad': VALUE}].

The size of both lists can run upwards of 100,000 items each.

My current code is posted below, but it's very inefficient.

    filteredList = []
    for i in range(len(sList)):

            minx = (sList[i]['x']) - (sList[i]['radius'])
            maxx = (sList[i]['x']) + (sList[i]['radius'])
            miny = (sList[i]['y']) - (sList[i]['radius'])
            maxy = (sList[i]['y']) + (sList[i]['radius'])
            minz = (sList[i]['z']) - (sList[i]['radius'])
            maxz = (sList[i]['z']) + (sList[i]['radius'])

            for j in range(len(nList)):
                    if minx <= nList[j]['x'] <= maxx:
                            if miny <= nList[j]['y'] <= maxy:
                                    if minz <= nList[j]['z'] <= maxz:
                                            tmpRad = findRadius(sList[i],nList[j])
                                            if tmpRad <= sList[i]['radius']:
                                                    filteredList.append(int(nList[j]['num']))

I'm at a loss and appreciate any ideas.

Edit: Adding extra information about the data format.

List A (nList) -- defines nodes, with locations x,y,z, and identifier num

[{'y': 0.0, 'x': 0.0, 'num': 1.0, 'z': 0.0},

{'y': 0.0, 'x': 1.0, 'num': 2.0, 'z': 0.0},

{'y': 0.0, 'x': 2.0, 'num': 3.0, 'z': 0.0},

{'y': 0.0, 'x': 3.0, 'num': 4.0, 'z': 0.0},

{'y': 0.0, 'x': 4.0, 'num': 5.0, 'z': 0.0},

{'y': 0.0, 'x': 5.0, 'num': 6.0, 'z': 0.0},

{'y': 0.0, 'x': 6.0, 'num': 7.0, 'z': 0.0},

{'y': 0.0, 'x': 7.0, 'num': 8.0, 'z': 0.0},

{'y': 0.0, 'x': 8.0, 'num': 9.0, 'z': 0.0},

{'y': 0.0, 'x': 9.0, 'num': 10.0, 'z': 0.0}]

List B (sList) -- defines spheres using x,y,z, radius

[{'y': 18.0, 'x': 25.0, 'z': 26.0, 'radius': 0.0056470000000000001},

{'y': 29.0, 'x': 23.0, 'z': 45.0, 'radius': 0.0066280000000000002},

{'y': 46.0, 'x': 29.0, 'z': 13.0, 'radius': 0.014350999999999999},

{'y': 0.0, 'x': 20.0, 'z': 25.0, 'radius': 0.014866000000000001},

{'y': 27.0, 'x': 31.0, 'z': 18.0, 'radius': 0.018311999999999998},

{'y': 10.0, 'x': 36.0, 'z': 46.0, 'radius': 0.024702000000000002},

{'y': 27.0, 'x': 13.0, 'z': 48.0, 'radius': 0.027300999999999999},

{'y': 14.0, 'x': 1.0, 'z': 13.0, 'radius': 0.033889000000000002},

{'y': 31.0, 'x': 20.0, 'z': 11.0, 'radius': 0.034118999999999997},

{'y': 23.0, 'x': 28.0, 'z': 8.0, 'radius': 0.036683}]

Body:
one we can remove from the sample

unless you need to iterate over a list by index, one shouldn't, also avoid using range, and merge ifs together

filteredList = []
for a in sList:

        minx = (a['x']) - (a['radius'])
        maxx = (a['x']) + (a['radius'])
        miny = (a['y']) - (a['radius'])
        maxy = (a['y']) + (a['radius'])
        minz = (a['z']) - (a['radius'])
        maxz = (a['z']) + (a['radius'])

        for b in nList:
                if minx <= b['x'] <= maxx and miny <= b['y'] <= maxy and minz <= b['z'] <= maxz:
                    tmpRad = findRadius(a,b)
                    if tmpRad <= a['radius']:
                        filteredList.append(int(b['num']))


问:
Keep sap.m.MultiComboBox permanently open even after selecting an option
Is it possible to keep sap.m.MultiComboBox open by disabling the drop down toggle upon selecting a checkbox option or any other way of achieving the same.</p>

答:
For this you will need to override the close method of MultiComboxBox. Below is the working code:

View:

```<code><MultiComboBox selectionChange="handleSelectionChange" id='cb'
  selectionFinish="handleSelectionFinish" width="500px"
        items="{/ProductCollection}">
        <core:Item key="{ProductId}" text="{Name}" />
    </MultiComboBox>
</code>```

Controller:

```<code>onAfterRendering: function() {
        var cb = this.byId('cb');
        cb.open(); // Open the MultiCOmboxBox. Remove this if you want user to open this.
        cb.close = function (evt) {
          // dont do anything. Just return; Override default functionality.
        }
        // this makes sure that popup is not closed if clicked outside the popup
       cb.getAggregation('picker').oPopup._bAutoClose = false;

    },
</code>```

Let me know if this works for you.

Body:
For this you will need to override the close method of MultiComboxBox. Below is the working code:

View:

<MultiComboBox selectionChange="handleSelectionChange" id='cb'
  selectionFinish="handleSelectionFinish" width="500px"
        items="{/ProductCollection}">
        <core:Item key="{ProductId}" text="{Name}" />
    </MultiComboBox>

Controller:

onAfterRendering: function() {
        var cb = this.byId('cb');
        cb.open(); // Open the MultiCOmboxBox. Remove this if you want user to open this.
        cb.close = function (evt) {
          // dont do anything. Just return; Override default functionality.
        }
        // this makes sure that popup is not closed if clicked outside the popup
       cb.getAggregation('picker').oPopup._bAutoClose = false;

    },

Let me know if this works for you.


问:
How to make letter grow on type and shrink on backspace in input tag
I'm trying to make an animated input field, such that every letter animates in/out on type/backspace. I imagine that I will have to wrap every letter with a span, like so:

```<code><span class="animateLetter">A</span>
<span class="animateLetter">B</span>
<span class="animateLetter">C</span>
</code>```

But then I lose the dynamic nature of the <input> tag.

The ultimate goal is

```<code><input onChange=animateLetter />
</code>```

Where animateLetter is a function that determines the letter just typed or deleted, and animates its addition or deletion.

Since you cannot wrap the letter values of the value property on the 'input' tag, let alone add a class to those spans, this becomes rather tricky.

答:
You know, you can make it like how element in gmail work. in gmail. each time you add people to recipient, it add one div besides of the text area. so in your problem, whenever javascript detect change in input, you add an element (span or div) right before the input text. You can mask it like the one I do below.just remember that, everytime onchange fired, you need to delete the text in  add  or  text before the input. I don't really have time to implement the script to add text and the animation. for animation, you can take it from https://daneden.github.io/animate.css/. it has many great animation that you can use.

.wrapper {
  border: solid 1px #cccccc;
  display: inline-block;
  font-size: 0;
}

.wrapper .letter {
  letter-spacing: 0px;
  display: inline-block;
  vertical-align: top;
  font-size: 16px;
}

input {
  border: none;
}

input:focus {
  outline-width: 0;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="wrapper">
  <div class="letter">h</div>
  <div class="letter">e</div>
  <div class="letter">l</div>
  <div class="letter">l</div>
  <div class="letter">o</div>
  <input onchange='addTextAnimation()'/>
</div></code>```

Body:
I'm trying to make an animated input field, such that every letter animates in/out on type/backspace. I imagine that I will have to wrap every letter with a span, like so:

A
B
C

But then I lose the dynamic nature of the <input> tag.

The ultimate goal is

<input onChange=animateLetter />

Where animateLetter is a function that determines the letter just typed or deleted, and animates its addition or deletion.

Since you cannot wrap the letter values of the value property on the 'input' tag, let alone add a class to those spans, this becomes rather tricky.

Body:
You know, you can make it like how element in gmail work. in gmail. each time you add people to recipient, it add one div besides of the text area. so in your problem, whenever javascript detect change in input, you add an element (span or div) right before the input text. You can mask it like the one I do below.just remember that, everytime onchange fired, you need to delete the text in  add  or  text before the input. I don't really have time to implement the script to add text and the animation. for animation, you can take it from https://daneden.github.io/animate.css/. it has many great animation that you can use.

.wrapper {
  border: solid 1px #cccccc;
  display: inline-block;
  font-size: 0;
}

.wrapper .letter {
  letter-spacing: 0px;
  display: inline-block;
  vertical-align: top;
  font-size: 16px;
}

input {
  border: none;
}

input:focus {
  outline-width: 0;
}

<div class="wrapper">
  <div class="letter">h</div>
  <div class="letter">e</div>
  <div class="letter">l</div>
  <div class="letter">l</div>
  <div class="letter">o</div>
  <input onchange='addTextAnimation()'/>
</div>


问:
Smallest Sum Algorithm
I feel like I may not have been clear enough about the requirements so let me try to make things more clear.

You are provided a dictionary that contains keys that are either single letters or multiple letters. Each key has an associated value. Given an input, you must find the keys that contain the input letters. Return the lowest key values that satisfy this requirement.

Here are a few examples:

Input Dictionary

Key -> Value

a -> 4

b -> 6

e -> 5

abc -> 8

Input: 'a'
Output: 4

Input: 'c'
Output: 8

Input: 'ab'
Output: 8

Input: 'ac'
Output: 8

Input: 'ce'
Output: 13

Input: 'd'
Output: null

Note on the third example, the input is ab. So here, we can either get the letter 'a' from the key 'a' or the key 'abc'. We can either get the letter 'b' from the key 'b' or the key 'abc'. In order to get both keys with the lowest total value, 'abc' with a value of 8 is the correct output.

Note on the fifth example, the input is ce. The letter 'c' is only available in the key 'abc'. The letter 'e' is only available in the key 'e'. The correct output in this situation is 13.

UPDATE: I was able to solve this recursively by starting off with the first letter in the input sequence, finding all keys that contain that letter, and for each key, building a list of all the possible combinations. I was able to track the lowest sum by recursively moving through one letter of the input sequence at a time.

答:
What I am suggesting here is a bit long method but this is what i can think of to help you right now
Take a max count variable
Now if the input is multiple letters check for all the strings who have the required alphabets. Also look for "sum of alphabets" separately.

Keep on updating the max_count variable accordingly.

Title: Smallest Sum Algorithm


问:
How to kill all processes with a given partial name?
I want to kill all processes that I get by:

```<code>ps aux | grep my_pattern
</code>```

How to do it?

This does not work:

```<code>pkill my_pattern
</code>```

答:
If you judge pkill -f PATTERN a bit too dangerous, I wrote ezkill a bash script that prompt you to choose which processes amongst those that match the PATTERN you want to kill.

Warning: This project is no more maintained.

Body:
I want to kill all processes that I get by:

ps aux | grep my_pattern

How to do it?

This does not work:

pkill my_pattern

ContentLicense: CC BY-SA 4.0


问:
PHP MySQL - Access denied for user
I know that there are a tons of related threads but none of them fixes my problem. i'm having a problem connecting to my database. I get the following error:
Access denied for user ''@'localhost' (using password: NO)

My code for register.php is the following:

```<code><?php
require 'config.php';

if(isset($_POST['submit'])){
    //does verification
    $mail1 = $_POST['email1'];
    $mail2 = $_POST['email2'];
    $pass1 = $_POST['pass1'];
    $pass2 = $_POST['pass2'];

    if(($mail1 == $mail2) && ($pass1 == $pass2)){
        //everything is k
        $name = mysql_escape_string($_POST['name']);
        $lname = mysql_escape_string($_POST['lname']);
        $uname = mysql_escape_string($_POST['uname']);
        $email1 = mysql_escape_string($_POST['email1']);
        $pass1 = mysql_escape_string($_POST['pass1']);

        $pass1 = md5($pass1);

        //Checks if username is taken
        $check = mysql_query("SELECT * FROM users WHERE uname = '$uname'")or die(mysql_error());
        if (mysql_num_rows($check)>=1) {
            echo "Username already taken";
        } else {
        mysql_query("INSERT INTO `users` (`first_name`, `last_name`, `username`, `mail`, `password`, `id`) VALUES ('$name', '$lname', '$uname', '$email1', '$pass1', NULL)") or die(mysql_error());
        echo "Registration Successful";
    } }
    else {
        echo "sorry, something doesn't match.";
    }
} else {
    //displays form
    echo $form = <<<EOT
    <form action="register.php" method="POST">
    First Name: <input type="text" name="name" /><br />
    Last Name: <input type="text" name="lname" /><br />
    Username: <input type="text" name="uname" /><br />
    Email: <input type="text" name="email1" /><br />
    Confirm Email: <input type="text" name="email2" /><br />
    Password: <input type="password" name="pass1" /><br />
    Confirm Password: <input type="password" name="pass2" /><br />
    <input type="submit" value="Register" name="submit" />
EOT;
}

?>
</code>```

and my config.php is:

```<code><?php
mysql_connect("localhost", "root", "");
mysql_select_db("MyDB");
?>
</code>```

What to do? My PHP version is 5.6.27 and MySQL version is 5.6.33

答:
First of all, you'd better use mysqli or pdo (https://stackoverflow.com/a/12860046/2660794)

Once you have modified your code, you need to use the credentials you use to connect to database on your server (eg : the one you use for phpmyadmin).

Title: PHP MySQL - Access denied for user

Body:
I know that there are a tons of related threads but none of them fixes my problem. i'm having a problem connecting to my database. I get the following error:
Access denied for user ''@'localhost' (using password: NO)

My code for register.php is the following:

<?php
require 'config.php';

if(isset($_POST['submit'])){
    //does verification
    $mail1 = $_POST['email1'];
    $mail2 = $_POST['email2'];
    $pass1 = $_POST['pass1'];
    $pass2 = $_POST['pass2'];

    if(($mail1 == $mail2) && ($pass1 == $pass2)){
        //everything is k
        $name = mysql_escape_string($_POST['name']);
        $lname = mysql_escape_string($_POST['lname']);
        $uname = mysql_escape_string($_POST['uname']);
        $email1 = mysql_escape_string($_POST['email1']);
        $pass1 = mysql_escape_string($_POST['pass1']);

        $pass1 = md5($pass1);

        //Checks if username is taken
        $check = mysql_query("SELECT * FROM users WHERE uname = '$uname'")or die(mysql_error());
        if (mysql_num_rows($check)>=1) {
            echo "Username already taken";
        } else {
        mysql_query("INSERT INTO `users` (`first_name`, `last_name`, `username`, `mail`, `password`, `id`) VALUES ('$name', '$lname', '$uname', '$email1', '$pass1', NULL)") or die(mysql_error());
        echo "Registration Successful";
    } }
    else {
        echo "sorry, something doesn't match.";
    }
} else {
    //displays form
    echo $form = <<<EOT
    <form action="register.php" method="POST">
    First Name: <input type="text" name="name" />

    Last Name: <input type="text" name="lname" />

    Username: <input type="text" name="uname" />

    Email: <input type="text" name="email1" />

    Confirm Email: <input type="text" name="email2" />

    Password: <input type="password" name="pass1" />

    Confirm Password: <input type="password" name="pass2" />

    <input type="submit" value="Register" name="submit" />
EOT;
}

?>

and my config.php is:

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("MyDB");
?>

What to do? My PHP version is 5.6.27 and MySQL version is 5.6.33


答:
Aside from the fact that you should be using mysqli functions instead of mysql for security reasons, have you checked:

Your MySQL username is correct?

That a password is not required?

The database you are connecting to is correct?

The do:

```<code>$db = mysql_connect("localhost", "root", "");
mysql_select_db("MyDB", $db);
</code>```

And your queries should be:

```<code>$query = mysql_query("SELECT * FROM users WHERE uname = '$uname'", $db);
</code>```

Title: PHP MySQL - Access denied for user

Body:
Aside from the fact that you should be using mysqli functions instead of mysql for security reasons, have you checked:

Your MySQL username is correct?

That a password is not required?

The database you are connecting to is correct?

The do:

$db = mysql_connect("localhost", "root", "");
mysql_select_db("MyDB", $db);

And your queries should be:

$query = mysql_query("SELECT * FROM users WHERE uname = '$uname'", $db);


问:
Bootstrap hamburger menu not collapsing on iOS Safari
I'm working on a little personal website project and slowly improving my terrible skills. I've got my site to a point I'm happy with although on mobile (iOS Safari), when I expand my hamburger menu, it won't collapse again upon touching the button or the rest of the screen. Can't seem to get around it. Any advice would be great.

HTML:

```<code>    <!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <!--fonts-->
        <link href='http://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,800,900' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'>
    <!--//fonts-->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
    <!-- for-mobile-apps -->
    <meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="Personal Website" />
    <!-- //for-mobile-apps -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
    <header>
        <a class="navbar-brand" href="index.html" id="logo"></a>
        <nav>
            <a href="#" id="menu-icon" input type="checkbox"></a>
            <ul>
                <li><a href="#about">ABOUT</a></li>
                <li><a href="#">WORK</a></li>
                <li><a href="#">BLOG</a></li>
                <li><a href="#">CONTACT</a></li>
            </ul>
        </nav>
    </header>
</code>```

CSS:

```<code>/*RESET*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0; padding:0; border:0; outline:0; font-size:100%; vertical-align:baseline; background:transparent;} body {line-height: 1;}ol, ul{list-style:none;} blockquote, q{quotes:none;} blockquote:before, blockquote:after, q:before, q:after{content:'';content:none;} :focus{outline:0;} ins{text-decoration:none;} del{text-decoration:line-through;} table{border-collapse:collapse; border-spacing:0;}

/*MAIN*/
body {
    font-size: 1.05em;
    line-height: 1.25em;
    font-family: Helvetica Neue, Helvetica, Arial;
    background: #f9f9f9;
    color: #444;
}

h1,h2,h3 {
    font-family: 'Raleway', sans-serif;
}

a {

    color: #414141;
    text-decoration: none;
    font-weight: 300;

}

a:hover {

    color: #000;
    font-weight: 500;
    text-decoration: none;

}

img {

    width: 100%;

}

header {

    background-color: rgba(255,255,255,0.95);
    width: 100%;
    height: 79px;
    position: fixed;
    top: 0;
    left: 0;
    border-bottom: 4px solid #515151;
    z-index: 100;

}

#logo{

    margin: 5px 0 10px 25px;
    float: left;
    width: 65px;
    height: 65px;
    background: url(../images/db_logo_clean_60.png) no-repeat center;
    display: block;

}

nav {

    float: right;
    padding: 20px;

}

#menu-icon {

    display: hidden;
    width: 40px;
    height: 40px;
    background: #515151 url(../images/menu-icon.png) center;

}

a:hover#menu-icon {

    background-color: #000;
    border-radius: 4px 4px 0 0;

}

ul {

    list-style: none;

}

li {

    display: inline-block;
    float: left;
    padding: 10px

}

.current {

    color: #515151;

}

section {

    margin: 80px auto 40px;
    max-width: 980px;
    position: relative;
    padding: 20px

}

/*--banner--*/
.banner{
    background: url(../images/1172.png) no-repeat 0px 0px;
    background-size: 100% 100%;
    -webkit-background-size: 100% 100%;
    -moz-background-size: 100% 100%;
    -o-background-size: 100% 100%;
    text-align: center;
    min-height:800px;
}
.banner-info{
width:70%;
margin: 200px auto 0 auto;
}
.banner-right h1{
font-size:36px;
font-weight:800;
color:#414141;
margin:35px 0 15px 0;
letter-spacing: 15px;
}
.banner-right h2{
  font-size: 40px;
  font-weight: 300;
  color: #313131;
  margin: 15px 0 45px 0;
}
.banner-right p{
text-decoration:none;
color:#414141;
font-size:16px;
font-weight:500;
padding:16px 20px;
border:2px solid #414141;
}

.banner-left{
float:left;
}
.banner-right{
float:right;
}

h1 {

    font-size: 2em;
    color: #2262AD;
    line-height: 1.15em;
    margin: 20px 0 ;

}

p {

    line-height: 1.45em;
    margin-bottom: 20px;

}

.about {
    padding: 60px 0 25px 0;
}
.about h3 {
    margin:0;
    color:#414141;
    font-size:36px;
    font-weight:500;
    letter-spacing: 16px;
}

.about p {
    margin: 60px 100px 0 100px;
}

.contact {
    padding: 60px 0 25px 0;
}
.contact h3 {
    margin:0;
    color:#414141;
    font-size:36px;
    font-weight:500;
    letter-spacing: 16px;
}

.contact p {
    margin: 60px 100px 0 100px;
}

/*MEDIA QUERY*/
@media only screen and (max-width : 1200px) {
    .banner-info {
      width: 87%;
      margin: 180px auto 0 auto;
    }

}

@media only screen and (max-width : 1000px) {
    .banner-info{
        display: inline-block;
        vertical-align: middle;
    }

    .banner-left {
        margin: 0 20px 0 0;
        width: 25%;
    }

    .banner-right {
        width: 70%;
    }

    .banner-right h1 {
        font-size: 30px;
    }

    .banner-right h2 {
        font-size: 36px;
    }

    .banner-right p {
        font-size: 14px;
    }

}

@media only screen and (max-width : 1000px) {
    .banner {
        min-height: 700px;
    }
}

@media only screen and (max-width : 640px) {

    header {

        position: absolute;

    }

    #menu-icon {

        display:inline-block;

    }

    nav ul, nav:active ul {

        display: none;
        position: absolute;
        padding: 20px;
        background: #fff;
        border: 5px solid #444;
        right: 20px;
        top: 60px;
        width: 50%;
        border-radius: 4px 0 4px 4px;

    }

    nav li {

        text-align: center;
        width: 100%;
        padding: 10px 0;
        margin: 0;

    }

    nav:hover ul {

        display: block;

    }

    .banner-info{
        margin-top: 140px;
        display: inline-block;
        vertical-align: middle;
    }
    .banner-left{
        float: none;
        margin: 0 auto;
        width: 35%;
        vertical-align: middle;
    }
        .banner-right{
        float: none;
        margin: 0 auto;
        vertical-align: middle;
    }

    .about p {
    margin: 50px 50px 0 50px;
    }
}
@media only screen and (max-width : 340px) {
    .about h3 {
        font-size: 28px;
    }
    .about p {
        margin: 25px 25px 0 25px;
    }
}
</code>```

答:
Could you try this Mega Menu.....

jQuery(document).on('click', '.mega-dropdown', function(e) {
  e.stopPropagation()
})```
<pre class="snippet-code-css lang-css prettyprint-override"><code>@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
  font-family: 'Open Sans', 'sans-serif';
  background: #f0f0f0;
  background: url(https://pcbx.us/bfjb.jpg);
}

h1,
.h1 {
  font-size: 36px;
  text-align: center;
  font-size: 5em;
  color: #404041;
}

.navbar-nav>li>.dropdown-menu {
  margin-top: 20px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.navbar-default .navbar-nav>li>a {
  width: 200px;
  font-weight: bold;
}

.mega-dropdown {
  position: static !important;
  width: 100%;
}

.mega-dropdown-menu {
  padding: 20px 0px;
  width: 100%;
  box-shadow: none;
  -webkit-box-shadow: none;
}

.mega-dropdown-menu:before {
  content: "";
  border-bottom: 15px solid #fff;
  border-right: 17px solid transparent;
  border-left: 17px solid transparent;
  position: absolute;
  top: -15px;
  left: 285px;
  z-index: 10;
}

.mega-dropdown-menu:after {
  content: "";
  border-bottom: 17px solid #ccc;
  border-right: 19px solid transparent;
  border-left: 19px solid transparent;
  position: absolute;
  top: -17px;
  left: 283px;
  z-index: 8;
}

.mega-dropdown-menu>li>ul {
  padding: 0;
  margin: 0;
}

.mega-dropdown-menu>li>ul>li {
  list-style: none;
}

.mega-dropdown-menu>li>ul>li>a {
  display: block;
  padding: 3px 20px;
  clear: both;
  font-weight: normal;
  line-height: 1.428571429;
  color: #999;
  white-space: normal;
}

.mega-dropdown-menu>li ul>li>a:hover,
.mega-dropdown-menu>li ul>li>a:focus {
  text-decoration: none;
  color: #444;
  background-color: #f5f5f5;
}

.mega-dropdown-menu .dropdown-header {
  color: #428bca;
  font-size: 18px;
  font-weight: bold;
}

.mega-dropdown-menu form {
  margin: 3px 20px;
}

.mega-dropdown-menu .form-group {
  margin-bottom: 3px;
}</code>```

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

      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-navbar-collapse">
        Toggle navigation

      </button>
      MegaMenu

          Collection

New in Stores

Summer dress floral prints

                      <button class="btn btn-primary" type="button">49,99 €</button>
                      <button href="#" class="btn btn-default" type="button"> Add to Wishlist</button>

Gold sandals with shiny touch

                      <button class="btn btn-primary" type="button">9,99 €</button>
                      <button href="#" class="btn btn-default" type="button"> Add to Wishlist</button>

Denin jacket stamped

                      <button class="btn btn-primary" type="button">49,99 €</button>
                      <button href="#" class="btn btn-default" type="button"> Add to Wishlist</button>

View all Collection

Dresses

Unique Features

Image Responsive

Auto Carousel

Newsletter Form

Four columns

Tops

Good Typography

Jackets

Easy to customize

Glyphicons

Pull Right Elements

Pants

Coloured Headers

Primary Buttons & Default

Calls to action

Accessories

Default Navbar

Lovely Fonts

Responsive Dropdown

Newsletter

                <form class="form" role="form">

                    Email address
                    <input type="email" class="form-control" id="email" placeholder="Enter email">

                  <button type="submit" class="btn btn-primary btn-block">Sign in</button>
                </form>

 Bootstrap Mega Menu
```

Body:
I'm working on a little personal website project and slowly improving my terrible skills. I've got my site to a point I'm happy with although on mobile (iOS Safari), when I expand my hamburger menu, it won't collapse again upon touching the button or the rest of the screen. Can't seem to get around it. Any advice would be great.

HTML:

    <!DOCTYPE html>

    <title>Title</title>

        <link href='http://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,800,900' rel='stylesheet' type='text/css'>
        <link href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700,900,100italic,300italic,400italic,700italic,900italic' rel='stylesheet' type='text/css'>

        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />

    <meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="Personal Website" />

ABOUT

WORK

BLOG

CONTACT

CSS:

/*RESET*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {margin:0; padding:0; border:0; outline:0; font-size:100%; vertical-align:baseline; background:transparent;} body {line-height: 1;}ol, ul{list-style:none;} blockquote, q{quotes:none;} blockquote:before, blockquote:after, q:before, q:after{content:'';content:none;} :focus{outline:0;} ins{text-decoration:none;} del{text-decoration:line-through;} table{border-collapse:collapse; border-spacing:0;}

/*MAIN*/
body {
    font-size: 1.05em;
    line-height: 1.25em;
    font-family: Helvetica Neue, Helvetica, Arial;
    background: #f9f9f9;
    color: #444;
}

h1,h2,h3 {
    font-family: 'Raleway', sans-serif;
}

a {

    color: #414141;
    text-decoration: none;
    font-weight: 300;

}

a:hover {

    color: #000;
    font-weight: 500;
    text-decoration: none;

}

img {

    width: 100%;

}

header {

    background-color: rgba(255,255,255,0.95);
    width: 100%;
    height: 79px;
    position: fixed;
    top: 0;
    left: 0;
    border-bottom: 4px solid #515151;
    z-index: 100;

}

#logo{

    margin: 5px 0 10px 25px;
    float: left;
    width: 65px;
    height: 65px;
    background: url(../images/db_logo_clean_60.png) no-repeat center;
    display: block;

}

nav {

    float: right;
    padding: 20px;

}

#menu-icon {

    display: hidden;
    width: 40px;
    height: 40px;
    background: #515151 url(../images/menu-icon.png) center;

}

a:hover#menu-icon {

    background-color: #000;
    border-radius: 4px 4px 0 0;

}

ul {

    list-style: none;

}

li {

    display: inline-block;
    float: left;
    padding: 10px

}

.current {

    color: #515151;

}

section {

    margin: 80px auto 40px;
    max-width: 980px;
    position: relative;
    padding: 20px

}

/*--banner--*/
.banner{
    background: url(../images/1172.png) no-repeat 0px 0px;
    background-size: 100% 100%;
    -webkit-background-size: 100% 100%;
    -moz-background-size: 100% 100%;
    -o-background-size: 100% 100%;
    text-align: center;
    min-height:800px;
}
.banner-info{
width:70%;
margin: 200px auto 0 auto;
}
.banner-right h1{
font-size:36px;
font-weight:800;
color:#414141;
margin:35px 0 15px 0;
letter-spacing: 15px;
}
.banner-right h2{
  font-size: 40px;
  font-weight: 300;
  color: #313131;
  margin: 15px 0 45px 0;
}
.banner-right p{
text-decoration:none;
color:#414141;
font-size:16px;
font-weight:500;
padding:16px 20px;
border:2px solid #414141;
}

.banner-left{
float:left;
}
.banner-right{
float:right;
}

h1 {

    font-size: 2em;
    color: #2262AD;
    line-height: 1.15em;
    margin: 20px 0 ;

}

p {

    line-height: 1.45em;
    margin-bottom: 20px;

}

.about {
    padding: 60px 0 25px 0;
}
.about h3 {
    margin:0;
    color:#414141;
    font-size:36px;
    font-weight:500;
    letter-spacing: 16px;
}

.about p {
    margin: 60px 100px 0 100px;
}

.contact {
    padding: 60px 0 25px 0;
}
.contact h3 {
    margin:0;
    color:#414141;
    font-size:36px;
    font-weight:500;
    letter-spacing: 16px;
}

.contact p {
    margin: 60px 100px 0 100px;
}

/*MEDIA QUERY*/
@media only screen and (max-width : 1200px) {
    .banner-info {
      width: 87%;
      margin: 180px auto 0 auto;
    }

}

@media only screen and (max-width : 1000px) {
    .banner-info{
        display: inline-block;
        vertical-align: middle;
    }

    .banner-left {
        margin: 0 20px 0 0;
        width: 25%;
    }

    .banner-right {
        width: 70%;
    }

    .banner-right h1 {
        font-size: 30px;
    }

    .banner-right h2 {
        font-size: 36px;
    }

    .banner-right p {
        font-size: 14px;
    }

}

@media only screen and (max-width : 1000px) {
    .banner {
        min-height: 700px;
    }
}

@media only screen and (max-width : 640px) {

    header {

        position: absolute;

    }

    #menu-icon {

        display:inline-block;

    }

    nav ul, nav:active ul {

        display: none;
        position: absolute;
        padding: 20px;
        background: #fff;
        border: 5px solid #444;
        right: 20px;
        top: 60px;
        width: 50%;
        border-radius: 4px 0 4px 4px;

    }

    nav li {

        text-align: center;
        width: 100%;
        padding: 10px 0;
        margin: 0;

    }

    nav:hover ul {

        display: block;

    }

    .banner-info{
        margin-top: 140px;
        display: inline-block;
        vertical-align: middle;
    }
    .banner-left{
        float: none;
        margin: 0 auto;
        width: 35%;
        vertical-align: middle;
    }
        .banner-right{
        float: none;
        margin: 0 auto;
        vertical-align: middle;
    }

    .about p {
    margin: 50px 50px 0 50px;
    }
}
@media only screen and (max-width : 340px) {
    .about h3 {
        font-size: 28px;
    }
    .about p {
        margin: 25px 25px 0 25px;
    }
}

Body:
Could you try this Mega Menu.....

jQuery(document).on('click', '.mega-dropdown', function(e) {
  e.stopPropagation()
})

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
  font-family: 'Open Sans', 'sans-serif';
  background: #f0f0f0;
  background: url(https://pcbx.us/bfjb.jpg);
}

h1,
.h1 {
  font-size: 36px;
  text-align: center;
  font-size: 5em;
  color: #404041;
}

.navbar-nav>li>.dropdown-menu {
  margin-top: 20px;
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.navbar-default .navbar-nav>li>a {
  width: 200px;
  font-weight: bold;
}

.mega-dropdown {
  position: static !important;
  width: 100%;
}

.mega-dropdown-menu {
  padding: 20px 0px;
  width: 100%;
  box-shadow: none;
  -webkit-box-shadow: none;
}

.mega-dropdown-menu:before {
  content: "";
  border-bottom: 15px solid #fff;
  border-right: 17px solid transparent;
  border-left: 17px solid transparent;
  position: absolute;
  top: -15px;
  left: 285px;
  z-index: 10;
}

.mega-dropdown-menu:after {
  content: "";
  border-bottom: 17px solid #ccc;
  border-right: 19px solid transparent;
  border-left: 19px solid transparent;
  position: absolute;
  top: -17px;
  left: 283px;
  z-index: 8;
}

.mega-dropdown-menu>li>ul {
  padding: 0;
  margin: 0;
}

.mega-dropdown-menu>li>ul>li {
  list-style: none;
}

.mega-dropdown-menu>li>ul>li>a {
  display: block;
  padding: 3px 20px;
  clear: both;
  font-weight: normal;
  line-height: 1.428571429;
  color: #999;
  white-space: normal;
}

.mega-dropdown-menu>li ul>li>a:hover,
.mega-dropdown-menu>li ul>li>a:focus {
  text-decoration: none;
  color: #444;
  background-color: #f5f5f5;
}

.mega-dropdown-menu .dropdown-header {
  color: #428bca;
  font-size: 18px;
  font-weight: bold;
}

.mega-dropdown-menu form {
  margin: 3px 20px;
}

.mega-dropdown-menu .form-group {
  margin-bottom: 3px;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <nav class="navbar navbar-default">
    <div class="navbar-header">
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".js-navbar-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">MegaMenu</a>
    </div>

    <div class="collapse navbar-collapse js-navbar-collapse">
      <ul class="nav navbar-nav">
        <li class="dropdown mega-dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Collection <span class="glyphicon glyphicon-chevron-down pull-right"></span></a>

          <ul class="dropdown-menu mega-dropdown-menu row">
            <li class="col-sm-3">
              <ul>
                <li class="dropdown-header">New in Stores</li>
                <div id="myCarousel" class="carousel slide" data-ride="carousel">
                  <div class="carousel-inner">
                    <div class="item active">
                      <a href="#"><img src="http://placehold.it/254x150/3498db/f5f5f5/&text=New+Collection" class="img-responsive" alt="product 1"></a>
                      <h4><small>Summer dress floral prints</small></h4>
                      <button class="btn btn-primary" type="button">49,99 €</button>
                      <button href="#" class="btn btn-default" type="button"><span class="glyphicon glyphicon-heart"></span> Add to Wishlist</button>
                    </div>
                    <!-- End Item -->
                    <div class="item">
                      <a href="#"><img src="http://placehold.it/254x150/ef5e55/f5f5f5/&text=New+Collection" class="img-responsive" alt="product 2"></a>
                      <h4><small>Gold sandals with shiny touch</small></h4>
                      <button class="btn btn-primary" type="button">9,99 €</button>
                      <button href="#" class="btn btn-default" type="button"><span class="glyphicon glyphicon-heart"></span> Add to Wishlist</button>
                    </div>
                    <!-- End Item -->
                    <div class="item">
                      <a href="#"><img src="http://placehold.it/254x150/2ecc71/f5f5f5/&text=New+Collection" class="img-responsive" alt="product 3"></a>
                      <h4><small>Denin jacket stamped</small></h4>
                      <button class="btn btn-primary" type="button">49,99 €</button>
                      <button href="#" class="btn btn-default" type="button"><span class="glyphicon glyphicon-heart"></span> Add to Wishlist</button>
                    </div>
                    <!-- End Item -->
                  </div>
                  <!-- End Carousel Inner -->
                </div>
                <!-- /.carousel -->
                <li class="divider"></li>
                <li><a href="#">View all Collection <span class="glyphicon glyphicon-chevron-right pull-right"></span></a></li>
              </ul>
            </li>
            <li class="col-sm-3">
              <ul>
                <li class="dropdown-header">Dresses</li>
                <li><a href="#">Unique Features</a></li>
                <li><a href="#">Image Responsive</a></li>
                <li><a href="#">Auto Carousel</a></li>
                <li><a href="#">Newsletter Form</a></li>
                <li><a href="#">Four columns</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Tops</li>
                <li><a href="#">Good Typography</a></li>
              </ul>
            </li>
            <li class="col-sm-3">
              <ul>
                <li class="dropdown-header">Jackets</li>
                <li><a href="#">Easy to customize</a></li>
                <li><a href="#">Glyphicons</a></li>
                <li><a href="#">Pull Right Elements</a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Pants</li>
                <li><a href="#">Coloured Headers</a></li>
                <li><a href="#">Primary Buttons & Default</a></li>
                <li><a href="#">Calls to action</a></li>
              </ul>
            </li>
            <li class="col-sm-3">
              <ul>
                <li class="dropdown-header">Accessories</li>
                <li><a href="#">Default Navbar</a></li>
                <li><a href="#">Lovely Fonts</a></li>
                <li><a href="#">Responsive Dropdown </a></li>
                <li class="divider"></li>
                <li class="dropdown-header">Newsletter</li>
                <form class="form" role="form">
                  <div class="form-group">
                    <label class="sr-only" for="email">Email address</label>
                    <input type="email" class="form-control" id="email" placeholder="Enter email">
                  </div>
                  <button type="submit" class="btn btn-primary btn-block">Sign in</button>
                </form>
              </ul>
            </li>
          </ul>

        </li>
      </ul>

    </div>
    <!-- /.nav-collapse -->
  </nav>
</div>

<h1 class="c-text"> Bootstrap Mega Menu </h1>


问:
import big csv with lots of columns into postgreSQL
I have a csv file with 2550 columns and I want to import it into postgreSQL.

For importing csv in postgreSQL at first I should create the table and them use \copy to copy from csv to table. but what if the table has huge amount of columns like my case that I cannot create table manually.

any solution?

Update

Data structure is as following:
dZ(01) till dZ(2550) are basically between -50 to +50:

```<code>id | date    | time      | localtime | pid | dZ(0)..dZ(1)......dZ(2550)|
---|---------|-----------|-----------|-----|---------------------------|
17|11-11-2014| 16:33:21 | 1.45E+15   |2375 |0 0 0 0 0 -1 0 -1 0 -5 -10|
</code>```

CSV structure: (I used '';' delimiter)

```<code>17;13-11-2014;08:09:37;1.45E+15;4098;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -4 3 0 -2 3 -2 1 0 0 1 1 3 -2 3 4 2 -2 -2 ....
</code>```

This is one line of data.

答:
Considering that the maximum is 1600 columns, so i devided the csv into two tables of each 1000, I wrote a python code to create dz columns and it works fine:

```<code>import psycopg2
sqlstring="CREATE TABLE z(id bigint, date date, time time,"
for i in range(1001):
    if(i<1000):
        sqlstring+="dz"+str(i)+ " int,"
    elif i==1000:
        sqlstring+="dz"+str(i)+ " int"
sqlstring += ");"

connection = psycopg2.connect("dbname='mydb' user='qfsa' host='localhost' password='123' port=5433")
cursor=connection.cursor();
cursor.execute(sqlstring)
connection.commit()
</code>```

now i could import csv into the table.

Body:
I have a csv file with 2550 columns and I want to import it into postgreSQL.

For importing csv in postgreSQL at first I should create the table and them use \copy to copy from csv to table. but what if the table has huge amount of columns like my case that I cannot create table manually.

any solution?

Update

Data structure is as following:
dZ(01) till dZ(2550) are basically between -50 to +50:

id | date    | time      | localtime | pid | dZ(0)..dZ(1)......dZ(2550)|
---|---------|-----------|-----------|-----|---------------------------|
17|11-11-2014| 16:33:21 | 1.45E+15   |2375 |0 0 0 0 0 -1 0 -1 0 -5 -10|

CSV structure: (I used '';' delimiter)

17;13-11-2014;08:09:37;1.45E+15;4098;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -4 3 0 -2 3 -2 1 0 0 1 1 3 -2 3 4 2 -2 -2 ....

This is one line of data.

Body:
Considering that the maximum is 1600 columns, so i devided the csv into two tables of each 1000, I wrote a python code to create dz columns and it works fine:

import psycopg2
sqlstring="CREATE TABLE z(id bigint, date date, time time,"
for i in range(1001):
    if(i<1000):
        sqlstring+="dz"+str(i)+ " int,"
    elif i==1000:
        sqlstring+="dz"+str(i)+ " int"
sqlstring += ");"

connection = psycopg2.connect("dbname='mydb' user='qfsa' host='localhost' password='123' port=5433")
cursor=connection.cursor();
cursor.execute(sqlstring)
connection.commit()

now i could import csv into the table.


问:
iOS (iPhone, iPad, iPodTouch) view real-time console log terminal
Is there a way to view the real-time console log to view NSLog and other debug messages in a real-time manner, such as adb logcat?</p>

答:
Just open the Application Console.app on mac osX.

You can find it under Applications > Utilities > Console.

On the left side of the application all your connected devices are listed.


问:
searching database and displaying on .cshtml page
I have this code in my controller:

```<code> public ActionResult Search(String searchstring)
    {

        var number = from n in db.UCountInfoes
                     select n;

        if (!String.IsNullOrEmpty(searchstring))
        {
            number = number.Where(i => i.IDNumber.Equals(searchstring));
        }
        return View(number);
    }
</code>```

and on my .cshtml page i have this which i use to search:

```<code><div class="form-group">
                        @Html.LabelFor(model => model.ID_Number, htmlAttributes: new { @class = "control-label col-md-2" })
                        <div class="col-md-10">
                            @Html.EditorFor(model => model.ID_Number, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.ID_Number, "", new { @class = "text-danger" })
                        </div>
                    </div>
<div class="form-group">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" name="SearchButton" value="Search" class="btn btn-inverse" />
                        </div>
                    </div>
</code>```

After clicking the search button i want to return the records found on another .cshtml page.

答:
```<code>  return RedirectToAction("Action Name", "Your Controller Name", number);
</code>```

Instead of return View you can use the above method.
Here Action Name is the View Name you want to show the results into.

Body:
I have this code in my controller:

 public ActionResult Search(String searchstring)
    {

        var number = from n in db.UCountInfoes
                     select n;

        if (!String.IsNullOrEmpty(searchstring))
        {
            number = number.Where(i => i.IDNumber.Equals(searchstring));
        }
        return View(number);
    }

and on my .cshtml page i have this which i use to search:

                        @Html.LabelFor(model => model.ID_Number, htmlAttributes: new { @class = "control-label col-md-2" })

                            @Html.EditorFor(model => model.ID_Number, new { htmlAttributes = new { @class = "form-control" } })
                            @Html.ValidationMessageFor(model => model.ID_Number, "", new { @class = "text-danger" })

                            <input type="submit" name="SearchButton" value="Search" class="btn btn-inverse" />

After clicking the search button i want to return the records found on another .cshtml page.

Body:
  return RedirectToAction("Action Name", "Your Controller Name", number);

Instead of return View you can use the above method.
Here Action Name is the View Name you want to show the results into.


问:
How to run an NUnit test in VisualStudio with OpenCover code coverage?
I am new to NUnit testing. I was able to write test cases for my functions, now what I want is to know the code coverage for my test cases. For that I use OpenCover. But I don't know how to install and get OpenCover to work with Visual Studio 2015, can anyone guide me to install OpenCover for Visual Studio and provide help to see the code coverage in Visual Studio?</p>

答:
You need some VS extension to include the coverage results in VS.
One example:
https://visualstudiogallery.msdn.microsoft.com/6950a046-8919-4935-8542-c6f37956f688/view/

you need OpenCover installed/present in solution

you need NUnitConsole installed/present in solution

it does not support VS2017

NUnit3 supported only when you do a custom build from git (not in latest release)

I have nothing to do with this extension, it is just working for me. Use at your own risk :)

If you mean it and you can spent some $ go for http://www.ncrunch.net/


问:
Converting NSString to char byte array
In my program, I receive a NSString like this one : AA010158AA7D385002. And I need to pass it to a method which accept a char byte array, as below :

```<code>char[9] = {0xAA, 0x01, 0x01, 0x58, 0xAA, 0x7D, 0x38, 0x50, 0x02};
</code>```

How to convert my NSString to char byte array like this one?

Thanks!

答:
I finally managed to find the answer to my own question. I am posting it here in case it helps someone else.

So I use a method to convert an NSString hex to bytes :

```<code>@implementation NSString (HexToBytes)

    - (NSData *)hexToBytes
    {
        NSMutableData   *data = [NSMutableData data];
        int             idx;

        for (idx = 0; idx + 2 <= self.length; idx += 2) {
            NSRange         range = NSMakeRange(idx, 2);
            NSString        *hexStr = [self substringWithRange:range];
            NSScanner       *scanner = [NSScanner scannerWithString:hexStr];
            unsigned int    intValue;
            [scanner scanHexInt:&intValue];
            [data appendBytes:&intValue length:1];
        }

        return data;
    }

@end
</code>```

And then, I simply use it like that :

```<code>NSString *str = @"AA010158AA7D385002";
NSData *databytes = [str hexToBytes];
char *bytePtr = (char *)[databytes bytes];
</code>```

And I finally get my char array. Hope it helps someone else.

Title: Converting NSString to char byte array

Body:
In my program, I receive a NSString like this one : AA010158AA7D385002. And I need to pass it to a method which accept a char byte array, as below :

char[9] = {0xAA, 0x01, 0x01, 0x58, 0xAA, 0x7D, 0x38, 0x50, 0x02};

How to convert my NSString to char byte array like this one?

Thanks!

Body:
I finally managed to find the answer to my own question. I am posting it here in case it helps someone else.

So I use a method to convert an NSString hex to bytes :

@implementation NSString (HexToBytes)

    - (NSData *)hexToBytes
    {
        NSMutableData   *data = [NSMutableData data];
        int             idx;

        for (idx = 0; idx + 2 <= self.length; idx += 2) {
            NSRange         range = NSMakeRange(idx, 2);
            NSString        *hexStr = [self substringWithRange:range];
            NSScanner       *scanner = [NSScanner scannerWithString:hexStr];
            unsigned int    intValue;
            [scanner scanHexInt:&intValue];
            [data appendBytes:&intValue length:1];
        }

        return data;
    }

@end

And then, I simply use it like that :

NSString *str = @"AA010158AA7D385002";
NSData *databytes = [str hexToBytes];
char *bytePtr = (char *)[databytes bytes];

And I finally get my char array. Hope it helps someone else.


问:
.show() not working in PtQt4
When I run the code below, I should be able to see a new window that I created. However, when I run it, I can see the new window appearing for a split second and disappearing. What could be the problem?</p>

```<code>import sys
from PyQt4 import QtGui
applicationDefinition = QtGui.QApplication(sys.argv)
windowFigure = QtGui.QWidget()
windowFigure.show()
</code>```

答:
```<code>import sys
from PyQt4 import QtGui

applicationDefinition = QtGui.QApplication(sys.argv)
windowFigure = QtGui.QWidget()
windowFigure.show()
applicationDefinition.exec_()
</code>```

Title: .show() not working in PtQt4

Body:
When I run the code below, I should be able to see a new window that I created. However, when I run it, I can see the new window appearing for a split second and disappearing. What could be the problem?

import sys
from PyQt4 import QtGui
applicationDefinition = QtGui.QApplication(sys.argv)
windowFigure = QtGui.QWidget()
windowFigure.show()


问:
Viewing the source code where something is defined within Juno for Julia-lang
Is there any easy way (such as Ctrl+click on a type, function, etc) to redirect to the source code definition of a type, function, macro, ... in the Juno IDE?</p>

答:
Use the @edit or @which macros.

Ex: @edit 2*2


问:
Import from github to android studio
Hey I am trying to build an android application regarding google adsense.
I want to import the android sample.
https://github.com/Ishaan-Kumar/googleads-adsense-examples

Since I am only interested in android I want to import only this.
https://github.com/Ishaan-Kumar/googleads-adsense-examples/tree/master/android

I tried to import via VCS in android studio by url https://github.com/Ishaan-Kumar/googleads-adsense-examples.git

But it imported the whole project including all the platforms(PHP,dontnet,ruby).
The thing is I want the android only plus the android files are not detected (I think there is not gradle file in here)

How do I overcome this problem?

答:
Often programmers explain that in there Git Page, some time don't explain. like it

Many way to import Github project into your android studio project like this ways

use zip git file Like this Step Answer [here]

use clone or git in android studio See this

use JitPack site for better performance and jump filters can help you

But

some programmers in Github don't like customizing them project

they try to damage files or redirecting for block modify

Title: Import from github to android studio


问:
Creating executable with Cx_freeze : ImportError: cannot import name _ni_support (scipy)
I am trying to create an executable from a python script, I have had a few issues that I have solved simply manually importing other modules/scripts, but for some reason it doesn't worth with this one. The error message:

```<code>File "C:\Program Files\Miniconda2\lib\site-packages\scipy\ndimage\filters.py", line 35, in <module>
from . import _ni_support
ImportError: cannot import name _ni_support
</code>```

Did anyone have this problem before? I can't seem to find it anywhere online. (I found similar problems with _ni_support but never with scipy.

I already tried reinstalling every package/module, but the problem is still there.

Thank you all for your patience.

答:
Solved:

For some unknow reason I had the following unused import added to my script a couple commits earlier:

```<code>from skimage.feature.tests.test_censure import img
</code>```

Removing it solved the issue.

Body:
I am trying to create an executable from a python script, I have had a few issues that I have solved simply manually importing other modules/scripts, but for some reason it doesn't worth with this one. The error message:

File "C:\Program Files\Miniconda2\lib\site-packages\scipy\ndimage\filters.py", line 35, in <module>
from . import _ni_support
ImportError: cannot import name _ni_support

Did anyone have this problem before? I can't seem to find it anywhere online. (I found similar problems with _ni_support but never with scipy.

I already tried reinstalling every package/module, but the problem is still there.

Thank you all for your patience.

Body:
Solved:

For some unknow reason I had the following unused import added to my script a couple commits earlier:

from skimage.feature.tests.test_censure import img

Removing it solved the issue.


问:
Android Videoview is not displaying video at all only sound is heard
Videoview is not showing video but is playing sound,It shows Black screen every time. I am running Android 4.0.I am running this on emulator.

This is my xml file.

```<code><VideoView
android:id="@+id/myVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"/>
</code>```

.java file

```<code>VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress ="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";

Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.setZOrderOnTop(false);

vidView.start();
</code>```

Please help I am stuck on it from one week. Searched a lot but nothing worked.

答:
solution 1:

```<code>videoView.setZOrderOnTop(true);
</code>```

this will set the videoview to the top layer; In other words: block everything under it.

solution 2:

```<code>videoView.setBackgroundColor(Color.TRANSPARENT);
</code>```

solution 3:

sometimes this is related about your apptheme;
In my case, I changed the apptheme from "@style/AppTheme" to "@android:style/Theme.NoTitleBar.Fullscreen" fix my problem.

Body:
Videoview is not showing video but is playing sound,It shows Black screen every time. I am running Android 4.0.I am running this on emulator.

This is my xml file.

<VideoView
android:id="@+id/myVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"/>

.java file

VideoView vidView = (VideoView)findViewById(R.id.myVideo);
String vidAddress ="rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";

Uri vidUri = Uri.parse(vidAddress);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.setZOrderOnTop(false);

vidView.start();

Please help I am stuck on it from one week. Searched a lot but nothing worked.

Body:
solution 1:

videoView.setZOrderOnTop(true);

this will set the videoview to the top layer; In other words: block everything under it.

solution 2:

videoView.setBackgroundColor(Color.TRANSPARENT);

solution 3:

sometimes this is related about your apptheme;
In my case, I changed the apptheme from "@style/AppTheme" to "@android:style/Theme.NoTitleBar.Fullscreen" fix my problem.


问:
SWI-Prolog family tree parent_of/2
```<code>male(jerry).
male(stuart).
male(warren).
male(peter).

female(kather).
female(maryalice).
female(ann).

brother(jerry,stuart).
brother(jerry,kather).
brother(peter, warren).

sister(ann, maryalice).
sister(kather,jerry).

parent_of(warren,jerry).
parent_of(maryalice,jerry).
</code>```

I was given the facts above and I need to define a rule using the predicate parent_of. Yes, it is the same predicate as the above facts defined by parent_of.

Assume I have a sibling(X, Y) rule that will return all the correct sibling pairs.

I write my parent_of(X, Y) rule as parent_of(X, Y) :- parent_of(X, A), sibling(A, Y).

However, this implementation will lead me to an infinity loop.

Is there a way to define the rule parent_of(X, Y) such that it will return

```<code>(warren, jerry),
(warren, stuart),
(warren, kather),
(maryalice, jerry),
(maryalice, stuart),
(maryalice, kather)
</code>```

I also tried

```<code>parent_of(X, Y) :-
    parent_of(X, jerry),
    brother(jerry, Y).
</code>```

I can get the correct answers by this way but it ended up in "Out of local stack" error. Besides that, I don't think the rule is fine as I hard coded it.

I have seen suggestions like change the rule name to something else such as another_parent_of(X, Y). It does solve the problem, but it is a requirement for me to define it using the same predicate.

Any help is greatly appreciated.

EDITED

The intention of this exercise is to write rules such that you can complete this family tree, though only minimal facts are given. As you can see, it only states that Warren is the father of Jerry, and from brother and sister facts, we know Jerry is the brother of Stuart and Kather. So I will have a rule, parent_of(X, Y) to deduce Warren is also the father of Stuart and Kather, though this was not stated in the facts above.

The main concern is how can I write my parent_of(X, Y) rule to avoid it getting into infinite loop.

答:
I do not understand why you need to use parent_of in the definition of sibling. Why you no just write:

```<code>sibling(X, Y) :-
    parent_of(Parent, X),
    parent_of(Parent, Y).
</code>```

I also don't understand the logic of the facts that you are given. You have male and female, but you also have brother and sister; why not define brother and sister in terms of "brother is a male sibling" and "sister is a female sibling"? I already show above how to define "siblings have same parent".

Anyway, this is really old tired question, it is very amazing how many times "Prolog family tree" has been regurgitated.

```<code>the cow the old cow she is dead
it sleeps well the horned head
we poor lads tis our turn now
to hear such tunes as killed the cow
</code>```

Title: SWI-Prolog family tree parent_of/2

Body:
male(jerry).
male(stuart).
male(warren).
male(peter).

female(kather).
female(maryalice).
female(ann).

brother(jerry,stuart).
brother(jerry,kather).
brother(peter, warren).

sister(ann, maryalice).
sister(kather,jerry).

parent_of(warren,jerry).
parent_of(maryalice,jerry).

I was given the facts above and I need to define a rule using the predicate parent_of. Yes, it is the same predicate as the above facts defined by parent_of.

Assume I have a sibling(X, Y) rule that will return all the correct sibling pairs.

I write my parent_of(X, Y) rule as parent_of(X, Y) :- parent_of(X, A), sibling(A, Y).

However, this implementation will lead me to an infinity loop.

Is there a way to define the rule parent_of(X, Y) such that it will return

(warren, jerry),
(warren, stuart),
(warren, kather),
(maryalice, jerry),
(maryalice, stuart),
(maryalice, kather)

I also tried

parent_of(X, Y) :-
    parent_of(X, jerry),
    brother(jerry, Y).

I can get the correct answers by this way but it ended up in "Out of local stack" error. Besides that, I don't think the rule is fine as I hard coded it.

I have seen suggestions like change the rule name to something else such as another_parent_of(X, Y). It does solve the problem, but it is a requirement for me to define it using the same predicate.

Any help is greatly appreciated.

EDITED

The intention of this exercise is to write rules such that you can complete this family tree, though only minimal facts are given. As you can see, it only states that Warren is the father of Jerry, and from brother and sister facts, we know Jerry is the brother of Stuart and Kather. So I will have a rule, parent_of(X, Y) to deduce Warren is also the father of Stuart and Kather, though this was not stated in the facts above.

The main concern is how can I write my parent_of(X, Y) rule to avoid it getting into infinite loop.

Body:
I do not understand why you need to use parent_of in the definition of sibling. Why you no just write:

sibling(X, Y) :-
    parent_of(Parent, X),
    parent_of(Parent, Y).

I also don't understand the logic of the facts that you are given. You have male and female, but you also have brother and sister; why not define brother and sister in terms of "brother is a male sibling" and "sister is a female sibling"? I already show above how to define "siblings have same parent".

Anyway, this is really old tired question, it is very amazing how many times "Prolog family tree" has been regurgitated.

the cow the old cow she is dead
it sleeps well the horned head
we poor lads tis our turn now
to hear such tunes as killed the cow


问:
sqlite3 user authentication bypassed by db browser
I have followed the steps to add user authentication in sqlite3 database.
When trying to access the tables from authenticated db, without the user name, gives me 'user not authenticated' error. That was what we wanted.

But now when i open the the db with db browser for sqlite3, it opens.
Why is it so?

Is there any way i can prevent my db from being accessed by anything else

答:
The documentation says:

The sqlite_user table is inaccessible (unreadable and unwriteable) to
  non-admin users and is read-only for admin users.  However, if the same
  database file is opened by a version of SQLite that omits
  the -DSQLITE_USER_AUTHENTICATION compile-time option, then the sqlite_user
  table will be readable by anybody and writeable by anybody if
  the "PRAGMA writable_schema=ON" statement is run first.

And a version of SQLite without the authentication checking code will not check the authentication.

To prevent anybody else from reading the database file, you must encrypt it.


问:
android activity how to clear top with same class?
I have 4 activity   A1 A2 B C ，  A1 and A2  is the same Activity

```<code>A1 -> A2 -> B -> C
</code>```

later. I want startActivity from C to  A1 ，

I used

```<code>it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
</code>```

but it open the A2 ， not A1.

答:
This is code to launch activity a1 from c. Place this inside class c from where you want to launch activity a1.

```<code> Intent intent = new Intent(this, a1.class);
 startActivity(intent);
</code>```

and inside android app manifest, place this within  tag. Replace 'myacticvity' with whatever class name you have given for class c:

```<code><activity android:name=".myactivity">
</code>```

Body:
I have 4 activity   A1 A2 B C ，  A1 and A2  is the same Activity

A1 -> A2 -> B -> C

later. I want startActivity from C to  A1 ，

I used

it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

but it open the A2 ， not A1.

Body:
This is code to launch activity a1 from c. Place this inside class c from where you want to launch activity a1.

 Intent intent = new Intent(this, a1.class);
 startActivity(intent);

and inside android app manifest, place this within  tag. Replace 'myacticvity' with whatever class name you have given for class c:

<activity android:name=".myactivity">


问:
Not able to display success message after sending email in codeigniter php
Hi i am having a request form same as contact form once i send the mail not able to display any success message once i send email.Not displaying any success message or failure message after sending email.

Controller:

```<code>function request()
{
    $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
        $this->form_validation->set_rules('name','First Name' , 'required');
        $this->form_validation->set_rules('email','Email','required|valid_email');
        $this->form_validation->set_rules('phone','Mobile Number','required|numeric');
        $this->form_validation->set_rules('description','Description','required');
        if($this->form_validation->run()== FALSE)
        {
        $data['mainpage']='index';
        $this->load->view('templates/template',$data);
        }

    else
    {
        echo "hi";
        //get the form data
        $name = $this->input->post('name');
        $from_email = $this->input->post('email');
        $phone = $this->input->post('phone');
        $description = $this->input->post('description');

        //set to_email id to which you want to receive mails
        $to_email = 'mail@gmail.com';

        $config=Array(
    'protocol'=> 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
    'smtp_port' => '465', //smtp port number
    'smtp_user' => 'mail@gmail.com',
    'smtp_pass' => 'abcdefgh', //$from_email password
    'mailtype' =>'html',
    'newline'  =>"\r\n",
    'crlf' =>"\r\n",
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
    );

    $message            = array();
$message[] = 'Username  :  '.trim($name).' ';
$message[] = 'Phone Number :  '.trim($phone).' ';
$message[] = 'Description :  '.trim($description).' ';
$message = implode(PHP_EOL, $message);
    //send mail
    $this->load->library('email',$config);
    $this->email->from($from_email);
    $this->email->to($to_email);
    $this->email->subject('Request Free Quote');
    $this->email->message($message);
    $this->email->set_newline("\r\n");

        if ($this->email->send())
        {
            // mail sent
            echo "hi";
            $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
            redirect('welcome');
        }
        else
        {
            //error
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');
            redirect('welcome');
        }
    }
}
</code>```

View:

```<code><div class="col-md-3 requestfree">
<img src="<?php echo base_url();?>theme/images/icon1.png" class="requesting">
<h3 class="request">REQUEST</h3>
<h5 class="free"> FREE QUOTE</h5>
<h5 class="receive">You will receive quote within 24 hours</h5>
<form name="contact"  id="contactform" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>welcome/request">
<?php if(isset($msg)){?>
     <?php echo $msg;?>
       <?php } ?>

<div class="name"><span class="mandatory"></span>
    <input type="text" class="form-control" name="name" placeholder="Name" required>
    <?php echo form_error('name', '<div class="error">', '</div>'); ?>
</div>
<div class="name">
    <input type="text" class="form-control" name="phone" placeholder="Phone" required>
    <?php echo form_error('phone', '<div class="error">', '</div>'); ?>
</div>
<div class="email">
    <input type="email" class="form-control" name="email" placeholder="Email" required>
    <?php echo form_error('email', '<div class="error">', '</div>'); ?>
</div>
<div class="description">
    <textarea name="description"  style="width:100%;overflow:auto;" placeholder="Description" required></textarea>
</div>
<div class="">
    <div class="captchas">
        <img src="captcha.php?rand=<?php echo rand();?>" class="captchass" id='captchaimg'/>
        <p class="change"><a href="javascript: refreshCaptcha();" class="clickto">click to change</a></p>
    </div>
    <div class="captcha">
        <input type="text" class="form-control"id="captcha_code" name="captcha_code"  style="background-color: #EAD5D2;border: none;">
    </div>
</div>
<input type="hidden" value="true" name="isSubmitted">
<button type="submit" class="btn btn-success" onclick="return validate();"  >Submit</button><!--  id="demo"!-->
<div class='message'>
<p class="thankyou">
Thank You
</p>
<p>
Our team will contact you shortly.
</p>
</div>
<p class="privacy">We respect your privacy</p>
</form>
</div>
</code>```

答:
try in your view

```<code>echo $this->session->flashdata('msg');
</code>```

Body:
Hi i am having a request form same as contact form once i send the mail not able to display any success message once i send email.Not displaying any success message or failure message after sending email.

Controller:

function request()
{
    $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('
 ','');
        $this->form_validation->set_rules('name','First Name' , 'required');
        $this->form_validation->set_rules('email','Email','required|valid_email');
        $this->form_validation->set_rules('phone','Mobile Number','required|numeric');
        $this->form_validation->set_rules('description','Description','required');
        if($this->form_validation->run()== FALSE)
        {
        $data['mainpage']='index';
        $this->load->view('templates/template',$data);
        }

    else
    {
        echo "hi";
        //get the form data
        $name = $this->input->post('name');
        $from_email = $this->input->post('email');
        $phone = $this->input->post('phone');
        $description = $this->input->post('description');

        //set to_email id to which you want to receive mails
        $to_email = 'mail@gmail.com';

        $config=Array(
    'protocol'=> 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
    'smtp_port' => '465', //smtp port number
    'smtp_user' => 'mail@gmail.com',
    'smtp_pass' => 'abcdefgh', //$from_email password
    'mailtype' =>'html',
    'newline'  =>"\r\n",
    'crlf' =>"\r\n",
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE
    );

    $message            = array();
$message[] = 'Username  :  '.trim($name).' ';
$message[] = 'Phone Number :  '.trim($phone).' ';
$message[] = 'Description :  '.trim($description).' ';
$message = implode(PHP_EOL, $message);
    //send mail
    $this->load->library('email',$config);
    $this->email->from($from_email);
    $this->email->to($to_email);
    $this->email->subject('Request Free Quote');
    $this->email->message($message);
    $this->email->set_newline("\r\n");

        if ($this->email->send())
        {
            // mail sent
            echo "hi";
            $this->session->set_flashdata('msg','
Your mail has been sent successfully!
');
            redirect('welcome');
        }
        else
        {
            //error
            $this->session->set_flashdata('msg','
There is error in sending mail! Please try again later
');
            redirect('welcome');
        }
    }
}

View:

<img src="<?php echo base_url();?>theme/images/icon1.png" class="requesting">

REQUEST

 FREE QUOTE

You will receive quote within 24 hours

<form name="contact"  id="contactform" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>welcome/request">
<?php if(isset($msg)){?>
     <?php echo $msg;?>
       <?php } ?>

    <input type="text" class="form-control" name="name" placeholder="Name" required>
    <?php echo form_error('name', '
', '
'); ?>

    <input type="text" class="form-control" name="phone" placeholder="Phone" required>
    <?php echo form_error('phone', '
', '
'); ?>

    <input type="email" class="form-control" name="email" placeholder="Email" required>
    <?php echo form_error('email', '
', '
'); ?>

    <textarea name="description"  style="width:100%;overflow:auto;" placeholder="Description" required></textarea>

        <img src="captcha.php?rand=<?php echo rand();?>" class="captchass" id='captchaimg'/>

click to change

        <input type="text" class="form-control"id="captcha_code" name="captcha_code"  style="background-color: #EAD5D2;border: none;">

<input type="hidden" value="true" name="isSubmitted">
<button type="submit" class="btn btn-success" onclick="return validate();"  >Submit</button>

Thank You

Our team will contact you shortly.

We respect your privacy

</form>

Body:
try in your view

echo $this->session->flashdata('msg');


问:
Using a channel for multiple commands, replys, and interactive commands?
I'm beginning to learn twisted.conch to automate some tasks over SSH.

I tried to modify the sample sshclient.py from http://www.devshed.com/c/a/Python/SSH-with-Twisted/4/ . It runs 1 command after login and prints captured output.

What I wanted to do is to run a series commands, and maybe decide what to do based on the output.

The problem I ran into is that twisted.conch.ssh.channel.SSHChannel appears to be always closing itself after running a command (such as df -h). The example will sendRequest after channelOpen. Then the channel is always closed after dataReceived no matter what I did.

I'm wondering if this is due to server sending an EOF after the command. And therefore this channel must be closed? Should I just open multiple channels for multiple commands?

Another problem is those interactive commands (such as rm -i somefile). It seems that because the server didn't send EOF, SSHChannel.dataReceived never gets called. How do I manage to capture output in this situation, and what do I do to send back a response?

答:
Should I just open multiple channels for multiple commands?

Yep.  That's how SSH works.

SSHChannel.dataReceived never gets called

This doesn't sound like what should happen.  Perhaps you can include a minimal example which reproduces the behavior.


问:
Parsing Date Time in C#, Getting wrong output
I am trying to parse the date by using below code

```<code>DateTime mydate = DateTime.ParseExact(datetoconvert,"dd/mm/yyyy",System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);
</code>```

but its output is wrong, the datetoconvert in above code is 30/Mar/2017 but output is 29/Jan/2017

looking forward for your valuable answers...

答:
The date format is wrong. try "dd/MM/yyyy" instead of "dd/mm/yyyy"

If you need abbrivated month name, use "dd/MMM/yyyy"

Body:
I am trying to parse the date by using below code

DateTime mydate = DateTime.ParseExact(datetoconvert,"dd/mm/yyyy",System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat);

but its output is wrong, the datetoconvert in above code is 30/Mar/2017 but output is 29/Jan/2017

looking forward for your valuable answers...


问:
In Grails, is there a way to restrict the HTTP request method type (other than the allowedMethods map)?
For example, if I have a save() method, how can I restrict the HTTP request method of this action?

Looking at the grails documentation, it looks like I can use this static allowedMethods = [...] block to restrict access. However, it looks quite a bit clunky because the list can grow quite big and it can get very messy.

Ideally, I would like to use annotations to describe the method. It could be something like this:

```<code>@POST
def save() {
    // save logic
}
</code>```

This way I know all the information related to the save() method right there. Instead of scrolling up and potentially seeing a huge messy list.

I'd be happy to use an alternative way.

答: You can create your own annotations and use filters/interceptors to check if request method corresponds the given annotation. You can find more details here.</p>

Body:
For example, if I have a save() method, how can I restrict the HTTP request method of this action?

Looking at the grails documentation, it looks like I can use this static allowedMethods = [...] block to restrict access. However, it looks quite a bit clunky because the list can grow quite big and it can get very messy.

Ideally, I would like to use annotations to describe the method. It could be something like this:

@POST
def save() {
    // save logic
}

This way I know all the information related to the save() method right there. Instead of scrolling up and potentially seeing a huge messy list.

I'd be happy to use an alternative way.


问:
Is there any way to load poster after html5 video ended
I was wondering if any event can be called after an HTML video have been played. </p>

答:
```<code>$("video").bind("ended", function() {
    this.load();
    $('video').prop("autoplay", false);
});
</code>```