Value assigned never used. Delphi bug or code bug?

Question: This code is part of a third party component I am using in my application.
I am trying to solve all possible problems related to hint in my application.
But I can not understand this.
Delphi Compiler marks first line of this code for a hint "Value assigned to NewState never used!.
I just want to understand situation
  NewState := STATE_UNCHECKED;   //Value assigned never used?Really?
  while ( Node <> nil ) and ( Node.Parent <> nil ) do
  begin
    Node := Node.Parent.GetFirstChild;
    CheckedCount := 0;
    UnCheckedCount := 0;
    while True do
    begin
     ....
      if ( Node.StateIndex = STATE_PARTCHECKED ) or
         ( ( CheckedCount > 0 ) and ( UnCheckedCount > 0 ) ) then
      begin
        NewState := STATE_PARTCHECKED; ///assign value on condition
        Break;
      end;

      if Node.GetNextSibling = nil then
      begin
        if CheckedCount > 0 then
          NewState := STATE_CHECKED //assign value on condition
        else
          NewState := STATE_UNCHECKED;
        Break;
      end
      else
        Node := Node.GetNextSibling;
    end;
    Node := Node.Parent;
    if Node <> nil then
      SetState( Node,  NewState );
  end;

But when both of this statments are false this value must be used.Am i wrong?
 if ( Node.StateIndex = STATE_PARTCHECKED ) or
             ( ( CheckedCount > 0 ) and ( UnCheckedCount > 0 ) ) then

and
if Node.GetNextSibling = nil then

UPDATE
answers are correct .The Break Statment runs only after a new value assigned to variable and overwriting first value. then assigned value is never used.
a Minimal, Complete, and Verifiable example:
procedure TForm1.btn1Click(Sender: TObject);
Var x,y,z,k:integer;
begin
   X:=1;
   Y:=strtoint(edit1.text);
   Z:=Strtoint(edit2.text);
   K:=Strtoint(edit3.text);
     while true do
     begin
      If Z=y*2 then
      begin
        X:=2;
        Break;
      end;

      If Y=3 then
      begin
        If K=7 then
        begin
        X:=3;
        Break;
        end
        else
        begin
        x:=6;
        Break;
        end;
      end
     end;

    showmessage(inttostr(x));

end;

Comment: Sadly, you didn't show the entire function, and you showed loads of code that was not necessary. This could have been a good question if only you'd provided a [mcve].
Comment: If I were a _human compiler_, I would say the same. The assigned value `STATE_UNCHECKED` is not compared in that `if` statement.
Comment: Ah, I think that I see it. The inner loop is a 'While TRUE'. The only ways out of that loop require that NewState be assigned. So the compiler is correct.
Comment: dear @DavidHeffernan , As I said , This is not my code. I was Trying to solve all hints ( you know an assigned but not used value or declared but not used variable in many cases represenst a possible bug in code ).
I noticied this one in a component's source.
Comment: @DavidHeffernan
Also I was not sure including lines that 3rd party component name is clearly there . i did not know this is allowed or not when it is not free component set .(like a kind of advertisement).
Thank you for your reply
Comment: Don't post the entire code. Post a [mcve].
Answer: If both the statement you highlight are FALSE then the while True loop continues. The only ways out of this loop require the NewState value to be assigned. So The compiler is correct.
Answer: First, you misunderstand the concept "is used". In this context it means "is the variable read for any purpose before its value is changed again or the variable goes out of scope". You seem to think it means "is the variable name referred to again"; so you're incorrectly thinking when the existing value is being overwritten it "is being used".

You clearly haven't shown all the code. Whether the missing code is relevant? Without seeing it, I can't be sure.
But from the code you do show: the value in assigned in the first line is overwritten without being read in the while True loop. i.e. initial assignment is never used up to that point. However, whether those lines are reached is not clear because of the conditional code leading there.
The only place where NewState is read is in the line SetState(Node, NewState);. As Dsm points out, in the code you do show, the only way to get there is by breaking out of the while True loop immediately after overwriting the initial value.

You don't say which version of Delphi you're using, but I don't think old versions were capable of picking up this slightly complex case. It should be noted that there are certainly complex cases where compilers are incapable of making an accurate determination. But since this warning involves the compiler removing the line from compiled output, these cases are typically only reported when the logic clearly indicates it's not used.
Comment: I removed a part of code that make no sesce with this issue.
And you are right. That is Because only way out of while loop is after changing this variable
Comment: @Shahram My point is that your question implied a misunderstanding of the "Value assigned ... never used" hint. This made you ill-equipped to reliably determine if the part of code you removed _really was_ relevant. This particular hint (and the closely related 'variable not initialised' warning) are both subtly affected by: `Exit`, `Break`, loops, `try..finally`, `try..except`, `with`, branching, `raise`, and reference parameters. I believe you're now in a better position to this decision. But for future reference, you're better off testing and then asking about a **complete** [mcve].


Deleted content type shows in the "Add content" menu

Question: I had some content types I wanted to delete so I went to Structure >> Content types. I deleted the content types that I didn't want to have anymore, and I cleared all the cache through drush and performance.
I also went to my database and look through to double check if they were deleted, and I found they were deleted correctly.
I have also restarted my MAMP local server.
The problem is that the deleted content types appears on "Add content" but they are not clickable. I don't want them to appear there. why does this happen?
Comment: Probably someone manually added / edited menu entries for them. Can't you just manually delete them?
Comment: No, I'm the only one devolping the site. It's under progress. There is no entries for them.
Comment: Magic happens. Flushing menu registry should help. But clearing all caches should have it done for you already.
Comment: Content types added by modules are implemented in hook_menu often times. So, I would bet that the contrib module that created the content type is to blame.
Answer: I had the same problem which I just managed to fix - thanks to  Mołot's comment which made me think of menus.  It looks like creating a content type adds an entry to the Navigation menu but deleting it doesn't delete the entry.  I just disabled that menu item and now it's gone from the Add Content page.


I need to send lots of web requests as fast as possible for many hours a day. What is the most efficient approach?

Question: I have a script which does a lot of HttpRequsts in a while loop as follows. It is run in a BackgroundWorker.
<code>CookieContainer cookieJar = new CookieContainer();
string searchURL = "http://blablabla.com/";
bool shouldRun = true; //this is set elsewhere

while (shouldRun)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(searchURL);
    request.ContentType = "application/json";
    request.Method = "POST";
    request.ServicePoint.Expect100Continue = false;
    request.CookieContainer = cookieJar;
    request.Headers.Add("X-HTTP-Method-Override: GET");
    request.Timeout = 1000;

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    // Get the stream containing content returned by the server.
    Stream responseStream = response.GetResponseStream();
    // Open the stream using a StreamReader for easy access.
    StreamReader reader = new StreamReader(responseStream);
    // Read the content.
    string responseFromServer = reader.ReadToEnd();

    JObject o = JObject.Parse(responseFromServer);

    //Do something with the JObject
}
</code>
Running the script takes up about 10 % of the CPU (Intel i5 @ 2.5GHz), and I would like to explore other approaches to see if it would be able to reduce the CPU load without reducing the number of requests made per second (current rate is around 3 to 4 requests/s) or whether it would be possible to increase the number of requests per second.
I've been looking at asynchronous requests, but would it be able to give me one of the two improvements mentioned above?
Comment: You'll do better to put your `Stream` and `StreamReader` into a `using` block. That will free resources for later requests.
Comment: Arranging a little DOS attack are we?
Comment: Nope, not a DOS attack. I need it to monitor some data. :-)
Answer: Doing an HTTP request isn't very CPU intensive, you could do 20+ of these without using 10% of the cpu.  What is cpu intensive is what you do with that data.  Parsing it (as well as whatever you're doing with that parsed data) is what's taking up most of your cpu.  You should look into other ways of dealing with that data to save processing power.  For example maybe instead of processing the data as you get it, you could save that data and once a minute process all that saved data at once with some script.
Comment: I tried commenting out the parsing after the requests, and it did help a bit, of course, but it went down from those 10 to 15 % to an average of 8 to 9 %, so the requests are still taking up quite som CPU
Comment: After further investigation, it turns out that you were actually right. I changed a few things in the code and it's now down to 1 % of cpu. Thanks a lot for the eye opener. I was certain that it was the http request which was taking up power. :-)
Comment: Glad it worked out.  Usually (perhaps always?) when dealing with anything over a physical network, there's not going to be much load on the cpu from it.  The amount of latency between communicating with a target dwarves any load on the cpu.  IPv6 may be excluded from this statement.


Proper way of Link generation from string

Question: How can I generate a link in a proper way in Drupal 8? I have a field where the user can say an internal or external page/website.
Internal:
/node/6
/articles
/articles#Subheading
etc.
External:
www.google.com
//www.google.com
https://www.google.com
How can I transform these into a link with the following condition:
the site root is: www.mydomain.com/mysite/
internal links should have language versions: i.e. en/articles or pt/articles .
I've tried with Link::fromTextAndUrl('My link', Url::fromUri('internal:/articles')), but this requires a URI which is not my goal and it doesn't follow the selected user language.
Comment: Why aren't you using core link field?
Comment: This data is saved into config. (as a module's config)
Answer: You do not need internal:/ you just need to have some help text that says an internal path should begin with a slash.
After that, when you create the links, you can do:
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;

....
....
....

function or method.... {
  $path = // get config value
  $label = // get config value

  if (UrlHelper::isExternal($path)) {
    $url = Url::fromUri($path);
  } else {
    $url = Url::fromUserInput($path);
  }

  return Link::fromTextAndUrl($label, $url);
}

Of course I am assuming there is always a value... you'd have to add your own checks so you don't get errors calling Url:: for null or empty input, etc.
The return will be an renderable array to use. I am using a similar method to allow input for third party settings on a config entity. This way the value can be internal or external.
Comment: I don't know why but this does not follow the selected site language. I hope not because I'm using the `Link::fromTextAndUrl(..., ...)->toString()` function...
Comment: I don't work with languages much, but it seems like either the link needs to have the langcode in it: https://www.drupal.org/project/language_hierarchy/issues/3088151  but there appears to be a core issue as well https://www.drupal.org/project/drupal/issues/2924653
Comment: Well, the interesting part is if I generate it from the route it has language code in the URL. But from a string, it's not really want to generate a language code in it... which is a problem. Another interesting thing, if I use node/nid then there will be language code in the URL, but it won't be alias... If I use the alias, then there won't be language code in the URL...
Comment: Actually it worked fine, but I didn't have some translation for some languages and that's why I had problems, between reality and the expectations...


Drive reports as failed when attempting to assemble a RAID array created on another machine

Question: I'm working on a script to automate the process of creating a RAID array and am currently trying to figure out how to get multiple machines to recognize the array so the data can be transferred after collection.
The ultimate goal is to use a set of 5 SATA drives in a RAID 5 array, but I'm currently doing the proof of concept using 3 USB drives. I think I'm missing something in the process when stopping the RAID array on the original machine before attempting to assemble it on the other one. I copied the entries for the array from /etc/fstab and /etc/mdadm.conf from the original machine to the other one (I'm not sure if this was necessary... I'm assuming I could do it without this, just with a longer --assemble command). I had to change the /dev location because a /dev/md0 already existed on the second system, but otherwise made no other changes. However, upon assembling it on the second machine, only two of the 3 drives reported as active, and the third drive was ignored because it reported one of the other drives as failed. When using --examine, the array state information is as follows:
/dev/sdd - Array State: AA.
/dev/sde - Array State: AA.
/dev/sdf - Array State: ..A

The /dev/sdf drive is the one that is being ignored. So it looks like the first two drives report sdf as missing, but sdf thinks the other two are missing.
To stop the array on the first system, I simply unmounted the RAID location, then --failed and --removed the drives and --stopped the RAID. Is there something else I forgot to do? Or is this confusion caused by my manually copying over the RAID config info? Or something else?
Answer: Don't --fail the drives out, and don't --remove them.  Typically the only times you manually fail drives out of an array are when the drive is actually toast, or if you need to reclaim the drive for another purpose.
You should be able to follow your procedure, but skip failing and removing the drives.
When you fail a drive out of an array, the other array members say "that drive is no longer part of this array".  You can't assemble with it. You have to re-add it once the array has been assembled.  That's why you see "AA." on two of the drives.  It looks like the metadata gets flushed out to the drive you failed out too, as he thinks he's not in the array either.  When you tried to --fail the second drive out, it would have created an array that didn't function, so it didn't write the metadata out.
So you should, on the first system:

unmount the filesystem that you created on the array on the first machine.
mdadm --stop the array on the first machine.
Since they're USB drives, you should eject them.

Then move them to the second machine and do an mdadm --assemble /dev/mdX /dev/sdX /dev/sdY /dev/sdZ.
Comment: Ah. I thought I had to `fail` and `remove` the drives so that they wouldn't be in use by the array so I could stop the array. What do you mean by "eject"? I unmount the array, so they aren't mounted, and then I `sync`. The target systems are Scientific Linux (RHEL 6.4). I'll give this a try. Thanks!
Comment: That did the trick for the most part, but when attempting to assemble it on the second system, `mdadm` says all the devices in the array are busy. I've run into this a number of times throughout the project... what's causing it?
Comment: After some further investigation, I apparently had another array with a different name take over those resources even though it wasn't in my `mdadm.conf` file. Only found it by looking at `blkid`.
Comment: If the drives are connected via USB, the old `eject` command is like the "Safely remove this device" drop down menu on Windows.  It ensures that dirty blocks are flushed out to the device before acting like it's going away.  You *probably* don't need that, as stopping the array should have synced the blocks, but, still...


Best way to compare several cases to a null model

Question: At the moment I am doing analysis in some data that is (currently) divided by number of individuals in a group. More or less like:
Groups w/ two individuals: Value_1, Value_2, ..., Value_N
Groups w/ three individuals: Value_1, Value_2, ..., Value_M
In this case there were N groups of 2 individuals and M groups of 3 individuals. And so on until groups of about 300 individuals. Basically, I have different amount of data for each group size. For example:
N (and M) is the number of groups with 2 (or 3 in the case of M) individuals which the value was measured. If we had 50 individuals in the groups of size 2, N=25. And so on for all groups sizes.
I am trying to compare these experimental results with simulations I've ran as a null model. Currently, I run my simulation for each different group size then do a t-test for the means.
However, I am left wondering: Is there any better/more interesting way to test how the experimental data differs from my null model/simulation instead of doing individual t-tests for each group size? Is there a way to aggregate all these tests into just one thing?
The whole thing is a bit of a complex biological system. My simulation is what would happen if the system itself behaved in a certain (super simple, totally trivial manner) way. I'm trying to show that the experimental data is different enough from this trivial behaviour (that is, the individuals actually follow some specific behaviour and do not just do randomly uniform actions).
Comment: How will you control your type 1 error rate if you are doing that many T tests?
Comment: Well, thats another good reason for posting here before actually doing it!
Answer: It sounds as if you'd want to compare multiple means at the same time. Perhaps a straight forward ANOVA would do the trick with an F-test to see if all means (including the null group one) are the same. If you indeed reject the Null hypothesis of equal means across all groups you can then do post-hoc t-tests with an appropriate correction for multiple comparisons.


How do I use curl in a cron job?

Question: I need to set up a cron job in cpanel that calls a URL (on the same server) once a week. I was going to use wget but it turns out this is disabled on the shared server being used.
Is there an alternative to wget? I've heard that curl can be used but I don't know how to set that up in a cron command.
Also, what's the command to make the cronjob do nothing on completion?
Any ideas greatly appreciated!
Comment: What would the wget do if you could use it ?
Comment: Why would they allow curl in case they have disabled wget?
Comment: @Iain - it's needed to process a PHP script
Comment: @Andol - very good question. that's just how it is
Answer: instead of using wget, curl works like this:
curl --silent http://domain.com/cron.php

which will work in the same way as wget. if its a php file you are launching, is there any reason you cant run it via the command line php interpreter like so:
php -q /path/to/cron.php

same on a webserver request and often will work much faster and without certain timeout restrictions present when called via webserver/curl
Comment: Also, calling the php script from the command line might not necessarily yield the same result. In addition to the possibility of different configuration there is also the not uncommon scenario of the script being run as a different user that way. It alls depends on the setup.
Comment: The first command sends all output to /dev/null, the second will create a file called `-url` in the home directory of the user running the script, which contains the output of your php file, all other output goes to /dev/null.
Comment: Calling curl that way will print the result to stdout. If you want to behave equivalent to wget, and save the output to a file name based on the url, you also want to add the --remote-name flag.
Comment: does the --silent mean that there's no response or output?
Comment: Well, I got it to work using "curl --silent http://domain.com/script.php >/dev/null 2>&1"

but it also works fine with "curl -o --url http://domain.com/script.php >/dev/null 2>&1"

what's the difference?
Comment: from CLI things run much faster bypassing web server but note that in most cases it will run as root rather than your www user, it might cause some problems like creating files with wrong permissions or so.
Answer: If curl is available you could try something like
1 1 * * 0  /usr/bin/curl --silent http://example.come/some.php &>/dev/null

That should cause curl to be completely silent so you don't get any email from it on completion.
Comment: I would recommend using the option --show-error too, so it is silent for normal operation but will yield an error if it happens.
Answer: I'd suggest to add "-m" parameter in addition to --silent as this parameter sets the maximum time allowed for the transfer. Imagine you call the cron every minute and the script takes 2mins - this can have bad impact on the server load or other things.
1 1 * * 0  /usr/bin/curl -m 120 -s http://example.come/some.php &>/dev/null

How do I use curl in a cron job?


Why doesn't Mertens's second theorem prove the Prime Number Theorem?

Question: Mertens's second theorem states that $$\sum_{p \le x} \frac 1p = \log \log x+O(1).$$ Defining $p_x=p_{\lfloor x \rfloor}$ for all real $x \ge 1$, we can replace the sum by the integral $$\int_1^x \frac 1{p_t} \; dt=\log \log x+O(1)$$ and thus $\frac 1{p_x}$ is on the order of $\frac d{dx} \log \log x=\frac 1{x \log x}$, which simplifies to the prime number theorem. This is clearly not a valid proof, but why not? I suspect that it's in the step from the integral to the expression for $\frac 1{p_x}$, but I don't see why that isn't valid.
Comment: Related (on MathOverflow): [Why could Mertens not prove the prime number theorem?](https://mathoverflow.net/questions/95743/why-could-mertens-not-prove-the-prime-number-theorem)
Answer: The prime number theorem, as proved by de la Vallée-Poussin, states that
\[\pi(x) = \sum_{p \leq x} 1 = \mathrm{Li}(x) + O\left(xe^{-a\sqrt{\log x}}\right),\]
where
\[\mathrm{Li}(x) = \int_2^x \frac{dt}{\log t} \sim \frac{x}{\log x}.\]
Mertens' second theorem is sometimes stated as
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + o(1),\]
but the result that Mertens proved is actually slightly stronger, namely that there exists a constant $M$, the Meissel-Mertens constant, such that
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + O\left(\frac{1}{\log x}\right).\]
To get from $\sum_{p \leq x} \frac{1}{p}$ to $\sum_{p \leq x} 1$, one uses partial summation, which is the rigorous way of a replacing a sum by an integral. This states that if $c_n$ is a series of complex numbers and $f(n)$ is a differentiable function, then
\[\sum_{n \leq x} c_n f(n) = C(x) f(x) - \int_{1}^{x} C(t) f'(t) \, dt,\]
where
\[C(x) = \sum_{n \leq x} c_n.\]
So if $c_n = 1/p$ if $n = p$ is a prime and $0$ otherwise, and if $f(n) = n$, then this gives
\[\sum_{p \leq x} 1 = x \sum_{p \leq x} \frac{1}{p} - \int_{e^2}^{x} \left(\sum_{p \leq t} \frac{1}{p}\right) \, dt + O(1).\]
Here I've changed the endpoints on the integral on the right-hand side, which leads to a change by a constant. Using Mertens' second theorem shows that the integral on the right-hand side is
\[\int_{e^2}^{x} \left(\sum_{p \leq t} \frac{1}{p}\right) \, dt = \int_{e^2}^{x} \log \log t \, dt + \int_{e^2}^{x} M \, dx + O\left(\int_{e^2}^{x} \frac{dt}{\log t}\right).\]
Using integration by parts, one can show that
\[\int \log \log x \, dx = x \log \log x - \mathrm{Li}(x) + C,\]
and so combining everything, we get
\[\sum_{p \leq x} 1 = x \left(\sum_{p \leq x} \frac{1}{x} - \log \log x - M\right) + O(\mathrm{Li}(x)) = O\left(\frac{x}{\log x}\right)\]
where the last step follows by Mertens' second theorem again. So we just fall short of the prime number theorem. Indeed, if we had the slightly stronger statement that
\[\sum_{p \leq x}\frac{1}{p} = \log \log x + M + o\left(\frac{1}{\log x}\right),\]
then we can use partial summation to prove the prime number theorem.
Comment: There's a couple of things wrong with the method in question. The main bit is the statement that "and thus $1/p_x$ is on the order of $1/\log x$". This is a heuristic connection that you've made, but it doesn't mean anything. $p_x$ is a piece-wise continuous function that has derivative $0$ almost everywhere, whereas $\log\log x$ is analytic. So differentiating the left-hand side gives $0$ almost everywhere, whereas $\log \log x$ has derivative $1/x\log x$. The key problem is that the big-oh term is not preserved by differentiation.
Comment: @Edi, this is analytic number theory. Try Apostol's textbook.
Comment: Gotcha, accepting answer. What if we were to somehow smooth $p_x$ to make it differentiable, though?
Comment: @Edi, see Theorem 2.7 of Montgomery and Vaughan's book.
Comment: Upvoting for good explanation of the ideas involved and why summation by parts is insufficiently powerful, but $why$ doesn't the prime number theorem follow by the method in the question?
Comment: Then you would basically have to use partial summation to get it to look like the prime number theorem!
Comment: Hi Peter, I have two questions. I would truly appreciate it if you please help me. What area of maths is it required to learn to reach to a level of understanding your answer? (I've read only advanced calculus by Fitzpatrick but I love to learn more). And, what area of maths is the first formula in https://en.wikipedia.org/wiki/Meissel%E2%80%93Mertens_constant related and where can I find a simple proof for that?
Comment: Thank you very much. I looked at Apostol's textbook and I think it cover my first question! But it doesn't have the formula for meissel mertens constant in wiki. Where can I study it? the book "gamma exploring euler's constant" talked about it but didn't prove since it should be harder than the text.
Comment: Thank you so much :)) You helped a lot. I posted the questions in http://math.stackexchange.com/questions/1740608/what-prerequisite-knowledge-are-required-to-learn-on-meissel-mertens-constant-re but no answer (so I'm goin' to delete it today).


Is there a way to specify which NetworkInterface .net will use?

Question: I would like to run a series of tests on a device using its Wifi and LAN connections.  I have two network interface cards, one is WiFi, the other is wired.  The device has a single IP address that is accessible through both Network Interfaces.  Is there a way to guarantee that my machine is using a particular Network Interface so that I can run all tests through the wired connection, and then run all tests through the Wifi connection?
Keep in mind, both connections share the same subnet, so either will successfully connect to the device.  I just want to be able to switch back and forth and specify which connection I'm using at any given time.
I'm using HttpClient on .net with C#.  Is there a way to force HttpClient to use a particular Network Interface?  It seems to automatically choose one based on IP Address, but in this case, there are 2 Network Interfaces that can work.  I need to be able to programatically switch back and forth to run my automated tests.
I have noticed something called an 'Interface Metric' that can be changed manually via IP4 Properties Advanced TCP/IP Settings.  Will the smaller numbered interface be used every time?  Is there a way to change this value programatically?
MORE CLARIFICATION:  The reason I didn't directly jump to Disabling the WiFi NIC or the Wired NIC back and forth was when you disable the WiFi NIC, you disconnect the device it was connected to and it doesn't automatically reconnect when you enable it.  (even when you say 'connect automatically' it doesn't connect when re-enabled).  However, I found a quick solution.  Set the Interface Metric on the Wired NIC to be lower than the Interface Metric on the WiFi NIC.  Then, just enable and disable the Wired NIC.  When disabled, the WiFi NIC will be used by the system.  When enabled, the Wired NIC will be used by the system because its Interface Metric is set lower.  Now, I just need to figure out how to programatically enable/disable the Wired NIC...
Comment: I'm curious as to why you have this set up that way? Just disable the wireless when you test the wired and vice-versa. Really though I'm not sure why you'd have a single IP for two network interfaces unless you have some kind of bridging adapter installed, at which point it is supposed to be transparent to the client applications as to which one is being used...
Comment: Just to be clear, you are asking how to force *outgoing* traffic to use either NIC1 or NIC2 - you are not talking about *incoming* traffic?
Comment: Just outgoing traffic, I don't care about incoming traffic
Comment: It's for an automated test.  I need to have it run both flavors of the test without user intervention.  I want to be able to have it run by itself for days switching back and forth between adapters without losing connection.  This isn't normal usage, just so the test will exercise both connections.
Comment: https://stackoverflow.com/questions/172875/how-to-disable-enable-network-connection-in-c-sharp
Answer: One way would be to update your route table to force traffic for a particular IP onto a particular NIC. The route table is what is used to decide which NIC to send traffic out on.
You could do this in a couple of ways:
1) Use P/Invoke to update the route table with C# code (see here for a good example, but basically you are calling CreateIpForwardEntry).
2) Use Process.Start to call route.exe, e.g.
route.exe ADD destination_network MASK subnet_mask  gateway_ip metric_cost

and
route.exe CHANGE destination_network MASK subnet_mask  gateway_ip metric_cost

Answer: You can use the library WlanAPI.cs
static public void Connect_to_wifi(string ssid)
            {
                WlanClient client = new WlanClient();
                foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
                {
                    // Lists all networks with WEP security
                    //Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
                    //foreach (Wlan.WlanAvailableNetwork network in networks)
                    //{
                    //    if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP)
                    //    {
                    //        Console.WriteLine("Found WEP network with SSID {0}.", network.profileName);
                    //    }
                    //}

                    // Retrieves XML configurations of existing profiles.
                    // This can assist you in constructing your own XML configuration
                    // (that is, it will give you an example to follow).
                    foreach (Wlan.WlanProfileInfo profileInfo in wlanIface.GetProfiles())
                    {
                        if (profileInfo.profileName == ssid)
                        {
                            wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, wlanIface.GetProfileXml(profileInfo.profileName), true);
                            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileInfo.profileName);
                            break;
                        }
                    }
                }
            }

Answer: Best way is to use WinSock bind: TCP/IP connection on a specific interface
But once you have single IP for bith NICs then:
Disable NIC from PowerShell: https://learn.microsoft.com/en-us/powershell/module/netadapter/disable-netadapter?view=win10-ps
Calling PowerShell from c#: https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/
Answer: I ended up solving this by setting the Interface Metric on the wired NIC to be lower than the Interface Metric on the Wifi NIC.  In this way, I was able to simply disable and enable the Wired NIC which would effectively change which NIC was being used at any time during the test.  To Disable the NIC, I use the netsh.exe command with the following code.  The 'command' was either 'enable' or 'disable' depending if I was turning it on or off:
        System.Diagnostics.Process p = new System.Diagnostics.Process
        {
            StartInfo =
            {
                FileName = "netsh.exe",
                Arguments = $"interface set interface \"{nicName}\" {command}",
                UseShellExecute = false,
                RedirectStandardOutput = true
            }
        };

        bool started = p.Start();


Simple way to add an additional octave in Musescore?

Question: I wrote an arrangement in Musescore, and I got complaints that some (most) notes on a particular instrument were too high for a beginner. So now I want to add an additional lower octave for each note. I can do this manually, but that's very tedious. Is there an easy way to do this?
I know about those 8va-lines that changes the octave, but that's not an option.
Answer: There is, thankfully! This answer assumes MuseScore 2 or higher. (It may also work on MuseScore 1, but I can't verify that.)

Find the group of pitches where you want to add the optional lower octave.
Select the entire group of pitches by clicking on the first pitch and Shift+Click-ing on the final pitch; the group of pitches should now be boxed in blue.
From the menu, select Notes, then Add Interval, then Octave Below.
Comment: Perfect! Exactly what I wanted. But I must confess that I feel a bit embarrassed that I have not seen that before. Afterall, I use Transpose, which is in the same menu, quite a lot.
Answer: I agree with Richard's way, but there is another way. I myself very often do this, be it for orchestration or to add an octave variation to a theme. Here is what I do to add an octave below an existing melody or bass line:

Click first note and Shift + Click last note of desired selection, rests at the end of the selection don't need to be in there because they won't be affected by the octave change
Ctrl + Down arrow, This lowers the existing music by an octave, so you get your lower octave for free. But now you need back the upper octave
Alt + 8, This adds an octave interval above the notes in the selection, giving you back your upper octave

And there you have it, an upper and lower octave in 3 steps with minimal clicking.


How to find chromatic number of graph in R?

Question: I have the adjacency matrix of the graph (graph theory). First of all, I want to get the chromatic number of this graph (the smallest number of colors needed to color the vertices of a graph so that no two adjacent vertices share the same color). Then I want to get colors (like groups: from 1 to 4 maximum) of the vertices. Is it possible to get it in R using the igraph package? Thanks a lot.
Comment: @G5W This is absolutely not true. IGraph/M, igraph's Mathematica interface, [contains a very competitive method for computing the chromatic number](http://szhorvat.net/mathematica/IGDocumentation/#graph-colouring).  There are several other packages, such as Sage or Maple, that have such functionality.  Some day I'll port over the implementation I wrote for IGraph/M to igraph's C core, to make it available in other interfaces, such as R. It's not a trivial amount of work though.
Comment: Basically all competitive implementations make use either of a SAT solver or an ILP solver. I used the former for IGraph/M.
Comment: igraph package v.1.3 include the vertex_greedy_coloring() function
Answer: You can use the greedy_vertex_coloring() function to estimate the chromatic number.
<code>library(igraph)
set.seed(44)
n = 8
m <- t(matrix(c(
0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,
1,0,0,1,1,0,0,0,
0,0,1,0,0,1,1,0,
0,1,1,0,0,0,0,0,
0,0,0,0,0,0,0,0,
1,1,0,0,1,0,0,1,
0,1,0,0,0,1,0,0),ncol=n))
g1 <- graph_from_adjacency_matrix(m, weighted=TRUE, mode="directed")
ch_number <- max(greedy_vertex_coloring(g1))
</code>


how to background pic zoom animate without affecting the elements inside

Question: I am trying to zoom in to the background but the elements inside the div get affected by it. I tried using this part with transform scale but the elements get zoomed in with the bg zoom in
.img-background {
  background-image: url(./img.jpg);
  height: 100vh;
  width: 100vw;
  background-repeat: no-repeat;
  position: relative;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  background-position: 48% 10%;
  }

.bg-img-animate {
  animation-name: bg-animate;
  animation-duration: 3s;
  animation-iteration-count: 1;

  animation-fill-mode: forwards;
  -webkit-animation-fill-mode: forwards;
}

@keyframes bg-animate {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(2);
  }
}

js

text

Comment: Can you post a minimum working example via snippet? There are a couple of ideas I have, but I would have to see the code to know which would be better for your application. :)
Answer: Instead of having a background image on an element, place the img element inside the element whose background you want to set as an image. Scale the image instead of the container element. Set position of other child elements as absolute so they are placed over the image

.container {
  width: 300px;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 50px auto;
  position: relative;
  overflow: hidden;
}

.container img {
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
}

.container img:hover {
  transform: scale(1.2);
}

.container div {
  position: absolute;
  border: 2px solid #fff;
  padding: 15px;
  background: #eee;
  height: 100px;
  width: 100px;
  text-align: center;
  line-height: 100px;
}

      Hello World


How to add data to a message type custom field that's inherited by all message instances?

Question: I'm using the Message module, and I have some message types. Each message type needs to have a node reference field on it whose value would not change for the entire message type. But different values per message type.
Right now I can create a new message type with a field on it, but the instances of messages are generated programmatically on demand as sent.
What I ultimately need to do is generate a token based on the value of this field.
So how would I go about creating a value that would be inherited by all instances of a message type? Ideas?
Any advice useful. Sort of don't know what functions would be useful here and the docs really don't address this use case.
Answer: I didn't actually figure this out. I probably could have by looking at the way commerce orders get attached via entity reference to messages and done that. Instead, I used the commerce order that was attached to the message, which had the commerce store ID, to load the field on the organic group that was referencing the store and then add that field as a token.


Issues with XML Data source

Question: I have to use an XML as a data source in my report.
My xml has multiple child tags with the same name(ex. author). Please refer the XML pasted below.
<BookStore>
<Book>
<title>History</title>
<author>Tom</author>
<copies>10;</copies>
<price>80</price>
</Book>

<Book>
<title>Basic Mathematics</title>
<author>Roy</author>
<author>Jon</author>
<copies>5</copies>
<price>100</price>
</Book>

<Book>
<title>Java</title>
<author>Harry</author>
<author>Potter</author>
<copies>6</copies>
<price>100</price>
</Book>
</BookStore>

I have added a XML data source and a dataset in my report. I have made the following mappings in my XML dataset.
Row mapping: /BookStore/Book and
Column Mapping: Mapped all the child tags
In the data set, I am getting three records, one for each of the  tag. But, the author column contains the value of only the first tag.For example, the second record contains only "Roy". The second author tag is not being recognised by the BIRT. I need to get both "Roy" & "Jon" from the second Book
element. And, I need  to get both "Harry" & "Potter" from the third Book element. Can you please let me know how to get all the values from tags with the same name into the dataset.
Appreciate your help. Please let me know how to design the XML dataset.
Answer: In your data set you could make multiple columns such as author[1], author[2], author[3]. Then you could make a computed column that concatenates those columns together.
I do not think that XPath functions are supported in BIRT reports.
Answer: public class ExportPDF {

    public static void main(String[] args) throws JRException {
        String sourceFileName = "E:/ireport/issueVoucher.jasper";

        String printFileName = null;

        JRXmlDataSource beanColDataSource = new JRXmlDataSource("E:/ireport/dbsource.xml","/root/data");

        Map<String, Object> parameters = new HashMap<String,Object>();
        parameters.put("reqNo", "33434");
        parameters.put("requestorName", "Shaan");
        parameters.put("empCode", "E03030");
        parameters.put("voucherNo", "E03030");
        parameters.put("issueDate", "E03030");
        parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, beanColDataSource);

        try {
            printFileName = JasperFillManager.fillReportToFile(sourceFileName, parameters, beanColDataSource);
            if (printFileName != null) {
                JasperExportManager.exportReportToPdfFile(printFileName, "E:/sample_report.pdf");

                JRXlsExporter exporter = new JRXlsExporter();
                exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, printFileName);
                exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "E:/sample_report.xls");

                exporter.exportReport();
                System.out.println("done!!!!!!!!!!!!!!!!");
            }
        }catch (JRException e) {
            e.printStackTrace();
        }
    }
}

Comment: JRXmlDataSource beanColDataSource = new JRXmlDataSource("E:/ireport/dbsource.xml","/root/data");
Answer: You asked for help to know how to design your XML dataset, I would rename the author tag to authorFirstName and authorLastName so that there is no confusion on Birt's end.

Issues with XML Data source


IE9+ don't like media-query css

Question: Sorry, if this is already solved somewhere in this community, but couldn't find proper solution to this, thus far. I have wrote a html/css for http://www.smartmarine.ee, that works fine in every browser, except IE9+ (no surprise here).
As the css is written in mobile-first approach, then media-query's are used for desktop version, but not implemented by IE9+ (currently no particular need to work in older IE versions). IE9+ seems to read only the first css styling and ignoring everything that comes with media'querys.
I've tried:

changed measurements in media querys to "px"
added "meta" tag to html "<meta http-equiv="X-UA-Compatible" content="IE=edge">"
tried also with "meta" tag "<meta http-equiv="X-UA-Compatible" content="IE9">"
used "@media all and (min-width:0\0) {}" in css

When I tested it in IE9 and IE10, I always closed the browser and deleted all the history, to insure that the browser is not stuck with some old data.
I am been stuck with this over a week now and would be thankful to get some solutions to this. It feels to be something simple, that I am missing, but then again ...
I would not copy the html, nor css, here, as it would make this question unnecessarily long, but if you feel I should do it, then let me know.
The site is: http://www.smartmarine.ee
Thank you all in advance!
Answer: IE doesn't seem to recognize any of your backgrounds as well.
I think you need to revise your paths.
I saved the files from different browsers (Chrome and IE), and I've got different folder names with different CSS file names. Also saved one of my websites that work fine and both browsers saved same files, same folders.
Comment: Strange. I have the html and css on root level, where locates also the "imgs" folder for any images.

IE though reads the core (mobile-first, before media-query's) part of css and finds the images, but seems to refuse to apply the media-query styling rules, that should be applied when the viewport widens.

IE9+ don't like media-query css


Easily add term to vocabulary with long list of terms

Question: A client is complaining about the way on how to add terms to a vocabulary in taxonomy.
It's a long list of terms and sub-terms. So I told him when he adds a term he can select a Parent term and set the weight in the Relations block.
But the list of parent terms is long and not very clear. Isn't there a way to make this more user friendly? Maybe search in parent terms or .. ?
Answer: For better UI management of taxonomy terms try Taxonomy Manager
<code>This module provides a powerful interface for managing taxonomies. A vocabulary gets displayed in a dynamic tree view, where parent terms can be expanded to list their nested child terms or can be collapsed.

The Taxonomy Manager has following operations and key features:

 - dynamic treeview
 - mass deleting
 - mass adding of new terms
 - moving of terms in hierarchies
 - merging of terms (using the Term merge module in 7.x)
 - fast weight changing with up and down arrows (and AJAX saving)
 - AJAX powered term editing form
 - simple search interface
 - CSV Export of terms
 - i18n support for multilingual vocabularies (per language terms)
 - Double Tree interface for moving terms in hierarchies, adding new
   translations and switching terms between different vocabularies
</code>
Answer: The way the default terms are added to a vocabulary is not so nice indeed, and we get to hear this kind of complaints often.
But, there is a module which is made exactly for this purpose :)
Check Taxonomy CSV import/export.

This module allows you to import or export taxonomy from or to a CSV (comma-separated values) file or with a copy-and-paste text.
It helps you to quick import a non-standardized vocabulary, for example an old thesaurus, a hierarchical taxonomy or a simple list of children, synonyms, descriptions, weights or related terms to terms. It can be used as a module or as an API with a plug-in mechanism. It can manage internationalized vocabularies with i18n_taxonomy, a submodule of i18n module [Drupal 7 only].

After that you just have to train the client on how to import the terms. The terms can be added in a single configuration textarea and can be comma separated.


if a song is writting in one tuning on guitar can it be then translated into standard tuning

Question: If a song is played in C G C F A D tuning on guitar. Can it be then translated into standard tuning. Can you extract standard tuning chords for a song played in C G C F A D ?
I hope my question is clear.
Comment: Yes, probably. But if the song really *features* the three lowest strings - lots of barre or harmonics - it would be hard to reproduce on a normally-tuned guitar. And the timbre will be different, of course. But if they're 'normal' chords, not avant-garde or dissonant ones, yes, they translate fine.
Comment: You can play a song in any tuning and *translate* it in standard tuning and vice-versa. You just have to know what notes there are.
Answer: Every chord needs to use notes from that chord. In standard tuning, chord shapes are what they are due to that tuning.
In the alternative tuning you quote, every chord shape will be different from those in standard tuning. The shapes will be different and sometimes that will mean the voicings will also be different.
However, the intervals between the top five strings is the same in both tunings. So, yes any chord shapes using only the top five strings are interchangeable. Problem comes concerning the fat 'E'string.
And to keep at the same pitch for the rest in the drop tuning, , a capo on fret 2 will solve that. Or put it on fret 10 on the standard - not a good solution!
Comment: @OldBrixtonian - of course, that was a typo... Thanks!
Answer: You play the same chords and notes in any tuning.  You just finger them differently.   Some licks that rely on open strings in the alternative tuning may not translate well.  The reason for the alternative tuning was doubtless to facilitate such licks.  But the SONG will transfer.
Comment: You may be able to play the same note *names* in any tuning, but the *voicings* may well be different. Any *song* will transfer, but there are reasons why specific guitar driven songs only sound 'right' in one particular key.
Answer: Not only can you "extract standard tuning chords" from your chords but you can play the exact same ones!  I think there may be different uses of the term chord.  There is the "shape" which will be different in different tunings and then there is the order of the notes which is the same.  There isn't much that cannot be played in standard tuning but the hand may have to work really hard to get it.  This is, in part, why other tunings are used.


Sqlite Android, 2 apps acessando um banco de dados

Question: Como faço para que 2 aplicações utilizem o mesmo banco de dados?
Se crio o banco em um app o outro não acessa esse banco, então como fazer esse 2º app acessar esse mesmo banco?
Comment: Veja [Provedores de conteúdo(Content providers)](https://developer.android.com/guide/topics/providers/content-providers.html)
Answer: Não sei se entendi bem sua pergunta, mas, se você criou o banco num smartphone, outro provavelmente não terá acesso. O que deve fazer nesse caso é criar um serviço na web com um banco na nuvem onde os apps independente de em que smartphone esteja, possa acessar. Entende?
Se é necessário ter bancos de dados nos smartphones, certifique-se se é necessário sincronizar com o banco na nuvem, via serviço (API, Web servisse, etc).
Comment: Mas eu teria que fazer um banco nuvem se quisesse acessar um banco em 1 smartphone porém em duas aplicações? Exemplo : uma aplicação de registro de dados e outra com a consulta desses dados
Comment: O mesmo banco e acessado. Porém via api.


Algorithms for automatic model selection

Question: I would like to implement an algorithm for automatic model selection.
I am thinking of doing stepwise regression but anything will do (it has to be based on linear regressions though).
My problem is that I am unable to find a methodology, or an open source implementation (I am woking in java). The methodology I have in mind would be something like:

calculate the correlation matrix of all the factors
pick the factors that have a low correlation to each other
remove the factors that have a low t-stat
add other factors (still based on the low correlation factor found in 2.).
reiterate several times until some criterion (e.g AIC) is over a certain threshold or cannot or we can't find a larger value.

I realize there is an R implementation for this (stepAIC), but I find the code quite hard to understand. Also I have not been able to find articles describing the stepwise regression.
Comment: Frankly, I think this is a *disastrous* idea, just about guaranteed to lead to many false conclusions.
Comment: *All* model selection procedures are subject to the problems that I discuss in my answer below. In addition, the larger the number of possible factors you want to search over, the more extreme those problems become, and the increase is not linear. While there are some better approaches (discussed by @Zach), which should be used in conjunction with cross-validation (discussed by @JackTanner), selecting based on t, r and AIC are not among them. Moreover, with hundreds of factors the amount of data needed could easily be in the millions. Unfortunately, you have a *very* difficult task before you.
Comment: Interesting views here, but I think the negative view towards algorithmic model selection procedures is a bit dated. Take, for instance, the recent work by David Hendry in the field of econometrics, particularly his work on the PcGive software and saturation methods. A lecture providing an overview of his approach can be found [here](https://www.youtube.com/watch?v=2zzI2fN1ebc). As @MichaelChernick has pointed out (and Hendry would do, too!), subject matter knowledge is (vastly) important. This is why there's value in subject specialists - to let the algorithms act alone is the mistake.
Comment: What is the purpose of doing model selection? Is it for a predictive/forecasting model or are you looking for the important variables?  Also how big is the data set you are using - how many obsevations and how many variables?
Comment: @gung: while I agree that blindly following the result of a model selection is a bad idea, I think it can be useful as a starting point of an analysis. In my case I have several hundreds of factors available, and I would like to pick the 5-10 most relevant. I don't see how I could do that without automatic model selection (which will later be manually amended).
Comment: I always say beware of automatic algorithms.  It always helps to include subject matter knowledge.  Stepwise procedures have problems.  I twould pay for you to read one of the many books available on model selection.
Comment: What about bootStepAIC Package in R?
Answer: I think this approach is mistaken, but perhaps it will be more helpful if I explain why.  Wanting to know the best model given some information about a large number of variables is quite understandable.  Moreover, it is a situation in which people seem to find themselves regularly.  In addition, many textbooks (and courses) on regression cover stepwise selection methods, which implies that they must be legitimate.  Unfortunately, however, they are not, and the pairing of this situation and goal is quite difficult to successfully navigate.  The following is a list of problems with automated stepwise model selection procedures (attributed to Frank Harrell, and copied from here):

It yields R-squared values that are badly biased to be high.

The F and chi-squared tests quoted next to each variable on the  printout do not have the claimed distribution.

The method yields confidence intervals for effects and predicted values that are falsely narrow; see Altman and Andersen (1989).

It yields p-values that do not have the proper meaning, and the proper correction for them is a difficult problem.

It gives biased regression coefficients that need shrinkage (the coefficients for remaining variables are too large; see Tibshirani
[1996]).

It has severe problems in the presence of collinearity.

It is based on methods (e.g., F tests for nested models) that were intended to be used to test prespecified hypotheses.

Increasing the sample size does not help very much; see Derksen and Keselman (1992).

It allows us to not think about the problem.

It uses a lot of paper.

The question is, what's so bad about these procedures / why do these problems occur?  Most people who have taken a basic regression course are familiar with the concept of regression to the mean, so this is what I use to explain these issues.  (Although this may seem off-topic at first, bear with me, I promise it's relevant.)
Imagine a high school track coach on the first day of tryouts.  Thirty kids show up.  These kids have some underlying level of intrinsic ability to which neither the coach nor anyone else, has direct access.  As a result, the coach does the only thing he can do, which is have them all run a 100m dash.  The times are presumably a measure of their intrinsic ability and are taken as such.  However, they are probabilistic; some proportion of how well someone does is based on their actual ability, and some proportion is random.  Imagine that the true situation is the following:
<code>set.seed(59)
intrinsic_ability = runif(30, min=9, max=10)
time = 31 - 2*intrinsic_ability + rnorm(30, mean=0, sd=.5)
</code>
The results of the first race are displayed in the following figure along with the coach's comments to the kids.

Note that partitioning the kids by their race times leaves overlaps on their intrinsic ability--this fact is crucial.  After praising some, and yelling at some others (as coaches tend to do), he has them run again.  Here are the results of the second race with the coach's reactions (simulated from the same model above):

Notice that their intrinsic ability is identical, but the times bounced around relative to the first race.  From the coach's point of view, those he yelled at tended to improve, and those he praised tended to do worse (I adapted this concrete example from the Kahneman quote listed on the wiki page), although actually regression to the mean is a simple mathematical consequence of the fact that the coach is selecting athletes for the team based on a measurement that is partly random.
Now, what does this have to do with automated (e.g., stepwise) model selection techniques?  Developing and confirming a model based on the same dataset is sometimes called data dredging.  Although there is some underlying relationship amongst the variables, and stronger relationships are expected to yield stronger scores (e.g., higher t-statistics), these are random variables, and the realized values contain error.  Thus, when you select variables based on having higher (or lower) realized values, they may be such because of their underlying true value, error, or both.  If you proceed in this manner, you will be as surprised as the coach was after the second race.  This is true whether you select variables based on having high t-statistics, or low intercorrelations.  True, using the AIC is better than using p-values, because it penalizes the model for complexity, but the AIC is itself a random variable (if you run a study several times and fit the same model, the AIC will bounce around just like everything else).  Unfortunately, this is just a problem intrinsic to the epistemic nature of reality itself.
I hope this is helpful.
Comment: Phenomenal explanation of data dredging.
Comment: This is a very well thought out answer, although i completely disagree with the idea that aic is an improvement over p-values (or bic or similar), in the context of linear model selection.  any penalty like aic which is of the form $-2L+kp$ is equivalent to setting the p-value to $Pr(\chi^2_1>k)$ (both entry and exit).  aic basically tells you how to choose the p-value.
Comment: @gung - if you take the difference between two models with one parameter different you get $(-2L_1+2p_0+2)-(-2L_0+2p_0)=-2(L_1-L_0)+2$.  Now the first term is the likelihood ratio statistic upon which the p-value is based.  So we are adding the extra parameter if the likelihood ratio statistic is bigger than some cutoff.  This is the same as what the p-value approach is doing.  There is only a conceptual difference here
Comment: My comment was in regards to using aic for stepwise or similar algorithm.  My comment was also too brief.  Note $p$ is number of variables, $k$ is penalty ($2$ for aic $\log N$ for bic), and $-2L$ is negative twice the maximised log likelihood. Aic and bic are different conceptually but not operationally from p-values when doing "subset" style selection with no shrinkage of the non-zero coefficients.
Comment: for an illustration why AIC does not solve the problem see: Mundry, R. (2011). Issues in information theory-based statistical inference—a commentary from a frequentist's perspective. Behavioral Ecology and Sociobiology, 65(1), 57-68.
Comment: @Benjamin, you are simply picking the biggest coefficients (in absolute value). Realized values will bounce randomly around their true values; by picking only the biggest to keep, you are selecting the ones that are too high.
Comment: @Benjamin, LASSO doesn't 'select' variables in the sense that stepwise selection does; it just shrinks estimates to 0. At some value of lambda, some betas may actually be 0, but all betas will be shrunk in this manner. The selected variables may be similar, but their betas will not be. If you have a lambda a-priori, that's it; alternatively, you could use cross-validation to search over possible values for lambda that optimize the out of sample predictive accuracy. Neither of which are equivalent to stepwise selection.
Comment: @nalzok, not quite. Stepwise is a dominated strategy.  There is basically always a better option.  In addition, the ways to mitigate against it's problems requires a level of sophistication that would make better methods doable. However, if you absolutely have to use poor methods, then there are things you can do to make it less bad, but what exactly you would do would depend on your situation, your data, & your goals.
Comment: Among other things, if you drop a 2nd variable & the 1st becomes significant, it means that the p-value for the 1st is now invalid due to data dredging. I'm glad this helped you. I can take a look at your Q later; if appropriate, you might edit it to reflect what you've learned here & what you still need to know, so that the other Q wouldn't be a duplicate.
Comment: @thistleknot, sure. You can always use this (or whatever) to generate hypotheses & then test them in a new dataset. Likewise, you can partition your dataset first, explore & generate hypotheses in 1 set, & then test in the 2nd. You still need to beware that there is considerable risk of finding nothing for your efforts, though, because stepwise just sent you on a wild goose chase.
Comment: I think it has 2 advantages: deals w/ model-as-a-whole, & equivalence to $P(\chi^2>k)$ is not to a static arbitrary value--the p that minimizes AIC in 1 model isn't necessarily the same p in another model. In other words, there's a rationale for that p in each case that is better founded than just <.05 = good!, >.05 = bad!
Comment: Please edit that information (if appropriate) into your other Q, not as a comment here. In addition, if this answer helped you, you might consider upvoting it. Unfortunately, I don't have time to address this right now, but that is a reasonable question; I'll try to put something together for you later.
Comment: While I understand that the lasso shrinks (and is just soft thresholding in orthogonal case), why is it true that model search inflates coefficients?
Comment: @thistleknot, data dredging has a number of bad effects (see list at top), not just overfitting (albeit my answer focuses on overfitting). Eg, hypothesis tests are invalid. You can do whatever you want in a new sample, though. That can be running another study, or you could 1st partition your data, run stepwise (or do whatever you like) in 1 partition, then fit the model you decided on in the hold out set. How to do this w/ k-fold cross validation is more complicated. There should be existing threads on that on CV. You would never get valid p-values, though.
Comment: @thistleknot, I have no idea what "p-values mean nothing until validated" means. The full answer is (as always) more nuanced, but to a 1st approximation, *stepwise is bad*. There is a tun of published literature to show that (cf, [here](https://stats.stackexchange.com/a/115850/)). I teach graduate level courses, & I teach my students *not* to use stepwise, so I don't know what you have in mind by "in a partitioned setup" that supposedly makes this OK. I can't tell if you're mostly interested in arguing about this, but if you want to understand some aspect further, you could ask a new Q.
Comment: @nalzok, as stepwise model selection is typically done, there are no training / testing / validation sets, just the original dataset. You don't necessarily have the same problems if you nest this within CV, or if you fit your final model on a holdout set.
Comment: @gung Wait a second, you mean stepwise model selection is not inherently wrong, and we discourage them simply because people are doing it wrong (not spliting the dataset)? In other words, it's OK to use stepwise model selection on the training set as long as I use CV?
Comment: I don't understand how "from the coach's point of view, those he yelled at tended to improve, and those he praised tended to do worse". Isn't the second run a new draw from the same distribution of the first run? Did you draw the "second run" again and again until, by chance, the low performers are on average better than what they used to be, and the best performers worse?
Comment: @Geoff, you should ask new questions for this, not buried far down in the comments where no one will ever see it.  Note also that #3 has a citation you can track down and read for yourself.
Comment: @probabilityislogic, thanks for your comment! I'm afraid I don't completely follow you, though. 1st, you disagree AIC>(p or BIC), or (AIC or BIC)>p? 2nd, what I was thinking of was selecting the model-as-a-whole based on AIC is better than selecting individual covariates to include based on their individual p-values calculated by $\beta$/SE (i.e., equivalent to type III SS) <.05 (that is, typical software output), as this method is the one people typically use. Would you still disagree?
Comment: @probabilityislogic, that helps to clarify, and I agree with all that. I didn't mean to suggest that stepwise selection based on AIC is good, only that it's *less bad* than using p-values. I understand what you mean by saying that AIC helps you choose a p-vlaue, but isn't that different (and slightly less bad) than having an arbitrary, fixed $\alpha$ that doesn't take model complexity into account? Are you suggesting there is no difference *whatsoever*?
Comment: So what does leaving out a predictor mean? cutting a predictor usually tend to increase significance of the others. What does it mean when a predictor before largely not significant improves and became significant after removing a not significant one? it means the the second was hiding the first. I'm pretty confused on the topic and I love your examples! Would you mind to take a look at this other my question? http://stats.stackexchange.com/questions/102834/to-step-or-not-to-step-for-model-selection-in-regression
Comment: I'd like to find a good clear question to this answer: when it's appropriate to leave out a predictor. What I don't understand is that if stepping out a variable messes the model, than every model is messed and type 1 error prone in respect of infinite variables never taken in account to begin with! on the other side, to include more and more variables you need more and more observations to have significant result and avoid other problems for example in logistic glm. So the only good model is one made on the whole population with all the possible variables taken in account!I'm clearly confused
Comment: @Gung, thanks for the quick reply!

Oh, I see! It's due to the nature of the stepwise procedure--and isn't a feature of model searching in general. Thanks! I misunderstood to think this might be an alternative reason (besides bias+variance tradeoff) in favor of lasso shrinkage.

In fact, now, I don't see any connection between lasso and these stepwise procedures. The lasso doesn't shrink the model selected by stepwise procedures--the selected variables may be different. (I know that it is related to stagewise via LARS though.) Why is lasso cited?
Comment: Forgive me if this has been naively raised, but if the concern is over training data being dredged... can't you take your hypothesis out of training and validate/test them in the subsequent data partitions to rule out dredges?
Comment: I'm in school for data science at Fullerton so I have a vested interest in getting to the root of the issue for future coding. Isn't data dredging over fitting and isn't over fitting addressed w data partitioning? What about k fold validation? I'm confused how these issues aren't weeded out in validation/testing data. I have a chapter on evaluating model performance using lift charts and propensties. All over fitting issues are related to the training data, its the whole reason we partition data in the first place. DSS trees have methods for evaluating accuracy and impurity for validation
Comment: p-values mean nothing until validated.  This whole thread has a lot of people think stepwise is bad, but the way the question is framed, it seems the OP is trying to figure out how to do something like stepwise on training data (doesn't specify actually) and all these issues seem to be dealing with not partitioning data... which means there is nothing wrong with stepwise if it's applied in a partitioned setup as instructed by graduate level courses ;)~
Comment: "p-values mean nothing until validated" means don't trust a p value for being significant until validated (against validation data)
Comment: I've read that stepwise, forward, and backward have issues, but not in the context of this problem, which seems to be describing overfitting (?) [when done 'correctly' in a partitioned scheme], which is what this answer seems to focus on.  I'm trying to figure out what the proper methods are.  I'm reading graduate level courses too, and I'm finding it odd that there is some miscommunication.  I've asked our dept chair to look into this post
Comment: long story short, RSS (linear only), RMSE (Jack Tanner's answer) is where I'm leaning at.
Comment: I'm reading, "Data Mining for business analytics by Wiley" and there is a chapter on variable selection in Mutiple Linear Regression (ch 6),  iterative methods are criticized for their lack of groupwise selection.  However, the issues raised in this question seem to all be addressable by data partitioning, which is the method proposed in the book.  I'm down for other methods, but I don't see how these issues are relevant to stepwise in a partitioned setup.
Comment: Are you implying "stepwise model selection" and "using train set as test set" are the same concept? It appears to me that the coach example is only attacking the later.
Comment: @gung I really hope you elaborate on the issues of stepwise model selection by example. In fact, you have listed the problems by quoting Frank Harrell, but explaining the most serious ones in more detail would make your answer even better. Of course, it's already so good that I can't ask for more :-)
Comment: @robertspierre, you can run the code yourself. *No*, I didn't rerun it until I got what I wanted.  It's [regression to the mean](http://en.wikipedia.org/wiki/Regression_toward_the_mean); that's the phenomenon. People, variables, etc., that look good at 1st will, on average, do worse the 2nd time, & those that did worst typically do better the 2nd time. Beyond my explanation here, it may help you to read the linked wikipedia page. Some of the threads returned by [this search](https://stats.stackexchange.com/search?tab=votes&q=%22regression%20to%20the%20mean%22%20is%3aquestion) might also help.
Comment: But besides choosing the best model we also need to report the p-value of the variables.
There are some libraries which include regularization methods, but many other don't: for example is difficult to find survival models and models with random effects including also regularization.
Comment: Does anyone know why, from the list in the answer, 2, 3, 4 and 7 are true?
Answer: Check out the caret package in R.  It will help you cross-validate step-wise regression models (use <code>method='lmStepAIC'</code> or <code>method='glmStepAIC'</code>), and might help you understand how these sorts of models tend to have poor predictive performance.  Furthermore, you can use the <code>findCorrelation</code> function in caret to identify and eliminate collinear variables, and the <code>rfe</code> function in caret to eliminate variables with a low t-statistic (use <code>rfeControl=rfeControl(functions=lmFuncs)</code>).
However, as mentioned in the previous answers, these methods of variable selection are likely to get you in trouble, particularly if you do them iteratively.  Make absolutely certain you evaluate your performance on a COMPLETELY held-out test set.  Don't even look at the test set until you are happy with your algorithm!
Finally, it might be better (and simpler) to use predictive model with "built-in" feature selection, such as ridge regression, the lasso, or the elastic net.  Specifically, try the <code>method=glmnet</code> argument for caret, and compare the cross-validated accuracy of that model to the <code>method=lmStepAIC</code> argument.  My guess is that the former will give you much higher out-of-sample accuracy, and you don't have to worry about implementing and validating your custom variable selection algorithm.
Comment: @probabilityislogic Do you know of any good implementations of the double pareto penalty, in a language like `r` or `python`?  I'd love to try it out.
Comment: Penalties like the double pareto are better than ridge and lasso from a statistical perspective, as they don't shrink the clearly non-zero coefficients.  But unfortunately, they always lead to a non-convex penalty, so they are worse from a computational perspective.  I would think a penalty based on the Cauchy distribution would be good $\log(\lambda^2+\beta^2)$.
Comment: From what I understand, model selection by AIC and leave-one-out-cross-validation is essentially the same thing (asymptotic equivalence, see [Stone, 1977)](http://www.jstor.org/stable/2984877), so AIC and some types of cross-validation are likely to lead to very similar results. However, I haven't used the caret package, and from the method calls it seems like AIC is indeed used in some cases.
Answer: I fully concur with the problems outlined by @gung. That said, realistically speaking, model selection is a real problem in need of a real solution. Here's something I would use in practice.

Split your data into training, validation, and test sets.
Train models on your training set.
Measure model performance on the validation set using a metric such as prediction RMSE, and choose the model with the lowest prediction error.
Devise new models as necessary, repeat steps 2-3.
Report how well the model performs on the test set.

For an example of the use of this method in the real world, I believe that it was used in the Netflix Prize competition.
Comment: The kind of setting that I testing data splitting on was n=17000 with a fraction of 0.3 having an event, and having about 50 parameters examined or fitted in a binary logistic model.  I used a random 1:1 split. The validated ROC area in the test sample changed substantively when I re-split the data and started over.  Look under Studies of Methods Used in the Text in http://biostat.mc.vanderbilt.edu/rms for simulation studies and related papers giving more information.
Comment: Data splitting is not reliable unless $n>20000$.
Comment: Because of poor precision.  If you split again you can get much different results.  That's why people do 100 repeats of 10-fold cross-validation, or bootstrapping.
Comment: @FrankHarrell What does that n>20000 figure depend on? Is it based on the original poster's comment about having "_several hundreds of factors_"? Or is it independent of any aspect of the data?
Comment: @Frank:  Why do you think N needs to be so high?
Comment: Do you have some more details about the Netflix competition, and how the solution was using this method?
Comment: probably why capstone courses want 20k+ records
Comment: @FrankHarrell updated link to RMS https://hbiostat.org/doc/rms/book/
Comment: The correct current link is https://hbiostat.org/rmsc
Answer: To answer the question, there are several options:

all-subset by AIC/BIC
stepwise by p-value
stepwise by AIC/BIC
regularisation such as LASSO (can be based on either AIC/BIC or CV)
genetic algorithm (GA)
others?
use of non-automatic, theory ("subject matter knowledge") oriented selection

Next question would be which method is better. This paper (doi:10.1016/j.amc.2013.05.016) indicates "all possible regression" gave the same results to their proposed new method and stepwise is worse. A simple GA is between them. This paper (DOI:10.1080/10618600.1998.10474784) compares penalized regression (Bridge, Lasso etc) with "leaps-and-bounds" (seems an exhaustive search algorithm but quicker) and also found "the bridge model agrees with the best model from the subset selection by the leaps and bounds method". This paper (doi:10.1186/1471-2105-15-88) shows GA is better than LASSO. This paper (DOI:10.1198/jcgs.2009.06164) proposed a method - essentially an all-subset (based on BIC) approach but cleverly reduce the computation time. They demonstrate this method is better than LASSO. Interestingly, this paper (DOI: 10.1111/j.1461-0248.2009.01361.x) shows methods (1)-(3) produce similar performance.
So overall the results are mixed but I got an impression that GA seems very good although stepwise may not be too bad and it is quick.
As for 7), the use of non-automatic, theory ("subject matter knowledge") oriented selection. It is time consuming and it is not necessarily better than automatic method. In fact in time-series literature, it is well established that automated method (especially commercial software) outperforms human experts "by a substantial margin" (doi:10.1016/S0169-2070(01)00119-4, page561 e.g. selecting various exponential smoothing and ARIMA models).
Comment: Be aware that you can get differing performance in simulation studies of different selection algorithms by changing the data generating process to favor (even if not intentionally) a particular routine. The issue of what approach will be faster or slower is distinct, but potentially still important.
Comment: In fact the examples in Tibshirani's [original paper on LASSO](http://statweb.stanford.edu/~tibs/lasso.html) illustrate @gung's point well. The same goes for comparative studies of different methods on real data. BTW, is your last reference right? The paper by Clements & Hendry with the DOI you give doesn't make the claim that automated methods out-perform human experts, or use the words "by a substantial margin" at all. (It'd be nice if you gave full references.)
Comment: Found it: Goodrich (2001), "Commercial software in the M3-Competition", Int. J. Forecast., 17, pp 560–565. It's under the same "Commentaries on the M3-Competition" collection as the Clements & Hendry paper, which is why Googling the DOI sent me there.
Comment: @Scortchi it may be more clear on the article starting from page 581 on that issue of journal. It is more related to "M2-Competition" in which, automatic forecasting methods were compared with invited human experts (including some big names in time-series literature) who knew economic/industry context and could even ask for additional information from companies that provided the data.
Comment: Anyway, it's not at all clear that Goodrich's comment has anything to do with *subject-matter* expertise.
Comment: @heran_xp Can you please be more specific to which article you refer? Volume 16, Issue 4 of the International Journal of Forecasting ends on page 540, so there is no article on page 581.
Answer: Here's an answer out of left field- instead of using linear regression, use a regression tree (rpart package). This is suitable for automatic model selection because with a little work you can automate the selection of cp, the parameter used to avoid over-fitting.
Answer: Answers here advises against variable selection, but the problem is real ... and still done. One idea that should be tried out more in practice is blind analyses, as discussed in this nature paper Blind analysis: Hide results to seek the truth.
This idea has been mentioned in another post at this site, Multiple comparison and secondary research.  The idea of blinding data or introducing extra, simulated noise variables have certainly been used in simulation studies to show problems with stepwise, but the idea here is to use it, blinded, in actual data analysis.
Comment: +1 see e.g. the boruta algorithm (for feature selection)
Answer: linear model can be optimised by implementing genetic algorithm in the way of choosing most valuable independant variables. The variables are represented as genes in the algorithm, and the best chromosome (set of genes) are then being selected after crossover, mutation  etc. operators. It is based on natural selection - then best 'generation' may survive, in other words, the algorithm optimises estimation function that depends on the particular model.
Comment: That would select the "best" variables in the *data*, not necessarily the best variables in the data generating process / population, as it only has access to the data. It isn't really that dissimilar from the stepwise method the OP wanted.
Answer: I see my question generated lots of interest and an interesting debate about the validity of the automatic model selection approach. While I agree that taking for granted the result of an automatic selection is risky, it can be used as a starting point. So here is how I implemented it for my particular problem, which is to find the best n factors to explain a given variable

do all the regressions variable vs individual factors
sort the regression by a given criterion (say AIC)
remove the factors that have a low t-stat: they are useless in explaining our variable
with the order given in 2., try to add the factors one by one to the model, and keep them when they improve our criterion. iterate for all the factors.

Again, this is very rough, there may be ways to improve the methodology, but that is my starting point. I am posting this answer hoping it can be useful for someone else. Comments are welcome!
Comment: (1) I haven't witnessed any "debate" in this thread: all replies and comments present the same basic message.  (2) Your implementation appears to be an *ad hoc* version of [stepwise regression](http://en.wikipedia.org/wiki/Stepwise_regression).  I agree that it can be useful as a starting point provided it is not automatically accepted as an end in itself.
Comment: you did actually accept your own answer that moves against every argument brought forward by the community. Not surprising to see the negatives here...
Comment: I believe it's the first time i see so many downvotes. @SAM why don't you just accept some of the other excellent answers and delete your "answer"?
Comment: Is this SE's most downvoted answer ever?
Comment: You seem to have answered @probabilityislogic 's important question by saying your goal "to find the best n factors to explain a given variable."  Model-building to explain (to understand causality) needs to be done more intentionally and usually much more intensively than model-building to predict.


Exchange 2010 Export to PST using just Keywords

Question: I'm trying to Export one of our Mailboxes into a .PST file and having problems finding the right cmdlets. We are trying to export certain keywords of a users mailbox. I've tried using the cmdlet of -ContentFilter {All -like "*Keyword Test*"} without any luck.
This is what I've tried so far, but without any luck.
New-MailboxExportRequest -ContentFilter {All -like "*Keyword Test*"} -Mailbox "Pelton" -Name DPeltonExp -FilePath \ExServer1\Imports\DPelton.pst

I've also tried the other following, but all .PST are empty of any emails.
New-MailboxExportRequest -ContentFilter {All -like "Firstword Secondword"} -Mailbox "Pelton" -Name DPeltonExp -FilePath \ExServer1\Imports\DPelton.pst

New-MailboxExportRequest -ContentFilter {All -eq "Firstword Secondword"} -Mailbox "Pelton" -Name DPeltonExp -FilePath \ExServer1\Imports\DPelton.pst

New-MailboxExportRequest -ContentFilter {All -eq "*Firstword Secondword*"} -Mailbox "Pelton" -Name DPeltonExp -FilePath \ExServer1\Imports\DPelton.pst

Any and all help is appreciated.
Answer: Please try using the Export-Mailbox command rather than New-MailboxExportRequest
Export-Mailbox -Identity <MailboxIdParameter> -TargetMailbox <MailboxIdParameter> -TargetFolder <Target_Folder_Name> -ContentKeywords "<String[]>" -AttachmentFilenames "<String[]>" -StartDate "<Month/Day/Year> <Time>" -RecipientKeywords <String[]>


CL Format recipe: Dealing with nil as a value

Question: I've been looking through formatting recipes , and I can't quite find what I'm looking for...
(format nil CONTROL-STRING day name num-apples)
Suppose I don't want to change the arguments in the above form, just CONTROL-STRING.
day and num-apples will always be non-nil, but name might be nil.
When name is nil, I want the output to look like
"Today is Monday. Hello, you have 3 apples."
but when name is defined, I want it to look like
"Today is Monday. Hello Adam, you have 3 apples."
So the control string needs to look at name, use it in the non-nil case, not use it in the nil case, but consume it in both cases.
Maybe it can be accomplished by consuming nil and printing it as ""? If so I don't know how to do that.
Comment: My original search-fu wasn't good enough. I think this has my answer. http://stackoverflow.com/questions/5729032/lisp-format-directive-that-interprets-nil-argument-to-empty-string-instead-of-n?rq=1
Answer: The question you linked to, Lisp format directive that interprets nil argument to empty string instead of "NIL", does include an answer that shows how you can do this, but doesn't cite any of the documentation.  Since you're generating English text, there are also a few other options that you might want to consider as well.
First, with ~@[consequent~], you can process the consequent format directive just in the case that the argument is non-nil, and the argument to ~@[ isn't consumed, so it's still available. In general,
188.8.131.52 Tilde Left-Bracket: Conditional Expression describes lots of options, but about ~@[ it says:

~@[consequent~] tests the argument. If it is true, then the argument
  is not used up by the ~[ command but remains as the next one to be
  processed, and the one clause consequent is processed. If the arg is
  false, then the argument is used up, and the clause is not processed.
  The clause therefore should normally use exactly one argument, and may
  expect it to be non-nil.

You can use this as follows:
(defun test (day name n-apples)
  (format nil "Today is ~a. Hello~@[ ~a~], you have ~a apples."
          day name n-apples))

CL-USER> (test 'monday 'adam 2)
"Today is MONDAY. Hello ADAM, you have 2 apples."
CL-USER> (test 'tuesday nil 42)
"Today is TUESDAY. Hello, you have 42 apples."

To make this even more robust, you should consider using ~p for pluralization, so that you get "1 apple" and "3 apples".
(defun test (day name n-apples)
  (format nil "Today is ~a. Hello~@[ ~a~], you have ~a apple~:P."
          day name n-apples))

CL-USER> (test 'monday 'john 2)
"Today is MONDAY. Hello JOHN, you have 2 apples."
CL-USER> (test 'tuesday 'john 1)
"Today is TUESDAY. Hello JOHN, you have 1 apple."
CL-USER> (test 'wednesday nil 0)
"Today is WEDNESDAY. Hello, you have 0 apples."

Finally, since you're generating text, you might appreciate some case normalization (e.g., print proper nouns with initial capitals), and writing the numbers in text:
(defun test (day name n-apples)
  (format nil "Today is ~:(~a~). Hello~@[ ~:(~a~)~], you have ~r apple~:P."
          day name n-apples))

CL-USER> (list
          (test 'monday 'adam 4)
          (test 'tuesday 'john 1)
          (test 'wednesday 'mary\ sue 42)
          (test 'thursday 'jim-bob 0))
("Today is Monday. Hello Adam, you have four apples."
 "Today is Tuesday. Hello John, you have one apple."
 "Today is Wednesday. Hello Mary Sue, you have forty-two apples."
 "Today is Thursday. Hello Jim-Bob, you have zero apples.")


Get a list of all open windows from the command line

Question: In Windows 7, is it possible to obtain a list of all open desktop windows from the command line? I know that it's possible to obtain a list of all running processes from the command line, but I want to know if it's possible to obtain a list of open windows as well.
Comment: [This solution](http://stackoverflow.com/questions/191206/how-to-get-list-of-running-applications-using-powershell-or-vbscript) appears similar, but I'm not sure if it does exactly the same thing. Is obtaining a list of all running Windows applications equivalent to obtaining a list of all open windows?
Comment: Here's one possible solution: http://stackoverflow.com/questions/18456091/get-a-list-of-all-open-windows-using-autoit
Comment: there is a solution: https://stackoverflow.com/questions/25771386/get-all-windows-of-a-process-in-powershe
Answer: The "/v" option lists the window names in the last column.  As in "tasklist /v".  You can also pipe it into another application or find to do filtering.
Comment: tasklist /v is super slow
Comment: And `tasklist /v` fails to query many titles, for instance when you have a lot of chrome tabs open, it only lists the title of the chrome tab that is in front.
Answer: Use
tasklist /fi "windowtitle eq <Title of window*>"

For example:
tasklist /fi "windowtitle eq Notepad*"

Comment: Now I wonder if it would be feasible to obtain the list of open windows without knowing the title of each window in advance.
Comment: There should be a eq or ne condition in there as well:

tasklist /fi "windowtitle eq Notepad*"
Comment: I don't need active processes, I need active windows. One process can open few windows. Also this command doesn't work even if only one window is created.
Comment: @Almund - You should have edited the answer to fix that. I've taken care of it.
Answer: WinLister from NirSoft list all windows active on a machine as well as associated information (title, path, handle, class, position, process ID, thread ID, etc.). It has a GUI interface rather than command-line.
Comment: better then is GUIPropView from nirsoft.
Answer: if you just use the following command, it will list all active processes

tasklist

Or filtering by session name would restrict a bit more to get processes started by console:

tasklist /FI "SESSIONNAME eq Console"
Comment: I don't need active processes, I need active windows. One process can open few windows.
Answer: Use powershell. The command is: Get-Process
You can try this:
##Method 1: (Gives you all the processes)
Get-Process

## Method 2: Detailed Info On a specific named Process
$ProcessTerm="chrome"
#Run This:
$FindProcess = Get-Process | Where-Object {$_.MainWindowTitle -like "*$processterm*"}
Get-Process -ID $FindProcess.ID | Select-Object *

# FindProcess.ID will give you the ID of the above process

#Method 3: (if you know the process ID)
$ProcessID = "9068"
$FindProcess = Get-Process | Where-Object {$_.id -eq "$ProcessID"}
Get-Process -ID $FindProcess.Id | Select-Object *

Comment: The question was about windows and not about processes.


Cannot display page in the IE; make by ASP.net

Question: I made a project Asp.net
When Default.aspx files in Windows through Internet Explorer open to error.
As follows:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

A name was started with an invalid character. Error processing resource 'file:///G:/My Programming/Asp/My Project (90)/Defa...

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
-^

Comment: This only happens with IE? Does work fine with other browsers?
Comment: I thing you are trying to run dynamic generated page simply on Ie. is that right. you need to run it from Vs or VWD to run dynamic file properly.
Answer: The root cause of this problem is here:
file:///G:/My Progr.....

The problem is that the browser is looking directly at the source code file on the network.
In order for ASP programs to work, they have to be run by a web server; by accessing it directly on the G: drive, you're bypassing the web server, so the program isn't actually being run at all.
What you're seeing is the result of the browser trying to interpret the program source code as if it were XML. It isn't XML because it contains program code, so the browser is complaining about that.
To fix this, you need to access it via a http:// address, not a file:/// address.
The HTTP address must obviously be valid, which means you need to have a web server running. You haven't given us any detail about whether you have this or not, but that's what you need.
Hope that helps point you in the right direction.


Windows 7, IIS 7.5, Selfssl

Question: The windows iis6 resource kit won't install on Windows 7 (Home Premium) so I copied it from another machine and selfssl.exe is giving me:
Failed to generate the cryptographic key: 0x5
I tried the instructions here but am still getting the above error.
I'm trying to set the common name of the certificate to a name other than the machine name so I can avoid the certificate errors in the browser.  This is a test web application.  I know I can just test with the browser errors, but I'd like to mimic real world conditions as much as possible.
Is there any other way to generate your own ssl certificates for iis7.5 and set the common name yourself?
Answer:
I'm trying to set the common name of
  the certificate to a name other than
  the machine name so I can avoid the
  certificate errors in the browser.

To my knowledge, unless you install the cert into the root store of each machine that visits, you'll continue to get those cert errors (at least initially) because they aren't from a trusted root source.  There's really no way around that with self-signed certs.
As for creating the self-signed certs, you can do that right in IIS manager.  Open IIS Manager, click on Server certificate, select the create self signed certification action link.
Comment: Yeah, when I did the self signed certs via iis manager, I got the certificate warnings on the browser.  I guess I can just live with them, or change the name of my site to the server name.
Answer: You can get a free cert from http://www.startssl.com/ for your site. With self-signed certs, you will always get a warning unless it is in the trusted root certificate store as GregD pointed out. There is no other way to verify a self-signed cert.
In a sense, all CA roots are self-signed certificates your machine trusts, but they also have the ability to sign other certs, so that is how certificate chains work.
Comment: So if I get a startssl free certificate for testing purposes and then later on, I want to use another certificate from another company when the site goes live, that would work?  But then for the test certificate, the common name would be peanut.com rather than peanut, which is how I access the webapp in my test environment - http://peanut.
Comment: Yes, getting another cert will work fine, as long as the Subject or Subject-Alternate-Names field contains the name you use to reach the webapp. You can change certificates at your convenience.
Comment: I forgot to add that you can get a certificate (probably not the free one) that has multiple names for the same site, which will allow you to access it over https using different names. You can add peanut and peanut.com to the SAN field (subject-alternate-names) and it will work just fine : ).
Answer: It is possible to create Self-Signed Certificate... directly from IIS 7.5 MMC. You will need to open IIS MMC -> click on the Machine Name (e.g. SERVER2) and in the Features View you will see Server Certificates -> double click and it will open Server Certificates -> on the right hand side under Actions click on Create Self-Signed Certificates. Check this out

(source: dotnetscraps.com)

(source: dotnetscraps.com)
Ignore the marking's as it was used for some other purpose ;-)
Comment: The Self-Signed option is three rows lower.

Windows 7, IIS 7.5, Selfssl


Why will the validation set error underestimate the generalisation error?

Question: In my book about machine learning the concept of a validation set is introduced. It's a subset of the training set that is used to "train" the hyperparameters. More specifically, the validation set is used to estimate the generalisation error during or after training, allowing the hyperparameters to be updated accordingly.
The book states that since the validation set is used to train the hyperparameters, the validation set will underestimate the generalisation error.
Question: Why? I understand that this is true most of the time, but why would it be true in general?
Thanks in advance!
Answer: Say the data is generated by some underlying distribution $f$. We want to learn a model that performs well on future data generated by the same distribution. The true generalization performance of a model is the expected value of the error over $f$. Unfortunately, we only have access to a finite dataset sampled from $f$, which must be used both to train the model (including hyperparameters) and estimate generalization performance. Finite samples are variable--if we were to draw multiple datasets from $f$, each one would be different, and none would perfectly represent the underlying distribution.
Suppose we split the dataset into a training set (used to train the model parameters) and a validation set (used to select the hyperparameters). By tuning the hyperparameters on the validation set, we're selecting a model (out of multiple possibilities) that performs best on that particular sample. In that sense, this operation is not fundamentally different than choosing regular parameters using the training set. Just as it's possible to overfit the training set, it's possible to overfit the validation set. Because samples are variable, a model may have low error on the validation set because it happens to be a good match for the particular, random values in that sample, rather than because it truly matches the underlying distribution $f$. In this case, the model's error on the validation set will be lower than its expected error over $f$. The chance of finding such a model increases as the number of models we select from grows, and as the size of the validation set shrinks.
The remedy to this issue is to estimate generalization performance on an independent subset of the data that has not affected the model in any way (including affecting regular parameters, hyperparemeters, or even preprocessing and decisions by the analyst). For example, the data can be split into independent training, validation, and test sets, or nested cross validation can be used.
For more information about these issues, see:
Cawley and Talbot (2010).  On Over-fitting in Model Selection and Subsequent Selection Bias in Performance Evaluation.