SQL query group rows by column PRN

Question: Hi i need a bit of help with the SQL query below
DECLARE @company nvarchar(50)
DECLARE @theweek date

SET @company = 'RWF'
SET @theweek = '2014-02-03'

SELECT [thedate],[PRN],[StartTime] ,[FinishTime],[Grade],[BreakTime],[TotalCost],[Department],[CompanyCode]
FROM LabourHireCost
WHERE thedate BETWEEN @THEWEEK AND CONVERT(datetime, @theweek) +7
ORDER BY CompanyCode, PRN, thedate

this return result like this( below ) but what i would like to do if possible is return the employee and the times worked for the week
    Thedate    PRN  Start   Finish  Grade Break  Cost   Department Company
| 2014-02-03 | 179 | 06:00 | 06:00 | 2  | 01:00 | 26.17 |      2   |   DH  |
| 2014-02-04 | 179 | 06:00 | 06:00 | 3  | 01:00 | 36.17 |      2   |   DH  |
| 2014-02-03 | 178 | 06:00 | 06:00 | 2  | 01:00 | 26.17 |      2   |   DH  |
| 2014-02-04 | 178 | 06:00 | 06:00 | 4  | 01:00 | 46.17 |      2   |   DH  |

i was thinking of something like this
PRN 179
 Thedate      Start   Finish  Grade Break  Cost   Department Company
| 2014-02-03 | 06:00 | 06:00 | 2  | 01:00 | 26.17 |  2   |   DH  |
| 2014-02-04 | 06:00 | 06:00 | 3  | 01:00 | 36.17 |  2   |   DH  |

PRN 178
| 2014-02-03 | 06:00 | 06:00 | 2  | 01:00 | 26.17 |  2   |   DH  |
| 2014-02-04 | 06:00 | 06:00 | 4  | 01:00 | 46.17 |  2   |   DH  |

Answer: Based on your current results vs. expected results, it looks like the query is already returning the data that you want.  If you want to present it differently, that would be done in your client application (whether it is web app, reporting software, or even Excel), but SQL Server generally should not be used for breaking datasets into nicely formatted reports.
Comment: i was able to do this in the Front End PHP application
Answer: Well how about using a cte to calculate the amount of time everyone (time frame between start and finish )worked on x date and then selecting it?
Answer: This looks speciously like a homework assignment.  I believe what you are looking for though is a join http://en.wikipedia.org/wiki/Join_%28SQL%29

SQL query group rows by column PRN


Column space and Im(T) and the rank

Question: Is there a connection between the Column space and Im(T) and the Rank?
Are there all equal (except the Rank which is the dimension)  ?
Comment: The column space of $T$ and $\text{im}(T)$ are the same thing. The rank is the dimension of this subspace, sometimes it is so by definition, sometimes it is so because you can prove it.
Comment: Indeed, yes they are!
Comment: @GitGud "sometimes it is so because you can prove it", ok.. and what is the definition of the rank in this case?
Comment: @Surb For instance the dimension of the row space.
Answer: They are the same. Let $T\colon V \to W$ and Let $T^t \colon W^* \to V^*$ be the transpose of $T$, $T^t(f) = f(T)$. If $B_V = \{e_1,\ldots,e_n\}$ is a basis for $V$ and $B_W=\{d_1,\ldots,d_m\}$ a basis for $W$, let $A$ be the matrix of $T$ in the basis $B_V$ and $B_W$. Let $B^*_V=\{f_1,\ldots,f_n\}$ and $B^*_W=\{g_1,\ldots,g_n\}$ be dual basis for $V^*$ and $W^*$. Now, the matrix of $T^t$ in the basis $B^*_V$ and $B^*_W$ is exactly $A^t$. Now $Im(T)^0 = Ker(T^t)$, but since $\dim(Im(T)) + \dim(Im(T)^0) = \dim(V)$ and then $\dim\ Ker(T) = \dim\ Ker(T^t)$. But since $\dim\ V^* = \dim\ V$ and $\dim\ W = \dim\ W^*$, we have $\dim\ Im(T) = \dim\ Im(T^t)$ and so the column space and row space are the same.

Column space and Im(T) and the rank


Convolutional Neural Network Scale Sensitivity

Question: For the sake of example, lets suppose we're building an age estimator, based on the picture of a person. Below we have two people in suits, but the first one is clearly younger than the second one.

(source: tinytux.com)

There are plenty of features that imply this, for example the face structure. However the most telling feature is the ratio of head size to body size:

(source: wikimedia.org)
So suppose we've trained a CNN regression to predict the age of the person. In a lot of the age predictors that I've tried, the above image of the kid seems to fool the predictions into thinking he's older, because of the suit and likely because they rely primarily the face:

I'm wondering just how well can a vanilla CNN architecture infer the ratio of head to torso?
Compared to a regional RCNN, which is able to get bounding boxes on the body and head, will the vanilla CNN always perform worse?

Just before global flattening in the vanilla CNN (i.e. just after all convolutions), each output has a corresponding receptive field, which should have a sense of scale. I know that faster RCNN exploits this by making bounding box proposals exactly at this stage, so that all prior convolutional filters automatically train to all scales.

So, I would think that the vanilla CNN should be able to infer the ratio of head to torso size? Is this right? If so, is the only benefit of using a faster RCNN framework to exploit the fact that may have been pre-trained on detecting people?
Comment: Do you know where exactly your age recongnizer fails? Why do you think it's head size proportion? Did you look at the output of middle layers?
Comment: @Aksakal I don't think he experimented training a CNN. From what I've understood, he's been making tests with existing web services: " In a lot of the age predictors that I've tried[..]".
Answer: CNNs are too large a class of models, to answer this question. LeNet, AlexNet, ZFNet and VGG16 will behave very differently than GoogLeNet, which was built specifically to do most of what R-CNN do, with a CNN architecture (you may know GoogLeNet with the name of Inception, even though strictly speaking Inception is just the basic unit (subnetwork) upon which GoogLeNet is built). Finally, ResNets will behave differently. And all these architectures were not built to classify age classes, but the 1000 ImageNet classes, which don't contain age classes for humans. One could use transfer learning (if you have enough training images) to train one of the widely available trained models above, and see how they perform. In general, however, especially the older architectures (let's say up to VGG16) have an hard time learning "global features" which require to learn about "head" (already a complex feature), "torso" (another complex feature) and their ratio (which also requires that the two features are in a certain spatial relationship). This kind of stuff is what Capsule Networks should have been able to do.
Convnets were born to do exactly the opposite: be sensitive to local features, and relatively insensitive to their relative position/scale. A good Convnet should recognize "white cat" whether the picture is a close-up or an American shot. Combining convolutional layers (which are sensitive to local features) with pooling layers (which remove part of the sensitivity to variation in scale or translation of the image) gives you an architecture which in its most basic form is not great at learning the kind of spatial relationships among objects which you're looking for. There was an example somewhere (but I can't find it anymore) where, after splitting a cat image in various rectangular nonoverlapping tiles and putting them together in a random order, the CNN would keep identifying the image as cat. This indicates that CNNs are more sensitive to local features (textures or something like that) than to the spatial relationship among high level features. See also the Capsule networks paper for some discussion of this. Hinton also showed an example of this in a video about the limits of convnets.
My wild guess is that one of the recent architectures would be perfectly capable (given enough data) of discerning men from children, but not because of a "threshold" on a metric relationship among high level features such as "head" and "torso". It would learn some statistical regularity, maybe completely unnoticeable to humans, which separates adult images from child images in the training set.
Comment: My apologies for the confusion. I know there are like, 20 different RCNN architectures out there, each claiming the other ones are obsolete.
Comment: https://blog.piekniewski.info/2016/12/29/can-a-deep-net-see-a-cat/ Also, a different issue, but still related to texture matching, and from more respected researchers, https://arxiv.org/pdf/1703.06857
Comment: I appreciate your answer, but, I'm having trouble agreeing. RCNN architectures have essentially the same structure of filters as object convnets, for example VGG and Resnet. And since RCNN can detect scale and relative position, it follows that VGG and Resnet should also be able to detect scale. However, RCNN architectures rely on box proposals, of which they make thousands per image, after which each box proposal is evaluated. So it seems like if I incorporate at least some of these box proposals, a vanilla CNN should detect scale better. I'm just not sure if it's necessary to do so.
Comment: RCNN are not CNN. Not only you miss the selective search for the bounding boxes, but you also miss the linear SVM and the bounding box regressor stages. Also, there is a big difference between the ability to detect scale of AlexNet (which is the CNN used in the original RCNN paper), or VGG, and the ability of GoogLeNet or ResNet: GoogLeNet
 was developed precisely to do what RCNN do. I think both GoogLeNet and ResNet would be able to classify age, but there's no way to know if they would do it by using a feature which makes sense to us (head to torso ratio) or by finding some statistical 1/
Comment: 2/ regularities which a human would never notice. I'd suggest you to experiment and try, but unfortunately only building the image database would be a research project in itself (unless you work in a fashion company).
Comment: In faster RCNNs, the bounding boxes are proposed at the very last stage of convolution, so in principle there's zero architectural difference between object and RCNNs. The boxes are just outputs of neurons connected to the convolutional feature layer. That's why I'm debating whether you need such explicit formalism to detect scale. The only difference is during training, your loss function includes the quality of your bounding box proposals. Maybe that's a better question: is there a need to supply bounding box proposals (that would detect head, face) for relative scale detection?
Comment: (reference for the above: https://arxiv.org/pdf/1506.01497.pdf)
Comment: And in faster RCNN, you don't use selective search because it's slow and not very accurate. That's what I'm trying to say: the region proposals are generated via regression, purely from the output of the convolutional feature map. At least that's my understanding, and I would welcome criticism.
Comment: Ah FasteRCNN are probably a different beast - I'm not familiar with that paper. Until now, you always referred to RCNN, so I thought you were referring to them.
Comment: No problem. But I wonder if I should delete my answer now - we're clearly talking about different things.
Comment: About second paragraph, I always see people claiming things like you do: ' be sensitive to local features, and relatively insensitive to their relative position/scale', but I have actually seen nothing that backs up this claim.
Comment: @lugi then it looks like you haven't read much about convolutional neural networks. I encourage you to consult the relevant literature, there seems to be no scarcity of it. Some scale invariance was built into literally the **first** famous CNN http://yann.lecun.com/exdb/lenet/scale.html
Comment: _There was an example somewhere (but I can't find it anymore) where, after splitting a cat image in various rectangular nonoverlapping tiles and putting them together in a random order, the CNN would keep identifying the image as cat._

I was talking about this part. I've seen this claim fairly often, but never actually seen an experiment confirming it. Do you have any proof of this?
Comment: @Lugi obviously also [Hinton's famous video on what's wrong with CNNs](https://youtu.be/rTawFwUvnLE) is a perfect example of the claim of which "you have never seen proof". Conclusion: look better.
Answer: Firstly, thanks for posting a very interesting question.
To answer it shortly, a vanilla convnet trained end-2-end to predict age from a photo will be generally prone to mis-classify images such as the one you posted. Secondly, note that accurately estimating the age of a person is a nearly impossible task1.
The main difference from your proposed approach using some object detectors (be it RCNN, Faster RCNN, YOLO or SSD) is that you are using different information to train the models. The CNN is trained only on images and needs to find out all the necessary features itself. It is most likely going to find various facial features, but it will also rely on clothing and perhaps scene features (kids may be often in the picture with some toys, adults will be more likely in office environments, etc.). These features will not be robust to your counterexample.
On the other hand, if you train the network to explicitly detect objects as "torso" and "head", you are providing extra information that these objects are important for the task, and thus simplify the problem2.
While the approach of detecting head and torso and then evaluation the size ratio of the bounding boxes sounds interesting, I can see several obstacles:

Obtaining data: I am not aware of the availability of large dataset where both age and bounding boxes would be present.
Imperfect FOV: In most images (e.g. both your examples), the people are not displayed whole. You would have to deal with the fact that the torso bounding boxes would not be always perfect simply because part of the person is not in the image and the net would have to guess how large part is missing (and the ground truth bounding boxes would most likely not capture this information). Also, the aforementioned object detectors don't always handle predictions of partial objects properly. This might introduce too much noise in the model.
Various poses: The torso-to-head ratio would be very different for people viewed frontally and from the side.
Adults: It seems the ratio works well to predict ages between 0-21, but I don't see how it would help to predict ages of adults (I suppose the ratio does not change in higher age).

All these problems suggest that the head-to-torso ratio approach is also not going to work perfectly, although it might be more robust to your particular counterexample.
I guess the best way to perform this task would be to 1) detect the face, 2) predict age only from the facial crop (removes potentially misleading information). Note that some R-CNN-like architecture using ROI-pooling could be trained to do this end-2-end.

1 Even using very sophisticated medical methods (which are arguably much more informative than a photo of the person) this is not possible to do accurately. See this Quora thread for more information.
2 Check the article Knowledge Matters: Importance of Prior Information for Optimization for an example how providing some intermediate knowledge about the task can greatly simplify learning.
Answer: Well, it all depends on how your dataset is constructed. From my experience neural networks tend to go for simplest explanations. And inferring the age from the outfit is actually simpler than using head to body ratio. If you can expand your dataset having this in mind your CNN should work as expected.


What were the advantages of the DAS system in Mercedes' W11 car?

Question: In 2020, Mercedes implemented the DAS system in their W11 Formula 1 car. The system, which alters the toe angle of the front wheels through the steering wheel being pushed backwards and forwards, was protested against by Red Bull.
What were the advantages of that system that made other teams protest this? Does this system give more grip?
Answer: Formula One cars usually run with "toe out" at the front, meaning that the wheels aren't perfectly straight but instead splayed out slightly, with the front of the tyre pointing slightly away from the car.

This improves the car's performance when it first turns into a corner, but also causes the front tyres to heat up unevenly, with the inner edge of the tyre heating up faster than the rest of it. This can lead to parts of the tyre becoming too hot or too cold, affecting both grip and tyre wear.
With DAS, Mercedes were able to switch to a neutral toe angle while on the straights, allowing the tyres to be heated evenly, then switch back to a toe-out while cornering for improved handling.
So DAS didn't provide more grip, but it did make the Mercedes W11 more efficient at warming its tyres up while preventing them from overheating, especially on circuits with long straights. Given Mercedes' dominance during 2020 - scoring as many points as the next two teams combined - the results speak for themselves.
[Info from this F1 article, image from this Autosport article.]


printing dynamic variables before render

Question: I am trying to write a preact script which will display different images depending on the API data fetched. However, the fetchWeatherData() function does not seem to call before the output is rendered, even though I use the function componentWillUpdate().
When I try to print this.state.locate in the render() function before returning the data, the output is always undefined, however I need this variable in order to manipulate the images I want to display.
Thanks for your help.
// import preact
import { h, render, Component } from 'preact';
// import stylesheets for ipad & button
import style from './style';
import style_iphone from '../button/style_iphone';
// import jquery for API calls
import $ from 'jquery';
// import the Button component
import Button from '../button';

export default class Iphone extends Component {
//var Iphone = React.createClass({

// a constructor with initial set states
constructor(props){
    super(props);
    // temperature state
    this.state.temp = "";

}

componentWillUpdate(){
    this.fetchWeatherData();
}
    // a call to fetch weather data via wunderground
    fetchWeatherData = () => {
        // API URL with a structure of :
ttp://api.wunderground.com/api/key/feature/q/country-code/city.json
        var url =
"http://api.wunderground.com/api/mykey/conditions/q/UK/London.json";
    $.ajax({
        url: url,
        dataType: "jsonp",
        success : this.parseResponse,
        error : function(req, err){ console.log('API call failed ' + err); }
    })

}

// the main render method for the iphone component
render() {
    // check if temperature data is fetched, if so add the sign styling to the page

    const tempStyles = this.state.temp ? `${style.temperature} ${style.filled}` : style.temperature;
    document.write(this.state.locate);
    // display all weather data

    return (

{ this.state.locate }

{ this.state.cond }

                { this.state.temp }

                { this.state.display }

    );
}

parseResponse = (parsed_json) => {
    var location = parsed_json['current_observation']['display_location']['city'];
    var temp_c = parsed_json['current_observation']['temp_c'];
    var conditions = parsed_json['current_observation']['weather'];

    // set states for fields so they could be rendered later on
    this.setState({
        locate: location,
        temp: temp_c,
        cond : conditions
    });
}

}
Answer: You should use the componentDidMount() method. You couldn't call setState in componentWillUpdate() method. That method is used to:

Now we've committed to updating. "Want me to do anything before I re-render?" our component asks. No, we say. Stop bothering us.

You could find more detail at this link:
https://engineering.musefind.com/react-lifecycle-methods-how-and-when-to-use-them-2111a1b692b1


solving ODE with power law solution

Question: If I have this equation:
$$ 3R' ^2  =-2R \frac{d^2R}{dt^2}$$
How can I show that If
$$R=R_0 t^\alpha $$
then
$$\alpha = 2/5$$
Comment: If $R(t)=R_0t^\alpha$, then $-2R(t)R''(t)=-2\alpha (\alpha -1)R_0^2t^{2\alpha -2}$
Answer: If $R=R_0t^{\alpha}$ then $R'=\alpha R_0t^{\alpha-1}$ and $R''=\alpha(\alpha-1) R_0t^{\alpha-2}$. So your equation becomes: $$3\alpha^2R_0^2t^{2\alpha-2}=-2R_0t^{\alpha}\times\alpha(\alpha-1) R_0t^{\alpha-2}=-2\alpha(\alpha-1)R_0^2t^{2\alpha-2}$$ It implies that $3\alpha^2=-2\alpha(\alpha-1)$ so...
Answer: If $R(t)=R_0t^\alpha$, then
$$3R'^2(t)=3\alpha^2R_0^2t^{2\alpha-2} \tag 1$$
and
$$-2R(t)R''(t)=-2\alpha (\alpha -1)R_0^2t^{2\alpha -2} \tag 2$$
Now equate the right-hand sides of $(1)$ and $(2)$.
Comment: I see, if I put into wolfram I Get alpha = 2/5
Comment: Even easier;  for $\alpha\ne 0$, note that $$-2\alpha(\alpha -1)=3\alpha^2\implies 2-2\alpha=3\alpha$$
Comment: I see, thanks! Could you take a look here http://math.stackexchange.com/questions/1699005/solving-ode-for-cylindrical-and-planar-cases  it is very related question but for cylindrical and planar. Not sure how to approach since there are move variables that just R

solving ODE with power law solution


Derangement formula; proof by induction

Question: Proof by induction that
$
d_{n}=nd_{n-1}+(-1)^{n}
$
where $d_{n}$ is number of $n$-element derangements.
Comment: What have you tried? Do you have any more detailed thoughts or questions about what you need to do?
Comment: Look at [this question](http://math.stackexchange.com/questions/1056610/combinatorial-argument-for-recursive-formula) and its answers; you can use its recurrence in the induction step of your argument.
Answer: Hints
The number of derangements is given by
$$d_n = n! \sum_{k=0}^n \frac{(-1)^k}{k!}.$$
To prove your relationship by induction, show that

it is correct for the base case $n=1$, i.e. that $d_1 = 1 d_0 + (-1)^1$ by plugging in.
it is correct in the inductive step; i.e., assuming that this is true for all $k=1, \ldots n-1$, prove that this is true for $k=n$.

Can you finish this?
Answer: Do the derangements of the first $n-1$ elements (from $1$ to $n-1$) and swap one of them ($x$) with $n$. Note that $n$ will never be in the original position of $x$, so we need to add that case. First case: $(n-1)d_{n-1}$ (there are $n-1$ possible choices of $x$ and $d_{n-1}$ derangements). Second case: $(n-1)d_{n-2}$ (same thing, but without $x$ and $n$ there are $d_{n-2}$ derangements). Use the recursion formula do add both cases:
$$\begin{align}
d_{n-1} &= (n-1)d_{n-2}+(-1)^{n-1}\\
d_{n-2} &= \frac{1}{n-1}\left[d_{n-1}+(-1)^n\right]\\
d_{n} &= (n-1)d_{n-1}+(n-1)d_{n-2}\\
 & = (n-1)d_{n-1}+\frac{n-1}{n-1}\left[d_{n-1}+(-1)^n\right]\\
 &= nd_{n-1}+(-1)^n
\end{align}$$
Finally, just show that the recursion formula works for the initial cases $d_0 = 0$ and $d_1 = 1$.

Derangement formula; proof by induction


Module to allow multiple paths for a single node?

Question: Is there a module that would allow me to define multiple paths for a single node? (Not just one node; I need to do this for multiples.) For example, I need to be able to access http://www.example.com/node/153 via both http://www.example.com/tracks/big-picture and http://www.example.com/big-picture.
I need to be able to define at least one of the paths manually, i.e. not using a pattern.
Comment: I'd be curious to know who downvoted this and why. It's a perfectly legitimate question, especially for people not intimately familiar with Drupal admin settings.
Comment: Leaving a comment, you are not notifying the down-voters. Keep in mind that the tooltip of the button for down-voting says: "This question does not show any research effort; it is unclear or not useful."
Answer: You can already do this using core's Path module in Drupal 6. If memory serves, it should be in admin/build/path/add. Simply create two aliases that both point to node/153.
I should caution, however, that this may raise red flags with search engines. They typically frown on duplicate content, and your SERP rankings will likely suffer as a result.
Comment: Thanks. All of our content is available only after login, so we're not particularly concerned with search engines.
Comment: Either way, I figure the information will be helpful to those with similar issues later on down the line. :]  Glad I could help.


How do I get the program to print the number of times a number occurs in the list?

Question: This is as much as I know how to do, not sure if I'm doing it correctly.
L = [4, 10, 4, 2, 9, 5, 4 ]

n = len(L)
element = ()

if element in L:
    print(element)

print("number occurs in list at the following position, if element not in list")
print("this number does not occur in the list")

How do I go about getting elements that appear more than once, to print as
4 occurs in L at the following positions:  [0, 2, 6]

Answer: The compulsory defaultdict post:
from collections import defaultdict

el = [4, 10, 4, 2, 9, 5, 4 ]
dd = defaultdict(list)
for idx, val in enumerate(el):
    dd[val].append(idx)

for key, val in dd.iteritems():
    print '{} occurs in el at the following positions {}'.format(key, val)

#9 occurs in el at the following positions [4]
#10 occurs in el at the following positions [1]
#4 occurs in el at the following positions [0, 2, 6]
#2 occurs in el at the following positions [3]
#5 occurs in el at the following positions [5]

Then dd can just be used a normal dict... dd[4] or dd.get(99, "didn't appear")
Answer: You could use a list comprehension:
>>> L = [4, 10, 4, 2, 9, 5, 4]
>>> [i for i,x in enumerate(L) if x==4]
[0, 2, 6]

enumerate(L) gives you an iterator over L that yields a tuple (index, value) for each element of L. So what I'm doing here is take each index (i) if the value (x) equals 4, and construct a list from them. No need to look at the length of the list.
Comment: so I don't have to use the length of the list?
Comment: It's worth noting that to display this information for all the elements, you can loop over ``set(L)`` (avoiding showing the each item multiple times as sets don't store duplicates).
Comment: @Lattyware well I thought that I would have to use the index for the number in the list.
Comment: @neonlights That sentence doesn't really make sense.
Comment: @neonlights That's what `enumerate` does - it loops over an iterable, and returns an auto-incrementing count (which can be used as the index) and the value of that element. It's an oft-used function - it's worth reading the docs.
Answer: You can use Counter to count distinct element in list, then use list comprehension to find the index of each element: -
>>> l = [4, 10, 4, 2, 9, 5, 4 ]
>>> from collections import Counter
>>> count = Counter(l)
>>> count
Counter({4: 3, 9: 1, 10: 1, 2: 1, 5: 1})

>>> lNew = [[(i,x) for i,x in enumerate(l) if x == cnt]  for cnt in count]
>>>
>>> lNew[0]
[(4, 9)]
>>> lNew[1]
[(1, 10)]
>>> lNew[2]
[(0, 4), (2, 4), (6, 4)]
>>>

In fact you don't need Counter here. You can just get off with a Set
Create a Set of the list with the factory function : - set(l) and then you can do the same with it..
Comment: Do not use `is` for equality comparison!
Answer: def print_repeated_elements_positions(L):
    for e in set(L): # only cover distinct elements
        if L.count(e) > 1: #only those which appear more than once
            print(e, "occurs at", [i for i, e2 in enumerate(L) if e2 == e])

L = [4, 10, 4, 2, 9, 5, 4]
print_repeated_elements_positions(L)
# prints: 4 occurs at [0, 2, 6]


evaluation of the definite integral

Question: Actually i am finding the arc length of curve
$24xy = y^4 + 48$ from $y = 2$ to $y = 4$
i have found the derivative with respect to $y$ and that is $$\frac{y^2}6 -\frac{x}y$$
by putting this derivative in the arc length formula i get the following
$$\int_2^4 \sqrt{1+ \left(\frac{y^2}6 -\frac{x}y\right)^2}$$
I solve this definite integral by substitution but i am failed please help me, give me some hints. I will be thankful.
Comment: how you got this result x(y)= y^3/24 + 2/y show me
Answer: From $$24xy=y^{4}+48$$ we find $$x=\frac{1}{24}\frac{y^{4}+48}{y}.$$ Thus
$$
\frac{\mathrm{d}x}{\mathrm{d}y}=\frac{1}{8}\frac{y^{4}-16}{y^{2}}.
$$
The length of the curve is
$$\begin{eqnarray*}
L &=&\int_{2}^{4}\sqrt{1+\left( \frac{\mathrm{d}x}{\mathrm{d}y}\right) ^{2}}\mathrm{d}y=\int_{2}^{4}
\sqrt{1+\left( \frac{1}{8}\frac{y^{4}-16}{y^{2}}\right) ^{2}}\mathrm{d}y
&=&\dots\end{eqnarray*}$$
Comment: @Zia ur Rahman: You are welcome.
Answer: HINT It might be easier to think of $x$ as a function of $y$: $$x = \frac{y^4}{24y} + \frac{48}{24y} = \ldots (\text{simplify}),$$
where $y$ ranges from $2$ to $4$. I presume you know how to calculate the arclength when the curve is given in this form.
Comment: how you did that, x(y)=y^3/24 + 2/y
Comment: @Zia The given equation is $24 y x = blah$. So just divide the whole thing by $24y$. Note: By $x(y)$, I mean: $x$ as a function of $y$; it does not mean $x$ multiplied by $y$.
Comment: ok now i try to solve this whole question thank you i will contact you if i could not just after five minutes ok?
Comment: @Zia Sure. You can can post your progress either in the question itself or in the comments.
Comment: derivative with respect to y of this function of x comes out y^2/8 - 2/y^2 now if we put this into the definite integral and suppose it u then we again need to take the derivative with respect to y that comes out du/dy = y/4 +4/y^3 now what i do?
Comment: I have no idea what $u$ is, and why you are differentiating that w.r.t. $y$. You only need to integrate $(1+(dx/dy)^2)^{1/2}$ w.r.t. $y$ between the given limits. Is this where you are stuck?

evaluation of the definite integral


missing parameter type error by calling toSet

Question: Why this code doesn't work:
scala> List('a', 'b', 'c').toSet.subsets.foreach(e => println(e))

<console>:8: error: missing parameter type
              List('a', 'b', 'c').toSet.subsets.foreach(e => println(e))
                                                        ^

But when I split it then it works fine:
scala> val itr=List('a', 'b', 'c').toSet.subsets
itr: Iterator[scala.collection.immutable.Set[Char]] = non-empty iterator

scala> itr.foreach(e => println(e))
Set()
Set(a)
Set(b)
Set(c)
Set(a, b)
Set(a, c)
Set(b, c)
Set(a, b, c)

And this code is OK as well:
Set('a', 'b', 'c').subsets.foreach(e => println(e))

Comment: possible duplicate of [Type inference on Set failing?](http://stackoverflow.com/questions/5544536/type-inference-on-set-failing)
Answer: First, there's a simpler version of the code that has the same issue:
List('a', 'b', 'c').toSet.foreach(e => println(e))

This doesn't work either
List('a', 'b', 'c').toBuffer.foreach(e => println(e))

However, these work just fine:
List('a', 'b', 'c').toList.foreach(e => println(e))
List('a', 'b', 'c').toSeq.foreach(e => println(e))
List('a', 'b', 'c').toArray.foreach(e => println(e))

If you go take a look at the List class documentation you'll see that the methods that work return some type parameterized with A, whereas methods that don't work return types parameterized with B >: A. The problem is that the Scala compiler can't figure out which B to use! That means it will work if you tell it the type:
List('a', 'b', 'c').toSet[Char].foreach(e => println(e))

Now as for why toSet and toBuffer have that signature, I have no idea...
Lastly, not sure if this is helpful, but this works too:
// I think this works because println can take type Any
List('a', 'b', 'c').toSet.foreach(println)

Update: After poking around the docs a little bit more I noticed that the method works on all the types with a covariant type parameter, but the ones with an invariant type parameter have the B >: A in the return type. Interestingly, although Array is invariant in Scala they provide two version of the method (one with A and one with B >: A), which is why it doesn't have that error.
I also never really answered why breaking the expression into two lines works. When you simply call toSet on its own, the compiler will automatically infer A as B in the type for the resulting Set[B], unless you do give it a specific type to pick. This is just how the type inference algorithm works. However, when you throw another unknown type into the mix (i.e. the type of e in your lambda) then the inference algorithm chokes and dies—it just can't handle an unknown B >: A and an unknown type of e as well.


Hook into node operation from theme template.php?

Question: I have made a new content type in Drupal 7 in Drupal Admin (not via module). What I want to do is to add a Hook on the insert and update operation. How can this be done when my node type is not created by a module?
Can this be done at all?
Comment: Is there a reason for not writing your own module for this?
Comment: I like to create node types in Drupal through the admin interface rather than using modules. This is done so that making changes is easier, and even maybe let the customer do necessary changes. Of course, I am starting to think this is not possible, so I guess I'll be starting on a module shortly.
Answer: You want to create a custom module. Note that nothing stops you from creating content types through the user interface, it is in fact the suggested way to do so nowadays with fields and stuff (instead of using hook_node_info())
Node API Hooks contains an overview of all hooks that can be used to interact with nodes at different events like create, view, delete..
Comment: If I understand correctly, I can create a node type through the user interface, and create a module that hooks into node operations on this node type?
Comment: Yes. Only the node type callbacks (hook_form, hook_insert, ..) are only called for the module that defines a node type.
Comment: Oh my how embarrassing. I of course use the hook hook_node_insert and hook_node_update in a module I have to create, and perform necessary operations when the module type in question is created and updated. Thank you for the help Berdir.
Answer: Just wanted to add a comment on how I solved it in case anyone else needs it. This function ads a taxonomy term equal to the node title into a vocabulary defined in the function when a new node of your chosen type is inserted:
function node_title_taxonomy_node_insert ($node) {
if ($node->type == '<your node type>'):
    // Get vocabulary ID for vocabulary name
    $vocabulary_name = "<Vocabulary name>";

    // Prepare taxonomy term
    $taxonomy_term_name = $node->title;

    // Add vocabulary and term
    _node_title_taxonomy_add_vocabulary_term($vocabulary_name,$taxonomy_term_name);
endif;
}

Thanks for the help Berdir :)


How to allow navigation for only certain linkIds in Here API (using custom routes or otherwise)?

Question: I am trying to use Here Telematics Api to allow only certain road segments. First, we are doing route matching to get the linkIds and then generate allow and deny list of links (or road segments) which we want to navigate on. The number of links in deny list are more than 30,000.
Now, we want to use this in the navigation api of Here maps. To do this I saw 2 ways - 1) using avoidLinks query parameter and 2) using custom routes and overlays maps.
This is what I have tried so far.
1. Using Navigation Api:
I called the navigation api with avoidLinks query parameter. Here is how it will look:
curl https://fleet.api.here.com/2/calculateroute.json?app_id=XXXX&app_code=XXXX&mode=fastest;car;traffic:disabled&waypoint0=52.512623,13.321814&waypoint1=52.587389,13.279046&avoidLinks=linkId1,linkId2....

But because this is a get call, I cannot go beyond 20000 links, because otherwise I get status code 414, i.e. request uri is too long. So, this route is closed!
2. Using Overlays and Navigation:
Then I looked at this link, and tried using custom routes.
I used this documentation to create overlay map using the overlays api:
curl https://cre.api.here.com/2/overlays/upload.json

But this again is a GET api, and it doesn't allow more than ~1000 linkIds as I again get http code 414 i.e. request uri is too long.
This overlays can be use
 curl http://cre.api.here.com/2/calculateroute.json
  ?waypoint0=50.10951,8.68951
  &waypoint1=50.10703,8.68222
  &mode=fastest;car;traffic:disabled
  &overlays=overlaydemo1
  &storage=readonly
  &app_id=XXXX
  &app_code=XXXX

Now I am struck, because I cannot have 1 big overlay map, but I can create multiple maps, which is fine. But then in the navigation api, I can only use 1 overlay map.
Can you please help me in somehow solving this issue?
Answer: Get api to upload overlay is used only for small request. For larger ones you have to use the post api. You can read more about it here : https://developer.here.com/documentation/custom-routing-extension/topics/resource-overlay.html.

For small examples, overlays can be submitted in a GET request, but
  bigger overlays should be submitted via POST request, either as
  application/x-www-form-urlencoded or as multipart with one part named
  overlay_spec.
Comment: Thank you. Will try and let you know. Thanks.
Comment: Hi @here-developer-support, I tried following and get bad request with 'overlay_spec' is not present:
curl -X POST -d '{"map_name": "overlaymapdemo1", "overlay_spec": [{"op": "restrict", "data": {"VEHICLE_TYPES": "custom1"}, "type": "access", "bidirectional": "true", "shape": [[52.53503, 13.32593], [52.53519, 13.3277]]}, {"op": "restrict", "data": {"VEHICLE_TYPES": "custom1"}, "type": "access", "bidirectional": "true", "shape": [[52.54644, 13.29427], [52.54714, 13.29695]]}]}' 'https://cre.api.here.com/2/overlays/upload.json?app_id=XXXX&app_code=XXXX'. Can you please help?


Is it ok to repeat MANCOVA until all interactions are significant

Question: In order to enlighten the relation of three (related) scales describing psychopathology (1 anxiety score and 2 shame scores) with demographic data (gender, place of residence, age etc) collected by convenient sampling I conducted a MANCOVA, where only main effects and 2nd order interactions was included in the model (limited to 2nd order due to large number of independent variables)
I know that when an interaction is significant then the corresponding main effects (if significant) are marginal and should not reported or reported with caution.
My question is: if some interactions are not significant is it a good practice to remove those non significant interactions from the model and repeat the MANCOVA procedure until all remaining interactions are significant? (so that the most clear picture of effects and interactions will appear)
In case of an affirmative answer is there any reference for that practice?
Thank you in advance.
Answer: Peter Flom's answer to this question is also relevant in your case. Especially the last point; if you hypothesize an interaction, it should remain in the model. Gelman and Hill argue that "people sometimes think that if a coefficient estimate is not significant, then it should be excluded from the model. We disagree. It is fine to have nonsignificant coefficients in a model, as long as they make sense" (Gelman and Hill, 2006: 42). Saying that, in a subsection titled "building regression models for prediction" (and prediction is the keyword here), they suggest that "if a predictor is not statistically significant and does not have the expected sign..., consider removing it from the model (that is, setting its coefficient to zero)" (Gelman and Hill, 2006: 69). But if you look at the answers to similar questions on Cross Validated (for example, here and here), you will see that it is recommended to keep interactions (and predictors in general) that are not statistically significant in the model, especially if they are of substantive interest.
Although you did not ask about it, I think there is another issue. You say that the data are collected by convenient sampling which is a type of nonprobability sampling. According to Groves et.al., there are two benefits of using probability sampling (such as simple random sampling): "(1) Important types of sample statistics are unbiased. (2) We can estimate the sampling variance (standard error) from one realization of the sample design." (Groves et.al., 2004:381). There is some statistical rule involved in the probability sampling which is not the case for nonprobability, hence convenient, sampling. It does not mean necessarily that the nonprobability samples are not representative of the population, but it means "nonprobability samples cannot depend upon statistical probability theory" (de Leeuw, Hox and Dillman, 2008: 9). So, we need more information about the joint distributions of the variables in the population, which is not usually the case, and a model-based approach is recommended to make inference about the population (de Leeuw, Hox and Dillman, 2008). I think you should take this into consideration in your analysis.

de Leeuw, E., Hox, J. J., & Dillman, D. A. (2008). The Cornerstones of Survey Research. In E. de Leeuw, J. J. Hox, & D. A. Dilman (Eds.), International Handbook of Survey Methodology (pp. 1–18). New York and London: Lawrence Erlbaum Associates.
Gelman, A., & Hill, J. (2006). Data Analysis Using Regression and Multilevel Models. Cambridge: Cambridge University Press.
Groves, R. M., Fowler, J. J. J., Couper, M. P., Lepkowski, J. M., Singer, E., & Tourangeau, R. (2004). Survey methodology. New Jersey: Wiley.
Comment: Thank you for your excellent answer. I think the last sentence of your answer about a model-based approach is the most essential conclusion, although I am not sure whether I could succeed in doing so in the collected data, since the factors and the interactions that appear to be significant varies a lot with the assumed model and all factors and interactions (theoretically) could find an explanation in the context of a theory...


Solve the PDE $xu_x + u_y+ yu=0$

Question: It is asked to solve the PDE
$$xu_x + u_y+ yu=0$$
where $u=u(x,y)$
**My attempt: **
Let $x=x(s), y=y(s), v(s)=u(x,y)$ such that
$$\frac{dx}{ds}=x, \;\frac{dy}{ds}=1, \;\frac{dv}{ds}=-yv$$
$ \Rightarrow\frac{dx}{dy}=x \Rightarrow \ln|x| = y + C_1$
$\Rightarrow\frac{dv}{dy}=-yv \Rightarrow \ln|v| = - \frac{y^2}{2} + C_2 \Rightarrow v = u = K e^{-y^2/2}$
As $u$ is constant in its characteristcs
$$u=K(\ln|x|-y)e^{-y^2/2}$$
BUt wolfram gave a different answer. What am I doing wrong?
Thanks!
@Edit Now I see that my solution is correct. We just need to substitute $y=\ln|x| - C_1$. Wolfram solved it for $x$.
Answer: Follow the method in http://en.wikipedia.org/wiki/Method_of_characteristics#Example:
$\dfrac{dy}{dt}=1$ , letting $y(0)=0$ , we have $y=t$
$\dfrac{dx}{dt}=x$ , letting $x(0)=x_0$ , we have $x=x_0e^t=x_0e^y$
$\dfrac{du}{dt}=-yu=-tu$ , letting $u(0)=f(x_0)$ , we have $u(x,y)=f(x_0)e^{-\frac{t^2}{2}}=f(xe^{-y})e^{-\frac{y^2}{2}}$

Solve the PDE $xu_x + u_y+ yu=0$


Server is giving me a SMART Failure Predicted

Question: I have an older xSeries 306 that has started giving me a SMART Failure Predicted on Hard Disk 2: SATA Port 0 message, a warning about backing up, and a message to Press F1 to continue. It's my understanding that SMART is actually part of the hard drive itself but this happens with hard drives that work fine in other systems. I've put a new hard drive in and am attempting to reinstall server 2003 (still get the SMART warning). The installer sees the hard drive and I get as far as formatting the drive. It just hangs at 0%. I assume this isn't really the the computer sensing a SMART problem but a problem with the server itself. Any ideas other than a bad motherboard of what could cause this?
By the way, this system only has 1 hard drive. I've never noticed it being referenced as "hard disk 2: SATA Port 0". Is that normal?
thanks
Comment: What causes the problem is a hard disk that is potentially about to go bad. Given the inconvenience of a hard drive failure plus the cost of your hourly rate for the time spent messing about, frankly I think that when you see something like this its worth just replacing the hard disk and not worrying too much more about it.
Answer: Those SMART alerts are showing up for a reason.
Yes, the hard drive itself has the SMART circuitry/logic on it. It measures many different performance metrics such as spin-up time, bad sectors, etc. etc.  There are myriad free tools online to easily pull this data and see for yourself.
The Windows installer doesn't care about the SMART data.
Answer: SMART variables are aprt of the drive firmware. When certain parameters go over defined limits, the machine is supposed to start crying. This has NOTHING to ddo on an OS level. It is totalyl in the drive firmware.
This does NOT mean teh disc is crap - it means the disc starts having issues. It can work well for years to come, or fail within days.
So, for pro machines / servers where data integrity counts, it is practice to relpace the disc the moment SMART starts crying IF you validate it is a SMART issue (could be abus / controller issue - seen one disc interfere with other ports ona a SAS bus).

I've never noticed it being referenced as "hard disk 2: SATA Port 0". Is that normal?

Possibly. Check what else is there according to BIOS. For example my main server has 2 keyboards - a real one, one from the lights out management that comes via a "fake" usb port. Maybe you have some "ghost" hd 0? DVD drive?
Answer: Yes, SMART metrics are gathered by the drive firmware, and as such are independent of which system they are put in.
However, the fact that some systems complain and some do not has nothing to do with any of the above-mentioned reasons.
It is simply the monitoring OS or application that decides what those metrics mean.
EDIT: well, not entirely - SMART also provides a single-value PASS/FAIL status that the OS or application can check, and that status is determined by the drive firmware.
However, any monitoring solution worth its salt will not only use that, but also interpret the actual values from the SMART table.
Answer: Others have rightly noted that SMART is an on-drive function.  It may be that other chassis don't complain about this HDD because they don't check its SMART status at boot.
As I have noted in an earlier answer, Google famously released a paper some years back about (inter alia) SMART monitoring, and one conclusion was that the presence of SMART errors correlates strongly with incipient drive failure.
Of course, this is only a statistical argument, but if I were you I'd put that HDD into a Linux box, use smartctl to confirm that the drive really is reporting predicted failure, and immediately retire the drive.


A value of type 'T?' can't be assigned to a variable of type 'T'

Question: I am trying to assign to an int value, however, I get this error:
A value of type 'int?' can't be assigned to a variable of type 'int'

The line causing this compile-time error is the following:
int number = someFunction();

Answer: The problem here is that the value returned from someFunction is nullable and trying to assign that value to a non-nullable variable is a compile-time error (null-safety was introduced in Dart 2.7).
You need to check for null using a != null condition.
Example
void exampleFunction<T>(T? input) {
  T result = input; // <- ERROR here

  print(result);
}

In this example, input is nullable and thus cannot be assigned to the non-nullable variable result.
Solution
The given example problem can be solved like this:
void exampleFunction<T>(T? input) {
  if (input != null) {
    T result = input;

    print(result);
  }
}


Adding links to a menu without re-selecting the menu each time

Question: I am adding links to a (SuperFish) menu in Drupal 8. Each time I add a link it returns me to the list of menus (admin/structure/menu).
How can I add menu links without having to re-select the menu each time?
I think that newly created menus operate the way I want, but I want to add links to an existing menu.
So far my best method is to store the URL for adding a menu item in the clipboard.

admin/structure/menu/manage/main-ejn-menu/add
Answer: So do you want it to go add to the add menu item screen after creating one? What is in the url does it have something like ?destination=/admin/structure/menu
You could change that to
<code>admin/structure/menu/manage/main-ejn-menu/add?destination=admin/structure/menu/manage/main-ejn-menu/add
</code>
Comment: That works once.  I can add two menu items and then I am in edit mode for the second item.


nslookup resolves domains to IPs, but I can't get a response to pings to external servers

Question: I have a fresh install of CentOS 4.8 running on an internal development server. I haven't done anything to it besides setting up sudoers and SSH. I can SSH into the server and from there resolve domains to IPs and ping internal servers, but for some reason I don't get any response from pinging external servers.
The software firewall is disabled, and the problem is present with both static and DHCP-assigned network configurations. The network domain controller is a Windows Server 2003 box.
$ nslookup google.com
Server:         10.254.2.5
Address:        10.254.2.5#53

Non-authoritative answer:
Name:   google.com
Address: 220.127.116.11
Name:   google.com
Address: 126.96.36.199
<etc...>

10.254.2.5 is the Win2K3 server.
$ ping google.com
PING google.com (184.108.40.206) 56(84) bytes of data.

It just hangs here indefinitely.
$ cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search <...snip...>.local
nameserver 10.254.2.5
nameserver 10.254.2.124

10.254.2.124 is the backup DC server, which is currently off and tombstoned by this point. The snipped section is our company name.
# ifconfig
eth0      Link encap:Ethernet  HWaddr <snip>
          inet addr:10.254.2.101  Bcast:10.254.2.255  Mask:255.255.255.0
          inet6 addr: <snip>/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:80066 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4421 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7810133 (7.4 MiB)  TX bytes:590550 (576.7 KiB)
          Interrupt:225 Base address:0xc000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:32 errors:0 dropped:0 overruns:0 frame:0
          TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8104 (7.9 KiB)  TX bytes:8104 (7.9 KiB)

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.254.2.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         10.254.2.5      0.0.0.0         UG    0      0        0 eth0

And, for good measure, a snapshot of the current ethernet config via the system-config-network GUI.
Edit: I don't yet have enough rep to post images, so here's a link. Sorry!
system-config-network snapshot
I'm pretty green when it comes to setting up *nix dev servers and network configuration in general, so please let me know if I've left out critical information, or posted information I shouldn't have posted.
Thanks!
Answer: Nothing requires that ping be possible between two hosts. It might be that somebody between you and google is dropping ICMP packets. If everything else is working I'd not worry much about this.
If you are particularly worried check with whoever runs your networking equipment or firewall and see if they are letting ICMP traffic through. Also check to see if you can ping anybody else in the outside world other than google?
Comment: While all of the Windows workstations seem to be able to access the internet just fine (in spite of the inability to ping and trace route), the development server I started the thread about is a different story. It has all the same symptoms (inability to ping, etc.) but it can't access the outside world via browser, even though it can see, connect to and ping any internal machine and resolve external IPs.

We're unable to ping any outside server. At this point I guess it's an issue with our ASA.
Answer: Check your local netfilter rules:
iptables -L -n
If there are no rules affecting ICMP and it is otherwise routing, as it appears to be due to DNS resolution, there is likely some filtering occurring at either 10.254.2.5 or its next hop.
Edit
Based on your update, it looks like you have local firewall rules on the Linux server preventing the ping.
To remove all rules:
iptables -F
iptables -X

They will likely return on reboot.  I suspect they are managed by an init script.  I'm guessing to disable the init script:
/sbin/chkconfig iptables off
This varies between distributions.  I wrote a quick introduction to iptables in a previous answer:
Can you recommend a good intro to iptables?
Typically, simply disabling the firewall is not well advised.  However, it does look you are using intranet routable addressing, and your description indicates that you probably already have a firewall further up the route.  Be cautious about your actions unless you understand the potential risks of what you are undertaking.
Comment: Running that command results in a long list of rules, with the pertinent one (I believe) being:
`REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited`

I assume that is the ICMP rule you were referring to. I guess I need to go learn how to modify iptables rules.
Comment: Please see my edit.
Comment: Hmm, I was able to confirm that the rules had been removed (running `iptables -L -n` returns a bunch of empty chains now), but even after restarting the network service and rebooting the machine (I also ran `/sbin/chkconfig iptables off`), I still can't ping external servers. I'm becoming increasingly aware that I'm in way over my head.
Comment: Can the DC with the .2.5 address ping google?
Comment: I was all set to say, "Psh, of course!" but as it turns out, no. It can access Google (and the rest of the internet) via browser seemingly unhindered, but it cannot ping Google (or any other external server). In fact, none of the machines on the local network can, but they can all access the internet via browser.
Answer: This looks like a routing and/or firewall problem.
How do you connect to the Internet? Is 10.254.2.5 (your default gateway) also your Internet gateway, or do you have other routing in the middle before you can actually reach your perimeter firewall? How is/are your firewall/s configured?
Please post the output of a traceroute -n google.com, so we can see where your packets are actually being blocked.
Comment: Hmm... I guess I'm in over my head. We're a really small web development shop without an IT guy, and our internal network was set up by a third party long ago. All I really know is that we have a router connected to a cable modem, and that connection is split among all of our machines (including the DC) via gigabit switches.

`# traceroute -n google.com
traceroute: Warning: google.com has multiple addresses; using 220.127.116.11
traceroute to google.com (184.108.40.206), 30 hops max, 38 byte packets
 1  * * *
 2  * * *`


Why aren't the argv and envp arguments to execve pointers to const?

Question: Take e.g. execve(2), which according to posix has this prototype [1]:
int execve(const char *path, char *const argv[], char *const envp[]);

To me, it seems as if
int execve(const char *path, const char *const argv[], const char *const envp[]);

would have been an obvious improvement.
So, does anyone know why this is as it is? What can explain the need
to possibly manipulate the given argv/envp strings?
[1] http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html
Comment: Since questions about the C API (as opposed to general system design) are off-topic here, I'm voting to migrate to [so]. (Do not repost, the question will be moved soon.)
Comment: [In response to your comments on my deleted answer] Oh, I see what you mean — yes, my answer addresses the arguments of `main`, not the arguments of `argv`. That's really a C API question, not a Unix system design question. I think the answer is simply historical compatibility with the original, pre-const APIs.
Comment: Presumably some programs mutate these buffers
Comment: That buffer may indeed be mutated in the new process but that would be on the other side of the exec, with a new memory layout which has nothing to do with the process sending off those arguments to the kernel before the exec happens.
Comment: Just stumbled over the same thing when looking at posix_spawn.
chainging the api to const char ** or const char * const * shouldn't even break existing implementations. To use these methods with the given signature I either have to copy the argv and envp arrays or just cast them and hope nothing goes wrong... Too bad!
Answer: The argv and envp arguments to execve() are not pointers to const in order to preserve backwards compatibility with valid C code that was written before const was added to C.
C first appeared in 1972.  Later on, const was added to C in 1987.
In order to maintain compatibility with pre-const code, the updated-with-const declaration of execve() must be able to accept non-const inputs.  C does not allow assignments from char *[] to const char *[].  This can be verified by trying (and failing) to compile the following program:
void  foo  ( const char * argv[] )  {  return;  }
void  main  ( int argc, char * argv[] )  {  foo ( argv );  }

Therefore, char *const[] is the strictest type that is backwards compatible with pre-const code.
The question provides a link to the POSIX documentation for execve().  The linked POSIX documentation does explain this as follows:

The statement about argv[] and envp[] being constants is included to
  make explicit to future writers of language bindings that these
  objects are completely constant. Due to a limitation of the ISO C
  standard, it is not possible to state that idea in standard C. ...

Actually, to be precise: it is not possible to state that idea in a way that is backwards compatible with pre-const code.

... Specifying two levels of const- qualification for the argv[] and
  envp[] parameters for the exec functions may seem to be the natural
  choice, given that these functions do not modify either the array of
  pointers or the characters to which the function points, but this
  would disallow existing correct code. Instead, only the array of
  pointers is noted as constant. The table of assignment compatibility
  for dst= src derived from the ISO C standard summarizes the
  compatibility:
        dst:          char *[]   const char *[]   char *const[]   const char *const[]
src:
char *[]               VALID           -              VALID               -
const char *[]           -           VALID              -               VALID
char * const []          -             -              VALID               -
const char *const[]      -             -                -               VALID

Since all existing code ...

Meaning all code that existed prior to const being added to C.

... has a source type matching the first row, the
  column that gives the most valid combinations is the third column. The
  only other possibility is the fourth column, but using it would
  require a cast on the argv or envp arguments. It is unfortunate that
  the fourth column cannot be used, because the declaration a non-expert
  would naturally use would be that in the second row.

Sources: 2018 edition, 2004 edition.
Answer: This is basically due to the hole in the C standard that prevents the implicit conversion from T ** to const T * const *.  Such a conversion would be safe (a conversion from T** to const T ** would be problematic), but the standard has not been updated to allow it.
mpb quotes from the POSIX standard

The statement about argv[] and envp[] being constants is included to make explicit to future writers of language bindings that these objects are completely constant. Due to a limitation of the ISO C standard, it is not possible to state that idea in standard C.

which implies that the POSIX standard will be changed when/if the C standard is ever updated.
Answer: Some programs manipulate the argv strings so that ps output show some state information. For example:
root      6550 10809  0 13:10 ?        00:00:00 pure-ftpd (IDLE)
root     32216     1  0 Apr05 ?        00:00:00 vtund[s]: waiting for connections on port 5000
1023     30448  9847  0 09:01 ?        00:00:01 imap [username 192.168.1.135]

Hence the argv values are not constant and should not be declared as such.
Comment: Presumably, however, those programs modify the copy of the argv strings in their *own* address space, not the address space of the process which called `execve`.


How to trigger a Line break on a SMS

Question: I'm gonna write SMS service that sends SMS's automatically.In that case i am going to create my SMS content by SQL.
So is it possible to add a line break by using some special command or a character?
Comment: have you tried something?
Comment: yes.i used "%0a","\0x0A" & "/n".. but didn't successful..
Answer: i have concatenate CHAR(10) to my SQL message content an it worked !!!
Answer: Have you tried \n? I notice you say you've tried forward slash... Give back slash a try.
If that doesn't work, since you have tried the line feed character already (%0A), try carriage return (%0D) or a combination of the two (%0A%0D)
Edit: To let us help you better, what are you using to write this service? What technologies are involved here?
Comment: I'm sorry i have commented wrongly.. i have used "\n".And "%0A%0D" also not working.. i'm using SMPP for send SMS.
Comment: hmmm ok. Try the other combination of the line feed and carriage return characters (\r\n)
Comment: Environment.NewLine ?
Comment: Environment.NewLine may not be far off... If OP is using C#... Are you, @RangaNirmana?
Comment: But I'm using SQL Stored procedure for create my SMS content.. and found a solution

How to trigger a Line break on a SMS


Matlab ROC curve calculation question

Question: I'm working through the example code given by Matlab, but I can't seem to exactly reproduce the ROC curve that is plotted. I want to make sure I am understanding the thresholding concept properly. Could anyone help me to understand why the two figures plotted below are different?
clear; clc; load fisheriris;
pred = meas(51:end,1:2);
resp = (1:100)'>50;  % Versicolor = 0, virginica = 1
mdl = fitglm(pred,resp,'Distribution','binomial','Link','logit');
scores = mdl.Fitted.Probability;
[X,Y,T,AUC] = perfcurve(species(51:end,:),scores,'virginica');

figure; plot(X,Y);
xlabel('False positive rate'); ylabel('True positive rate');
title('ROC , built-in');

tpr = nan(length(T),1); fpr = nan(length(T),1);
for ind_F = 1:1:length(T)
  t_true = scores >= T(ind_F);
  group = resp; grouphat = t_true;
  t_cm = confusionmat(group,grouphat);
  % ROC : TPR / FPR
  tpr(ind_F) = t_cm(1,1)/sum(t_cm(1,:));
  fpr(ind_F) = t_cm(2,1)/sum(t_cm(2,:));
end

figure; plot(fpr,tpr); xlabel('fpr'); ylabel('tpr');
title('ROC , derived');

Thanks for the help.
Answer: After looking into the confusionmat code, I realized the problem. Matlab orders the "positive" variable as the 2nd dimension, i.e. second row and second column. In most specificity / sensitivity docs I had read the positive variable is ordered as the first dimension. As a result, the following plot matches:
tpr = nan(length(T),1); fpr = nan(length(T),1);
for ind_F = 1:1:length(T)
  t_true = scores >= T(ind_F);
  group = resp; grouphat = t_true;
  [t_cm,t_c] = confusionmat(group,grouphat);
  % ROC : TPR / FPR
  tpr(ind_F) = t_cm(2,2)/sum(t_cm(2,:));
  fpr(ind_F) = t_cm(1,2)/sum(t_cm(1,:));
end

figure; plot(fpr,tpr); xlabel('fpr'); ylabel('tpr');

Hopefully this might be helpful for someone else.

Matlab ROC curve calculation question


Cloud DNS forwarding not resolving in other networks of shared VPC

Question: Our setup:
We have a master project A, and two other projects, B and C. In project A, we have a shared VPC with networks A, B, and C (related to which project they're meant to serve). The VPC for B is shared from project A to project B, and the VPC for C is shared from project A to project C. The networks are peered with each other.
Within project A, we have a private Cloud DNS zone which forwards to two DNS servers. One of these servers is in project A and network A, and one of them is in project B on network B. We have selected all networks (A, B, and C) to be included in this DNS zone.
Our problem:
Cloud DNS appears not to be sharing properly across these networks. With experimentation, we have found that instances will be able to resolve records that are on a DNS server on the same network, but not on another network. ie:
An instance on network A will be able to resolve a domain from the network A DNS server, but not from a network B DNS server, and vice versa. However, if you explicitly define the DNS server, it works as expected.
For example, let 10.0.0.1 have an A record for foo.com, and 10.0.1.1 have an A record for bar.com. They are hosted on network A and network B respectively:
On an instance from network A:

Running nslookup foo.com will resolve.
Running nslookup bar.com will
return SERVFAIL.
Running nslookup bar.com 10.0.1.1 will resolve.

Similarly, using an instance on network B

Running nslookup bar.com will resolve
Running nslookup foo.com will return SERVFAIL
Running nslookup foo.com 10.0.0.1 will resolve

And network C:

Running nslookup foo.com will return SERVFAIL
Running nslookup bar.com will return SERVFAIL
Running nslookup foo.com 10.0.0.1 will resolve
Running nslookup bar.com 10.0.1.1 will resolve

I'm unsure why this behaviour is as it is.
What has been tried/confirmed

We have ensured all networks can communicate on TCP/UDP port 53, and that both nameservers can be seen from all networks
We have tried adding policies (which gave a similar result, only failures returned NXDOMAIN rather than SERVFAIL)
We have looked into DNS peering, which is not applicable here

Any help here would be appreciated. I'm aware that private zones in Cloud DNS are still a Beta feature, but this setup should currently be possible according to the documentation.
Answer: From your description, it looks like the networks A, B and C are peered with each other. The documentation about Peering zones says that, "when two networks are peered, they do not automatically share DNS information". This could explain why the DNSs can only resolve names to instances within the same VPC ehn using Cloud DNS forwarding; and in the other hand, the DNSs have to be asked directly to resolve when they are set in peered VPCs.
I can see there ins't documentation to use Peering Zones with Forwarding DNS at the same time, so you may want to try by adding both domains foo.com and bar.com in both DNS servers.
Answer: From the same page, it also explains that there is DNS Peering beta available, whereby a Consumer Network can forward DNS requests to a Producer Network.
If I understand it correctly, that would mean having the DNS setup on the producer network A, and let the networks B and C forward their respective queries to A.
But what if B and C have different private zones (which should not be so far from real)?
Would that mean having both setup on A  so that records for the respective VPCs are uniquely managed from within project A.
I would like to try it as well, moreover because on top of this I have a VPN with on-prem (let's call it D) and the next step would be to setup a conditional forwarder to the on-prem DNS.
Not sure if B and C would be able to resolve D queries through A project.


Irrational painting device

Question: Part a) of the following problem appeared in one of the Putnam Exams (sorry, don't know which year exactly).
If you want to solve Part a) don't read Part b).
You have a painting device, which given the co-ordinates of a points in the 2D plane, will colour all points on that plane black, which are at an irrational distance from the given point.
Initially you start out with the 2D plane being white.
a) You want to colour the whole plane black. What is the minimum number of points you need to feed to the painting device?
b) Show that it is sufficient to feed $(0,0), (1,0), (\sqrt{2},0)$.
Comment: I think you are going to receive flak for this question because people favor questions the OP genuinely wants to know the answer to. This answer for instance could be found here: http://amc.maa.org/a-activities/a7-problems/putnamindex.shtml However I could be off-base and people could be cool with this. I guess we'll see :/
Comment: @BBischof: Well, at least it will help define the FAQ in that case. I am fine if you close this. I was under the impression there might be a minimum (quantity) requirement for questions/answers for the site to move out of Beta and become permanent. Also, the link you posted won't have the solution to Part b) I suppose.
Comment: @BBischof: I suppose it is because the guidelines are not very clear. Do you want to open a meta question to discuss this? Also, the part b) I have added to the problem and I don't think you will find it with the standard putnam exam solutions on the web. Perhaps that is another reason people are reluctant to close?
Comment: BTW, I don't think there is a dearth of questions here. If anything, there are so many questions that one cannot look at every question in detail.
Comment: I'm voting to close this question because OP already knows and understands the answer. This isn't a "puzzling" site.
Comment: @Moron Oh the irony! Four upvotes on my comment, yet no votes to close! I didn't even vote to close, yet instead left that comment! What a strange situation. I cannot in good faith vote to close until another person jumps the shark.
Comment: I will leave it alone and let it run its course. If you want to start a meta thread, feel free. BTW, I don't want to give the impression I dislike this question. I am just a little obsessed with precedent and sticking to it for the good of the future of the community.
Comment: @Shree: by dearth I meant the critical mass of question/answers required to move this site from Beta to a permanent site. If I have read the area51 faq/etc correctly, we need around 10 questions/answers per committed person. Currently we seem to be way below that threshold. Anyway...
Comment: related: how many GPS satellites do you need to see to be able determine your location.
Answer: Each proof thus far is computational, some relying heavily on number theory.  The top-rated answer has a noted flaw.  Below, I've reproduced a proof from Halmos' "Problems for Mathematicians, Young and Old" (problem 4k):
It's easy to see that two points will not suffice: take a point on the perpendicular bisector of the first two points with irrational distance from both.  To show that three points are sufficient, we note that each of the first two points leaves unpainted countably many circles of points (those with rational distance from the center).  Thus, after two applications, we are left with countably many points, corresponding to intersection points of countably many circles.  Take an arbitrary line in $\mathbb{R}^2$.  It will intersect the remaining points in a countable set.  Take a point on the arbitrary line, not one of the countably many points.  Center our painting device here; then it is (by definition) an irrational distance from each remaining point.
The upshot of this approach: full generality to higher dimensions.
Comment: Thanks. I was aware of this proof of part a). I was more interested in proofs for part b). +1 though.
Answer: Suppose that there exists a point A that is left uncolored after feeding in the three points (0,0), (1,0), and $(\sqrt{2},0)$.  The distances from point A to each of these three points (call these b, c, and d, respectively) must be rational numbers.

Apply Stewart's Theorem: $$b^2(\sqrt{2}-1)+c^2\cdot 1=\sqrt{2}(d^2+(\sqrt{2}-1)\cdot 1).$$ So $$\sqrt{2}(b^2-d^2+1)=b^2-c^2+2$$ or $$\sqrt{2}=\frac{b^2-c^2+2}{b^2-d^2+1}.$$  Since b, c, and d are rational numbers, the right side is rational, but the left side is irrational, so there is no such point A.  Thus, to color the entire plane black, it is sufficient to feed in the three points (0,0), (1,0), and $(\sqrt{2},0)$.
Comment: This proof is incomplete. What if $b^2 - d^2 +1 = 0$?
Answer: I decided to give this problem a go, but I couldn't get a complete solution. Lets look at the distances squared:

$x_1^2+y_1^2$
$(x_1-1)^2+y_1^2$
$(x_1 - \sqrt{2})^2+y_1^2$

These must all be rational. The difference between any two rational numbers must be rational, so $-2x_1+1$ is rational and so is $x_1$. Subtracting 2. and 3., we get: $(-2 \sqrt(2)-2)x_1+3$, implying that $x_1$ must be 0 if it is rational.
This then gives us:
$y_1^2, y_1^2+1, y_1^2+2$
Suppose $y_1^2=a^2/b^2$ where a and b are integers. Clearly, $y_1^2+1, y_1^2+2$ are rational if and only if $a^2+b^2$ and $a^2+2*b^2$ are perfect squares. Using modular arithmetic it is pretty clear that b needs to be divisible by 2 (squares are only 0 or 1 mod 4), implying $b^2$ is divisible by 4.
Comment: Not so fast :-) What if x_1 = 0?
Comment: How about taking the difference of 2 and 3?
Comment: Good point. $(-2 \sqrt{2}-2)x_1+3$ needs to be rational as well. Since $x_1$ is irrational, that won't occur.
Comment: Hmm, then we need the roots of $y_1^2$, $y_1^2+1$, $y_1^2+2$. If we let $y_1^2=a^2/b^2$ where a,b are integers, then we need $a^2+b^2$ and $a^2+2*b^2$ to be perfect squares
Answer: Just so I don't forget, here is the solution I was thinking of, for part b).
Let $(x,y)$ be a point which is at a rational distance from $(0,0), (1,0)$ and $(\sqrt{2},0)$.
Then we have that $x^2 + y^2$, $(x-1)^2 + y^2$ and $(x-\sqrt{2})^2 + y^2$ are all squares of rational numbers.
The difference of the first and second implies $x$ is rational.
The difference of the second and third implies that $x = 0$.
Thus $y$ is rational.
Thus we have that for some integers $a,b,p,q$, $a \neq 0$, $b \neq 0$ that
(1) $a^2 + b^2 = p^2$
and
(2) $a^2 + 2b^2 = q^2$
Square (1) and multiply (2) by $a^2$ and subtract.
We get
$b^4 = p^4 - (aq)^2$.
It is well known that the equation $x^4 + y^2 = z^4$ has no non-trivial solutions (and in fact can be used to show that Fermat's Last theorem is true for $n=4$).
See here for instance: Link

Irrational painting device


To understand MySQL's error messages in OS X

Question: I am reading MySQL's manuals.
I run
<code>. /usr/local/mysql/bin/mysql                                                                                ~
</code>
I get
<code>/usr/local/mysql/bin/mysql:1: command not found: ????^G
/usr/local/mysql/bin/mysql:2: permission denied:
/usr/local/mysql/bin/mysql:3: parse error near `}'
</code>
I run
<code>. /usr/local/mysql/bin/mysqladmin                                                                                ~
</code>
I get
<code>/usr/local/mysql/bin/mysqladmin:9: parse error near `)'
</code>
These error messages suggest me that my MySQL seems to be corrupted.
I did not found by Google explanations for the error messages.
What do the messages really mean?
Answer: try running
<code>/usr/local/mysql/bin/mysql
</code>
[without the dot]
if you use "dot space" at the beginning file you provide path to will be interpreted as bash-script, but what you point is actual binary executable, not a script.
what you try is NOT the way to start mysql server, those are attempts to run mysql client.
Comment: that is much better. do you have mysqld [ mysql server ] running ?
Comment: but what you try to run is mysql client [ /usr/local/mysql/bin/mysql ], mysql server is usually called mysqld or mysqld_safe.
Comment: I get the error: `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)`
Comment: The other command seems to work without "." --- I do not understand how you can run a file without "."
Comment: @pQd: I do not have it running, since I have this problem: http://serverfault.com/questions/35859/unable-to-start-a-mysql-server-on-mac-os-x/35967#35967
Comment: i dont really know mac os, but i don't think you can run for instance . /bin/ls [ path might differ ]. i might bet wrong.
Comment: @Masi do not run mysqld with & just open another console and let it sit there, run mysqld --verbose - maybe you'll get some more useful error msgs.
Comment: See http://serverfault.com/questions/36052/what-is-the-purpose-of-source-as-a-shell-command for a discussion of "the dot".


Are 1-dimensional numpy arrays equivalent to vectors?

Question: I'm new to both linear algebra and numpy, so please bear with me. I'm taking a course on linear regression, where I learned that we can express our hypothesis as $\theta^TX$ where $\theta$ is our coefficient vector (written in math notation as a column vector) and $X$ is our design matrix with $m$ features and $n$ rows.
Now, a vector can be viewed as one column or one row of a matrix. But in numpy, there is a difference between an array with shape (5,) and an array with shape (5,1).

Is there a mathematical equivalent to the numpy distinction between shape (5,) and shape(5,1), or are we to view both as vectors?
When we transpose a numpy array with shape (5,) its shape doesn't change, whereas transposing an array with shape (5,1) results in the shape (1,5). What would be the correct numpy equivalent of $\theta^TX$?
Comment: "Vector" in programming languages $\ne$ "vector" in mathematics, the same with matrices. Moreover, different programming languages have different implementations of those of objects. Looking for similarities and differences is pointless (e.g. mathematical vectors do not have `print()` methods and you can find a number of other absurd differences). You should rather learn how to translate math to the code.
Comment: This belongs on [stackoverflow](https://stackoverflow.com/) (i.e. A coding question), as this is asking specifically about the functionality of a python package, rather than being a question related to stats or machine learning.
Answer: A NumPy array is a N-dimensional container of
items of
the same type and size. As a computer programming data structure, it is limited
by resources and dtype --- there are values which are not representable by NumPy
arrays. Due to these limitations, NumPy arrays are not exactly equivalent to the
mathematical concept of coordinate vectors. NumPy arrays are often used to
(approximately) represent vectors however.
Math also has a concept of vector spaces whose elements are called vectors. One
example of a vector is an object with direction and magnitude.  A coordinate
vector is merely a represention of the vector with respect to a particular
coordinate system.  So while a NumPy array can at best record the
coordinates of a vector (tacitly, with respect to a coordinate system), it can
not capture the full abstract notion of a vector. The abstract notion of vector
exists without any mention of coordinate system.
Moreover, vector spaces can be collections of things other than
coordinates. For example, families of functions can form
a vector space. The functions would then be vectors. So here is another example
where NumPy arrays are not at all equivalent to vectors.

Linear algebra makes a distinction between "row vectors" and "column vectors".
There is no such distinction in NumPy. There are only n-dimensional arrays.
Keep in mind that NumPy was built around a desire to generalize array-like containers to N dimensions where N is bigger than 2. So NumPy operations are defined in ways that generalize to higher dimensions.
For example, transposing a NumPy array of shape (a,b,c,d) returns an array of shape (d,c,b,a) -- the axes are reversed. In two dimensions, this means an array of shape (a,b) (i.e. a rows, b columns) becomes an array of shape (b,a) (i.e, b rows, a columns). So NumPy's notion of transposition matches up nicely with the linear algebra notion for 2-dimensional arrays.
But this also means that the transpose of a 1-dimensional NumPy array of shape
(a,) still has shape (a,). Nothing changes. It is still the same
1-dimensional array.  Thus there is no real distinction between "row vectors"
and "column vectors".
NumPy apes the concept of row and column vectors using 2-dimensional arrays.
An array of shape (5,1) has 5 rows and 1 column. You can sort of think of this as a column vector, and wherever you would need a column vector in linear algebra, you could use an array of shape (n,1). Similarly, wherever you see a row vector in linear algebra you could use an array of shape (1,n).
However, NumPy also has a concept of broadcasting and one of the rules of broadcasting is that extra axes will be automatically added to any array on the left-hand side of its shape whenever an operation requires it. So,
a 1-dimensional NumPy array of shape (5,) can
broadcast to a 2-dimensional array of shape (1,5) (or 3-dimensional array of
shape (1,1,5), etc).
This means a 1-dimensional array of shape (5,) can be thought of as a row vector since it will automatically broadcast up to an array of shape (1,5) whenever necessary.
On the other hand, broadcasting never adds extra axes on the right-hand side of the shape. You must do so explicitly. So if theta is an array of shape (5,), to create a "column vector" of shape (5,1) you must explicitly add the new axis yourself by using theta[:, np.newaxis] or the shorthand theta[:, None].

What would be the correct numpy equivalent of $\theta^TX$?

If, for example,
In [4]: import numpy as np
In [5]: theta = np.array([1,2,3,4,5])[:, np.newaxis]
In [7]: X = np.random.randint(10, size=(5,3))
In [8]: X
Out[8]:
array([[4, 0, 3],
       [6, 9, 1],
       [7, 8, 7],
       [4, 2, 6],
       [7, 7, 2]])

then you could compute $\theta^TX$ using
In [18]: np.dot(theta.T, X)
Out[18]: array([[88, 85, 60]])

Note that np.dot is defined so that

For N dimensions it is a sum product over the last axis of a and
  the second-to-last of b

    dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])

This has the property that

For 2-D arrays it is equivalent to matrix multiplication, and for 1-D
  arrays to inner product of vectors (without complex conjugation).

Note that NumPy also has a matrix subclass of ndarray whose multiplication operator is defined to match 2-dimensional matrix multiplication. So if theta and X were NumPy matrices, then you could write theta.T * X instead of np.dot(theta.T, X). This can make translating math into NumPy code a bit more readable.
Or, if you have Python3.5 or newer, you can use regular NumPy arrays and write theta.T @ X.