ZFS: Best-practices doc state: "On systems with 1,000s of ZFS file systems..."?

Question: The docs state:
"On systems with 1,000s of ZFS file systems, provision 1 GB of extra memory for every 10,000 mounted file systems including snapshots."
What does that mean - how do these people use ZFS? Are they using ZFS inside per-user mounted files? Or does it refer to really huge datacenters??
I always thought ZFS advocates for a single file-system, a giant one. Why do the docs talk about people mounting 1000s??
Comment: I'm struggling to find an answer to this question, we're a Q&A site, not a discussion site - could you edit your question to make it more easily answerable please. If it's just "Do people really mount tens of thousands of ZFS filesystems" then I'm not sure what benefit the question would have other than out of curiosity.
Comment: You actually catched me misusing serverfault - agreed.
Answer: You are missing some of the basic concepts of ZFS. ZFS is meant to be one large pool of disks.
After you have established the pool, you are suposed to put file systems on the disks of the pool. All of these file systems then benefit from the pool's underlying RAID layout and other IO characteristics (ZIL et al). Seeing 1000s of file systems reside on a pool is a possible scenario on larger systems.
Comment: OK. For me ZFS was mostly a file-system. My mistake: I didn't separate that ZFS does pooling and file-system, as I would use it to pool and build one big fs inside.
Comment: So each ZFS dataset in a ZFS pool is a separate filesystem. I have about 20 datasets in a 2-disk mirror pool in a small company.
Answer: A potential use-case for ZFS that would see thousands of filesystem mounts would be an organization that uses ZFS for NFS-mounted home directories. Imagine a large company or small university with zpools dedicated to home directory exports. Each user could have a dedicated ZFS filesystem with separate quotas and parameters. If rolling snapshots are implemented, it would be possible for users to see previous versions of their files by descending into the ~/.zfs/snapshot directory. Self-service restores!
Comment: Be aware that ZFS de-duplication is not really supported in production on ZFS appliances.
Comment: That's what I oversaw: I was so consumed by the perspective of having a central /home dir and populating userdirs in there that I oversaw that it might be nice to separate/ lock users into their own filesystem (!), while still being able to let ZFS deduplicate, compress etc. one level below, technically on block level (right?). I think it came from me being very shocked the other day, when I saw people backing up solid 90GB VHDs containing one nearly empty fs each.
Comment: And I am on Linux... No dedup anytime soon. Was dreaming... I guess.
Comment: right, so given this situation given enough disk can zol handle 10s of thousands of filesystems? it is very memory intensive?
Comment: @Stu Sure it can.
Comment: Thanks for the reply, are there any known limitations or documentation on where it starts to fall apart? Lots of filesystems? Lots of files in a few filesystems? Millions of snapshots on large filesystems? Anything like that?


Random slopes for interactions without random slopes for main effects?

Question: I have a GLMM with the following form:
m1 <- glmer(Y ~ A*B + (A*B|Subject), data, family=binomial(logit))

where A and B are categorical factors with 2 levels, and Subject is my grouping factor, with a relatively small number of levels (e.g., 10). A likelihood ratio test indicates that the random slope for the interaction A:B makes a significant contribution to the fit of the model, so I keep it.
Let's say I have no prior hypothesis about the structure of the random effects, and I want to find the model that provides the best and most parsimonious description of the data. Does it makes sense to proceed testing random slopes for the main effects?
More specifically, is it appropriate to compare (with a likelihood ratio test) the model above (m1) with this reduced model where I removed the random component for one of the main effects?
m2 <- glmer(Y ~ A*B + (A + A:B|Subject), data, family=binomial(logit))

I would say that intuitively it makes sense, as m2 would be a model where the effect of B is pretty much constant for all subjects, while the magnitude of the interaction A:B varies from subject to subject. However I am wondering whether in practice one can distinguish between variability in the effect of B vs. variability in the interaction A:B. I know that, for fixed-effects predictors, it is generally wrong to fit a model that has an interaction term without including the main effects marginal to that interaction, so I guess that I am asking whether I should respect the marginality principle also for testing random slopes.
Thanks!
Answer: I'm not sure this makes sense.
First of all, it won't work the way you expect: A:B will expand to a model of the same dimensionality as A*B (and lme4 isn't quite as smart as it might be about handling the redundancies
set.seed(101)
dd <- expand.grid(A=factor(1:2),B=factor(1:2),Subject=1:40,rep=1:20)
dd$Y <- simulate(~A*B+(A*B|Subject),
                 newdata=dd, family=binomial,
                 weights=rep(1,nrow(dd)),
                 newparams=list(beta=rep(1,4),
                                theta=rep(1,10)))[[1]]
library(lme4)

Your original model:
m1 <- glmer(Y ~ A*B + (A*B|Subject), dd, family=binomial)

This gives convergence warnings, and ends up with a log-likelihood 0.003 less than the original (basically, numeric fuzz)
m2 <- update(m1, . ~ A*B+(A+A:B|Subject))

This is also equivalent:
m3 <- update(m1, . ~ A*B+(A:B-1|Subject))
all.equal(logLik(m1),logLik(m3),tolerance=1e-4) ## TRUE

If you really wanted to leave out the main effect of B you'd have to use dummy variables.
For the meaning of this: can you explain what the model would mean? In particular, the model that you intend (not what lme4 actually does) when you use (A+A:B|Subject) would have among-individual variation in the effects of A, no effects of B at the baseline value of A (assuming you are using the standard treatment contrasts), but variation in the effect of adding B to A. Another analogy would be to a model with fixed intercepts but variable slopes.
Comment: thanks! for the meaning, `A` indicates the experimental condition; `B` is a factor that has weak effects (with very small individual variation) in the condition corresponding to the baseline value of `A`, but larger effects (with larger individual variation) in the other condition. Would it make sense in this case to simplify the model by removing the random slope of `B`?
I noticed that if I set manually the dummy variables (in your example I'd recode both factors in this way `dd$A<-ifelse(dd$A=="2",1,0)`) then `lme4` seems to do what I want. Is that a correct approach?
Comment: You could, although I don't think you will gain very much by removing the random slope.  Yes, coding the dummy variables in the way you suggest will work (I think); there's also a `dummy()` function in lme4 that may be helpful.


What is the login name of the account logged in with Microsoft ID when connect to Windows 10 remotely or in Remote Desktop Client?

Question: When I was coding C# to connect from Mac to a Windows 10 PC I found a failed connection. I tried again with Microsoft Remote Desktop Client and it said authorization failed. The only account on the PC is logged in with a Microsoft ID which was a LIVE ID before(eg. firstname.lastname@example.com).
I tried

firstname.lastname@example.com"

or the full name displayed in account list which is

A B (email@example.com)"

or the user name of the account, also name of the user home folder

abc

None of them is working.
I managed to connect with a local account credential(regular account name with password) but I need to know how to automatically set the account name in application when the user only logged in with a Microsoft ID(with no offline account).
Any comment?
Answer: I also required the same mapping from a Windows Service code and did the following:
Enumerated all users using the API NetUserEnum() with level 0 to get each username.
For each username called NetUserGetInfo() with level 24. It uses the structure _USER_INFO_24 to return its Internet Identity for the username.
If the usri24_internet_principal_name member of the structure matched with the given Microsoft Id then we have located the required username.
Note: Level 24 is available in Windows 8 and above. But can be easily used with previous SDK by simply defining the _USER_INFO_24 structure in the code.
For a code snippet please see my answer at:
Get the local login name for the given Microsoft Account returned by NetWkstaUserEnum API on Windows 8 and above


How to change the background color of an icon in the action bar, when clicked?

Question: The solution provided here doesnt work for me because it requires api14 and I want to support earlier verions:
Change action background color when selected (ActionBarSherlock)
Right now when I tap an item on the action bar with my finger it turns blue and I dont want that to happen.
Information:
I'm using SherlockActionBar.
and this doesnt work because it requires api11:
        ImageView icon = (ImageView) findViewById(android.R.id.home);
        icon.setBackgroundColor(getResources().getColor(R.color.black));

Here is my action_bar_items.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/abFeed"
        android:icon="@drawable/ic_action_content_paste"
        android:title="@string/abFeed"
        android:showAsAction="always"/>
    <item
        android:id="@+id/abNotifications"
        android:icon="@drawable/ic_action_social_cc_bcc"
        android:title="@string/abNotifications"
        android:showAsAction="always"/>
    <item
        android:id="@+id/abAddNewItem"
        android:icon="@drawable/ic_action_content_new"
        android:title="@string/abAddNewItem"
        android:showAsAction="always"/>
    <item
        android:id="@+id/abSearch"
        android:icon="@drawable/ic_action_action_search"
        android:title="@string/abSearch"
        android:showAsAction="always"/>
</menu>

EDIT: Here is what helped me solve the issue, thanks to Mario Lenci:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@FF000000" />
<item android:drawable="@android:color/transparent" />
</selector>

and in styles:xml

Comment: how you are adding items in actionbar , through menu.xml??
Comment: yes, I will attach it to the question
Answer: you have to set this attribute in your application/Activity main Theme
<item name="android:actionBarItemBackground">@drawable/your_drawable</item>

with action bar sherlok you also have to set
<item name="actionBarItemBackground">@drawable/your_drawable</item>

you can find a good documentation on ActionBar styling here
Comment: You have to define a drawbale as selector ( http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList )
Comment: just right click on the project -> android tools -> clear lint. I know that we should follow lint. but in this case it doesn't provoce any crash or something cause the "new" attribute will be just ignore when not supported
Comment: The raccomented solution would be to create a style.xml file in values-v14/ and define there the same theme with the attributes that are not supported before. In the other one you then leave the ActionBarSherlok ones in the other
Comment: android:actionBarItemBackground requires API level 14 (current min is 10)
Comment: yeah i know, but you are using ActionBarSherlok to solve that problem.
So you define both the attribute( with and without android: ) and the right one will be loaded according to the device
Comment: but Im getting an xml red error underline and I cant run the project
Comment: ok thank you for that! now problem is the color is always applied, not on click. How can I make that background change upon click only?
Comment: so how to I change this to make it work
Comment: let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/39116/discussion-between-mario-lenci-and-j-kowalski)


Confusion Regarding Definition of Lie Derivative

Question: I am having some trouble reconciling two definitions for the Lie derivative.
Let $X$ be a vector field on a smooth manifold, $M$, and let $\varphi_t(x)$ be the local flow through the point $x \in M$. Then, the usual formulation of the Lie derivative of a vector field, $Y$, at a point, $a \in M$, is
$$
\mathcal{L}_X Y (a) := \lim_{t \rightarrow 0} \frac{(D\varphi_{-t})(Y(\varphi_t(a))) \, - \, Y(a)}{t}
$$
However, in the lecture notes I am using, the Lie derivative is defined as
$$
\mathcal{L}_X Y (a) := \left[\frac{\partial}{\partial{t}}((\varphi_t)_*Y)(a)\right]_{t=0}
$$
When I unroll the definitions in the second formulation, I get a slightly different result to the usual definition of the Lie derivative (see below).

Where am I going wrong:
The second definition is given by
\begin{align}
& \quad \,\, \left[\frac{\partial}{\partial{t}}((\varphi_t)_* Y)(a)\right]_{t=0} \\
&= \lim_{t \rightarrow 0} \frac{((\varphi_{t})_* Y)(a) \, - \, ((\varphi_{0})_*Y)(a) }{t} \\
&= \lim_{t \rightarrow 0} \frac{((\varphi_{t})_* Y)(a) \, - \, Y(a)}{t}
\end{align}
Hence, to reconcile this with the usual definition, we want to show $((\varphi_{t})_* Y)_a = (D\varphi_{-t})Y_{\varphi_t(a)}$ (where, for ease of notation, we have moved the point at which we are evaluating the vector field to the subscript).
But, for $f \in C^\infty{M}$
\begin{align}
& \,\, \quad ((\varphi_{t})_* Y)_a(f) \\
&= ((D\varphi_t) Y_{\varphi_{t}^{-1}(a)})(f) \\
&= ((D\varphi_t) Y_{\varphi_{-t}(a)})(f) \\
&= Y_{\varphi_{-t}(a)}(f \circ \varphi_t)
\end{align}
whereas
\begin{align}
& \,\, \quad ((D\varphi_{-t})Y_{\varphi_t(a)})(f) \\
&= Y_{\varphi_t(a)}(f \circ \varphi_{-t})
\end{align}
This seems to show that the two definitions for the Lie derivative agree only up to sign. Where am I going wrong?
Comment: Normally, we define the Lie derivative as the derivative of the pullback vector field by the flow: $\dfrac{d}{dt}\bigg|_{t=0} (\phi_t)^*Y$, but in your second definition, there is a pushforward by time $t$, i.e $(\phi_t)_*Y$, rather than a pullback. There are related as $(\phi_t)_* = \left((\phi_t)^{-1}\right)^* = (\phi_{-t})^*$ (pushing forward is same as pulling back by the inverse). This is why when taking the derivative at $t=0$ using the second definition, you get an extra minus sign
Answer: The first definition is the correct one, the second one measure the derivative through the flow $t \mapsto \varphi_{-t}$ which is just the orginal one with the sign changed.


Code::Blocks returns -10737741819 (0xC0000005) when executing MySQL loop insert c++

Question: I've been making program that need to continuously insert data to a database. I'm new to C++.
I'm using xampp for my database. I want to make insert loop inside one of my function.
my code looks like this
#include "stdio.h"
#include "fstream"
#include "iostream"
#include "mysql.h"
#include "sstream"

void loop();
void print();

int i;
const char* hostname    = "localhost";
const char* username    = "root";
const char* password    = "";
const char* database    = "testinsertdb";
unsigned int port       = 3306;
const char* unixsocket  = NULL;
unsigned long clientflag = 0;

insertion(){
    MYSQL* conn;
    conn = mysql_init(0);
    conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);
    int qstate=0;
    using namespace std;
    stringstream ss;
        ss << " INSERT INTO test (number) values ('" <<i<<"')";
        string query = ss.str ();
        const char * q = query.c_str();
        qstate = mysql_query(conn, q);
         if (qstate == 0)
        {

            cout <<" Record inserted successfully ..."<<endl;
        }
        else
        {
            cout <<" Error, data not inserted..."<<endl;
        }
}

int main()
{
    print();
    return 0;
}

void print()
{
    for (int j = 0; j < 1000000; j++) {
     loop();
}
}

void loop()
{
    i=1;
    insertion();
}

When I run the program, I managed to insert some data to the database, but after several seconds the program stopped with code -10737741819 (0xC0000005).  On my build log Process the terminated with status -1073741510
How can i solve this?
Comment: You're leaking memory like a sieve, making a million connections to the database. You should init and connect *once*, and you should clean up after yourself.
Comment: Connect once (when your program starts) instead of connecting every time you want to make an insertion. And don't forget to close the connection when your program exits. Beside the point but using function parameters instead of global variables wouldn't hurt either.
Comment: How many connections to one database can you make?
Comment: @john thank you for the advice, it's working now, i make the MySQL* conn into global variable
Comment: @PepijnKramer i'm not sure about this sir, i'm still new and learning.
Comment: @WhozCraig thank you for the advice sir, i'll keep it in mind, it's just that i need this program to be done as fast as possible now. I'll keep learning.
Answer: Preferablly try this one.
Your code is trying to connect database as many times as the loop proceeds.
There is the description of that error from this link
#include "stdio.h"
#include "fstream"
#include "iostream"
#include "mysql.h"
#include "sstream"

void loop();
void print();

MYSQL* conn;

const char* hostname    = "localhost";
const char* username    = "root";
const char* password    = "";
const char* database    = "testinsertdb";
unsigned int port       = 3306;
const char* unixsocket  = NULL;
unsigned long clientflag = 0;

void insertion() {
    int qstate=0, i;
    using namespace std;
    stringstream ss;

    ss << " INSERT INTO test (number) values ('" <<i<<"')";
    string query = ss.str ();
    const char * q = query.c_str();
    qstate = mysql_query(conn, q);

    if (qstate == 0)
    {

        cout <<" Record inserted successfully ..."<<endl;
    }
    else
    {
        cout <<" Error, data not inserted..."<<endl;
    }
}

int main()
{
    print();
    return 0;
}

void print()
{
    conn = mysql_init(0);
    conn = mysql_real_connect(conn, hostname, username, password, database, port, unixsocket, clientflag);

    for (int j = 0; j < 1000000; j++) {
     loop();

    mysql_close(conn);
}

void loop()
{
    i=1;
    insertion();
}

Comment: thank you sir, it's working now. But i put the connection inside main() but still works fine.
Comment: That's great. Yep. It's nice to help you.
Comment: And, also for this process, you should close the database connection after running all necessary tasks for database.


What is the role of CUDA_CACHE_DISABLE=1? Please explain in detail

Question: I saw some codes using CUDA_CACHE_DISABLE=1 in run.sh file.
But there is no thorough explanation on website.
What I get from the online document is something abstact, like below:

Disables caching (when set to 1) or enables caching (when set to 0) for just-in-time-compilation. When disabled, no binary code is added to or retrieved from the cache.

But what is binary cache and retrieval?
Where can be better with this command, better utilization of GPU-memory or something else?
Thanks in advance.
Answer: It is explained for example here by Nvidia.
In short: CUDA code has to be recompiled for every major new GPU architecture. Binaries of CUDA code typically contain PTX as an intermediate representation for this. The compilation results will be cached.
Disabling cache will affect startup time and disk memory usage but not runtime performance.
Comment: In the context of python one might want to also mention JIT compilation and if this affects the caching of JIT compiled kernels.


What is ResolveAssemblyReference.cache?

Question: What is the file ResolveAssemblyReference.cache used for and does it need to be checked in?
Answer: It is a file produced by the ResolveAssemblyReference build target.  MSDN has this to say about it:

Visual Studio attempts to execute
  targets with certain names when it
  loads a project. These targets include
  Compile, ResolveAssemblyReferences,
  ResolveCOMReferences,
  GetFrameworkPaths, and
  CopyRunEnvironmentFiles. Visual Studio
  runs these targets so that the
  compiler can be initialized to provide
  IntelliSense, the debugger can be
  initialized, and references displayed
  in Solution Explorer can be resolved.
  If these targets are not present, the
  project will load and build correctly
  but the design-time experience in
  Visual Studio will not be fully
  functional.

If I interpret this correctly, I'd say that the file is used to help the IDE provide proper IntelliSense and assembly reference status in the References node.  It is a fairly expensive operation since there are potentially a lot of assemblies that can be referenced.  So instead of doing this repeatedly, the .cache file can help make this quick.  Deleting it isn't an issue, it will be recreated when the project is reloaded.
Comment: Ah, great.  It's not checked in, so I knew it's automatically generated.  I wanted to make sure it didn't provide something useful in a (semi-)production environment, like improving the usefulness of stack traces (*.pdb files), but it sounds like it doesn't.  Cool.
Comment: I guess this file can safely be ignored (not cheked in) in your source control system.
Answer: It is not needed to be checked in, so to exclude it from git, add the obj folder, for "obj\debug", to be excluded during git processes which will exclude it properly.
Comment: Was this comment attempting to answer a question? It doesn't seem to make any sense.

What is ResolveAssemblyReference.cache?


Interpretation of mixed model output in lme4 and stan

Question: here's my model in lme4
library(nlme)   # for the data
data("Machines")  # the data

fit2 <- lmer(score ~  -1 + Machine + (1|Worker), data=Machines)
summary(fit2)

Linear mixed model fit by REML ['lmerMod']
Formula: score ~ -1 + Machine + (1 | Worker)
   Data: Machines

REML criterion at convergence: 286.9

Scaled residuals:
    Min      1Q  Median      3Q     Max
-2.7249 -0.5233  0.1328  0.6513  1.7559

Random effects:
 Groups   Name        Variance Std.Dev.
 Worker   (Intercept) 26.487   5.147
 Residual              9.996   3.162
Number of obs: 54, groups:  Worker, 6

Fixed effects:
         Estimate Std. Error t value
MachineA   52.356      2.229   23.48
MachineB   60.322      2.229   27.06
MachineC   66.272      2.229   29.73

Correlation of Fixed Effects:
         MachnA MachnB
MachineB 0.888
MachineC 0.888  0.888

when I model this in STAN using rstanarm, I get a totally different output:
library(rstanarm)
fit2a <- stan_glmer(score ~  -1 + Machine + (1|Worker), data=Machines)
fit2a

stan_glmer(formula = score ~ -1 + Machine + (1 | Worker), data = Machines)

Estimates:
         Median MAD_SD
MachineA -6.3   24.4
MachineB  1.6   24.3
MachineC  7.5   24.4
sigma     3.6    0.4

Error terms:
 Groups   Name        Std.Dev.
 Worker   (Intercept) 38.2
 Residual              3.6
Num. levels: Worker 6

Sample avg. posterior predictive
distribution of y (X = xbar):
         Median MAD_SD
mean_PPD 59.6    0.7

my interpretation is this: I get the fixed effects by adding mean_PPD to the estimates, e.g. 59.6-6.3 = 53.3  ~ 52.3 as in lme.
Are the error terms in the stan output the random effects? And why does it use the median for the estimates or is this a rstanarm specific thing?
Comment: The `print` method in the rstanarm package reports posterior medians because they always exist (whereas the mean may not, although that is unlikely for the models currently in rstanarm) and perhaps are better estimated than is the mean in cases where the Markov chain has issues sampling from the tails of the posterior distribution.
Comment: The output under `Error terms` in rstanarm is comparable to the output under `Random effects` in lme4. But since rstanarm is largely Bayesian, the phrases "fixed effects" and "random effects" are avoided, although there are `fixef` and `ranef` extractor functions for compatibility with lme4. Either way, you can think of the `(1|Worker)` term as an error in the sense that the `Machine` predictor is unable to explain some variation in `score`.
Comment: To your main question, I think you have encountered a bug in rstanarm. See https://github.com/stan-dev/rstanarm/issues/49 .
Answer: The main question was the result of a bug in rstanarm that has since been fixed on GitHub.
However, in general, we do not recommend rstanarm models that exclude the intercept. A better alternative is to place a tight prior with mean zero on the intercept. In this case, including the intercept yields a better fit and similar results between lme4::lmer and rstanarm::stan_lmer.
Comment: "We allow priors, use them!" But more seriously, I hadn't thought of this before and it makes a lot of sense. There are probably several CV discussions about excluding intercepts and the issues involved, and priors provide a better (continuous, partially-data-driven) way to handle this kind of thing.


Find if 4 lines form a Quadrilateral in 2D space

Question:
How can I know if 4 lines form a Quadrilateral in 2D space?
And how would I obtain the corners? (in clockwise order starting with the top left corner)

Note that lines are formed by 2 points in my case, however the length is not limited to those points but goes on infinitly.
All points are in a fixed 2D space, say (0, 0, 100, 100). The Quadrilateral is either in that space too, or I do not care about it. Also lines are hardly ever parralel since the data comes from an actual image.

The blue lines here is the data, and the green points are the corners I want to obtain. Note that my input data is not always this nice, but mostly consists of lines which do not form any quadrangle in the fixed space.
What I tried

Find all intersection points within that space.
Create a convex hull

But this seems inefficient to me and is sometimes inaccurate. I was hoping that there is a somewhat better approach.
Comment: 2D, 3D or n-D? How are your lines defined: point+vector, point+point...? Please, try to be more specific. This will prevent people from telling you things you already know, and help them give their answers at the right level.
Comment: @AugSB You are right. I am sorry, I have added some context.
Comment: @mvw A quandrangle is a name often used for a `quadrilateral`. So yes, just a polygon with four edges. The constraint: that it lies in a 2D plane is just an requirement on its own.
Comment: @mvw Actually yes, I have to find the homography of this quadrangle (if the lines represent an quadrangle at all). More info in a previous question of mine: http://math.stackexchange.com/questions/1724967/largest-four-line-segments-of-polygon
Comment: @mvw But I actually have already the four lines, that is not really the problem. Now I just need to test and form the quadrilateral from them. I appreciate your thinking though!
Comment: Four lines in general position always form a quadrilateral.
Comment: I assumed in my answer that you are looking for a _convex_ quadrilateral. Is this right?
Answer: Call the lines $L_1,L_2,L_3,L_4$, and let $P_{ij}$ be the intersection of lines $L_i$ and $L_j$. Then the quadrilateral is determined uniquely by which of the lines $L_2,L_3,L_4$ is opposite $L_1$. So there are only three possibilities:

$L_2$ is opposite $L_1$: $P_{13}P_{32}P_{24}P_{41}$
$L_3$ is opposite $L_1$: $P_{12}P_{23}P_{34}P_{41}$
$L_4$ is opposite $L_1$: $P_{12}P_{24}P_{43}P_{31}$

If none of the lines are parallel, and no three lines meet at a single point, then exactly one of these will be a convex quadrilateral.
Do you know how to determine whether a quadrilateral $ABCD$ is convex?
Comment: Yes, if the diagonals intersect. Thank you for your answer. I was indeed looking for a convex quadrilateral.


Cliente e Servidor socket com Indy

Question: Caros,
estou tentando criar um programa que vai receber uma lista de produtos vendidos, através de uma conexão Socket.
Consigo conectar via TCPClient, porém não estou conseguindo enviar a lista de comandos, e nem receber o resultado que vem do server.
No meu teste, consigo receber uma linha, mas preciso receber várias linhas.
Estou fazendo assim:
procedure TForm1.Button4Click(Sender: TObject);
var
  LLine : string;
begin
  try
    if not IdTCPClient1.Connected then
      IdTCPClient1.Connect;

    IdTCPClient1.SendCmd(Edit3.Text);

    //LLine := IdTCPClient1.IOHandler.ReadLn();
    Lline := IdTCPClient1.Socket.ReadString(6000);
    mmLog.Lines.Add(LLine);

  except
  on E:Exception do
      if ( E.Message <> 'Connection Closed Gracefully.') then
        mmLog.Lines.Insert(0, 'ERROR: ' + E.Message);
  end;
end;

Estou usando Indy 10 e Delphi Tokio.
Answer: Prefiro utilizar o componente socket padrão, mas para TIndy já utilizei da seguinte maneira:
Considerando que o servidor escreva linha a linha, basta informar na primeira linha a quantidade de linhas que esta sendo enviada.
procedure TFormulario.IdServidor1Execute(AContext: TIdContext);
begin
  AContext.Connection.IOHandler.WriteLn('3');
  AContext.Connection.IOHandler.WriteLn('MENSAGEM 1');
  AContext.Connection.IOHandler.WriteLn('MENSAGEM 2');
  AContext.Connection.IOHandler.WriteLn('MENSAGEM 3');
end;

Agora imagine que no cliente você já possui a solução. Ou seja, ao invés de utilizar  ReadString utilize o ReadStrings que lhe devolvera uma lista de mensagens:
var
  i: Integer;
  vTexto: TStringList;
  vTamanho: Integer;
begin
  vTexto := TStringList.Create;

  vTamanho := IdTCPClient1.IOHandler.ReadLn.ToInteger;
  IdTCPClient1.IOHandler.ReadStrings(vTexto, vTamanho);

  for i := 0 to Pred(vTexto.Count) do
    Memo1.Lines.Add(vTexto[i]);
...

Neste caso, cabe uma pequena modificação no lado do Servidor para que ele sempre informe a quantidade de mensagens que esta enviando no pacote.
Comment: Entendi a ideia... O problema é que congela quando chama a linha: vTamanho := IdTCPClient1.IOHandler.ReadLn.ToInteger;
Comment: O que esta enviando em `AContext.Connection.IOHandler.WriteLn('3');` ?

Cliente e Servidor socket com Indy


Echo "part" of array (decoded from JSON)

Question: I'am quite new to JSON and more "advanced" arrays. Therefore I don't know what I should search for...
I have this "JSON array" (what do you call it?):
<code>{
   "id": "321123321",
   "statuses": {
      "data": [
         {
            "message": "testmessage",
            "updated_time": "2012-12-25T16:33:29+0000",
            "id": "123321123"
         }
      ],
      "paging": {
         "previous": "1",
         "next": "1"
      }
   }
}
</code>
I want to create a variable from "message" that is called $message and a variable from "up_datedtime" that is called $updated.
To get id I simple:
$json_a=json_decode($string,true);
$id $json_a['id'];
And for statuses:
$json_a=json_decode($string,true);
$status = $json_a['id']['statuses'];
But when I try to get "message" I get " Cannot use string offset as an array in":
    $message = $json_a['id']['statuses']['data']['message'];
How do I get $message from the array the proper way?
Answer: You can get like this
<code>$message = $json_a['id']['statuses']['data'][0]['message'];
</code>
or you can get from loop
<code>$dataArr = $json_a['id']['statuses']['data'];

foreach ($dataArr as $val) {
    echo "message".$val['message'];
}
</code>
Comment: $message = $json_a['id']['statuses']['data'][0]['message'];
    echo $message;"

Gives me "Cannot use string offset as an array i". I have googled the error, but I have not found any solution for my problem...
Comment: then u can debug by printing step by step like, print_r( $json_a['id']['statuses']['data']);
Comment: print_r( $json_a['id']['statuses']); works fine, but print_r( $json_a['id']['statuses']['data']); gives me this error: " Cannot use string offset as an array in". What should I do to avoid the error?


LSTM time series forecasting on sparse dataset

Question: I am working on the LSTM time series forecasting of solar energy production. The available data is one year on a half hourly basis. More than 60% of the data values are zero as the PV stations cannot produce solar energy at night. Now my questions are as follows,

1) If this big amount of zeros somehow affecting the learning process?
2) Is there any way to deal with such sparse data set?
Answer:
1) If this big amount of zeros somehow affecting the learning process?

Have you actually tried. Yes, there are a lot of zeros, but if they are all occurring at night, then they would show up as regular daily seasonality pattern, so they shouldn't effect your ability to predict too much.

2) Is there any way to deal with such sparse data set?

What is the purpose of your forecast? Do you need half-hourly forecasts? If not, I would suggest that you aggregate up to a daily level. You will end up with 365 data points, which is a lot smaller than the original data set, but is still enough for fitting a time series model.


Trigger event for an svg element that moves behind another one?

Question: the desired output is for example: When the red masked rectangle is moving behind one of the "holes", the hole needs to change the fill (or some other attr).
Is it possible to add some sort of event that triggers when the moving_rect is entering/leaving the area of the hole element?
in action:
https://jsfiddle.net/qwertasyx/n9v7L95j/
also here as snippet:

var draw = SVG('myDrawing').size('100%',200);

var rect_group = draw.group()

//we dont want to see this
var background = rect_group.rect(200,150).center(250,100).fill('#000')
// we want too see through those 'holes'
var hole1 = rect_group.rect(40,40).center(290,70 ).fill('#fff')
var hole2 = rect_group.rect(40,40).center(290,130).fill('#fff')
var hole3 = rect_group.rect(40,40).center(220,70 ).fill('#fff')
var hole4 = rect_group.rect(40,40).center(220,130).fill('#fff')

// object that we see through the holes
var moving_rect = draw.rect(40,40).fill('red').center(250,100)

//mask obj
var mask = draw.mask()
$('#mask').on('click',function(e){
 mask.add(rect_group)
  moving_rect.maskWith(mask)
})

$('#animate').on('click',function(e){    moving_rect.animate(250).move(160,40).animate(250).move(250,40).animate(250).move(300,80).animate(250).move(250,160).animate(250).center(250,100)
})
svg{
  border-style: solid;
  border-width: 1px;
}

Example svg -> click button for animation
<button id="mask" class="btn btn-primary">mask rect</button> <button id="animate" class="btn btn-primary">animate</button>

Comment: Event - no. The nearest you can get would be the [isPointInFill()](https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/isPointInFill) method, but support is patchy at the moment.
Comment: Why not? You just have to check whenever the rectangle moves whether or not one of these circles intersect with the rectangle
Answer: So I crafted together a solution where on every animation step it is checked if one of the rectangles (holes) is intersecting with the moving rectangle.
If an intersection is detected, it changes the fill color of the "holes".
    // animate()...
    .duringAll(function () {
        // get box of the rectangle
        var bbox = this.bbox()

        // intersection function. You should define it somewhere outside
        // instead of redefining every time
        var intersect = function(boxA, boxB) {
            return (boxA.x < boxB.x2 && boxA.x2 > boxB.x &&
            boxA.y < boxB.y2 && boxA.y2 > boxB.y)
        }

        // go trough the boxes of every hole defined before
        boxes.forEach(function (el, index) {
            if(intersect(bbox, el)) {
                // change color of fill on intersection
                rects[index].fill('#555')
            } else {
                rects[index].fill('#fff')
            }
        })

    })

Working fiddle:
https://jsfiddle.net/Fuzzy/n9v7L95j/5/
It would be trivial to fire an event instead. You can just go:
this.fire('intersection', {index: index})

// then bind with
moving_rect.on('intersection', function (ev) {
    var index = ev.detail.index

    // do somthing
    rects[index].fill('#333')
})


Unbiased estimator of Bernoulli distribution

Question: Let $X_{1},...,X_{n}$ be a random sample from Bernoulli (p), where p$\epsilon$(0,1) is unknown.
(a) Find an unbiased estimator W of $\tau$(p) = $p(1-p)$ .
(b) Find an unbiased estimator which has smaller MSE than W.
My approach:
I know sample variance is unbiased estimator of population variance. Hence $S^2=\frac{1}{n-1}\sum_{i=1}^{n}(X_i - \bar{X})^2$ is an unbiased estimator of $p(1-p)$. But I don't know how to find an unbiased estimator of W. Can someone assist me in answering (a) and (b)?
Comment: it seem, $X_i$ are independent.
Comment: Yes... they are independent.
Comment: Related: https://math.stackexchange.com/q/3086919/321264.
Answer: (a)
$W=X_1 (1-X_2)$
$E(W)=E(X_1 (1-X_2))==E(X_1) E(1-X_2)=p(1-p)$
(b)
$T=\sum_{i=1}^{n} X_i$ is complete and sufficient estimator so  $E(X_1 (1-X_2)|T)$  is UMVUE for $p(1-p)$
$\begin{array}{c|c|c}
X_1 & X_2 & X_1 (1-X_2) \\ \hline
0 & 0 & 0 \\
0 & 1 & 0 \\
1 & 0 & 1 \\
1 & 1 & 0 \\
\end{array}$
so $X_1 (1-X_2)$ is a Bernoulli random.
$p(X_1 (1-X_2)=1|T=t)=p(X_1=1,X_2=0|\sum_i X_i=t)$
$=\frac{P(X_1=1,X_2=0,\sum_{i=1}^{n} X_i=t)}{P(\sum_{i=1}^{n} X_i=t)}$
$=\frac{P(X_1=1,X_2=0,\sum_{i=3}^{n} X_i=t-1)}{P(\sum_{i=1}^{n} X_i=t)}$
$=\frac{p q P(\sum_{i=3}^{n} X_i=t-1))}{P(\sum_{i=1}^{n} X_i=t)}$
$=\frac{p q {n-2 \choose t-1} p^{t-1} q^{n-2-t+1}}{ {n \choose t} p^{t} q^{n-t}}=$
$=\frac{{n-2 \choose t-1} }{ {n \choose t} }$  (for $t\geq 1$ O.W equal zero)
$E(X_1 (1-X_2)|T=t)=0+1\times \frac{{n-2 \choose t-1} }{ {n \choose t} }=\frac{{n-2 \choose t-1} }{ {n \choose t} }=\frac{t(n-t)}{n(n-1)} $
so UMVUE for $p(1-p)=\frac{\sum X_i(n-\sum X_i)}{n(n-1)}=\frac{n \bar X(n-n \bar X)}{n(n-1)}=\frac{n \bar X(1- \bar X)}{(n-1)}$
also it equal to $\frac{1}{n-1} \sum(X_i -\bar X)^2$
$\frac{1}{n-1} \sum(X_i -\bar X)^2=\frac{1}{n-1} (\sum X_i^{2} -n \bar X^2)$
since $X_i\in \{0,1\}$
$=\frac{1}{n-1} (\sum X_i -n \bar X^2)$
$=\frac{1}{n-1} (n \bar X -n \bar X^2)=\frac{n}{n-1}  \bar X (1- \bar X)$
at this step since $S^{2}=\frac{n}{n-1}  \bar X (1- \bar X)$ so $S^{2}$ is a function of $\bar X$ (sufficient and complete estimator) and also is unbaised so directly it is UMVUE for $p(1-p)$(and this is another proof for part(b))
Comment: is it clear or need explanation?


How to well order the set of all functions with domain an ordinal and codomain a set?

Question: Source: Set Theory by Kenneth Kunen.
Theorem I.12.14 ($ZFC^-$) Let $\kappa$ be an infinite ordinal. If $\mathcal{F}$ is a family of sets with $|\mathcal{F}|\leq\kappa$ and $|X|\leq\kappa$ for all $X\in\mathcal{F}$, then $|\bigcup\mathcal{F}|\leq\kappa$.
In the proof, the author goes: "...well order $\mathbf{\mathcal{S}:={}^{\kappa}(\bigcup\mathcal{F})}$, and let $g_{\alpha}$ be the least $g\in\mathcal{S}$ with $ran(g)=f(\alpha)$." Here ${}^{\kappa}(\bigcup\mathcal{F})$ denotes the set of all functions $\sigma: \kappa\to\bigcup\mathcal{F}$.
My Question: How exactly does one well order the set $\mathcal{S}$? It might be possible if $\bigcup\mathcal{F}$ is well ordered, but that is not necessary true in this case.
Any help would be greatly appreciated.
Comment: Doesn't the $C$ in $ZFC^-$ mean you can use the axiom of choice to get a well-ordering of any set you please.
Comment: @Tzimmo: I think it might be better if we just left it to Dick to say "oops!" to himself and delete the question.
Comment: @RobArthan No, the question should not be deleted. As simple as it is, there might be others wondering the same thing. And writing the solution down as an answer makes it visible to search engines.
Comment: @Tzimmo: I am not entirely convinced by your thinking. But I will write up an answer.
Comment: Just as a quick refresher, $ZFC^-$ means $ZFC$ minus the axiom of regularity, right?
Comment: @Arthor Negative-minus the Axiom of Foundation.
Comment: @RobArthan I think you should make an answer out of your comment, given that it contains the solution.
Comment: @RobArthan I think you are correct...
Comment: @Tzimmo It's okay, it is indeed a dumb question.
Answer: The "$C$" in Kunen's "($ZFC^-$)" means that the theorem is predicated on the axiom of choice. If you are given the axiom of choice, then any set can be well-ordered.


Menu items visible based on checkbox

Question: I want do show/hide menu items based on a checkbox that the user selects when he/she registers.
I use profile2 for register.  Should I use an external jquery script that calls on page load or should I use a hook_menu_alter() in my template file?  I am not too familiar with Drupal code yet and appreciate any input.
Answer: Solution 1
Add a custom access callback to your paths, that will then determine whether or not the user should have access to a path.
Important: the code below will deny access to those paths. If you just wanted to show a slightly different menu and not block the access to those pages, see solution #2.
For example:
function YOUR_MODULE_menu_alter(&$items) {
  $items['your_path']['access callback'] = 'YOUR_MODULE_menu_access_callback';
}

function YOUR_MODULE_menu_access_callback(){
  global $user;
  if ($user->uid) {
    // Load user's Profile2 profile.
    $profile = profile2_by_uid_load($user->uid, 'NAME_OF_YOUR_PROFILE');
    // Allow access only if the user selected the checkbox.
    if (isset($profile->field_YOUR_FIELD[LANGUAGE_NONE][0]['value']) && $profile->field_YOUR_FIELD[LANGUAGE_NONE][0]['value']) {
      return TRUE;
    }
  }

  // This assumes that anonymous users should not have the access to a
  // particular menu.
  return FALSE;
}

This code would go in a custom module.

Solution 2
Add a simple theme_menu_link() override in your front-end theme, and skip rendering of those links.
Important: this will not prevent the access to those pages, it will just skip rendering of those list items. Also, you must be rendering the links using a menu, e.g. place a menu block somewhere in your theme, and not render the menu directly (e.g. theme('links__system_main_menu', ...) or theme('links__system_secondary_menu), ...)).
For example:
function YOUR_THEME_menu_link($variables) {
  global $user;
  $element = $variables ['element'];
  $sub_menu = '';

  // Exclude certain paths.
  if ($user->uid) {
    // Load user's Profile2 profile.
    $profile = profile2_by_uid_load($user->uid, 'NAME_OF_YOUR_PROFILE');
    // Allow access only if the user selected the checkbox.
    if (!isset($profile->field_YOUR_FIELD[LANGUAGE_NONE][0]['value']) || !$profile->field_YOUR_FIELD[LANGUAGE_NONE][0]['value']) {
      // Define the list of paths that should be excluded.
      $paths_to_exclude = array(
        'sample',
      );
      if (in_array($element['#href'], $paths_to_exclude)) {
        // Stop processing here, meaning this list item will not be included in
        // the menu.
        return;
      }
    }
  }

  if ($element ['#below']) {
    $sub_menu = drupal_render($element ['#below']);
  }
  $output = l($element ['#title'], $element ['#href'], $element ['#localized_options']);
  return '
' . $output . $sub_menu . "
\n";
}

This code would go in the template.php file of your front-end theme.
Comment: Awesome answer, thank you very much. Option 1 is exactly what I am looking for.  However, I am struggling a bit.  The menu_alter seems to tackle the link + page. Perfect!  But I have multiple links.  Do I then create an array of my paths or create a new variable?  Also, in the function, the field_MY_FIELD is printing array values. But only the first value gets printed. How do I print all my values?  I tried using an if($profile... == 0){...} but I get an 'unidentified offset: 2' error if not all checkboxes are selected.  Thanks.
Comment: 1/ multiple links - yes, that's why I created an array, so you can list multiple links in that array and use it as is. 2/ not sure I understand completely, would you mind clarifying that a bit and updating the question?
Comment: Thanks for your help!  Had to use _module_implements_alter to get it working. Finally!
Comment: Sure, glad it helped!

Menu items visible based on checkbox


a leading whitespace before the result from regular expression

Question: I am using a rule to get substring in python using regular expression. But I found some results will have a leading whitespace while some of them don't. I know I can remove the whitespace with .strip(). But I want to understand why the whitespaces are there. Can anyone help?
Thanks
Ex 1. (no leading whitespace).
import re
utterance = 'can i make a call to +21231313'
re.findall('[-|#|+]*[0-9]*[-\s]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*', utterance.strip())

result:
['+21231313']

Ex 2. (leading whitespace).
import re
utterance = 'can i make a call to -21231313'
re.findall('[-|#|+]*[0-9]*[-\s]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*', utterance.strip())

result:
[' -21231313']

Ex 3. (leading whitespace).
import re
utterance = 'can i make a call to 21231313'
re.findall('[-|#|+]*[0-9]*[-\s]*[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*', utterance.strip())

result:
[' 21231313']

Comment: This `[-\s]*` will match the space as it scans from left to right since the part before that is optional. Maybe insisting on at least one number before that will help: `[-|#|+]*[0-9]+` `+` instead of `*`.
Answer: In RE, * will check for 0 or more occurrences of the expression. So the space comes only for the last block of your regex where every other block is interpreted as empty. Take a look to the state machine:

The last block([-\s\./0-9]*) will accept any number of the listed symbols that includes space and the sign - but not +. If your expression has the plus sign, the result will be:

Because the only block that accepts + is the first block, and there is not space in the first one. Because of that, if the regex recognize a plus sign, the match will not have any spaces.
Answer: The first chunk of patterns can match an empty string, '[-|#|+]*[0-9]*[-\s]*[(]{0,1}.
What you may use is make digit matching part obligatory while making the hyphen/space pattern optional and wrap that with an optional group, (?:[0-9]+[-\s]*)?. Also, you may avoid the whitespace at the end of the match if you re-factor the last [-\s\./0-9]* pattern to (?:[-\s./]*[0-9])*.
Use
[-#+]*(?:[0-9]+[-\s]*)?\(?[0-9]{1,4}\)?(?:[-\s./]*[0-9])*
      ^^^^^^^^^^^^^^^^^                ^^^^^^^^^^^^^^^^^^

See the regex demo
Details

[-#+]* - zero or more -, # or +
(?:[0-9]+[-\s]*)? - an optional non-capturing group matching 1 or 0 occurrences of 1+ digits and then 0+ hyphens/whitespaces
\(? - an optional (
[0-9]{1,4} - one to four digits
\)? - an optional )
(?:[-\s./]*[0-9])* - 0 or more occurrences of

[-\s./]*  - 0 or more hyphens, whitespaces, . or /
[0-9] - a digit.


Is there a way to use Google smart home actions while restricting certain users to unlock/lock a specific smart lock door?

Question: I'm currently working on a smart lock project. And we want to let our backend server send commands to the relating smart lock. And we are considering Google smart home actions to send some sort of command to the smart lock from our backend server to open/close the lock. But I want to ONLY let the backend server send these commands to the smart locks, and NOT everybody who is connected to the wifi network (as most of the times everybody on the network can control all smart home devices e.g. set volume of speaker, open front door, dim lights etc. etc.). I have seen some things about account linking inside, but not sure if that's what I need. So my question was: Is there a way using smart home actions to only give one person (or in this case entity) access to do certain actions? Thanks in advance.
Answer: You can use two-factor authentication to require a person to give an ack or PIN to send the final command.
The specific architecture of the lock and its connection is up to you, but I don't believe there is a way to limit control of the lock to specific accounts. If there is a Google Home, any individual in the home is able to issue the initial command. If this individual knows the PIN, they can say that as well.


How can I stop the full HTML editor from deleting my  paragraph?

Question: https://drupal.slack.com/archives/C1BB308HH/p1602318464360700 Link to slack question in #support
JSFiddle of the offending html: https://jsfiddle.net/tyeth/xr4ohast/
Demo Video showing the paragraph beneath second image being removed: https://www.youtube.com/watch?v=Hw9NACmMsps [Was private, now just unlisted, sorry]
Hi supportive people, you must get this one a lot. I'm aware of the filter options and have customised the Full-Html mode to not use the 3 offending filters, and cleared cache, but I'm still losing content.
I'm using the drupal 8(and 9) add a custom body block using layout designer, I then use the WYSIWYG editor in full-html mode with the filters (strip bad html/convert newline br+p/convert images -- see screenshot) disabled.
However it is DELETING html from the end of the editor. I wonder if it's technically an empty paragraph as that has been mentioned in other issues (it isn't but has a link inside so doesn't have it's own text content).

Also, which module is actually doing the rich editing these days?
Comment: Have you tried to check "Limit allowed HTML tags ..." and add the `` tag there?
Comment: The checkb9x for that option (which includes stripping faulty html) is not enabled. it was, but disabling it should have stopped this behaviour, hence my confusion. It only strips the certain paragraph elements. Bizarre!
Comment: Is there any other CKEditor config in place? From custom or contrib modules?
Comment: Not yet, but had read about the autoParagraph option from many years ago, just couldnt find official guidance for which editor d9/d8 uses and how to customise
Answer: Could be related to the auto paragraph funcitonality of CKEditor, which is used by default and can be disabled with this !deprecated setting:
"autoParagraph = false"

This can be easily disabled using the ckeditor_config module, see https://www.drupal.org/project/drupal/issues/3131055 for more information.
The whole paragraph wrapping in CKEditor is kind of buggy, you could also try these patches: https://www.drupal.org/project/drupal/issues/2876094 (but there the problem is an added p after an img)

I had some troubles when using linkit: https://www.drupal.org/project/linkit/issues/3162596 and made this core issue https://www.drupal.org/project/drupal/issues/3162605 (this is not related to your problem as your using the align and caption filters - but you see where the magic happens - on Drupal side).
Comment: Thanks for your answer. I had seen mention of that config value but no idea where to stick it or if ckeditor was still the default, hence end of question. Looking at your issue now to understand the mechanisms better. Also +1 for mentioning the !deprecated fact, would be plus two with a link hehe
Comment: You deserve the plus 2, link to deprecation in end of ckeditor_config related link, http://origin-docs.ckeditor.com/ckeditor4/docs/#!/api/CKEDITOR.config-cfg-autoParagraph
Answer: I checked your HTML code thoroughly. The culprit is data-align="center" used in the img tags. To fix the problem, we have two options:
Option 1. (Recommended) If you remove it(data-align="center") from your code, your problem will be resolved, ie; the p tag won't be removed automatically when Source button is clicked.
Option 2. You can uncheck the Align Images in the above configuration. This is not recommended because this will apply the changes globally which we don't desire.
Here is the fixed HTML code.
Explanation:
As seen in the Editor's configurations, there is an option called Align Images. This option also adds the same data-align attribute to centrally align the images. This could be causing the conflict and strangely removing the p tags.
Comment: Ooh, now that is interesting that it only affects center, hadnt spotted that, thanks! I'll see if I can get anywhere with the issue tracker
Comment: This is the desired functionality of the Image Properties dialog, it adds the align as the user desires (we use left/center/none). I expect this to work, can you suggest why it doesnt and how to make it respect my authority ;) I have found a work around (shown in video), but I consider it fatally flawed
Comment: In that case, you can go with option 2. It's not an issue if you keep in mind that this option has been unchecked.
Comment: We allow the non-technical users to use the align option, it avoids the designers having to paste classes on every element or the css to be too specific.
Comment: I got your point. This seems like a 'bug' in core's ckeditor module. As long as you select None, Left or Right, it works fine. But when you select the image to be center aligned, ie; whenever data-align="center" is added to the image tag, the p tag is getting stripped off. The best would be to create an issue in drupal.org. And for the temporary solution, you can avoid center aligning from Image Properties dialog. Keep the alignment to None and align with CSS.


How do I make the scrollbar's thumbtrack resize

Question: If you open Notepad, add ten lines and resize the editor to only show nine, the thumb track (the draggable block on a scroll bar) is almost the full length of the vertical scroll bar. If you add a couple of thousand rows, the thumb track is only a few pixels high.
I'd like to duplicate this bahaviour in a TCustomControl descendant where I implemented a horizontal scroll bar. So I added WS_HSCROLL to my window style (in CreateParams) and implemented a handler for WM_HSCROLL. Along the way, I use SetScrollRange and SetScrollPos to manage the range and the position of the thumb track - but the little bugger remains a near-perfect square.
What am I missing?
Comment: Cobus, an example of your code would be very useful for you to get help.
Comment: @RRUZ: No, absolutely no need. If you want to see how not to do it, look no further than the VCL grid control. If you want to see how to do it, look at VirtualTree, SynEdit or any other such control that works correctly. Source code for them is available.
Comment: hi, this is more of a related question: how are you adding scrolling to the control itself, is there a TScrollbar that is member of your TCustomControl descendent class?
Answer: You can use the PageSize property to influence the thumb size.
Example:
ScrollBar1.Min      := 0;
ScrollBar1.Max      := 100;
ScrollBar1.Position := 70;
ScrollBar1.PageSize := 50;

Will look like:
Comment: This is on scroll bar controls? I'm working with the scrollbars on the window.
Answer: The documentation recommends using SetScrollInfo rather than SetScrollRange and SetScrollPos.
As Wouter's answer points out, you also need to set the page size. The position and range tell the OS where the center of the thumb belongs, but the page size tells it how much of the range is visible, and that's what determines the size of the thumb. You have to use SetScrollInfo for that; as a bonus, it lets you set the position, range, and page size all at once.

TCustomControl differs from TWinControl in just one way: It has a canvas. TScrollingWinControl differs in just one way, too: It has scroll bars. Adding a canvas to a TScrollingWinControl descendant should be much easier than adding scroll bars to a TCustomControl descendant — it's less code to copy and paste from the VCL source code. Change your control's base class and then see where you are.
Even if that's not an option, you'd still do well to look at how TScrollingWinControl and TControlScrollBar work together.
Comment: +1, but I'm not sure that inheriting from `TScrollingWinControl` is less work in the long run. At least on Win9X it also severely limits the available scroll range (16 bit coordinates). Even on the NT line it would limit number of lines to 2^31 `div` (line height) in pixels. I would rather use `SetScrollInfo()` and calculate everything in code.
Comment: I don't agree with the TScrollingWinControl part of your answer either, partly because my scrolling needs to be rather complex. But I used SetScrollInfo and it works a treat, thanks.


setup ssl with nginx on linux

Question: I have this clients server where I would like to set up ssl on a site like this app..net
The server is running ubunto and written in laravel / php.
server {
    server_name <domain>.net www.<domain>.net;
    return 301 https://app.<domain>.net$request_uri;
}

server {
    listen 443 ssl;
    server_name app.<domain>.net;

    root /home/<domain>/www/site/public;

    location / {
        index index.php;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /index.php;

    location ~ \.php? {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/php5-fpm.<domain>.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    ssl on;
    ssl_certificate /etc/nginx/ssl/<domain>/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/<domain>/<domain>.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-R$
    ssl_prefer_server_ciphers on;

    access_log /home/<domain>/logs/access.log;
    error_log /home/<domain>/logs/error.log;
}

This is my config file for my specifik site. Right now when I go to app..net I land on www..com, I have no idea what the problem is.
EDIT:
If i change the config file to the following:
server {
    server_name <domain>.net www.<domain>.net;
    return 301 http://<domain>.net$request_uri;
}

server {
    server_name app.<domain>.net;

    root /home/<domain>/www/site/public;

    location / {
        index index.php;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /index.php;

    location ~ \.php? {
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_pass unix:/var/run/php5-fpm.<domain>.sock;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    ssl on;
    ssl_certificate /etc/nginx/ssl/<domain>/ssl-bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/<domain>/<domain>.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-R$    ssl_prefer_server_ciphers on;

    access_log /home/<domain>/logs/access.log;
    error_log /home/<domain>/logs/error.log;
}

Then I end up on the right page but no https
Comment: Do you have any other configs?
Comment: There is 5 config files in the sites-available folder
Comment: What about the sites-enabled folder?
Comment: There is 4 config files. But dont they just get copied from sites-available?
Comment: They aren't copied they should be sym-linked.... Can you post the config for the site that you end up on?
Comment: The site I end up on are not hosted on the same server
Comment: ok, in which case you need to find out where the redirect is happening. Can you curl the app site and add the response to the question
Comment: I have edited the question with a variasion of the config file that sents me to the right site
Comment: Have you set up DNS for the new domain, and can your server accept connections over port 443?
Comment: The domain is already setup and working over http, I would just like to have it working over https as well. I do not know, how can I check that?
Answer: From what I gather, your domain does not have a redirect from HTTP to HTTPS.
This would explain that without listening on port 80 for that domain, NGINX would fall back to the default server which I assume to be your primary domain.
In any case, if you want automatic HTTPS on the app..net, you should add app..net to the first block that redirects HTTP to HTTPS.
Answer: This server block from your edited config:
server {
    server_name <domain>.net www.<domain>.net;
    return 301 http://<domain>.net$request_uri;
}

makes no sense and just creates endless redirect loop: from http://<domain>.net/ back to http://<domain>.net/.
If main address is https://app..net/ and your want users to be redirected there (and always with https), just write:
server {
   server_name <domain>.net www.<domain>.net app.<domain>.net;
   return 301 https://app.<domain>.net/;
}

server {
   server_name app.<domain>.net;
   listen 443;
   ssl on;
   ...
}

If there is no other server { } blocks in nginx config first black can be written as
server {
   server_name _;
   listen 80 default_server;
   return 301 https://app.<domain>.net/;
}

Also check how PHP application is configured - may be some redirect sent by application.

setup ssl with nginx on linux


ProLiant ML150 G3 and HP-UX

Question: Does the ProLiant ML150 G3 support HP-UX?
Comment: I don't think this question deserves to go negative, except that it started on the wrong forum.
Comment: I'm going to say that it's not a real question for this site either.  It's a simple fact lookup.  Something that Google finds on the first hit.  Not really appropriate for this site (which attempts to build a knowledgebase of things are NOT simple fact lookups...).
Answer: No. HP-UX only runs on PA-RISC and Itanium processors.
Answer: Chris is correct, as you can also see from the HP-UX article on Wikipedia, and I'd also add that if you're asking if a generic x86 server runs HP-UX you probably don't know what HP-UX is and then you probably don't need it :)

ProLiant ML150 G3 and HP-UX


Button - Displaying Background

Question: I am fixing some broken code that an old coder did and he creates a button programmatically and puts it in a table (bad code if you ask me!) He creates a button like this:
- (UIButton *)recentButton {
    if (recentButton == nil) {
        recentButton = [[UIButton alloc] init];
    }

    UIImage *bgimage = [UIImage imageNamed:@"button_large.png"];
    [recentButton setBackgroundImage:bgimage forState:UIControlStateNormal];
    [self.view addSubview:recentButton];

    return recentButton;
}

The issue I have is within these lines which I added:
UIImage *bgimage = [UIImage imageNamed:@"button_large.png"];
[recentButton setBackgroundImage:bgimage forState:UIControlStateNormal];
[self.view addSubview:recentButton];

This code does not seem to add the background image to the button, the code does not fail to compile, it compiles fine just the background is not correct and is not being added to the button. I would consider myself a newbie at iOS programming so any help would be amazing! I was unable to find any help on stackoverflow which helped this to work Many thanks in advance, Anthony
Comment: Check if `bgimage` is nil.
Comment: It's not nil and has a value
Comment: Is button visible on screen? there is no frame for button. That's y asked.
Comment: Why you're adding the recentButton to the view and the you're returning the same button. Is this not adding the same object twice?
Comment: It's not adding the same button twice as far as I can tell, and yes the button is visible.
Comment: Then what is appear in screen? Could you show screen shot of that screen with that button..?
Comment: The button appears on the screen but it does not have the background on the button...
Comment: where do you set frame for button?
Comment: how are you calling this method without passing any object and allocating it in unbutton class.there is no reference for uibutton class in this method
Comment: Fixed it now, thanks to all!
Comment: I have already, without any code though, will be adding that later
Answer: Try initializing your button like this:
recentButton = [UIButton buttonWithType:UIButtonTypeCustom];

Answer: check with your image image. because it is case sensitive. check your resource folder once again
UIButton *btnClear = [[UIButton alloc] init];
btnClear = [UIButton buttonWithType:UIButtonTypeCustom];

btnClear.frame = CGRectMake(115, 200, 90, 40);

Comment: Thanks for your reply, when I do this, it adds a button with the correct image, but it seems to create a new button which is smack bang in the middle of the screen... I am trying a clean + build now
Answer: Found out that a tableview was holding all of the buttons and was overriding every bit of that code I had written, I changed the tableview code and now it works, thanks to everyone for their help :)
I changed the code to check what was being added, if a button was being added then to set the background image and set the text color to white, else to do what it did before. I will post the code later as I am typing from a PC right now and not the Mac.
Edit: Here is the code:
if ([cellControl isKindOfClass:[UIButton class]]) {
        static NSString *kCellButton = @"CellButton";
        cell = [tableView dequeueReusableCellWithIdentifier:kCellButton];

        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellButton] autorelease];

            cell.backgroundView =[[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"button_large"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]];
            cell.textLabel.textColor = [[[ConfigManager sharedInstance].skin valueForKey:@"tableCellHeadingTextColourButton"] toUIColor];

            cell.textLabel.textAlignment = UITextAlignmentCenter;
            cell.textLabel.font = [UIFont boldSystemFontOfSize:19];
        }

        cell.textLabel.text = [cellData objectForKey:kCellTitleKey];

    }

Once I added this it worked fine, I added the background image within the cellview because I have may buttons so the code is much more efficient this way.

Button - Displaying Background


Apache HTTPd FollowSymLinks path permission

Question: I'm configuring my development environment with a basic Apache HTTPd configuration.
But, to avoid a often problem, I want to map my test URL to my development folder.
I'm using Ubuntu.
My development path is located under the following example path:
/home/myusername/myworkspace/hptargetpath/src/pages

Considering the following symbolic link mapping:
#ls -l /opt/share/www/mydevelopmentrootpath:
lrwxrwxrwx 1 root root 77 2011-02-13 18:53 /opt/share/www/mydevelopmentrootpath -> /home/myusername/myworkspace/hptargetpath/src/pages

With this folder mapping, I configured Apache HTTPd with the following configuration:
<VirtualHost *:*>
        ServerName local.server.com
        ServerAdmin email@example.com
        DirectoryIndex index.html

        DocumentRoot /opt/share/www/mydevelopmentrootpath

        <Directory /opt/share/www/mydevelopmentrootpath/ >
                Options +Indexes
                Options +FollowSymLinks
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

But, I'm receiving a 403 Forbidden error when I want to access index.html under the address http://local.server.com/index.html.
403 Forbidden
You don't have permission to access /index.html on this server.

On httpd debug log, I checked the following message:
[Sun Feb 13 19:34:47 2011] [error] [client 127.0.1.1] Symbolic link not allowed or link target not accessible: /opt/share/www/mydevelopmentrootpath

I'm thinking that this problem is been generated by some path permission. It's not a direct permission to directory, but some intermediate directory in the path.
There's a directive on httpd core Options:
SymLinksIfOwnerMatch
The server will only follow symbolic links for which the target file or directory is owned by the same user id as the link.

But, I tested it without effects.
Somebody may help me? I think that it's a trivial configuration on development environment.
Best regards,
And Past
Answer: apache needs 'execute' right for all parent directories of /home/myusername/myworkspace/hptargetpath/src/pages in order to follow the symlink. you can grant that right with
chmod o+x /home
chmod o+x /home/myusername
chmod o+x /home/myusername/myworkspace
chmod o+x /home/myusername/myworkspace/hptargetpath
chmod o+x /home/myusername/myworkspace/hptargetpath/src
chmod o+x /home/myusername/myworkspace/hptargetpath/src/pages

in most cases, that helps.
Answer: We had a similar problem yesterday. we could solve it be changing the symlink ownership down to the userlevel:
chown -h <user>.<group> <symlink>

apache recognizes the symlink ownership and raises errors if symlink ownership does not fit. in the error_log you can only read "Symbolic link not allowed or link target not accessible". Don't forget the -h option since you change the target ownership otherwise.


Get value from a Combobox Binding MVVM not get correctly

Question: Hi i made a bindable combobox with MVVM and when i'm trying to get the value of combobox it gets the path of the value ex:I select a name and it return WpfApp1.Parts .

How can i get the name from combobox as string?
And if enyone know how can i save the combobox that when i add a new value , like when i enter again on the program my last entered value to be there!
View.Parts:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace WpfApp1
{
    public class Parts : Changed
    {
        public string name;

        public string Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    name = value;
                    RaisePropertyChanged("Name");
                }
            }
        }

    }
}

ViewModel.AddViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WpfApp1
{
    public class AddViewModel : Changed
    {

        private ObservableCollection<Parts> _persons;
        public string names;
        public AddViewModel()
        {
            Persons = new ObservableCollection<Parts>()
             {
                  new Parts{Name="Nirav"}
                 ,new Parts{Name="Kapil"}
                 ,new Parts{Name="Arvind"}
                 ,new Parts{Name="Rajan"}
             };

        }

public ObservableCollection<Parts> Persons
        {
            get { return _persons; }
            set {
                if (_persons != value)
                {
                    _persons = value;
                    RaisePropertyChanged("Persons");
                }
            }
        }
        private Parts _sperson;

        public Parts SPerson
        {
            get { return _sperson; }
            set {
                if (_sperson != value)
                {
                    _sperson = value;
                    RaisePropertyChanged("SPerson");
                }
            }
        }

    }
}

MainWindow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
    ///
    /// Interaction logic for MainWindow.xaml
    ///
    public partial class MainWindow : Window
    {
        public AddViewModel addviewmodel;

        public MainWindow()
        {
            InitializeComponent();
            addviewmodel = new AddViewModel();
            DataContext = addviewmodel;
        }

        public AddViewModel getModel()
        {
            return addviewmodel;
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //textshow.Text = holo.SelectedItem;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {

                getModel().Persons.Add(new Parts { Name = cmbtxt.Text});
        }

    }
}

MainWindowXaml:
 <Grid>
        <ComboBox x:Name="holo"  ItemsSource="{Binding Persons}" SelectedItem="{Binding SPerson}"    SelectionChanged="ComboBox_SelectionChanged" HorizontalAlignment="Left" Margin="391,17,0,0" VerticalAlignment="Top" Width="314" Height="27">
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Path=Name}" />
                    </StackPanel>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>

        <TextBox Name="cmbtxt" HorizontalAlignment="Left" Height="23" Margin="24,21,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="172" />

        <Button Content="Add" HorizontalAlignment="Left" Margin="24,88,0,0" VerticalAlignment="Top" Width="156" Height="49" Click="Button_Click"/>

        <TextBlock x:Name="textshow" HorizontalAlignment="Left" Text="{Binding Path=SPerson}"  TextWrapping="Wrap" VerticalAlignment="Top" Margin="391,104,0,0" Height="33" Width="223"/>

    </Grid>

Answer: The error is here
    <TextBlock x:Name="textshow" HorizontalAlignment="Left" Text="{Binding Path=SPerson}"

You cannot bind Text property to complex Object like Parts you should bind it to the Name as you did with ComboBox
Answer: You should bind to the Name property of the selected item returned by the SPerson property:
<TextBlock x:Name="textshow" HorizontalAlignment="Left"
           Text="{Binding Path=SPerson.Name}"
           TextWrapping="Wrap" VerticalAlignment="Top"
           Margin="391,104,0,0" Height="33" Width="223"/>

What you currently see is the ToString() representation of the Parts class so the other option would to override this method:
public class Parts : Changed
{
    public string name;

    public string Name
    {
        get { return name; }
        set
        {
            if (name != value)
            {
                name = value;
                RaisePropertyChanged("Name");
            }
        }
    }

    public override string ToString()
    {
        return name;
    }
}


How to configure the CORS module for multiple domains?

Question: I have JSON content I want to deliver to multiple domains. I have installed the CORS module. I have configured to deliver to one domain like this:
<code>*|<mirror>,http://www.other-domain.com
</code>
This works. However, I want to configure for a list of domains and can't work out how to configure that. The following doesn't work:
<code>*|<mirror>,http://www.other-domain.com,https://www.and-another.com
</code>
Nor does
<code>*|<mirror>,http://www.other-domain.com
*|<mirror>,https://www.and-another.com
</code>
How do I configure this?
Comment: This information doesn't really help. It's too specific to the module. You should read about CORS and what the expected output of headers should be. Specifically the output should either be `*` or `https://www.example.com`. Include the HTTP Request and HTTP Response headers.
Comment: It does not look like the module and patch implement CORS correctly. The response header `Access-Control-Allow-Origin` is set to a comma-delimited string when it must be exactly 1 origin or `*`. If I use the configuration `*|https://www.example.com,https://www.drupal.org` and `curl -vvv -H "Origin: https://www.example.com" https://something.ply.st/node/1.json`, then I get `Access-Control-Allow-Origin: https://www.example.com, https://www.drupal.org`, which is not valid. Trying a preflight request results in the same invalid response header.
Comment: I've resolved the issue by using /directory/*|* Whilst not ideal it is the only way I can get it to work.
Comment: I'm voting to close this question as off-topic because it's a bug report and needs to be handled in the issue queue on Drupal.org
Answer: Upon further investigation, this seems to be an issue with the CORS module, and has been patched, so hopefully fixed in future versions.
https://www.drupal.org/node/2780297
Comment: Still not working - I applied the patch but it is still not working...


Root term in Pathauto only works for child terms?

Question: My taxonomy structure looks like this:
Film
- Short film
- Special film

Using Pathauto, I would like the url to always include the root term.
So for nodes tagged with 'film' the path is: film/node-title. For nodes tagged with 'short film' the path is also: film/node-title
I thought the 'root term' token would do the trick, setting pathauto pattern to: [node:field-category:root:name]/[node:title]
But it only works for children. If a film is tagged 'film', the token isn't used for some reason. Perhaps I am misunderstanding the meaning of 'root'?
Comment: Why do you don't set it fix as a pattern? Pattern = film/[node:title]
Comment: Good point. It's because my vocabulary has other terms with children, such as Concert->Acoustic, Concert->Fundraising etc.
Answer: I encountered the same problem and wrote the patch for token module
Here is patch https://drupal.org/node/2050421#comment-7806099


Why is there an R^2 value (and what is determining it) when lm has no variance in the predicted value?

Question: Consider the following R code:
example <- function(n) {
    X <- 1:n
    Y <- rep(1,n)
    return(lm(Y~X))
}
#(2.13.0, i386-pc-mingw32)
summary(example(7))    #R^2 = .1963
summary(example(62))   #R^2 = .4529
summary(example(4540)) #R^2 = .7832
summary(example(104))) #R^2 = 0
#I did a search for n 6:10000, the result for R^2 is NaN for
#n = 2, 4, 16, 64, 256, 1024, 2085 (not a typo), 4096, 6175 (not a typo), and 8340 (not a typo)

Looking at http://svn.r-project.org/R/trunk/src/appl/dqrls.f) did not help me understand what is going on, because I do not know Fortran.  In another question it was answered that floating point machine tolerance errors were are to blame for coefficients for X that are close to, but not quite 0.
$R^2$ is greater when the value for coef(example(n))["X"] is closer to 0. But...

Why is there an $R^2$ value at all?
What (specifically) is determining it?
Why the seemingly orderly progression of NaN results?
Why the violations of that progression?
What of this is 'expected' behavior?
Comment: Well, to be fair, the user is supposed to actually *know* something about statistical methods before using tools (unlike, say, Excel users (ok, sorry about the cheap shot)).  Since it's rather obvious that R^2 approaches 1 as error approaches zero, we know better than to confuse a NaN value with the limit of a function.  Now, if there were a problem with R^2 diverging as ynoise-->0   (say, replace Y statement above with `Y <- rep(1,n)+runif(n)*ynoise` ), that would be interesting :-)
Comment: You're studying double precision rounding error.  Take a look at the coefficients; e.g., `apply(as.matrix(2:17), 1, function(n){example(n)$coefficients[-1]})`.  (My results, on a Win 7 x64 Xeon, range from -8e-17 to +3e-16; about half are true zeros.)  BTW, the Fortran source is of no help: it's just a wrapper for dqrdc; that's the code you want to look at.
Comment: (Continued) But, as a user, the choice of CV is a better site, for the simple reason that diligent statistical analysis is the responsibility of the user, not the developer.  If the user sees an erroneous $R^2$ relative to the magnitude of the RSS, then they should do their own post-processing before reporting further.  Programming-wise, I'd like to know how to avoid these numerical issues as much as possible, but I think that they can't be escaped, and that's where it's important to have  a diligent user and to educate others.
Comment: Note:   7's R^2 should be 0.4542  to see something more constructive see my answer.  :-)
Comment: @eznme: I think the results are machine specific, or at least 32 or 64 bit specific; I have a 32-bit machine that gives 0.1963 for 7, but my 64-bit machine gives NaN.  Interestingly, on the 64-bit machine, the R^2s that are not NaN are all very close to 0.5. Makes sense when I think about it, but it surprised me at first.
Comment: +1 This is a fascinating question, especially with the curious progression of `NaN`s.
Comment: I sort of object to the migration.  I know CrossValidated exists, but I specifically asked on StackOverflow because I wanted a more machine-level technical answer.
Comment: @drknexus  I slightly agree, but am rather ambivalent. The expertise on FP numerical computing is likely more numerous on SO; on CV there's a lot more expertise in the statistical side.  Either way, it's an R question, and Ben's comment below, about R Core, along with whuber's about Chambers' book, are likely the most insightful responses achievable on either site.  Only with these answers can we learn whether there are statistical or programming blunders.  It turns out that it's neither: it has more to do with numerical precision and the priorities of R core.
Comment: For whatever it's worth, you got the same answer from me that you would have gotten on SO -- I was busy composing it when the question got migrated, and I had to save my work and paste it over here ...
Answer: I'm curious about your motivation for asking the question. I can't think of a practical reason this behavior should matter; intellectual curiosity is an alternative (and IMO much more sensible) reason. I think you don't need to understand FORTRAN to answer this question, but I think you do need to know about QR decomposition and its use in linear regression.  If you treat dqrls as a black box that computes a QR decomposition and returns various information about it, then you may be able to trace the steps ... or just go straight to summary.lm and trace through to see how the R^2 is calculated.  In particular:
mss <- if (attr(z$terms, "intercept"))
          sum((f - mean(f))^2)
       else sum(f^2)
rss <- sum(r^2)
## ... stuff ...
ans$r.squared <- mss/(mss + rss)

Then you have to go back into lm.fit and see that the fitted values are computed as r1 <- y - z$residuals (i.e. as the response minus the residuals).  Now you can go figure out what determines the value of the residuals and whether the value minus its mean is exactly zero or not, and from there figure out the computational outcomes ...
Comment: mms and rss are both results of z, which is the name of the lm object inside of summary.lm.  So, an answer probably does require an explanation of QR decomposition, its use in linear regression, and specifically some details QR decomposition as instantiated in the code underlying R in order to explain why the QR decomposition ends up with approximations of 0 rather than 0 itself.
Comment: Intellectual curiosity is the majority of the reason for my question.  A colleague reported the behavior and I wanted to poke around and see if I could figure it out.  After I traced the issue beyond my skill-set, I decided to ask the question.  As a practical issue, sometimes analyses are done by batch, or other errors occur, and this behavior strikes me as decidedly 'odd'.
Comment: @drknexus I disagree. QR decomp is one of many numerical algorithms; if the underlying issue is numerical precision, this'll crop up in QR, matrix multiplication, non-linear solvers, and so many other places. The essential sequence is simple: the coefficients are very slightly off (should be (0,1)); this isn't unreasonable, yet produces the `mss` and `rss` "noise". It's the GIGO principle that assures that $R^2$ is precise, but incorrect.  I'd rather insert a "garbage detector" before calculating $R^2$ than to modify the QR algo, because I doubt its validity could be improved.
Comment: It seems to me that the garbage detector should be at the QR or right before it.  A simple sanity check on the variance of Y and warning that Y lacks variance would be fine (I may write an lm wrapper for my friends that does just this).  It seems to me that by the time you are calculating $R^2$, one is already too far down the computational rabbit hole to know if one is looking at garbage or not.
Answer: As Ben Bolker says, the answer to this question can be found in the code for summary.lm().
Here's the header:
function (object, correlation = FALSE, symbolic.cor = FALSE,
    ...)
{

So, let x <- 1:1000; y <- rep(1,1000); z <- lm(y ~ x) and then take a look at this slightly modified extract:
    p <- z$rank
    rdf <- z$df.residual
    Qr <- stats:::qr.lm(z)
    n <- NROW(Qr$qr)
    r <- z$residuals
    f <- z$fitted.values
    w <- z$weights
    if (is.null(w)) {
        mss <- sum((f - mean(f))^2)
        rss <- sum(r^2)
    }
    ans <- z[c("call", "terms")]
    if (p != attr(z$terms, "intercept")) {
        df.int <- 1L
        ans$r.squared <- mss/(mss + rss)
        ans$adj.r.squared <- 1 - (1 - ans$r.squared) * ((n -
            df.int)/rdf)
    }

Notice that ans\$r.squared is $0.4998923$...
To answer a question with a question: what do we draw from this?  :)
I believe the answer lies in how R handles floating point numbers.  I think that mss and rss are the sums of very small (squared) rounding errors, hence the reason $R^2$ is about 0.5.  As for the progression, I suspect this has to do with the number of values that it takes for the +/- approximations to cancel out to 0 (for both mss and rss, as 0/0 is likely the source of these NaN values).  I don't know why the values differ from a 2^(1:k) progression, though.

Update 1: Here is a nice thread from R-help addressing some of the reasons that underflow warnings are not addressed in R.
In addition, this SO Q&A has a number of interesting posts and useful links regarding underflow, higher precision arithmetic, etc.
Answer: $R^2$ is defined as   $R^2 = 1-\frac{\textrm{SS}_{err}}{\textrm{SS}_{tot}}$   ( http://en.wikipedia.org/wiki/R_squared ), so if the sum-of-squares-total is 0 then it is undefined. In my opinion R should show an error-message.
Comment: @Brandon -- Iterator put the smiley in there and you *still* got whooshed!
Comment: @eznme  While an error is good, it is quite difficult to catch all kinds of places where floating point issues arise, notably in the world of IEEE-754 arithmetic.  The lesson here is that even the bread and butter calculations with R should be handled delicately.
Comment: These considerations are especially important because in his writings, John Chambers (one of the originators of S and therefore a "grandfather" of R) strongly emphasizes the use of R for *reliable computing.*  E.g., see Chambers, *Software for Data Analysis: Programming with R* (Springer Verlag 2008): "the computations and the software for data analysis should be trustworthy: they should do what they claim, and be seen to do so."  [At p. 3.]
Comment: The problem is that for better or worse, R-core is resistant to (as they see it) festooning the code with many, many checks that intercept all corner cases and possible weird user errors -- they are afraid (I think) that it will (a) take huge amounts of their time, (b) make the code base much larger and harder to read (because there are literally thousands of these special cases), and (c) slow down execution by forcing such checks all the time even in situations where computations are being repeated many, many times.
Comment: Can you give a practical situation where this behavior would matter?
Comment: @BenBolker I can: Model selection based on a model with highest R-squared.  :)
Comment: @BenBolker Yea with real data this doesn't happen (not after the symmetry-break after the big-bang). How about my idea that R should show an error instead of just silently giving bogus-result? Would help in those situations when you accidentally did something to your data that made it have zero variance
Comment: @Iterator Of course i cannot check for float-equality (nor can we check whether R^2 is too small because what is "too small"), but what i would like is writing R^2=NaN instead of silently having undefined behavior.
Comment: @Iterator I can't see how that would matter? OtherR2 >< NaN would always return NA which would a) break your code anyways or b) force you to account for and ignore it.
Comment: @BrandonBertelsen  Hehe...  I address `NA`s over on StackOverflow.  ;-)  At least that's been my impetus for several recent questions - breaking my code doesn't happen often enough in some cases, and accounting for NAs: bring it on!  :)
Comment: ... to do that, we would have to modify `summary` to look at if it's input is bitwise identical. This would catch the cases in which un-initialized/zero'ed data is accidentally used (e.g. previous assignment to wrong variable...) even if it was linearily transformed; cool.
Comment: @BenBolker (a)-(c) all true.
Comment: @eznme In order to get the output, one has to detect possible underflow issues.  This is often, but not always, feasible.  In a simple case like this, I think that there should be an underflow check.  It's a ratio of two floats, which is an operation that's not a big part of the computational cost of the summary.  I don't excuse not checking, but, as Ben points out, it'll take some time and effort to get these checks inserted in lots of places.


Merge bootstrap css and JS file with our custom css and JS to make a sigle Http connection

Question: I want to make a single  server call for css and JS file for to optimize the speed. So can any one suggest me Is this good to merge  css and JS with our custom css and JS. And also i override Bootstrap css class in custom css It will create any problem???
Answer: well, no problem should happen. putting codes and rules in different files is to manage them in better way.
the point is don't forget to place bootstrap css rules above your own rules. this way your customized rules will override bootstraps.
Answer: I suggest you use UglifyCSS and UglifyJS. You can also use an asset management framework for PHP like Assetic that uses these tools easily.
The CSS cascading order is very important, the last declared is more relevant.
Comment: Hi pedro gamez one more thing is the good to merge bootstrap javascrip and our custom javascript with jquery???
Comment: In my HTML5 game I merge JQuery, my custom Javascript and others vendors libraries. It is recommended because you send only an asset :). Of course in the project the files are separated but when they are sent, my project merge all javascript and compress.
Answer: You can definitely combine them. Just be sure to do so in the same order you would load them if loading separate files.
Afterwards, minify them using any number of minifiers (just google it), and even gzip them for even smaller files.
Assuming you've done the same with your images and icons (i.e. spriting them) you'll have very few http requests.


Will NSLog slow my app?

Question: I have a lot of NSLog's in my app - some of which often print large amounts of data - ie results of a search. Will this make an appreciable difference in the speed of my app?
I'm not familiar with macros - would someone be able to suggest one that would enable/disable all NSLogs?
Comment: Definitely NSLog can slow your app.  How serious this is obviously depends on how much you use the macro.  Most folks use some variation of a macro that can be switched on/off with either a compile flag or a runtime switch.
Answer: Yes NSLog could make your app slower because of its synchronism.
To toggle all NSLog
#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif

Comment: @JoshDG you can place it in your project's `Project Name-Prefix.pch` file. The `DEBUG` constant is automatically defined by XCode when building for debugging.
Comment: @JoshDG The app is automatically compiled using the `Release` profile when you `Archive` it before send it in for the review.
Comment: When I make new project, it doesn't include the .pch file as it used to in previous releases of XCode.
Comment: Forgive my ignorance. Where would I put that bit of code - and where do I set the value for debug? Do I need to declare that in each file which calls NSLog?
Comment: How do I build for...not-debugging? I tried 'Build for running' but my the logs still printed.
Answer: You should use something like DLog from MY CURRENT PREFIX.PCH FILE. It'll disable logging in the Release build. This is a great explanation of why you shouldn't keep NSLog's in the Release build.
Answer: If your app is for production try to minimize them. Keep only the ones useful for errors or possible warnings. If you used them for helping you debug, then I advise you to remove them.
Answer: YES!! too many NSLOgs will definitely slow your app.
As a best practice I usually add this in my .pch(pre compiled header file)
#ifdef DEBUG
#define DebugLog(f, ...) NSLog(f, ## __VA_ARGS__)
#else
#define DebugLog(f, ...)
#endif

just enabled DEBUG in your preprocessor macro in build settings for debug target. Use DebugLog instead of NSLog().
Your distribution/release will not have DEBUG defined. So your app wont print anything in the log for distributed app.

Will NSLog slow my app?


Linear Discriminant Analysis for newbie (What is the meaning of dataset is linear separable?)

Question: What is the meaning of "LDA dataset is linear separable"?
"the classes are non-linearly separated"
"the features have nonlinear relationships"
As I know in maths for linear equation and non-linear equation.
Answer: If the classes are linearly separable, there exists a hyperplane (on the same feature space) to separate them. When there is not, the classes are either non-separable or separated by other types of hyper-surfaces, e.g. if instead of a line, a parabola in 2D feature space can separate the classes, it's said non-linearly separable. Features having non-linear relationships is like having features $x,y$ where $y=x^2$. When you add new features using the old ones, to be able to separate your samples in a higher dimensional space linearly (so non-linearly in the original feature space), you add new features that are nonlinearly related to the original ones.
Comment: original features.
Comment: Still, you could do the LDA in the new feature space.
Comment: LDA is not handling features, it handles the classes. Features can surely have nonlinear relationships. For example, we can add a new feature $x^2$ that makes the classes more separable, which means LDA will do a good job.
Comment: I'd say 'classes which have non-linear decision boundaries'
Comment: generally makes sense, and better to stay in your own words. I'd soften the statements a bit, e.g. LDA is less capable ... because ... requires the class separators to be hyperplanes.
Comment: thanks. I am confused with the sentences `When you add new features using the old ones, to be able to separate your samples in a higher dimensional space linearly`. What is the `old one`?
Comment: thanks. So  `When you add new features using the original features`, this situation is not suitable if I use LDA as `dimensional reduction method`. Adding new features using old features is like making a new prediction?
Comment: thanks. Are you familiar with `LDA, small sample size problem`?  I would be appreciated if you can give some comment/answer https://stats.stackexchange.com/questions/468095/linear-discriminant-analysis-have-small-sample-size-problem-sss-is-it-nd
Comment: Is it true that `LDA is not capable of dealing with features which have non-linear relationships`?
Comment: thanks. Maybe I read somewhere which I am confused / I make mistake. How about `LDA is not capable of dealing with classes which have non-linear relationships`?
Comment: thanks. You are brilliant! Can you read this sentence, make sense? `the classes of both datasets are not linearly separable in the original feature space. LDA fails to find the projection defining LDA space when the discriminatory information does not lie in the means of classes. Although the LDA method can effectively reduce the dimension of a dataset, it is not capable of dealing with classes which have non-linear decision boundaries because the LDA method requires the input data to have the property of linearity.`
Comment: thanks a lot. Brillant!
Comment: Is Linear Discriminate Analysis (LDA) and Fisher Discriminant Analysis (FDA) same meaning?

And also Fisher Criterion (FC)?

Do these three terms interchangeably, having the same meaning?
Comment: there are slight differences in some contexts: https://en.wikipedia.org/wiki/Linear_discriminant_analysis#/Fisher's_linear_discriminant
Comment: Linear discriminant analysis (LDA)  is a generalization of Fisher's linear discriminant.  The terms Fisher's linear discriminant and LDA are often used interchangeably, although Fisher's original article[1] actually describes a slightly different discriminant

I think is same meaning


Como deixar meu rodapé fixo abaixo de todo o conteúdo da página?

Question: Estou criando um rodapé fixo (cor laranja), imagem abaixo:

O problema é que ele esconde parte do conteúdo da página (um banner verde, como pode ser visto, e em outras páginas, notícias e informações)
Como deixá-lo por baixo de todo o conteúdo para que não oculte nada na tela.

div.rede-social-rodape{
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 150px;
    background-color: #E9CA2B;
    border-top: 2px solid #b79900;
}

Comment: tem que ser no último container antes do footer, ele tem que ter um padding-bottom com a mesma altura do footer, isso deve resolver. Ou então vc já coloca logo esse padding-bottom da altura do footer direto no body, isso deve resolver tb
Comment: Cara só com esse pedaço de código não da para te ajudar. Mas basicamente coloque na última div antes do Footer um padding bottom que tenha a mesma altura do footer. Se resolver me fala que posto como resposta.
Comment: @hugocsl quanto de código precisa? Posso postar.
Comment: Pelo menos o HTML da página e o CSS, se tiver script não precisa. só html e css mesmo, algo que de para simular seu problema
Comment: @hugocsl mas o que se faz para não ocultar o conteúdo é dar um padding bottom?
Comment: @hugocsl resolveu. Muito Obrigado! Se quiser formule uma resposta.
Comment: Valeu Gladison publiquei o comentário como resposta vlw  []´s
Answer: Gladison o que acontece é que um elemento com position:fixed acaba saindo do fluxo de conteúdo do documento, deixando de ocupar espaço. Devido a isso o conteúdo que está acima dele acaba "collapsando" e ocupando o espaço que seria do elemento fixado.
No seu caso uma das técnicas para resolver isso é colocar no elemento que precede o footer um padding-bottom com o mesmo height do footer. Esse padding vai evitar que um conteúdo fique por cima do outro, pois agora o espaço do footer vai ser ocupado pelo o padding.
Aqui tem uma documentação sobre position que pode te ajudar a entender o conceito https://developer.mozilla.org/pt-BR/docs/Web/CSS/position
Comment: Perfeito! Muito obrigado.
Comment: @Gladison tmj jovem!