Why use a train/test split with linear regression

Question: I am using linear regression to draw a y = mx + b line between my data, I just want to know how much of a good fit line my best linear line is. So I thought I would just use clf.score(X_train, y_train) on the points I've already used to train my algorithm. I just want to see how my line compares to the average y-line. Do I need to split my data into train and test data, and then run it. Or should I just use my train data to test, beacuse it can't deviate from the line anyways? And why?
Comment: Then it's fine.
Comment: See [Why not using cross validation for estimating the error of a linear model?](https://stats.stackexchange.com/q/122476/17230).
Comment: When you use training data for testing the model is not giving you any estimate of how generalised your model is and how it will behave if I will input new unseen dataset. It is always good to separate data into test and train.
Comment: I am not using it to predict on new data, I am just using it to draw a line through my 2 dimensional old data, so it's only predicting on old data
Answer: If you're not trying to generalise on new data, then you don't need to.
If you are trying to generalise to new data, and if your algorithm has no hyper-parameters (i.e. settings you can tweak), then you don't need to.
If you are trying to generalise to new data, and (as is usual), you have hyper-parameters to tune, then you need to.
For example, if you were using regularised linear regression (a.k.a. "ridge" regression), then you would need to have some way of choosing the regularlisation parameter, such that it will be valid when testing on new data, rather than just fitting the "training" data perfectly.
Comment: To add to this answer: Apart from regularization, other possible hyper-parameters for linear regression could be: adding/not adding an intercept, or using another error metric (e.g. MAE instead of MSE)
Answer:
I just want to know how much of a good fit line my best linear line is

Whilst there might only be a single way to fit a best-fit line to your data, which in fact isnt true, because you can vary various kinds of regularization and so on. But even if it was true, your training data is a single draw from the underlying production distribution. You dont know how well that draw matches the actual distribution. It'll probably match a bit, but clearly it cant match 'perfectly', since the distribution itself is continuous (I assume?), whereas your drawn examples are discrete, Dirac-delta type things.
To estimate how well your line of best fit will generalize to new data, you'll therefore almost certainly want to do some kind of cross-fold validation, and/or bootstrapping etc, to get some kind of measure of what happens to the line, and to the test samples, according to different draws.
A simple standard approach is cross-fold validation: randomly split the data you have into eg 80% train, 20% split. Train on the train, test on the split. Do this 5 times; and average the accuracy from each split.


Relation between averages in the sphere and the ball

Question: Let $\Omega$ be a domain in $\mathbb R^N$ and $u \in C(\Omega)$. If $\omega_N$ denotes the volume of $B_1(0) \subset \mathbb R^N$ and $0 < r < d(x, \partial \Omega)$, the averages are
$$
A_b(x) = \frac{1}{\omega_N r^N} \int_{B_r(x)} u(y) \ dy
$$
in the ball, and
$$
A_s(x) = \frac{1}{N \omega_N r^{N - 1}} \int_{\partial B_r(x)} u(y) \ d\sigma(y)
$$
in the sphere.
We know that if $u$ is harmonic, then $A_b(x) = A_s(x) = u(x)$.

In general, can one say something like $A_s \leq (\geq) A_b$?

I kindly ask for a hint, in case the answer is positive, or for examples, in case the answer is negative.
EDIT:
Ted's hint made me think of the following: take $u$ to be negative inside the ball and $0$ on the boundary. Then of course $A_b < 0 = A_s$. On the other hand, if $u$ is positive, it is clear that $A_b > 0 = A_s$. We conclude that the answer to the question is negative in general.
This seems to be very simple, am I missing something?
Comment: Do you expect any result when $N=1$? I would start there, where it's totally clear that the answer is no.
Comment: You're not missing anything, it is that simple. (When one looks at it from the right angle.)
Answer: The answer seems to be no in the case $N=3$. Fix $\epsilon > 0$ small, and
take $u$ to be a
continuous function with $u(x,y,z) = 1$ when $x > \epsilon$
and $u(x,y,z) = 0$ when
$x < 0$. Consider averages over $B = B_2(1,0,0)$ and $B' = B_2(-1,0,0)$ and their boundaries.
The sphere $\partial B$ has, modulo $\epsilon$,  $3/4$ of a diameter
in the region where $u= 1$, and by a result of Archimedes also has
$3/4$ of its area there, so that average is $3/4$. But $B$ itself has more
than $3/4$ of its volume in the region where $u=1$, so
$$ A_b > A_s $$
for this case.
The sphere $\partial B'$ has, modulo $\epsilon$, $1/4$ of its area in the
region where $u = 1$, so that average is $1/4$. But $B'$ has less than
$1/4$ of its volume in that region, so
$$
 A_b < A_s
$$
for this case.
I don't know what happens in other dimensions.


Drop-down opening all sub-menus, no matter what option I click

Question: I'm trying to dynamically open drop-down sub-menus depending on what option is clicked.
For example, if A is clicked, I want A.1 to appear. If B is clicked, I want B.1 to appear. And so on and so forth. But instead, when I click A for example, it opens A.1 and B.1. I'd like to do this dynamically with a for-loop or something. I don't really want to change any of my HTML. It seems like I'm really close in my JavaScript, I'm just not sure what I'm missing.

/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function mainDropDown() {
  document.getElementById("myDropdown").classList.toggle("show");
}

function subMenu() {
  for (var i = 1; i <= 2; i++) {
      document.getElementById("subMenu" + i).classList.toggle("show");

  }
}
/* Dropdown Button */
.dropbtn {
  background-color: #3498DB;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
  background-color: #2980B9;
}

/* The container
 - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.sub-menu-item{
  display: none;
  background-color: #ccc;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd}

.sub-menu-item a:hover {background-color: #bbb}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

  <button onclick="mainDropDown()" class="dropbtn">Dropdown</button>

    A

    A.1

    B

    B.1

    C
    D
    E
    F
    G

Answer: Right now your subMenu function opens all submenus.
To avoid this, you can pass the element that was clicked on to the click handler.  Then, your subMenu can receive this element, find out what the next element is, and apply the class to that item.

/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function mainDropDown() {
  document.getElementById("myDropdown").classList.toggle("show");
}

function subMenu(clickedElement) {
  let appropriateSubmenu = clickedElement.nextElementSibling;
  appropriateSubmenu.classList.toggle("show");
}
/* Dropdown Button */
.dropbtn {
  background-color: #3498DB;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

/* Dropdown button on hover & focus */
.dropbtn:hover, .dropbtn:focus {
  background-color: #2980B9;
}

/* The container
 - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: block;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.sub-menu-item{
  display: none;
  background-color: #ccc;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd}

.sub-menu-item a:hover {background-color: #bbb}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

  <button onclick="mainDropDown()" class="dropbtn">Dropdown</button>

    A

    A.1

    B

    B.1

    C
    D
    E
    F
    G

Answer: you mean like this? what do you mean by B.1 and B.2?

/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function mainDropDown() {
  document.getElementById("myDropdown").classList.toggle("show");
}

function subMenu(n) {
  document.getElementById("subMenu" + n).classList.toggle("show");
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.sub-menu-item{
  display: none;
  background-color: #ccc;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd}

.sub-menu-item a:hover {background-color: #bbb}

/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {display:block;}

  <button onclick="mainDropDown()" class="dropbtn">Dropdown</button>

    A

    A.1

    B

    B.1

    C
    D
    E
    F
    G

Comment: Sorry, just meant to say B.1. Those are just the sub-menus for the main options. Thanks for your answer!


apache2 config - variable not evaluated in string

Question: I want different routes to have their own password. So I have a LocationMatch:
<LocationMatch /shiny/(?<appname>.*)>
       AuthType Basic
       AuthName "Enter your login name and password"
       AuthUserFile "/path/to/directory/with/passwords/.%{env:MATCH_APPNAME}.pwd"
       Require valid-user
</LocationMatch>

But I am getting 500 Internal Server Error, because %{env:MATCH_APPNAME} is not evaluated:
[Thu Sep 20 12:11:21.678370 2018] [authn_file:error] [pid 16932:tid 140332725917440] (2)No such file or directory: [client xxx.xxx.xxx.xxx:52274] AH01620: Could not open password file: /path/to/directory/with/passwords/.%{env:MATCH_APPNAME}.pwd
I am following the official instructions here. What am I doing wrong? Thank you.
apache2 version: apache2 (OpenRC) 0.34.11 (Gentoo Linux)
Answer: As referenced in the docs you quoted, Apache supports this style of regex references in expressions (docs), but AuthUserFile expects a file-path as an argument - thus taking your string literally.
See the If directive's docs to see how a directive supporting an expression is listed. The documentation page about expressions has a list of directives supporting them.


I do not know how to check the results. (BaseHTTPRequestHandler)

Question: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler

class aaa(BaseHTTPRequestHandler):
    def do_GET(self):
        self.wfile.write("Hello World")

if __name__ == "__main__":
    server = HTTPServer(("", 8888), aaa)
    server.serve_forever()

It's a practice to create a web server in Python.
but,  I do not know how to check the results.
Comment: Please clarify what you are trying to achieve. Are you writing a client or a server or both? The code is the sever side. Where do you want to check the result of which operation? Are you missing a client? Your browser could be your test client.for a http request.
Answer: Open a web browser and type http://localhost:8888/ into the address bar. If you see Hello World, it worked. Otherwise, it didn't.
Whether or not it worked, you can see the actual results returned like this. Open a command prompt and type:
telnet localhost 8888

after the connection completes, type:
GET / HTTP/1.0

and hit enter twice.
Then the response from the web server should appear.
Comment: I did it the way you told me. but, Localhost has sent an invalid response.(ERR_INVALID_HTTP_RESPONSE) I get an error...
Comment: oh! it's success in internet Explorer! thank you so much!


Suppose that $a_n$, $b_n$ are such that $\lim_{n \rightarrow \infty} a_n = \infty$ and $\lim_{n \rightarrow \infty} \frac {a_n}{b_n} = \alpha$

Question: Problem: Suppose that $a_n$, $b_n$ are sequences of positive numbers such that $\lim_{n \rightarrow \infty} a_n = \infty$ and $\lim_{n \rightarrow \infty} \frac {a_n}{b_n} = \alpha$ for some $\alpha \in \Bbb R$, show that $b_n \rightarrow \infty$.
Thoughts: It seems that I could start with a proof by contradiction of 3 different cases where $b_n$ converges to a real number, or that it converges to negative infinity, and finally that it diverges. This seems like the wrong approach. Any hints much appreciated.
Comment: Have you tried the epsilon definition of the limits?
Comment: @Vik78 sorry my mistake edited.
Comment: Why did you accept a faulty answer?
Comment: @Did I was just going back to questions that I hadn't accepted and must have been careless. I rescinded the answer sorry about that.
Comment: Be aware that $a\in\mathbb{R_+}$ has to hold to deduct $b_n\to \infty$. Otherwise we can e.g. set $b_n = -a_n$.
Comment: @Sudix The problem includes assumptions that $a_n,b_n$ are sequences of positive numbers.  On the other hand, $\alpha = 0$ is possible and the statement still holds.
Answer: if $b_n $ is bounded, given any arbitrary large $\epsilon$ we can find an $N$ such that $\frac{a_n}{b_n} \ge \epsilon$ for some $n \ge N$. after ruling out $b_n$ being bounded, Only case remains is $b_n$ diverging. In this case we can always find a subsequnce of $b_n$ that is bounded, so $\frac{a_n}{b_n}$ contains a subsequence that is going to  $\infty$, which is again a contradiction.


Question regarding limiting probability

Question: Does there exist an irreducible discrete time Markov chain such that all limiting probabilities exist, i.e. $\lim\limits_{k \to \infty} \mathbb{P}(X_k = i)$ exists for all states $i$, and $\sum_{i} \lim\limits_{k \to \infty} \mathbb{P}(X_k = i) = \frac{1}{2}$? I'm currently stuck here and not sure how to prove/disprove this. Is there any suggestion on how I should proceed?
Comment: If I understand your notation and terminology, it seems to me the sum of limits has to b $1.$ Terminology can differ among texts. If you allow periodic chains maybe 1/2 is possible.
Answer: Consider the $2\times 2$ transition matrix, shown below.  In R,
matrix multiplication is denoted %*% We show the transition
matrix of an irreducible ergodic chain, and how to obtain its
limiting distribution.
First approach: Take higher powers of transition matrix, until
all rows of $\mathbf{P}^n$ become (nearly) the same.
P = matrix(c(.4, .6,
             .7, .3), byrow=T, nrow=2)
P.2 = P %*% P;  P.4 = P.2 %*% P.2;  P.4
       [,1]   [,2]
[1,] 0.5422 0.4578
[2,] 0.5341 0.4659
P.8 = P.4 %*% P.4;  P.16 = P.8 %*% P.8;  P.16
          [,1]      [,2]
[1,] 0.5384615 0.4615385
[2,] 0.5384615 0.4615385

So the 16th power of the transition matrix shows that the
steady state, thus limiting, distribution is the vector
$\sigma = (0.5384615,\, 0.4615385).$
Another approach, using eigenvectors: The left eigenvector
with the smallest modulus, listed first in R output, is proportional to $\sigma.$
Because R finds right eigenvectors, we use the transpose of
the transition matrix $\mathbf{P}.$
g = eigen(t(P))$vector[,1]; g  # first column of matris of eigenvectors
[1] 0.7592566 0.6507914
sg = g/sum(g);  sg
[1] 0.5384615 0.4615385

sg %*% P                       # verification
          [,1]      [,2]
[1,] 0.5384615 0.4615385

Third approach is possible tor a 2-state irreducible ergodic Markov Chain.
Starting in state 1, the mean waiting time to transition to state 2 is (by geometric
distribution $1/.6.$ Then the mean waiting time to return to state 1 is
$1/.7.$ Thus on average, over the long run, the chain spends $\frac{1/.6}{1/.6 + 1/.7} = \frac{7}{13} = 0.5384615$ of its time in state 1.
1/6/(1/6 + 1/7)
[1] 0.5384615

Comment: I'm not sure whether I understand the reasoning above. The sum of the limiting probabilities in all the examples is still 1. So I guess the question above is not true? Do you have any suggestion how to disprove it?
Comment: Not sure I understand question. My answer is is correct and contains info you might find useful, but maybe irrelevant to current question.

Question regarding limiting probability


SQL query that gives me the percentage of users that fail to run a game per day

Question: I'd really appreciate help on a SQL query I've been struggling to write.
Background:
Everytime a user plays a game, a record gets created in the table game_runs, along with their user_id and run_date (a MySQL timestamp).

When the user successfully plays the game, they get a score greater than 0.
If the game failed to run (e.g. maybe it crashed), the score is 0

The table looks something like this:
 id  |     run_date         |  user_id   |   score
-------------------------------------------------------
 1   |  2020-02-02 00:20:00 |    10      |     0      |
 2   |  2020-02-02 01:50:10 |    10      |    40      |
 3   |  2020-02-02 03:40:20 |    11      |    80      |

 4   |  2020-02-03 03:20:14 |    20      |    80      |
 5   |  2020-02-03 12:20:14 |    21      |     0      |

 6   |  2020-02-04 06:20:42 |    50      |     0      |
 7   |  2020-02-04 11:15:00 |    50      |     0      |
 8   |  2020-02-04 12:10:46 |    51      |    70      |

 9   |  2020-02-05 00:15:00 |    60      |     0      |
10   |  2020-02-05 01:10:40 |    61      |     0      |

I would like to find out what percent of users fail to run the game per day.
In the above example, here's what I'm hoping I can generate:
date         |   percent_users_who_failed_to_run_the_game
-------------------------------------------------------------
2020-02-02   |   0
2020-02-03   |   0.5
2020-02-04   |   0.5
2020-02-05   |   1

Notice how on 2020-02-02, the percent of users who failed to run the game is 0% (i.e. everyone succeeded at least once). This is because on 2020-02-02, there were three runs:

id=1: user_id 10 failed to run it initially (score=0)
id=2: user_id 10 succeeds the second time (score=40)
id=3: user_id 11 succeeds

Since both users were successful that day, the percent of users that failed was 0%.
I'd love any input on how to get started. I am using mySQL v8+ so have access to window functions if that is necessary (my research tells me that they may help, but have been unable to write a query that does this).
I think the right logic would be something along the lines of finding out the % of users that have a MAX(score) = 0 but unsure how to write the query.
I hope that wasn't too unclear - I really appreciate you reading thus far, and any pointers will be so helpful.
Thank you!
Comment: See: [Why should I provide an MCRE for what seems to me to be a very simple SQL query?](https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query)
Answer: I think you need to do this in two steps. The first step is to get the maximum score per user per day:
SELECT  CAST(Run_Date AS DATE) AS RunDate,
        User_ID,
        MAX(Score) AS Score
FROM    YourTable
GROUP BY CAST(Run_Date AS DATE), User_ID;

Then you can put this in a subquery and calculate your percentage:
SELECT  RunDate,
        COUNT(CASE WHEN Score = 0 THEN 1 END) / SUM(1.0) AS Failed_Percent
FROM    (   SELECT  CAST(Run_Date AS DATE) AS RunDate,
                    User_ID,
                    MAX(Score) AS Score
            FROM    YourTable
            GROUP BY CAST(Run_Date AS DATE), User_ID
        ) AS t
GROUP BY RunDate;

Example on SQL Fiddle
You can also achieve this without a subquery using COUNT(DISTINCT):
SELECT  CAST(Run_Date AS DATE) AS RunDate,
        1 - (1.0 * COUNT(DISTINCT CASE WHEN Score > 0 THEN User_ID END)
            / COUNT(DISTINCT User_id)) AS Failed_Percent
FROM    YourTable
GROUP BY CAST(Run_Date AS DATE);

Example on SQL Fiddle
This is really doing the reverse logic, but the result is the same. The relevant parts are:
COUNT(DISTINCT CASE WHEN Score > 0 THEN User_ID END)

This gets the total number of distinct users that ran the game successfully on any given date, Then
COUNT(DISTINCT User_id)

Gives the total number of users that logged a record on that date. The former divided by the latter gives the percent of successful users, so we then need to minus this from 1 to get the percent of failed. I have multiplied one of the counts by 1.0 to implicitly convert it to a decimal to avoid integer division
I would expect the first query to be more efficient, but I could be wrong.
Comment: Wow, thank you so much Gareth! I ran the two queries and you were right, the sub-query is indeed more efficient.
Answer: You can do this without a subquery:
select date(run_date) as dte,
       1 - count(distinct case when score > 0 then user_id end)) / count(distinct user_id)
from t
group by dte;

This counts the number of users who successfully ran the game each day.  1 - <this amount> is the number who were unsuccessful.


Failed to load the JNI shared Library (JDK)

Question: When I try opening Eclipse, a pop-up dialog states:

Failed to load the JNI shared library "C:/JDK/bin/client/jvm.dll"`.

Following this, Eclipse force closes.
Here's a few points I'd like to make:

I checked to see if anything exists at that path. It does exist.
My Eclipse and Java SE Development Kit are both 64-bit. I checked my system, and it can handle 64-bit.
I've searched for this problem on Google and on Stack Overflow, and the only answer I found was to download the 32-bit versions of JDK and Eclipse.

Downloading the 32-bit versions is something I only want to do as a very last resort.
What would be suggested to solve this issue?
Comment: I had, to my surprise, 5 or so Java installed onto my computer.  Not only that, but it turned out that I downloaded the 32-bit Eclipse by accident.  So, I uninstalled every Java I had, deleted Eclipse (Eclipse doesn't have an "uninstall"), and downloaded [Eclipse Classic 64-bit](http://www.eclipse.org/downloads/packages/eclipse-classic-42/junor) for my machine, along with a 64-bit Java (see SPP's answer for that link).
Comment: Also: if anyone has trouble "deleting" their Eclipse (e.g. the folder won't go away no matter how many times you remove it manually or via command prompt), try deleting it using safe mode with command prompt.. I have no idea why I had to do this, but that ended up working.
Comment: @MikeGates I had that problem too, used LockHunter. Obnoxious. Getting this tool to run on Windows is way too much work.
Comment: This might help - http://www.buggybread.com/2013/01/failed-to-load-jni-shared-library.html
Comment: hey. if you DO have 64-bit version of all of the below stated software, just try deleting the 'eclipse.ini' file. worked for me:)
Comment: Never delete `eclipse.ini` - very bad idea.
Comment: Updating java fixed this problem for me.
Comment: What exactly was the problem in your case?
Comment: Eclipse/Java sucks when it comes to 64bits, it is a f... disgrace. Best advice I can give is to stick to 32 bit only. Save heaps of time.
Comment: These answers below, are quite good; thanks everyone! I also had the problem before; Didn't know this had a solution! thanks!
Answer: You need a 64-bit trio:

64-bit OS
64-bit Java
64-bit Eclipse
Comment: @Tarik yes, its 2015 and unfortunatelly the Visual Page Editor(VPE) of JBoss Tools still awaiting since years for a 64-bit upgrade. Look at the "Working-Pairs" answer below, at the second pair. The JBoss Tools-Plug-in is bound to the same architecture you downloaded Eclipse. So Eclipse(with the JBossTools) must be 32bit, the JDK must be 32bit and the OS can be 64 bit. A 64bit eclipse does currently not work with JBoss Tools.... I remember a project called JBossIDE that works using Eclipse, you shall use this instead of install JBossTools into eclipse. Shame on you JBoss, shame on mozilla too.
Comment: **Explaination**: Imagine native code (DLL) being loaded into an application. Now imagine a 32bit function wants to call a 64bit one, or alike. Same with alignment and datasizes and everything. I guess I dont have to tell anything more =P
Comment: Correctly! My laptop is running on x64 OS but I installed x86 JDK. Just installed x64 jdk and the issue go away. Thanks.
Comment: This answer is actually not totally accurate. You do **not** need to run 64-bit JDK and 64-bit Eclipse if you're on a 64-bit OS. 64-bit OS can just as well run a combo of 32-bit Java + 32-bit Eclipse. What *must* match is the bittedness of JRE/JDK and Eclipse.
Comment: @E-Riz You are right, a correct answer can also be "take a 32-bit eclipse!". But is it a good answer?
Comment: Whether 32-bit is "good" or not depends on a lot of context. It's certainly not "bad" since Eclipse itself does't need the extra address space that 64-bit provides. I've heard arguments that 64-bit is actually a poor choice if you don't really need it; I won't pretend to really have thought much about that, just sayin'....
Comment: @E-Riz That eclipse does not need the extra address space is not absolutly right. I actually need 8GB of RAM for my MyEclipse+STS+JBDS. I think the OP has multiple kinds of java installed. Anyway this is not a chat, i refer to the last update of MikeS (21Jun) in the relation of time.
Comment: If you want that each eclipse or any other tool that is build up on eclipse run on individuals Jre then you can install those JRE right inside where your eclipse.exe is placed.

For example javaw.exe should be installed on eclipseexefolder\jre\bin\javaw.exe.

After this you dont need PATH variable.
Comment: but why if we want a 32-bit JVM in a 64-bit OS ?! how to resolve that (i must use 32-bit JVM for the Jboss tools)
Comment: @PeterRader thanks for your clear explanation, i thought that i can't use eclipse 32 in a windows 64 because in the download page of eclipse they used the terminology _Windows 32-bit 64-bit _ which made me confused
Comment: @Tarik ah, i see, indeed. The only reason why eclipse cares about the architecture; why eclipse can be downloaded for 32bit+64bit(cka Windows x64) and 32bit-only(cka Windows x32) is the swt-native-library binding. Also JBTools has a native binding to mozilla's native-32bit-only-library. Unfortunatelly all the native bindings must been compiled for the same architecture(because of the bigger pointers ...). But this is deep down in low-level-programming. No idea if mozilla support someday a 64bit library.
Comment: @PeterRader that's really interesting, but regarding JBTools i think there is now an Experimental support working with eclipse luna(4.1.0.Beta1)... Anyway, thanks for the additional infos :)
Comment: Worked for me! I also made sure that the file exists in `bin/server/jvm.dll` exists, however, the problem was that I happened to download the 32-bit version. I personally am not sure about the reason, I honestly expected the 32-bit version to work too.
Answer: Working pairings of OS, JDK and Eclipse:

32-bit OS | 32-bit JDK | 32-bit Eclipse (32-bit only)
64-bit OS | 32-bit JDK  | 32-bit Eclipse
64-bit OS |  64-bit JDK | 64bit Eclipse (64-bit only)

I had several JDKs and JREs installed.
Each of them had their own entry in the PATH variable, all was working more or less.
Judging from the PATH variables, some installations were completely useless, since they were never used. Of course, the "inactive" Javas could be referenced manually from within Eclipse if I needed, but I never did that, so I really did not need them. (At least I thought so at that time...)
I cleaned up the mess, deinstalled all current Java's, installed only JDK + JRE 1.7 64-bit.
One of the Eclipse 'installations' failed afterwards with the Failed to Load the JNI shared Library and a given path relative to the fresh installed JDK where it thought the jvm.dll to be.
The failing Eclipse was the only one of all my IDEs that was still a 32-bit version on my otherwise all-64-bit setup.
Adding VM arguments, like so often mentioned, in the eclipse.ini was no use in my case (because I had only the wrong JDK/JRE to relate to.)
I was also unable to find out how to check if this Eclipse was a 32-bit or 64-bit version (I could not look it up in the Task Manager, since this Eclipse 'installation' would not start up. And since it had been a while since I had set it up, I could not remember its version either.)
In case you use a newer JDK and a older JRE you might be in for trouble, too, but then it is more likely a java.lang.UnsupportedClassVersionError appears, IIRC.
Comment: to check which version 32-bit or 64-bit, open eclipse.ini and look for the equinox launcher used (e.g. org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502)
Comment: It should only use the first \bin it comes to in the Path variable
Comment: It was the comment by @ekinnear that solved my issue. I am not sure why it was looking for the JVM.dll in my windows/bin folder but putting the proper path in place seems to have resolved it.
Comment: Mmmm, that is always the question... The Oracle docs say it only uses the first one, but maybe something else was being changed/was already in place and working. Seems like its always something strange like that.
Comment: I had this combo with the error. 64-bit OS - 32-bit JDK - 32-bit Eclipse and it doesn't work. I resolved it with this combo: 64-bit OS - 64-bit JDK - 64bit Eclipse (64-bit only). The %PATH% variable has been updated to point to the 64 bit java version. Actually the %JAVA_HOME% has been updated as this variable is used into %PATH% variable values.
Comment: My fix was also the one suggested @ekinnear. Eclipse had been working fine but I had forgotten that I had added the offending JDK to my system PATH. Once I removed the JDK from PATH , Eclipse was able to load again.
Answer: Make sure your eclipse.ini file includes the following lines.
-vm
C:\path\to\64bit\java\bin\javaw.exe

My eclipse.ini for example:
-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.2.R36x_v20101222
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
-vm
C:\Program Files\Java\jdk1.6.0_32\bin\javaw.exe
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx512m

Use OS and Eclipse both 64 bit or both 32 bit keep same and config eclipse.ini.
Your eclipse.ini file can be found in your eclipse folder.
Comment: This solves the problem. I added the `-vm C:\Program Files\Java\jdk1.6.0_32\bin\javaw.exe` line to my eclipse.ini file and it started up just fine. Thanks for the help +1.
Comment: this works. but need to put -vm in the top of the ini file; at least before -vmargs or --launcher.xxx
Comment: Very Very Important point that I missed.
If you use like: "-vm C:\ProgramFiles\Java\jdk1.6.0_32\bin\javaw.exe" it will never work
Correct way
"-vm
C:\Program Files\Java\jdk1.6.0_32\bin\javaw.exe"
New line after the -vm is very important.
Comment: I did this with my Java 6 SDK, and it didn't work.  I tried it again, pointing to my Java 7 SDK, and it worked.  I'm on Windows 8 64-bit, Java 6 and 7 (both 64-bit) and Eclipse Helios (32-bit).  I was ready to uninstall and re-install Eclipse 64-bit, but it seems the java 7 SDK includes some new intelligence to run 32 bit apps better.
Comment: this work fine please check your version of Java, run java -version in a console and Check that this is the version being used by Eclipse or not
Comment: No need to change the .ini file. Just use the 64 bit combo for java and eclipse
Comment: This has been a problem for me since I went Windows 7 64 bit in 2010. I've had to do this to every Eclipse Install since at work and home. Why have the eclipse team not addressed this issue?
Comment: As of today (July 7, 2014), this is still an issue. Is it so hard to fix this issue when eclipse already knows where your java is?
Comment: Configure the path in `eclipse.ini` as @jayeshkavathiya mentioned. ***RESTART ECLIPSE AFTER MAKING THE CHANGES IN eclipse.ini***. And that should solve it. :-)
In my case, I could still see the error in the console. But once I restared eclipse, it vanished
Answer: I had same problem
I resolved it by installing 64 bit JVM from
http://www.java.com/en/download/manual.jsp
Answer: This error means that the architecture of Eclipse does not match the architecture of the Java runtime, i.e. if one is 32-bit the other must be the same, and not 64-bit.
The most reliable fix is to specify the JVM location in eclipse.ini:
-vm
C:\Program Files (x86)\Java\jdk1.7.0_55\bin\javaw.exe

Important: These two lines must come before -vmargs. Do not use quotes; spaces are allowed.
Comment: Hi, i'm working since some time ago with this .ini setup, Should i update the architecture to 64-bit or i can ignore the fact of having diferent architectures?? Thx
Answer: Another option is:
Create a shortcut to the Eclipse.exe. Open the shortcut and change the target to:
"C:\Program Files\eclipse\eclipse.exe" -vm "c:\Program Files\Java\jdk1.7.0_04\bin\javaw.exe"

For your installation, make sure the locations point to the correct Eclipse installation directory and the correct javaw.exe installation directory.
(The 64/32 bit versions of Eclipse and Java need to be the same, of course.)
Comment: No need to change the .ini file. Just use the 64 bit combo for java and eclipse
Comment: Good options but adding it to the ini file as above should work
Answer: I have multiple versions of Java installed, both Sun JDK & JRockit, both 32 bit and 64-bit, etc. and ran into this problem with a fresh install of 64-bit Eclipse for Java EE (JUNO).
What did NOT work:
64-bit trio as suggested by Peter Rader:
I'm using 64-bit Eclipse on 64-bit OS (Windows 7).
I ensured Sun JDK 7 64-bit was the default java version.  When I typed "java -version" from command line (cmd.exe), Sun JDK 7 64-bit was returned...
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

This did not resolve the problem for me.
What DID work:
Adding -vm option to eclipse.ini as suggested by Jayesh Kavathiya:
I added the following to eclipse.ini:
-vm
C:/apps/java/jdk7-64bit/bin/javaw.exe

Note:
I did not have to uninstall any of the various versions of JDK or JRE I have on my machine.
Comment: I did not have to uninstall the JDK's either, but I chose to clean my system to wipe out future error causes. I had also mentioned the VM arguments, and explained why they could obviously not work for me. It is your choice how you want to set up your system, depending on what you _really_ need.
Comment: I had to do both things, but adding the javaw.exe line then led me to install everything on 64 bit, anyways. It depends on how much karma punishment you are due to pay to android.
Comment: I have been developing for years, and with no change to my system (that I am aware of), Eclipse throws this error. Adding the -vm option sorted it out for me, without needing to change any other settings or un/re/install anything.
Answer: For a missing jvm.dll file, we can provide the path of the dll file in eclipse.ini file as
-vm
C:\Progra~1\Java\jdk1.6.0_38\jre\bin\server\jvm.dll

Here it is important to remove any space in the path and the double quotes.
It worked for me when i removed the quotes and space.
I hope it helps someone.
Comment: This helped me instead of -vm   javaw.exe
Answer: I had a similar problem. It was solved doing the following.

Move Eclipse to Program Files (not to Program Files (x86)).
Remove the path to the 32-bit version of Java from the 'path' environment variable.

I have both versions of Java installed, but Eclipse kept trying to use the 32-bit one.
Answer: Sure, you need to have a compatible version of JDK and Eclipse, but you also need to add in the eclipse.ini file the below lines:
-vm
yourdrive\java\bin

Make them the first two lines of your eclipse.ini file.
Answer: As many folks already alluded to, this is a 32 vs. 64 bit problem for both Eclipse and Java. You cannot mix up 32 and 64 bit. Since Eclipse doesn't use JAVA_HOME, you'll likely have to alter your PATH prior to launching Eclipse to ensure you are using not only the appropriate version of Java, but also if 32 or 64 bit (or modify the INI file as Jayath noted).
If you are installing Eclipse from a company-share, you should ensure you can tell which Eclipse version you are unzipping, and unzip to the appropriate Program Files directory to help keep track of which is which, then change the PATH (either permanently via (Windows) Control Panel -> System or set PATH=/path/to/32 or 64bit/java/bin;%PATH% (maybe create a batch file if you don't want to set it in your system and/or user environment variables). Remember, 32-bit is in Program files (x86).
If unsure, just launch Eclipse, if you get the error, change your PATH to the other 'bit' version of Java, and then try again. Then move the Eclipse directory to the appropriate Program Files directory.
Comment: It's clearly a problem as this page as 700k views currently... and a year later there's apparently no fix for it that doesn't involve poking around in environment variables just to get the IDE to run!
Answer: The answers above me got me tempted so much, that I decided to dry run all the possible combinations with OS, Eclipse and JVM trio. Anyway, whoever is digging down and reading my post, check the following as a hot spot (I am Windows 7 user).

You understand Program Files and Program File (x86) are two different folders... x86 stands for the 32-bit version of programs and the former is the 64-bit version.
If you have multiple versions of Java installed with different bitness and release versions, which is bound to happen with so many open source IDEs, managers, administrative consoles, the best option is to set the VM argument directly in the eclipse.ini file. If you don't, Eclipse will go crazy and try searching itself which is not good.
Answer: Alternatively, get the same "bit" version of JRE and Eclipse and then create a new shortcut with the below target (replace the installed JRE and Eclipse location/path):
"C:\studio\eclipse.exe" -vm "C:\Program Files\Java\jre7\bin\server\jvm.dll" eclipse.vm="C:\Program Files\Java\jre7\bin\server\jvm.dll" java.home="C:\Program Files\Java\jre7" java.runtime.version=1.7.0

That should do the trick.
Answer: You can solve that problem as many other replicated. You need that Eclipse and the JDK be 32-bits or both on 64-bits. The architecture of the OS doesn't matter while the others remains on the same type of arquitecture.
Answer: One of the easy ways to resolve it is to copy the jre folder from installed the JDK into the Eclipse installation folder. Make sure that JDK you copy from is the same architecture as your Eclipse installation.
I had to configure my machine that way, because I run both Eclipse and Appcelerator Titanium Studio on my machine. The Studio needs 32-bit Java, while Eclipse needs 64-bit.
Comment: I did the same thing a long time ago, but for eclipse-jee-juno-SR1-win32 and Java6, I could not get it to work, this time around. Did you also edit the eclipse.ini with an absolute path to the jre ?
Comment: I also have Eclipse 64 width jdk 7 64bit, but titanium tall me it's unable to load jni shared dll.
Comment: Because of Window's crazy autoupdates, whenever there is an update for JAVA, it blocks my Eclipe from launching. Above solution is the easiest way to work independently without caring about autoupdates. Thanks!
Answer: Yes, just make sure your versions of Eclipse and JDK are both 64-bit. Just to make sure everything is correct uninstalled JDK and install it in Program Files and not in Program Files (x86). At least that resolved my problem.
Answer: Just check the PATH environment variable. In My Computer - > Properties -> Advanced System settings -> Environment Variables -> (left upper window "User Variables for "some name of PC"" ) just check the PATH variable. If it doesn't exist create it with the following -- > C:\Program Files (x86)\Java\jre7\bin <--
I was faced with the same problem after had updated my Eclipse. I've found that the path asked 64-bit version, but I had the 32-bit in dif path. It was helpful for me. P.S.: I have a 64-bit OS, 32-bit JRE and 32-bit Eclipse. All works fine :)
Answer: You should uninstall all old [JREs][1] and then install the newest one... I had the same problem and now I solve it. I've:
Better install Jre 6 32 bit. It really works.
Answer: Thank you misterfrb, I realised that Eclipse was giving this error, because I had just installed Oracle 10g Developer suite, and it was looking for the jvm.dll file in the C:\DevSuiteHome_1 folder (I must have opted to install JDK again along with developer suite).
After removing the DevSuiteHome lines from the paths variable and adding the correction location for 64-bit jvm.dll (not sure if this was necessary, didn't try without), Eclipse worked again, and Developer suite still does too.
Answer: Downloaded 64 bit JVM from site and installed it manually and updated the system path variable. That solved the issue.

Default JVM is installed in my system was in "C:\Program Files
(x86)\Java\jre7"
Manually installed JVM got installed in
"C:\Program Files\Java\jre7" and after updating this pate to system
path variable it worked.
Answer: Simple, I have a 64-bit OS, 32-bit Eclipse and both JDK 32 & 64 installed... I just uninstalled the 64-bit JDK and Eclipse is working fine..
Answer: I had the same issue after upgrading from Java 6 to Java 7. After I removed Java 6 (64 bit) and reinstalled Java 7 (64 bit), Eclipse worked. :)
Answer: It is crucial to add the -vm parameter and its value on 2 lines AT THE BEGINNING of the eclipse.ini
-vm
C:\Program Files\Java\jdk1.7.0_45\bin\javaw.exe
Answer: You have change proper version of the JAVA_HOME and PATH in environmental variables.
Comment: Worked well for me. I've installed multiple Java versions to test and the Path and JAVA_HOME wasn't pointing to the same installation.
My Solution: Changed the Path to "%JAVA_HOME%\bin"
Answer: I want to previde another solution for this error, especially for who want to use 32-bit and 64-bit Eclipse in one system.
Eclipse will startup using the JRE/JDK in jre sub-directory if it exists. (STS or other eclipse based IDE also support this feature...)
The solution is create directory junction using mklink.exe command which exist in windows vista or newer version (junction.exe offer similar function for Windows 2000/XP)
Open the command line windows and exeute following command:

mklink /j "$ECLIPSE-HOME/jre" "$JDK_or_JRE_home"

Of course, if the Eclipse is for 64-bit Windows, the architecture of JDK/JRE must be the same.
Assume:

Eclipse for windows x86_64 is installed in d:\devTool\eclipse
JDK for windows x64 is installed in C:\Program Files\Java\jdk1.8.0

The command for creating the jre folder will be:

mklink /j "d:\devTool\eclipse\jre" "C:\Program Files\Java\jdk1.8.0"

BTW, delete directory junction will NOT delete any file. If you create a wrong link, you can delete it using file explorer or rmdir command.

rmdir "d:\devTool\eclipse\jre"
Answer: Make sure you are starting Eclipse with Administrator rights.
Answer: If you use whole 64-bit trio and it still doesn't work (I've come to this problem while launching Android Monitor in Intellij Idea), probably wrong jvm.dll is being used opposed to what your java expects. Just follow these steps:

Find the jvm.dll in your JRE directory:
C:\Program Files\Java\jre7\server\bin\jvm.dll
Find the jvm.dll in your JDK directory:
c:\Program Files\Java\jdk1.7.0_xx\jre\bin\server\
Copy the jvm.dll from JRE drectory into your JDK directory and overwrite the jvm.dll in JDK.

Don't forget to make a backup, just in case. No need to install or uninstall anything related to Java.
Answer: The same occurred to me. I had 64-bit Eclipse, but my JDK was 32-bit. So I installed the 64-bit version and it's OK right now.
Answer: I'm not sure why but I had the jre installed into my c:\windows directory and java.exe and javaw.exe inside my windows\system32 directory.
Obviously these directories were getting priority even AFTER adding the -vm flag to my eclipse.ini file.
Delete them from here fixed the issue for me.
Answer: You can install the 32-bit version of JDK on a 64-bit machine. See JDK 7 downloads.
Comment: Your answer is not helpful. It is already known that this is possible. The OP wants to avoid it.
Answer: On the download page of Eclipse, it should be written "JRE 32 bits" or "JRE 64 bits" and not "Windows 32 bits" or "Windows 64 bits".
Be sure to use the correct version compatible with your JDE, as answered previously.
Answer: And for PDT users - avoid the Zend download page - it doesn't have any 64-bit downloads linked.
Use the Elipse site itself.
The above link had an older 3.6 Eclipse which then failed to update itself due to Eclipse Bug #317785.
My solution was to just install 32-bit Java alongside 64-bit - this allowed the Zend installer to work.
It's depressing that amount of Java / Eclipse cruft one has to go through to get a PHP IDE.
Comment: I moved to PHPStorm - still Java-based - but no cruft :)
Answer: In my case, I tried to launch java from the command prompt and got this error

Error: could not open "C:\Windows\jre\lib\amd64\jvm.cfg"

It meant "java" was looked for in the PATH starting at this wrong directory. Deleting the folder C:\Windows\jre\ solved the issue
Answer: I had the same problem. with 64bit os all should be 64bit.
Java and Eclipse.
I tried all the methods in stackoverflow and also in youtube. non of them worked for me untill i found this easy method.
I installed 64bit java form Cnet download and the problem was automatically fixed.
I mentioned the source because it is too easy to google and go to first Cnet lint rather than oficial site if you are a new bee.
p.s. if you have Android ADT bundle and tried to open eclipse from it and got the same error, you can fix that problem too with this method.
Answer: The easiest solution is to include a specific JRE in eclipse.ini:
wiki.eclipse.org/Eclipse.ini
With this, you can start almost any Eclipse version
Comment: I realy like this answer because it refers official documentation. Right now the link looks broken. I would be pleased if you update the link.
Answer: This error we are getting because of different Java version download 32-bit version.
Answer: Installing JDK 1.8._91 (mixed mode) is another solution for this!
Answer: This happens because of the way the windows paths interact.  Your 32-bit JRE is listed BEFORE your 64-bit version.  Since javaw.exe is named the same for both 32 and 64 bit versions, it tries the first one it finds.  Change the order in your Path Environmental variables, so the 64-bit version higher on the list than the 32-bit, and it will work correctly.
Answer: I have experienced all of the Eclipse errors and this is one of them. The problem is Eclipse 64-bit version. Download the 32-bit version and launch it.


rails rake (3.1) why do all rake tasks error out with 'stack level too deep'

Question: Possible conflict with Rake extension maybe?
md:~/Dropbox_not_syncd/webs/3/tdd/rubyists$ rake db:drop
/home/durrantm/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/version.rb:4: warning: already initialized constant MAJOR
...
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
/home/durrantm/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.9.2/lib/rake/task_arguments.rb:73: warning: already initialized constant EMPTY_TASK_ARGS
..
rake aborted!
stack level too deep

(See full trace by running task with --trace)

Comment: I think you need to blow away your RVM installation and try again; most of these things you're posting are RVM related, and point to something having been done wrong, or getting tripped up in which ruby/gemset you're using, etc.
Answer: An answer to my problems - at least they have gone away and I can move on - was to use
bundle exec rake spec
over
rake spec
Some time later....
eventually I was able to blow away my rcm or at least delete all rvm related files and then I could go back to use 'rake spec', etc. Though I did also create and repopulate the application too along with this.


Calling Oracle Stored Procedure from Spotfire

Question: I've create a stored procedure (SP) within Oracle that has an OUT parameter of type SYS_REFCURSOR, this SP executes as expected within Oracle.
CREATE OR REPLACE PROCEDURE SCHEMA.MyProc
(
  p_Code IN varchar2,
  p_FromDate IN Timestamp,
  p_ToDate IN timestamp,
  p_ResultSet OUT SYS_REFCURSOR
)
AS
BEGIN
   OPEN p_ResultSet FOR
   -- Obtain required data

END SF_EquipmentStatusHistory;
/

However when the Spotfire guy in the organisation tries to create new Procedure in Spotfire and reference my SP, Spotfire complains that it can't have an OUT parameter.
Reading this link Spotfire Procedure Overview, seems to suggest that Spotfire "Information Designer only support procedures that return data of the type REF CURSOR"
Can somebody please help as to how I resolve this issue?
Thanks
Resolved:
As suggested changing the Stored Procedure to a Function within Oracle did resolve the problem of Spotfire complaining about OUT parameter:
CREATE OR REPLACE FUNCTION SCHEMA.MyFunc
(
  p_Equipment_code IN varchar2,
  p_FromDate IN Timestamp,
  p_ToDate in timestamp
)
return SYS_REFCURSOR
AS p_ResultSet sys_refcursor;
BEGIN
    OPEN p_ResultSet FOR
    -- Obtain required data
return  p_ResultSet;
END MyFunc
/

Comment: The doc is inconclusive - it mentions "(also known as Table Function)". A table function in Oracle is a `FUNCTION` (not `PROCEDURE`) that returns a table of ..., see http://docs.oracle.com/cd/B19306_01/appdev.102/b14289/dcitblfns.htm#CHDIIFEG
Answer: you might try something like this
CREATE OR REPLACE FUNCTION SCHEMA.MyFuctRC
(
  p_Code IN varchar2,
  p_FromDate IN Timestamp,
  p_ToDate IN timestamp
)
Return sys_refcursor

AS
my_rc sys_refcursor ;
BEGIN
   OPEN my_rc FOR
   -- your select statement

   return my_rc;

END MyFuctRC;
/


Testing HTTP status codes

Question: I'm running an Apache Tomcat server. Making some security testing I'd noticed than my server is returning a 200 HTTP status code of the default error page when I try to access to a non-existent element instead of return a 404 status code and redirect me to the default error page. I suspect that this is not the only fail with this issue.
Anyone can suggest me a process to check the most common HTTP status codes?
Answer: I would use a Bash script that invokes netcat once for each response type, with appropriate input to generate each different kind of response code.  I would pipe this though grep to check for the correct response and echo out a message on STDERR if it's not correct.
This should be relatively easy for the 2xx, 3xx and 4xx ranges assuming there exist URLs on your server that actually generate each different response code.  The 5xx ranges refer to server-side errors, so to deliberately invoke them you will need to set up specific URLs on your server that cause each error.  The 1xx range are probably best tested using a more complete HTTP client such as curl or wget.
There is most likely more than one way to solve this problem.

There's a nasty bug in some version of netcat that means that it exits as soon as it has finished reading from STDIN.  Also, the man pages shipped with this buggy version include an example that doesn't work.  The workaround is the -q <number> option which specifies a number of seconds to hang around waiting for an answer before quitting.
echo -ne "GET / HTTP/1.1\nHost: example.com\n\n" | nc -q 1 example.com 80 | grep -q "HTTP/1.1 301" || echo "HTTP 302 test failed!" >&2

Comment: Thanks for your help. I'd been reading the 'man netcat' page, but I can not figure how to force the server to return the codes. What I'm not understanding?
Comment: I added an example to my answer that avoids the bug I suspect you are running into.

Testing HTTP status codes


Remove  from column headers in tabulator xlsx export

Question: I am using Tabulator as frontend table framework in my browser. Some of my columns have long titles and are splitted by html line breaks (
).
When I download the table data in Excel file format, my column headers (= first row in this spreadsheet export) contain those
 as plain text, e.g.: Foo
bar.
How can I remove these characters in my excel export? Is this even possible? Any ideas?
EDIT
Here a screenshot from my Excel export for clarification:
Comment: I'm not clear on this. Are the `````` created by you as part of the title or by Tabulator when it wraps the titles? You do have an option to specify a download title [Download Title](http://tabulator.info/docs/4.7/download#advanced-title)
Comment: @AdrianKlaver I inserted the `` as part of the title. Huge thanks for the link! Feel free to post it as an answer and I will accept it
Answer: You can specify the title you want to be substituted for in the download here  Download Title as:
columns: [
    { title: "Name", field: "name", titleDownload: "Full Name" } //change column title to "Full Name" in download
]

If you really want to customize things you build your own custom file formatter Custom Format.


Como alterar estado de objetos complexos no React?

Question: tenho o seguinte objeto:
obj = {
  title: "obj1",
  tab: [{
     title: "titulo da tab 1",
     card: [{
        title: "card1",
        url: "url",
        image: "image"
     },
     {
        title: "card2",
        url: "url",
        image: "image"
     }]

  },
  {
     title: "titulo da tab 2",
     card: [{
        title: "card3",
        url: "url",
        image: "image"
     },
     {
        title: "card4",
        url: "url",
        image: "image"
     }]

  }
]

}
quando quero alterar o estado de uma variavel no react uso
setState({obj1: data})

quando quero alterar o estado de uma propriedade de um obj eu uso:
setState({obj1: {...this.state.obj1, title: "new title"} })

mas minha dificuldade é:

Como alterar o titulo de um card no obj?
Como alterar um titulo de tab no obj?
Answer: Para estrutura largamente aninhadas eu acho preferível:

Replicar o estado num objeto local, de forma a preservar o original.
Alterar o que pretende nesse objeto
Chamar o setState com esse novo estado

Exemplo:
const novoEstado = Object.assign({}, this.state);
novoEstado.obj1.tab[1].card[0].title = 'Novo titulo de um card';
novoEstado.obj1.tab[0].title = 'Novo titulo para o primeiro tab';
this.setState(novoEstado);

O Object.assign replica o estado que tem num novo objeto, preservando o original e seguindo o que a documentação indica de não alterar o estado diretamente.
Comment: é this.state mesmo ou é this.state.obj1 ? na linha 1
Comment: @JulioHenrique Foi lapso meu, não reparei que o estado tem como objeto raiz o `obj1`, mas a ideia é capturar o estado todo que é mais fácil. Vou ajustar


Break não funciona no foreach

Question: eu tenho um foreach dentro de outro foreach que vai rodar por vários valores de um objeto em específico. Mas eu preciso parar os dois foreach's quando ele entrar dentro do if, porém o comando break não funciona por algum motivo, ele simplesmente continua rodando os dois foreach's. O código é mais ou menos assim:
foreach($conteudo["data"] as $oddss) {

    foreach($oddss["types"]["data"] as $oddss2) {
        if($oddss2["type"] == "1x2") {

            $bookmarker = $oddss["bookmaker_id"];

            foreach($oddss2["odds"]["data"] as $oli) {

                switch($oli["label"]) {
                    case 1:
                        $cotCasa = $oli["value"];
                        break;
                    case 2:
                        $cotFora = $oli["value"];
                        break;
                    case "X":
                        $cotEmp = $oli["value"];
                }

            }
            break;
        }
    }

}

Comment: Não entendi muito bem, tem `break` ali que se refere ao `switch`. No `} break;}` coloque `break 2;` veja se esse é o resultado desejado.
Comment: Era exatamente isso que eu precisava. Eu não sabia que existia esse break 2. Obrigado!
Comment: Pode ser qualquer número só não pode ser uma variável :)
Comment: Ta bem, valeu!!
Answer: O break está saindo do switch e não do foreach, mude ele para if/elseif que não precisa de break para sair e aí o break sairá do foreach. Ou use o break 2 para fazer duas saídas, uma do switch e outra do foreach.
Comment: Obrigado, isso que eu precisava!

Break não funciona no foreach


Integrate upper $n$-sphere

Question: For a class on Monte-Carlo simulation methods I want to do a comparison of Monte-Carlo integration and numerical integration on sparse grids. For this purpose I need a function $f$ defined over the $n$-dimensional hypercube $[-1,1]^n$ of which I know the value of the integral $\int_{[-1,1]^n} f$ in order to compare the calculation errors of the different methods. I thought about integrating the unit $n$-sphere as this is defined over the hypercube and the exact volume of the unit $n$-sphere is given by
$$V_n=\frac{\pi^{\frac{n}{2}}}{\Gamma (\frac{n}{2} +1)}$$
Now integrating the whole $n$-sphere will result in the integral being 0 as it is symmetric. That's why I thought about using only the upper unit $n$-sphere. Then the value of the integral would be given by $V_n/2$. However, I did not manage to come up with a function describing this upper half of the $n$-sphere. In the 2-dimensional case the upper sphere $U_2$ would be given by $U_2=\left\{ x_2= \sqrt{1-x_1^2},x_2\geq 0\right\}$ or in the more general case of the unit $n$-ball $U_n=\left\{ \sqrt{1-\sum_{i=1}^{n-1}{x}_{i}^{2}},x_n\geq 0 \right\} $.
Is there a way to express $U_n$ as a function that I could plug into my implemented integration algorithms to integrate it over the $n$-dimensional hypercube?
Comment: The assertion "[the unit $n$-sphere] is defined over the hypercube..." is not true if $n \geq 2$. (The "shadow" of an ordinary hemisphere is a disk, not a square.) Separately, it's not clear what you mean by "integrating the whole $n$-sphere will result in the integral being $0$ as it is symmetric".
Comment: I think you want: The unit sphere is the union of two graphs $x_{n+1} = \pm\sqrt{1 - \|x\|^{2}}$ over the _unit ball_, the set of $x = (x_{1}, \dots, x_{n})$ in $\mathbf{R}^{n}$ where $\|x\|^{2} \leq 1$.
Comment: So on which set is the unit $n$-sphere defined?
Comment: @YukiJ: Offering a bounty but not awarding it is like making a promise but not keeping it: a very ugly kind of behaviour.
Comment: I am sorry @AlexM. But I Received an e-mail that the bounty will be automatically given to the best answer? Why has this not happened?!
Comment: @YukiJ: From http://math.stackexchange.com/help/bounty: *"If you do not award your bounty within 7 days (plus the grace period), the highest voted answer created after the bounty started with a minimum score of 2 will be awarded half the bounty amount (or the full amount, if the answer is also accepted). If two or more eligible answers have the same score (their scores are tied), the oldest answer is chosen. If there's no answer meeting those criteria, no bounty is awarded to anyone."* Since the only answer had less than 2 votes and it was not accepted, no bounty got awarded.
Answer: Why don't you try polynomials - the simplest of the non-trivial examples? Choose a degree $d \in \Bbb N$ and a set of coefficients $\{a_{i_1, \dots, i_n} \mid i_1 + \dots + i_n \le d\} \subset \Bbb C$ and consider the associated polynomial $p(x_1, \dots, x_n) = \sum _{i_1 + \dots + i_n \le d} a_{i_1, \dots, i_n} x_1 ^{i_1} \dots x_n ^{i_n}$. Then
$$\int \limits _{[-1,1]^n} p(x_1, \dots, x_n) \ \Bbb d x_1 \dots \Bbb d x_n = \int \limits _{-1} ^1 \dots \int \limits _{-1} ^1 \sum _{i_1 + \dots + i_n \le d} a_{i_1, \dots, i_n} x_1 ^{i_1} \dots x_n ^{i_n} \ \Bbb d x_1 \dots \Bbb d x_n = \\
\sum _{i_1 + \dots + i_n \le d} a_{i_1, \dots, i_n} \frac {1 + (-1)^{i_1}} {i_1 + 1} \dots \frac {1 + (-1)^{i_n}} {i_n + 1} ,$$
a formula simple enough to let you compare its value with the one that you obtain numerically.

Integrate upper $n$-sphere


How do I make a one-time popup for a webpage?

Question: I have a website and I would like every visitor (or at least every session) to help the site survive. By this, I mean integrating a CoinHive based script so when run once, it will mine (with the user's consent and knowledge) and the popup will automatically close with a popup after this.
For the CoinHive based script, I have the following:

<!DOCTYPE HTML>

  <title> Sample </title>

  <form action="?" method="post">

      Loading Captcha...

  If it doesn't load, please disable Adblock!

    <input type="submit" value="Submit" />
  </form>

For the popup displayed, I have:
function myFunction() {
    alert("Thank you for helping. You may now proceed.");
}

Finally, my text on the popup will be:
Dear Visitors. In order to keep this site running, you are required to complete a one-time captcha. This will require you to just click it and wait, however, it will increase CPU and power usage, so using a PC is recommended. This should be the only time you see this. Thank you and sorry for inconvenience.
Could someone help make this into a popup where this is required, users won't be able to scroll or exit and this is one-time?
Answer: You can use localStorage :

More complete answer : Here
I hope to help you.


The existence of a graph homomorphism

Question: Is there a graph homomorphism between the 6-hypercube (https://en.wikipedia.org/wiki/File:6-cube_graph.svg) and the cube (https://en.wikipedia.org/wiki/File:3-cube_graph.svg)?
Comment: The preposition "between" seems a bit confusing here -- an isomorphism is "between"; a homomorphism has a direction, which is more usually expressed by "from ... to".
Comment: Sorry, from the 6-hypercube to the 3-cube.
Answer: A graph $G$ is bipartite if and only if there is a homomorphism from $G$ to $K_2$. So trivially there is a homomorphism from any cube to another. The interesting question for bipartite graphs is whether there is a surjective homomorphism from
one to another.
Edit: View the vertices of $(d+1)$-cube as binary vectors with length $d+1$.
Each vector can be written as $0u$ or $1u$ and the vectors of the form $0u$
form a subgraph isomorphic to $Q_d$. Consider the map that sends $0u$ to $u$
and $1u$ to $u+e_1$, where $e_1$ is the vector of length $d$ with first entry 1 and all other entries 0. Then this map is a surjective homomorphism from
$Q_{d+1}$ to $Q_d$.
Comment: I suspect that there exists a surjective homomorphism.
Answer: Yes. For example, with $A=\{-1,1\}$, associate the vertices of the graphs with vectors in $A^6$ and $A^3$, respectively; then the function that maps $a\in A^6$ to $(\prod_ia_i,1,1)$ is a homomorphism.

The existence of a graph homomorphism


portable daemon management from bash (sysvinit/upstart/systemd)

Question: I have a little shell script which needs to stop a service. This needs to work on ubuntu (14.04), debian and Arch. Right now what I do is similiar to

   case $(cat /etc/issue) in
     *Ubuntu*)
       service command
     *Debian*)
       /etc/init.d/servicename command
     *Arch*)
       systemctl service command
   esac

Is there any better way to do this?
Comment: Just wait a few years. They're all switching to systemd :)
Answer: I would say don't look at the current distro to determine which init system to use to manage daemons:

It's a little nebulous to determine a distro (as described in Dennis's answer)
the init system in use changes between versions of a distro (as Michael Hampton noted, the big name distros are all gravitating toward systemd; Ubuntu is currently the one big-name holdout, and they plan to switch over by 2016).
The init system may be changed on an individual installation from the default (starting with 14.10 Utopic Unicorn this October, some Ubuntu installations may elect to switch over to systemd ahead of time).

Although this isn't foolproof (a system may elect to install multiple init systems alongside each other), the way I would do it is to look for the presence of the tools themselves:
if command -v systemctl >/dev/null; then
  # assume systemd
  systemctl $command $servicename
elif command -v initctl >/dev/null; then
  # assume upstart
  initctl $command $servicename
elif command -v service >/dev/null; then
  # assume old Debian `service` utility
  service $servicename $command

# ... elif cases for any other utils you'd want to check for ...

else
  # assume bare init.d scripts
  /etc/init.d/$servicename $command
fi

This answer to a similar question describes some further heuristics you can use to determine the init system currently in use, for cases where this isn't accurate enough.
Ultimately, though, there's no one way to truly detect which one init system an installation "uses" - it's possible to create a setup that switches between init systems every time it boots.
Answer: i would not go with /etc/issue as this file is sometimes changed or might not even mention the Version.
instead you should in my opinion search for the distribution specific file.
For your part:
Debian: /etc/debian_version
Ubuntu: /etc/lsb-release
Arch: /etc/arch-release

personally i would check for the file existence and "case" it based on that file
see here for some of the other distribution files
linuxmafia.com
Comment: In newer versions of modern distros, you can check the `ID` and `ID_LIKE` fields of [/etc/os-release](http://0pointer.de/public/systemd-man/os-release.html) to determine the current distro (and map it to a list of distros you expect/understand).
Answer: If you have it around for some other reason, facter has a operatingsystem fact that would do what you want.
Answer: Both Ubuntu and debian have the service utility. Use service servicname start|stop for everything but arch.


If an analytic map $f$ has "many" values in a negligible set $B$, does $\text{Image}(f) \subseteq B$?

Question: Let $k>n$ be positive integers, and let $f:\mathbb R^n \to \mathbb R^k$ be a real-analytic map (i.e. every component of $f$ is a real-analytic function).

Suppose that we have a measurable subset $B \subseteq \mathbb R^k$ of measure zero, such that  $f^{-1}(B)$ has positive measure in $\mathbb R^n$. Is it true that $\text{Image}(f) \subseteq B$?

Does anything change if we assume that $B$ is closed?
Here are some nice special cases:
If $B=\{ 0\}$, then the answer is positive: The zero set of a non-zero analytic function has measure zero.
Similarly, if $B$ is a hyperplane in $\mathbb R^k$, then we can compose $f$ with a linear functional which vanishes exactly on this hyperplane and use the previous observation.
Note that if we only know that $B$ is contained in a hyperplane $H$, the only thing we can conclude is that the image of $f$ is contained in $H$. As Holding Arthur's answer shows, we cannot in general conclude that image of $f$ is contained in $B$.
Answer: Are you missing something in your question? Let $f:\mathbb{R} \to \mathbb{R}^2: x \to (x,x)$. Then the set $B=\{(x,x):0\leq x\leq1\}$ have zero measure in $\mathbb{R}^2$, and $f^{-1}(\{(x,x):0\leq x\leq1\})=[0,1]$ has lebesgue measure $1$. But clearly the image of $f$ is NOT in $B$. Please tell me if I have misread your question.
Comment: No, your answer is perfect. I was quite sure there should be a simple counter-example, but somehow I only thought in terms of full hyperplanes, and did not consider subsets of them... Thank you.
Comment: @AsafShachar Glad that it is helpful. I was just shocked because my answer is "too simple"。


Can there be a number which is provably larger than any number, yet is provably not infinite

Question: Suppose a natural number N.
Is it possible for this number to have the following properties:

The number is finite.
The number is greater than any other natural number.
Comment: What's your definition of *natural number*?
Comment: No, because (2) is impossible on its own.
Answer: No. Under this assumption, $N+1$ is also a finite natural number, but $N+1>N$.


force image style generation on save node

Question: I've got still my problem described here Image style, reuse image in field collection item but i gave up to get a solution.
A workaround which came up in my mind is to force the generation of imagestyles on nodesave. are there any possibilites to do so?
Answer: Yes - you can implement hook_node_insert() and hook_node_update() in a custom module and create the images there using image API functions. For example
function MYMODULE_node_insert($node) {
  // Get some field items from a field called 'field_photo.
  if ($image_items = field_get_items('node', $node, 'field_photo')) {
    $image_item = array_shift($image_items);

    // Load the associated file.
    $file = file_load($image_item['fid']);

    // An array of image styles to create.
    $image_styles = array('style_1', 'style_2');

    foreach ($image_styles as $style_name) {
      // Get the location of the new image.
      $derivative_uri = image_style_path($style_name, $file->uri);

      // Create the image.
      image_style_create_derivative($style_name, $file->uri, $derivative_uri);
    }
  }
}

Comment: looks cool thanks! but do you might know how to get the value of the field collection items related to my nodetype?
Comment: Indeed - http://drupal.stackexchange.com/questions/11062/how-do-i-load-a-field-collection-from-a-node :) Oh and in case you need it: http://drupal.stackexchange.com/questions/11062/how-do-i-load-a-field-collection-from-a-node
Comment: i've noticed now, that the generated images are not resized, just stored in the original size. did this ever happen to you and you might have any idea how to solve it?
Comment: @sinini your answer is at http://drupal.stackexchange.com/questions/155823/image-style-create-derivative-not-resizing-the-image/155839#155839
Comment: D7's life is limited, but just in case someone comes across this as I did today, a correction. image_style_create_derivative() expects an array for the first parameter, so that line should be:

image_style_create_derivative(image_style_load($style_name), $file->uri, $derivative_uri);
Answer: The two answers with blocks of code are mostly correct except they are overlooking one major thing:
The first argument of image_style_create_derivative is expected to be an image style array.
What they're passing is just the name of the style. In the foreach if you add:

$style = image_style_load($style_name);

then change $style_name to $style in the image_style_create_derivative function it should work as expected and generate the styled image.

image_style_create_derivative($style, $file->uri, $derivative_uri);

Hope that helps anyone else having this issue.
Answer: Thanks for your help Clive, my whole function for the field collection items:
(another helpful post from you: Accessing a field collection)
function channelportal_gallery_node_update($node) {

  //get all the id's from the field collection values
  $galleryimages = field_get_items('node', $node, 'field_gallery_and_caption');
  $fieldcollectionids = array();

  foreach ($galleryimages as $key => $value) {
    $fieldcollectionids[] = $value['value'];
  }

  // Load up the field collection items
  $items = field_collection_item_load_multiple($fieldcollectionids);

  foreach ($items as $item) {

    $image_item = field_get_items('field_collection_item', $item, 'field_gallery_image');

    // Load the associated file.
    $file = file_load($image_item[0]['fid']);

    // An array of image styles to create.
    $image_styles = array('gallery_big', 'gallery_thumbnail');

    foreach ($image_styles as $style_name) {
        // Get the location of the new image.
        $derivative_uri = image_style_path($style_name, $file->uri);

        // Create the image.
        image_style_create_derivative($style_name, $file->uri, $derivative_uri);
    }
  }
}

Answer: There seems to be a module for that problem:
https://www.drupal.org/project/imageinfo_cache
Have a look at the "Related Modules"-Section on the page, too.
Answer: It's recommended to use both hook_node_insert() and hook_node_update() and to check if the needed image derivatives are not generated, then generate them, otherwise, do nothing.
/**
 * Implements hook_node_insert to generate derivative images for the new inserted node in
 * case they are not generated
 * @param object $node
 */
function YOUR_MODULE_node_insert($node) {
  //REPLACE field_YOUR_IMAGE_FIELD WITH YOUR FIELD IMAGE NAME
  if(isset($node->field_YOUR_IMAGE_FIELD['und'][0]['uri'])) {
    _generate_image_style($node->field_YOUR_IMAGE_FIELD['und'][0]['uri']);
  }
}

/**
 * Implements hook_node_update to generate derivative images for the new updated node in
 * case they are not generated
 * @param object $node
 */
function YOUR_MODULE_node_update($node) {
  //REPLACE field_YOUR_IMAGE_FIELD WITH YOUR FIELD IMAGE NAME
  if(isset($node->field_YOUR_IMAGE_FIELD['und'][0]['uri'])) {
    _generate_image_style($node->field_YOUR_IMAGE_FIELD['und'][0]['uri']);
  }
}

/**
 * Generates the needed image styles by the image uri if they are not already generated
 * @param string $image_uri
 */
function _generate_image_style($image_uri) {
  //This should be changed to your image styles names.
  $image_styles = array('image_style_name1', 'large_image', 'promo_image');
  foreach ($image_styles as $style) {
    $derivative_uri = image_style_path($style, $image_uri);
    file_exists($derivative_uri) || image_style_create_derivative(image_style_load($style), $image_uri, $derivative_uri);
  }
}

Note: If your image field take multiple images then you should loop through them like that:
if(isset($node->field_main_image['und']) && is_array($node->field_main_image['und'])) {
  foreach($node->field_main_image['und'] as $delta => $image_field) {
    _generate_image_style($node->field_YOUR_IMAGE_FIELD['und'][$delta]['uri']);
  }
}

The image styles generation is taken from here


Count data is numerical or categorical?

Question: I am working on road network data (csv) and my data has 6 features. Two of these features are continues and three of them are categorical. One of the these features is number of lanes of street. This feature shows how many lanes a road has. For instance, a road has two lanes a road has 4 lanes and so on. Plus, following image shows a road which has three lanes (this is an image just to show what is my mean exactly and my data is csv file).

I have three questions as follows:

The number of lanes is categorical or numerical? in some resources I read count data are categorical and some resources categorized them as numerical!!!! could you please let me know number of lanes is categorical or numerical?

What approaches you suggest to cluster a data with various data type (mixed quantitative and qualitative)?

Can I transform the continues data to categorical data and then perform clustering analysis?
Comment: Counts can be either of the three options: Scale (interval or ratio), categorical (ordinal, most likely), count. The third option, count, means it is a special quantitative feature called "frequency" which is similar but not identical to ratio scale. The choice is the investigator's and in a particular project.
Comment: @ttnphns could you please make clear your comment by an example to me how a count data can be ordinal?
Answer: The word numerical means 'consisting of numbers' ('expressed in or counted by numbers' in one dictionary). Counts are clearly numerical. Indeed they have a meaningful zero and '6' is literally twice as much as '3' and three times as much as '2' ... and so forth (3 bricks + 3 bricks = 6 bricks, etc,.. so 6 bricks is twice as many bricks as 3 bricks), so if you're considering Stevens' typology, arguably ratio scale to boot.
What matters more is how you see it coming into your model.
If you're reading a book that's telling you how to treat variables based only on the division 'categorical' or not, you may sometimes be led into poor choices of analysis.
You can bin variables. You can forget the bin boundaries and make them into (ordered) categories. You can even ignore the ordering. Every one of those steps result in loss of information, and in many cases the
introduction of bias, so the larger question is not whether you can, but whether you should. If you step back from "must use clustering" for a moment, what are you trying to achieve with it?
Comment: Data being on {0,1, 2, ...) doesn't make it a count, though. The variable was explicitly identified as a count in this case.
Comment: Those are certainly categorical or ordered categorical, but I don't quite see how that relates to the issue of the count of the number of lanes on a given road
Comment: +1 The one caveat that comes to mind is when clearly categorical data are encoded as categories 0, 1, 2, etc, though number of road lanes is not such an instance.
Comment: @Glen_b Thank you so much for your clear description. I tried to change the data type to categorical because the categorical features contain text. For example, one of the road features is road type and its values are highway, local road, second road, and primary road. So I need to convert them to categorical data in order to be able to perform clustering techniques like AHC or k-median on my data.
Answer: In a measurement theory sense, the count of the number of lanes is a ratio variable, since it is meaningful to interpret differences between numbers of lanes and ratios of numbers of lanes.  This means that you have the option of treating this variable either as a nominal, ordinal, or ratio variable in your statistical mode.  The choice of whether to treat the number-of-lanes as a categorical variables is a modelling choice that will depend on the degree of flexibility you wish to have in how the number-of-lanes might be statistically related to the outcome variable.  (It is not really helpful to ask if it is "numeric" --- that term largely refers to the way in which statistical computing packages store a variable, rather than referring to a measurement scale.)
For example, if you were to treat the number-of-lanes as a categorical variable, there will be no constraint on the effect of each category on the outcome.  Now, there is obviously an ordinal aspect to the number-of-lanes variable, with more lanes indicating a larger type of road, so you might decide you want to constrain the effects of the categories so that they obey some kind of ordinal (or perhaps even linear) effect size on the outcome variable.  This is a modelling choice you will need to make based on a combination of things; the a priori coherence of possible effects, the empirical data, diagnostic testing, etc.
Comment: Thank you so much for your response. Could you please look at [https://stats.stackexchange.com/questions/541937/clustering-a-dataset-with-mixed-skewed-semi-correlated-and-unscaled-values] and let me your answer? if it is wrong that I call you in the comments, I apologize in advance and I will do not that again.

Count data is numerical or categorical?


iCarousel in Xcode 5.0.2, multiple carousels in one view controller not getting caraousel's instance

Question: Created a project in Xcode 5.0.2 with storyboarding, autolayout and 3 carrousel's in one viewcontroller

imported icarousel in the viewcontroller.
Connected delegate, datasource.
Connected carousels to different objects of icarousels.
<code>@property (nonatomic, strong) IBOutlet iCarousel *carousel1;
@property (nonatomic, strong) IBOutlet iCarousel *carousel2;
@property (nonatomic, strong) IBOutlet iCarousel *carousel3;
</code>

When I run the project delegate, datasource are working fine, but when i am trying to check the instance as below
<code>    - (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
    {
        //return the total number of items in the carousel
        //return the total number of items in the carousel
        NSLog(@"Carousel%@", carousel);
            NSLog(@"carousel1%@", carousel1);
        NSInteger itemsTMP;
        if (carousel == self.carousel1)
        {
            itemsTMP = [_items count];
        }
</code>
In the nslog it showing as NULL for carousel1.
All the connections seems to be perfect. Unable to figure out the mistake.
Comment: Created one more project by including only iCarousel and it seems to be working fine. But in the current project RestKit is added to the project using cocoapods.Not able to figure out the error.
Comment: 2013-12-13 15:55:54.311 carouselApp[26002:70b] Carousel: >
2013-12-13 15:56:34.410 carouselApp[26002:70b] Carousel: >
The carousels frame is same as the views present in the storyboard view. But when checked for name its not matching.
Answer: Hate to overstate the obvious here, but the fact that no '*' precedes the carousel1 property would be the first remedy I'd perform.
Comment: @Mija: I had to change the names of the objects before posting the query but the actual code has '*'.Missed it. Thanks. Edited it.
Answer: No problem with RestKit adding to the project. Still not sure. How to solve the problem.
Followed below steps to overcome the issue:
 1. Deleted the old view and associated view controllers.
 2. Created new view, New controller. Be careful with connections and remove it before deleting any associated views.
3. Hurray the got instances of carousels worked.
But above seemed like a work around but still didn't figure out the issue.


como usar o LDAP_BIND no php utilizando NTLM2?

Question: estou utilizando ldap com NTLM para fazer SSO "LOGON UNICO" porem estou tendo uma dificuldade,
o LDAP_BIND não aceita a senha em hash que eu recebo do navegador,
minha classe que trabalha com NTLM tem as seguintes variáveis:
$auth = getAuth(); //RETORNA O NTLM TRABALHADO

        //$auth['user'] = $user;
        //$auth['domain'] = $domain;
        //$auth['workstation'] = $workstation;
        //$auth['clientblob'] = $clientblob;
        //$auth['clientblobhash'] = $clientblobhash;

          $con = ldap_connect('meudominio.com');
          ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
          ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
          ldap_bind($con, 'dominio\user', $auth['clientblob']);

ERRO> Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Invalid credentials in...
Obs: o LDAP_BIND funciona somente se eu usar a senha em string;
Comment: A senha que você passa para o `ldap_bind` tem que ser em plain text. Pelo menos todos os locais que implementei este tipo de autenticação, tive que fazer em plain text.
Comment: A senha que o NTLM envia não esta em texto plano...
O ntlm que criptografa a senha ? ou ele envia a senha já criptografada ? estou com essa dúvida tb.
Se for criptografada pelo NTLM2 como descriptografar ?
Desde ja agradeço a ajuda.
Answer: Respondendo sua pergunta nos comentários, que é mais simples: NTML não é um protocolo de criptografia, e sem um protocolo de autenticação baseado em challenge-response que faz uso de funções de hash para "ocultar" a senha e então trafegá-la.
Não é possível utilizar LDAP+NTLM em PHP diretamente através do mod_ldap, pois ele foi feito para seguir rigorosamente o protocolo LDAP. Utilizar NTLM sobre LDAP, tal qual a Microsoft faz, é uma extensão à funcionalidade tradicional do LDAP. Com certeza ele pode ser implementado, mas é necessário fazer engenharia reversa dos parâmetros utilizados pela Microsoft, uma vez que estes não são documentados.
A API da Microsoft responsável por fazer isso no Windows, é a ldap_bind_s [1].
Uma opção que não envolve todo esse esforço, é utilizar o mod_auth_ntlm_winbind, que implementa este tipo de autenticação. Talvez utilizando Kerberos mod_auth_kerb também seja possível, mas não sei ao certo. Mas, se você deseja apenas pegar o nome de usuário logado na máquina acessando seu site, este link provavelmente irá resolver o seu problema.
Em todo caso, recomendo que não "confie" no usuário/domínio enviado para você pelo browser: não é nem um pouco difícil forjar esta informação, especialmente se o sistema for acessado de fora da sua intranet. Para isto, recomendo que use LDAP + SSL (ou TLS), que apesar de exigir usuário e senha, trafegam as informações criptografadas e é de fácil implementação (mod_ldap já possui implementado). E não se esqueça de usar HTTPS na sua página de autenticação!


Filtro em update de uma tabela com base informações de uma outra tabela

Question: Olá, preciso fazer um UPDATE em uma tabela (no exemplo a tabela 'reservas'), com base em informações de uma outra tabela (no exemplo a tabela 'administracao'). Bom até ai consegui fazer com a ajuda de uma pessoa aqui do fórum...
Exemplo do que já tenho: (realiza o update na tabela 'reservas' se não existir a duplicação dos mesmos registro na tabela 'administracao').
UPDATES reservas t1 SET t1.status_reserva = 'Entregue' WHERE NOT EXISTS (SELECT * FROM administracao t2 WHERE t2.cod = t1.cod1 )
Agora preciso fazer isso, só que colocando um filtro para que o UPDATE execute apenas se o campo 'status_reserva' for diferente da palavra 'Cancelado'.
Tentei fazer da seguinte forma, porem não funcionou:
UPDATES reservas t1 SET t1.status_reserva = 'Entregue' WHERE NOT EXISTS (SELECT * FROM administracao t2 WHERE t2.cod = t1.cod1 ) AND status_reserva != 'Cancelado'
Por favor, alguém que tenha uma solução para esse problema, ou se não é possível fazer isso?!
Comment: O possível problema seria que você não está indicando de qual tabela pegar essa coluna `status_reserva`? Que no caso seria da seguinte forma `t1.status_reserva`
Comment: :( Não deu certo. Dessa forma não executa o Update, ele não reconhece se o campo `status_reserva` está ou não preenchido com a palavra `Cancelado`, haveria outra solução?
Comment: Postei duas soluções as quais necessito que teste em seu código, pois não estou com meios de testar no momento! Haha
Answer: Você poderia simplesmente estar fazendo um LEFT JOIN e verificando se ele é NULL no final... Ficaria algo +/- dessa maneira:
UPDATE reservas t1
LEFT JOIN administracao t2
ON t2.cod = t1.cod1
SET t1.status_reserva = 'Entregue'
WHERE t2.cod IS NULL && t1.status_reserva != 'Cancelado';

Ou até mesmo passar a condição do status_reserva para antes do EXISTS:
UPDATES reservas t1 SET t1.status_reserva = 'Entregue' WHERE t1.status_reserva != 'Cancelado' AND NOT EXISTS (SELECT * FROM administracao t2 WHERE t2.cod = t1.cod1 )

Veja se algum deles se adequa ao que você deseja fazer em seu código... :)
Comment: Consegui com a segunda solução apresentada, muito obrigado!!!


Search API requirements

Question: I'm trying to get the Search API module to work on my Drupal 7 installation, but I get the following error when I go to Home » Administration » Configuration » Search and metadata » Search API » Default node index:

The server this index currently lies on doesn't support facets. To use facets you will have to move this index to a server supporting this feature.

What steps should I follow, in order to make my server compatible with the Search API module?
Comment: What search server are you using (MySQL Solr etc)?
Comment: i'm using mysql
Answer: You can't use facets on MySQL (for the moment), from the project page:

Search facets
This module provides the ability to create facets on any search executed anywhere in Drupal, be it a search page, a view or any other source. The feature isn't available for all servers, though, since it would be too complex to implement for some service classes. Right now only the Solr servers support this, facet support for the database-based searches might be done in the future.

This means that you can't use facets, but you can still use Search API to search your content.
Comment: @matthewL Did you install and enable the [Search API Solr](http://drupal.org/project/search_api_solr) module? Did you copy the schema.xml and solrconfig.xml to the Apache Solr folder? Did you restart Solr one that was done?
Comment: oh so i need to install solr that's all ?
Comment: is it ok if i install apache-solr-1.4.1.zip ?
Comment: @matthewL What is described as "Solr server" is Apache Solr. It runs as Java servlet, and it requires a server like Tomcat, or other similar servers that runs as servlet container.
Comment: unfortunately i get same error even tho i sucessfully configured sorl, and apache solr module is configured perfectly and can communicate with solr on port 8080... not sure what to do now
Comment: yes, and then i configured the solr port and site on drupal, and it gave green message that it connected sucessfully.
Comment: one more thing, if i go configuration, search api, settings, edit (drop down), settings > on server there is no option to choose from, it says , and when i installed drupal i had only one option for sql server (sqllite) not the mysql server that i had configured
Comment: @matthewL Did you create the Solr server in the Search API interface?
Comment: @matthewL I just tested and you don't actually need Solr to setup the search index. You will need it to actually index the content. What you are missing is to create the server in the interfacer which is just an URL for a Solr server. You do this by clicking the add new server button.
Comment: i clicked Add Server in `config/search/search_api/add_server` and Service class is empty ``
Comment: @matthewL Then you are missing the search_api_solr module
Comment: yes, this fixed it!
Comment: ok maybe i dont see the bigger  picture  here , i had apache solr modules installed... hmm is there a overview of the whole installation procedure or other docs i should read? thanks again for help with this issue
Comment: There's a tonne of SOLR guides on the internet, google. This would be a good starting read https://drupal.org/node/504574

Search API requirements


How to use switch case with nullable string (*string) in Golang?

Question: Here is my code:
func ToSomething(arg *string) string {
    switch arg {
    case nil:
        return "something1"
    case "args1":
        return "something2"
    case "args2":
        return "something3"
    default:
        return "something4"
    }
}

It shows a red line under args1 and args2 that says

Invalid case '"args1"' in switch on 'arg' (mismatched types 'string'
and '*string')

anyone knows to use switch case with nullable string (*string) properly in golang?
Here is a go playground: https://go.dev/play/p/0TaeXSEIt06
Comment: Comparing a pointer to a string with a string is not going to work. You'll need to compare the dereferenced pointer's value.
Comment: I think thinking of pointers as "nullable strings" is the wrong mental model for pointers, and it's leading you towards some incorrect expectations for how comparisons between pointers and non-pointers work. Nullable types in other languages are not the same things as pointers, even though they may have similarities. A pointer contains an address to some other piece of memory, and you need to traverse *through* the pointer to reach the thing you want to perform comparisons on.
Answer: Since arg is of type *string, you'd have to list values of *string in the case branches.
But! You obviously want to match the pointed string values, so listing *string values is not what you want: that checks for pointer equality.
So instead you should not use arg as the switch expression, but provide sensible conditions on the case branches like this:
func ToSomething(arg *string) string {
    switch {
    case arg == nil:
        return "something1"
    case *arg == "args1":
        return "something2"
    case *arg == "args2":
        return "something3"
    default:
        return "something4"
    }
}

Testing it:
ptr := func(s string) *string { return &s }

fmt.Println(ToSomething(nil))
fmt.Println(ToSomething(ptr("args1")))
fmt.Println(ToSomething(ptr("args2")))
fmt.Println(ToSomething(ptr("xx")))

Output (try it on the Go Playground):
something1
something2
something3
something4

Answer: Each case must be the same type as arg. In your example, arg is *string and each case is string.
You could dereference arg:
func ToSomething(arg *string) string {
    if arg == nil {
        return "something1"
    }
    switch *arg {
    case "args1":
        return "something2"
    case "args2":
        return "something3"
    default:
        return "something4"
    }
}

Here is the playground.


TFS Build Template Nested Arguments

Question: Is it possible to nest TFS build template arguments in one another?
Example (Set via build definition ui):
$(ToolsRoot) = E:\BuildTools

$(MSPECTools) = $(ToolsRoot)\MSpec\

Alternatively, is it possible to use environmental variables.
I have tried both, and neither seemed to work.
I need to find a way of setting the build root dynamically, as it differs on our various build servers.
Answer: I suppose you have implemented a topology like the this:
So, you need to control the root for each Agent.If you open the TFS Admin Console > Build configuration in Build Machine #1 you 'll see the Build Controller & Agents A.1 & A.2.If you open TFS Admin Console > Build configuration in Build Machine #2 you 'll see Agents A.3, A.4, A.5 & A.6.
For any given build Agent, if you click on "Properties" you 'll see the "Working Directory" entry, which typically is set to something like $(SystemDrive)\Builds\$(BuildAgentId)\. On runtime this is transformed into something like C:\Builds\55.
For any given build, in the build definition area "Workspaces" this "Working Directory" equals the entry $(SourceDir).
Suppose you have set in Agent A.1 a working directory "C:\A.1\Build" & in Agent A.2 "C:\A.2\Build". In order to get what you need, you have to set in the build definition a mapping to $(SourceDir)\Template
Comment: See also section "More about the Working Directory Property" of http://msdn.microsoft.com/en-us/library/bb399135.aspx
Comment: Hi, thanks for a great answer. The topology is correct. Unfortunately my example was a bit misleading, my bad. The folders I need to set are not the working directory, but actually folders containing our build tools and unit test runners.

TFS Build Template Nested Arguments


Projection of Dirichlet distribution

Question: Suppose we have a random vector $(X_1,\dots,X_n)\sim Dir(\alpha_1,\dots,\alpha_n)$.
What is the distribution of $(X_1,\dots,X_n\mid X_1=x)$?

Intuitively, I would think a set value of $X_1$ does not affect the proportion between other random variables in the vector, i.e., the remaining random variables are distributed according to a scaled down version of a Dirichlet distribution: $(X_2,\dots,X_n)\propto (1-x) Dir(\alpha_2,\dots,\alpha_n)$. However, I am not sure how to prove this rigoroulsy.
Under the assumption that the pdf $f'$ of the Dirichlet distributed with $X_1$ projected away obeys $f(x_2,\dots x_n;\alpha_2,\dots,\alpha_n)\sim \prod_{i=2}^n x_i^{\alpha_i-1}$ it is easy to show that the claim above holds, but I am again not sure how to argue that this assumption indeed holds.

Bulding on @Renato Fernandes comment:
By conditional probability we have
$f_{X_2,\dots,X_n\mid X_1}(x_2,\dots,x_n\mid x)=\frac{f_{X_1,\dots,X_n}(x,x_2,\dots,x_n)}{f_{X_1}(x)}$
where the pdf in the numerator is the standard Dirichlet pdf and in the denonimator we have a Beta distribution pdf as $X_1\sim B(\alpha_1,\sum_{i=2}^n \alpha_i)$. Plugging this in:
$
\begin{align}f_{X_2,\dots,X_n\mid X_1}(x_2,\dots,x_n\mid x)
=&\frac{f_{X_1,\dots,X_n}(x,x_2,\dots,x_n)}{f_{X_1}(x)} \\
=&\frac{\frac{1}{B(\alpha_1,\dots,\alpha_n)}\prod_{i=1}^n x_i^{a_i-1}}{\frac{1}{B(\alpha_1,\sum_{i=2}^n \alpha_i)}x^{\alpha_1-1}(1-x)^{\sum_{i=2}^n \alpha_i}} \\
=&\left(\frac{1}{B(\alpha_2,\dots,\alpha_n)} \prod_{i=2}^n x_i^{\alpha_i-1}\right) \frac{1}{(1-x)^{\sum_{i=2}^n \alpha_i}}
\end{align}
$
Now the first part is almost the pdf of a Dirichlet again. The subtle difference is that the support of this pdf is defined by $\sum_{i=2}^n x_i = 1-x$ instead of the sum being $1$ as for a standard Dirichlet distribution. We can fix this by scaling each variable and define $x'_i=x_i/(1-x)$. We then have
$f_{X_2,\dots,X_n\mid X_1}(x_2,\dots,x_n\mid x)=\left(\frac{1}{B(\alpha_2,\dots,\alpha_n)} \prod_{i=2}^n x_i'^{\alpha_i-1}\right)\frac{1}{(1-x)^{n-2}}$
Now here's where I'm confused: As this is still a pdf, this should integrate to $1$. The first (bracketed) part is a standard Dirichlet distribution as we made sure the support is exactly all vectors $(x_2,\dots,x_n)$ summing to $1$. So this should also integrate to $1$. However, the second term is constant for a given $x$, so the integral would be $\frac{1}{(1-x)^{n-2}}$ which cannot be. So where is my mistake in the derivation?
The mismatch seems to stem from the fact that the exponents in the pdf are reduced by $1$, but when determining the parameters of the marginal distribution of $X_1$, we just sum all parameters $\alpha$.
Comment: Did you Tried to use the conditional probability? It may work, because We have that $P(X_2, \ldots, X_n | X_1 = x) \cdot P(X_1 = x) = P(X_1 = x, \ldots, X_n)$ and $X_1$ has a Beta distribution. https://en.wikipedia.org/wiki/Dirichlet_distribution
Comment: I tried and it was very promising, but I think I made a mistake somewhere. I will expand my question an explain.
Answer: You have some small mistakes:

First the beta distribution density is: $$f_{X_1}\left(x\right) = \frac1{B\left(\alpha_1, \sum_{i=2}^n \alpha_{i}\right)} x^{\alpha_1 - 1} (1-x)^{\sum_{i=2}^n \alpha_i - 1}$$

Second when you do a subtitution you need to multiply by the Jacobian of the transformation. Let $U_j = \displaystyle\frac{X_j}{1-x}$, $$f_{U_2,\ldots,U_n}\left(u_2,\ldots,u_n\right) = f_{X_2,\ldots,X_n | X_1}\left(x_2,\ldots,x_n|x\right) \times \left|\frac{\partial U}{\partial X}\right|^{-1} = \cdots$$

Can you continue from here?
Comment: Thanks! The first point is actually just a typo, i accounted for the $-1$ going forward. The second point fixed the integration. Also it made me realize that, if we scale down all variables by a factor of $(1-x)$, the integral w.r.t. the $x'_i$s actually *should* be $(1-x)^{n-2}$ since we integrate over a $n-2$-dimensional simplex (one dimension less since $x_1$ is missing and one less since $x_n$ is dependent)
Comment: @PattuX Exactly

Projection of Dirichlet distribution