How does the curves-fields correspondence fail in higher dimensions?

Question: It's embarassing how little I know about higher dimensional varieties.
Let $k$ be an algebraically closed field. Then, the category of smooth projective curves over $k$ and nonconstant morphisms is equivalent to the category of fields $K/k$ of transcendence degree one.
How does this fail in higher dimensions?
I'm looking for examples of smooth projective varieties $X,Y$ which have isomorphic function fields, but are not isomorphic.
Also, in higher dimensions, how can a rational map between smooth proj. varieties fail to be a morphism?
Comment: Blowup a surface in one point.
Comment: To add to MooS' pithy comment, the key word you are looking for is "birational". Good luck!
Answer: Perhaps this will aid your intuition.
Consider this rational map from a smooth curve to a projective space:
$$ f: \mathbb A^1 -\!\! \rightarrow\mathbb P^1, \ \ f(t) = [t:1/t^2] $$
At first glance, it looks like $f$ is not regular at $t = 0$. But that is an illusion. Clearing denominators, you see that $f$ can be rewritten as
$$ f(t) = [t^3:1]$$
which is manifestly regular.
So what is the algebraic property that makes the "clearing denominators" trick work? It's fact that the local ring on $\mathbb A^1$ at $t = 0$ is a discrete valuation ring. In this example, $t$ has valuation $1$ and $1/t^2$ has valuation $-2$ in the local ring, so the denominators are cleared by multiplying by $t^2$ which has valuation $+2$.
How does this generalise when you have a rational map
$$ f: X -\!\! \rightarrow \mathbb P^n $$
where $X$ is smooth, but of arbitrary dimension? Well, the local rings of $X$ in codimension 1 are discrete valuation rings. Using the same trick of "clearing denominators", you see that $f$ is regular everwhere except on a codimension 2 subspace of $X$. But as MooS points out, you can't do better than this - consider the blow up of a surface.


Mixed desgin ANOVA or LMM?

Question: I am hitting a wall and would appreciate some help.
Here is my data (raw data, before computing the means):
   'data.frame':   8000 obs. of  11 variables:
    $ group                : Factor w/ 5 levels "asiapic","asiavid",..: 3 3 3 3 3...
$ subject              : Factor w/ 80 levels "P17001","P17002",..: 1 1 1 1 1 ...
    $ gender_part          : Factor w/ 2 levels "female","male": 2 2 2 2 2 2 2 2 ...
$ order                : Factor w/ 2 levels "first","second": 2 2 2 2 2 2 2 ...
    $ condition            : Factor w/ 2 levels "baseline","experiment": 1 1 1 ...
$ voice                 : Factor w/ 10 levels "adam","aline",..: 6 7 6 9 3 ...
    $ sex                  : Factor w/ 2 levels "f","m": 1 1 1 2 2 1 1 1 1 1 ...
$ accent               : int  3 7 4 9 4 3 4 7 8 4 ...
    $ intelligibility      : num  0.571 0.857 0.75 0.714 0.429 ...
$ item                 : Factor w/ 100 levels "90","26","50",..: 1 2 3 4 5...
    $ comprehensibility    : int  7 3 7 3 8 5 6 5 3 7 ...

My DVs are accent (values 1-9), comprehensibility (values 1-9), intelligibility (ratio 0-1).
My main IVs are group (between subjects, 5 levels) and condition (within subject, 2 levels: baseline and experiment).
I have been looking (for a very long time) for the right way to analyze these variables. What I primarily interested in is the group * condition interaction.
Were all the group same in the baseline? Were they different in the experimental condition? - when it comes to my 3 DVs - and these DVs may be slightly correlated.
Additionally, I am interested in the possible effect of sex (this is the gender of the speaker in the stimuli) and maybe participant's gender.
I have tried mixed ANOVA (for each DV separately):
model = aov(accent ~ group * condition + Error(subject/condition), data=data)

This gives me the infamous Error() model is singular, which I think it's because the lowest level will always be included here, and since I have only 2 conditions this is included by default and I can just go with Error(subject), right?
Now I'm not sure if:
(1) Is this really the right way to do it?
(2) Which function to use for the post hoc test and how to make sure that the groups were comparable in the baseline condition?
(3) Should I analyze data for male and female voices (stimuli) separately or put it somehow into the model? sex*group*condition?
I have also tried lme with lme4:
model = lmer(accent ~ sex * group * condition + (1|subject) + (1|item), data=data)

(where item is the audio file in the stimuli)
(4) Would this be a better idea and if so how would you then deal with p-values and pair-wise comparison?
I realize this is a lot of questions but I would really appreciate some help.
Answer: A couple of notes:

Your depenent variables accent and comprehensebility are bounded and also seem to be discrete. Both the aov() and lmer() analysis assume normally distributed error terms. Hence, you need to see how good the normal approximation is for your data. With regard to intelligibility, this is binary, and therefore you will need to analyze it with a mixed effects logistic regression, i.e., glmer(..., family = binomial()).
The specification via random effects and lmer() is more flexible than the aov().
Fitting separate models for males and females means actually that the variance components (i.e., error variance, and variances for the random effects) are different between males and females. If you only include the interaction sex * group * condition only the fixed effects of group, condition and their interaction group:condition are different between males and females, but not the variance components. Using the latter approach, you can more easily test if you need the interaction with sex.
For a fitted mixed model, you can do multiple comparisons and obtain adjusted $p$-values using either the emmeans of multcomp packages.
Comment: - It is true that both `accent` and `comprehensibility` ratings seem to be discrete but this is the standard measure for these two dimensions (it was proved that it has a nearly 1.0 correlation to the linear rating). However, since these are bounded I am getting stripes in the residuals plot after fitting lme - which I assume I should not have.

- intelligibility is a ratio words_all/words_correct, I'm sorry I was not clear about it.
-I will try the package you mentioned. Thank you.
- Any good method to deal with influential data points?

Mixed desgin ANOVA or LMM?


Computing $\sqrt{2}+\sqrt[4]{2}$ over $\mathbb{F}_3$

Question: I'm computing different minimal polynomials in $\mathbb{F}_3$. I found that I can look at elements of the form $\sqrt[4]{2}$ in $\mathbb{F}_3[\sqrt{2}]$ and  in particular I found the four fourth roots of two in that field are $1+2\sqrt{2},1-2\sqrt{2},2+\sqrt{2},2-\sqrt{2}$ while the square roots of 2 are $\sqrt{2},-\sqrt{2}$.
Now I'm trying to calculate the minimal polinomial of $\alpha = \sqrt{2}+\sqrt[4]{2}$ over $\mathbb{F}_3$ and I obtain that any $\alpha$  must be a root of $$(X-1)^2(X^2+2X+2)$$ (see the edit below to understand how I obtain it) This gives me at most 3 possible $\alpha$. However, if I sum the elements above I get six different values.
What am I doing wrong?
Edit:
\begin{align*}
\alpha &= \sqrt{2}+\sqrt[4]{2}\\
(\alpha - \sqrt{2})^2 &= \sqrt{2}\\(\alpha^2+2)^2 &= ((2 \alpha + 1)\sqrt{2})^2\\\alpha^4 - 4 \alpha^2 - 8 \alpha + 2 &=0\\\alpha^4 - \alpha^2 + \alpha+2 &=0\\(\alpha-1)^2(\alpha^2+2\alpha^2+2)&=0
\end{align*}
Comment: When you compute $\sqrt2+\sqrt[4]2$ I presume you want the roots to be compatible, i.e., the $\sqrt2$ is the square of the $\sqrt[4]2$. You then get three possible values $\alpha=1$ or $\alpha=-1\pm\sqrt2$. I suppose you could choose your $\sqrt2$ to be $-(\sqrt[4]2)^2$, but that would be perverse surely?
Comment: Note that $\pm 2\sqrt{2}=\mp \sqrt{2}$.
Comment: @ThomasAndrews I specify my calculations in the edit. it appears to me that i'm assuming $\sqrt{2}=(\sqrt[4]{2})^2$ as LordSharktheUnknown suggests
Comment: @ThomasAndrews still i get six possible summands which can not be all roots of the polynomial i calculate
Comment: You don't tell us how you "obtain" that polynomial.
Answer: Let me suggest an approach that might be precisely orthogonal to your strategy. We're tourists in the land of characteristic three, in which $2=-1$, so your first adjunction is of $i=\sqrt{-1}=\sqrt2$. So you've adjoined a primitive fourth root of unity, which lies in the field $\Bbb F_9$, the (unique) quadratic extension of $\Bbb F_3$.
But the multiplicative group of $\Bbb F_9$ is of order eight, so that you have the eighth roots of unity free of charge by adjoining $i$. The nonzero elements of $\Bbb F_9$ that aren't in the set $\{\pm1,\pm i\}$ are $\pm1\pm i$, four in number, and there is your total list of the four possibilities for what you called $\sqrt[4]2$. Just take one of them, $1+i$, whose $\Bbb F_3$-conjugate is $1-i$. Their common minimal polynomial is clearly $X^2-X-1$. The other two are $-1\pm i$, and their common polynomial is $X^2+X-1$.
I think that with this explicit description of the elements of $\Bbb F_9$, you can answer your question. Note that one of the one of the elements "$\sqrt2+\sqrt[4]2$" is in fact equal to $1$.
Comment: In the spirit of @Lubin's answer, see math.stackexchange.com/a/2458854/300700. In the notations therein, $\omega$ is a primitive $8$-th root of $1$, and one choice for your ( $\sqrt [4] 2 , \sqrt 2$) could be ($\omega, \omega^2$) ; if $\omega$ is chosen to be a root of $X^2 + X -1$, then $\omega +\omega^2 =1$. Similar calculations for the other choices.


"Invalid column name" MVC

Question: Eu tenho uma tabela em um DbContext, troco o nome dela, atualizo a database e quando eu executo eu sou redirecionado para o Visual Studio com a seguinte mensagem de erro:

Invalid column name 'SetorId'.

Obs:O nome da tabela está Setor_Id. Eu mudo o nome no model e na própria table antes de atualizar a database.
Model:
public class RamalModel
{
    public int ID { get; set; }

    [Required(ErrorMessage = "O nome é obrigatório.")]
    public string Nome { get; set; }

    [Required(ErrorMessage = "O número é obrigatório.")]
    public int Numero { get; set; }

    [ForeignKey("Setor")]
    public int SetorId { get; set; }

    public Setor Setor { get; set; }
}

DbContext:
public class RamaDb : DbContext
{
    public DbSet<Usuario> Usuarios { get; set; }

    public DbSet<RamalModel> Ramais { get; set; }

    public DbSet<Setor> Setores { get; set; }

    public DbSet<Area> Areas { get; set; }
}

Table:
   CREATE TABLE [dbo].[RamalModels] (
[ID]       INT            IDENTITY (1, 1) NOT NULL,
[Nome]     NVARCHAR (MAX) NOT NULL,
[Numero]   INT            NOT NULL,
[Setor_Id] INT            DEFAULT ((0)) NOT NULL,
CONSTRAINT [PK_dbo.RamalModels] PRIMARY KEY CLUSTERED ([ID] ASC)
);

GO
CREATE NONCLUSTERED INDEX [IX_SetorId]
ON [dbo].[RamalModels]([Setor_Id] ASC);

Answer: O nome da coluna em banco está errado. Deveria ser SetorId, e não Setor_Id. Não use underscore para mapear suas chaves de entidades, pois eles não fazem parte da convenção do Entity Framework.
Você está usando o Entity Framework errado. É ele que deveria atualizar o banco automaticamente pra você, e não você atualizar o banco com scripts.

"Invalid column name" MVC


Elementary Number Theory : Prime

Question: Problem : Determine all twin primes $p$ and $p+2$ for which $p(p+2)-2$ is also prime.
First, $3$ and $5$ are primes and $3*5-2=13$ is also prime.
Assume that $p=3m+n$ $(n=0, 1, 2)$ and 1$\leq$m. i.e. $p>3$
Then $n$ cannot be $0$ since $p$ is prime.
And $p$ cannot be $3n+1$ since $(3n+1)+2=3(n+1)$ is not prime.
So $p=3n+2$
Then $p(p+2)-2=(3n+2)(3n+4)-2=3(3m^2+6m+2)$ is not prime.
Hence $3, 5$ are the only pair.
Is this right proof?
Comment: "*First 3 and 5 are primes and $3\cdot 5 \color{red}{-2=13}$ is also prime*"  $15$ is not prime, $13$ is.
Answer: Apart from a mistyping (you said $3×5=15$ where you meant $3×5-2=13$) the proof looks correct.
An alternate version: If $p\equiv2\bmod3$ then we can render
$p(p+2)-2\equiv2(2+2)-2\equiv6\equiv0\bmod3$
without computing the full polynomial.

Elementary Number Theory : Prime


Two proof questions about eigenvectors

Question: a. How do I prove that if $\lambda^2$ is an eigenvalues of $A^2$ then at least $\lambda$ or $-\lambda$ is an eigenvalue of $A$.
b. I want to show that an invertible linear transoformation $T$ and its inverse $T^{-1}$ have the same eigenvectors.
thank you!
Comment: What have you tried ? Where are you stuck ? We are not here to solve your homework !
Comment: What is the underlying field?
Comment: well about a im not sure if its true or false to begin with
Comment: I presume R, but its not clearly stated
Comment: @Surb Seems you habe been refuted.
Answer: Let $v$ be the eigenvector of $A^2$ corresponding to the eigenvalue ${\lambda}^2.$ Then we have
$$(A^2 - \lambda^2 I) v = 0 \implies (A- \lambda I) (A + \lambda I) v = 0.$$
So either $(A+\lambda I) v = 0.$ In which case $-\lambda$ is an eigenvalue of $A$ corresponding to the eigenvector $v.$  Otherwise $$(A+ \lambda I) v \neq 0.$$ Then $\lambda$ will be an eigenvalue of $A$ corresponding to the eigenvector $(A + \lambda I)v$.
For the second one let us take an eigenvector $v$ of $T$ corresponding to the eigen value $\lambda$. Then first show that $\lambda \neq 0$ and then try to show that $v$ is also an eigen vector of $T^{-1}$ corresponding to the eigenvalue $\frac {1} {\lambda}$. The converse can also be similarly proved.
Comment: The big $\;X\;$ as vector is pretty confusing, in particular when there are other big letters with other functions.. I'd rather go with $\;x, u, v, w\;$or something like that.
Comment: Well which one should I opt? Kindly suggest me one such according to your wish @DonAntonio. You are always welcome to do any kind of constructive edits if necessary.
Comment: If you invite constructive edits, then don't roll them back within seconds. I see you had a conflict with your own edit, but there are more elegant ways to solve that (which I implemented) than just crushing the other edit.
Comment: For the second half of the first proof, I would suggest it would be better to make a distinction as follows: either $(A+ \lambda I) v$ is zero (in which case $v$ is an eigenvector for $-\lambda$) or it is not (in which case $(A+ \lambda I) v$ itself is an eigenvector for $\lambda$, as in the part you wrote). This also avoids treating $\lambda=0$ as a special case, or having  to assume $\lambda^2\geq0$ (where is that assumption ever used).
Comment: Thanks for your valuable suggestion @Marc van Leeuwen. I have edited my answer.

Two proof questions about eigenvectors


How to filter Chinese punctuation in Scala/Java?

Question: I'm trying to make a language agnostic text parser in Scala/Spark. I was using regex to remove punctuation from large groups of text.
list_of_strings.map(_.replaceAll("""[\p{Punct}]"""))

However, I find a number of punctuation marks in Chinese text that are not removed. So far I have added [〝〞。,"] to my regex for these characters. Notice that many of these are similar to latin punctuation marks, but not quite the same.
Is there a 'cannonical' function built into Java regex that will allow me to strip punctuation in other languages? Other than Chinese, I'm concerned about Arabic.
Also, I want to ensure that stripped punctuation in one language isn't a critical language component in another. I am not familiar with either the Chinese or Arabic languages, so I'm looking for something premade by a native speaker.
Answer: You do not need to add all those Unicode punctuation chars into the character class. Make the \p{Punct} Unicode-aware with the Pattern.UNICODE_CHARACTER_CLASS or an equivalent (?U) embedded flag option:
.replaceAll("""(?U)\p{Punct}+""", "")
               ^^^^

See the Scala demo.
The + after \p{Punct} removes consecutive punctuation chars is chunks rather than one by one.


A clique in a tree decomposition is contained in a bag

Question: Let $G$ be a graph, $T$ a tree and $\mathcal{V}=\bigcup_{t \in T} V_t$ a tree decomposition of $G$. Let $H \subseteq G$ be a clique. Show that $H$ is contained in a bag $V_t$ for some vertex $t \in T$.
I've tried an induction on the size of the clique without success. I assume the proof relies on the fact that trees contain no cycles (i.e. given any two vertices $a,b \in T$, there is a unqiue path $a \rightarrow b$.
Any help would be grateful.
Answer: Proof by induction. This is true for cliques of size 2 by the definition of tree decomposition.
Suppose this is true for cliques of size k and you are given a clique S of size k+1. Choose some $v\in S$ and let $S_0=S-\{v\}$. By the hypothesis, there is some $t\in T$ such that $S_0 \subseteq V_t$ - denote by $T_0$ the set of all such $t$'s (which is actually a subtree). If one of them also contains $v$, then we are done, so assume (by negation) that $v$ can be found only in $V_t$ such that $t\notin T_0$.
The set $T-T_0$ is a forest. If $t_1,t_2\in T-T_0$ are in different connected components and $v \in V_{t_1}\cap V_{t_2}$, then $v$ must be in all the vertices on the path connecting them. This path must go through $T_0$ contradicting our assumption. It follows that there is some connected component $C$ of $T-T_0$ such that $v$ can appear only there. Since $T$ is a tree, there is a unique edge between $T_0$ and $C$ which we denote by $(t_0,c_0)\in T\times C$.
For each $u\in S_0$ there is some $t\in T$ such that $\{u,v\} \in V_t$ by the definition of tree decomposition (this is an edge in the clique $S$), and thus they all must be in $C$. The path from each of these vertices to $t_0$ must go through $c_0$, and because $u\in V_{t_0}$ we get that $u\in V_{c_0}$ for every $u\in S_0$ which means that $c_0\in T_0$ - contradiction.
Answer: The following is a non-induction proof, where we construct such a bag containing $H$ and verify it by the properties of trees.
Proof. Root $T$ arbitrarily. For each $v\in H$, define $L_v :=\{t\in T|v\in V_t\}$, i.e., $L_v$ is the set of all labels of bags containing $v$. Then we choose the label of minimal depth(distance from the root) in $L_v$, denoted by $l_v$. Let $l_{m}$ be the label of maximum depth in $\{l_v|v\in H\}$ and $m\in H$. Then we claim that the bag $V_{l_{m}}$ contains $H$.

To prove our claim, we first observe that for any $v\in H\setminus \{m\}$, $L_v$ induces a subtree $T[L_v]$ rooted in $l_v$ and edge $(v,m)\in E(G)$. Then by the definition of tree decomposition, tree $T[L_v]$ and  tree $T[L_m]$ have at least one node in common, i.e., $L_m \cap L_v \ne \emptyset$ (as illustrated in the figure above, the two trees share two nodes). For any node $l_x \in L_m\cap L_v$, there is a unique path from $l_x$ to $l_v$. This path must go through $l_m$. Again by the definition of tree decomposition, we have $V_{l_m} \supseteq V_{l_x}\cap V_{l_v}$. Thus, $v\in V_{l_m}$. $\square$


C#: Prepending to beginning of a file

Question: What is the best way to add text to the beginning of a file using C#?
I couldn't find a straightforward way to do this, but came up with a couple work-arounds.

Open up new file, write the text that I wanted to add, append the text from the old file to the end of the new file.
Since the text I want to add should be less than 200 characters, I was thinking that I could add white space characters to the beginning of the file, and then overwrite the white space with the text I wanted to add.

Has anyone else come across this problem, and if so, what did you do?
Comment: Interesting question.  Clearly the framework (and no doubt the underlying file system) is append-biased, since File.AppendText and File.AppendAllText are provided without corresponding prepend methods.  Makes sense -- bytes can be appended without "moving" the existing content.
Comment: hmm ok, so the answers seem to favor option 1 (either using a temp file or reading into memory). Is there a flaw with using option 2?
Comment: You can check out this http://stackoverflow.com/questions/1008742/adding-text-to-beginning-and-end-of-file-in-c post on Adding text to beginning and end of file in C#. Its for XML files, but easily modifiable for your use.
Comment: How do i do this within an existing file, lets say it looks for a specific word that can be anywhere in the file?
Comment: I really like the second option; it's the best solution when creating huge files with a fixed size header. E.g. writing a recording (sampling) file and overwriting its header to specify the total duration and sample count on file closing. Thank you so much for auto-answering your question :).
Answer: This works for me, but for small files. Probably it's not a very good solution otherwise.
string currentContent = String.Empty;
if (File.Exists(filePath))
{
    currentContent = File.ReadAllText(filePath);
}
File.WriteAllText(filePath, newContent + currentContent );

Answer: Adding to the beginning of a file (prepending as opposed to appending) is generally not a supported operation.  Your #1 options is fine.  If you can't write a temp file, you can pull the entire file into memory, preprend your data to the byte array and then overwrite it back out (this is only really feasible if your files are small and you don't have to have a bunch in memory at once because prepending the array is not necessarily easy without a copy either).
Comment: Oh right, "prepend." Thanks! I couldn't think of the correct word.
Answer: Yeah, basically you can use something like this:
public static void PrependString(string value, FileStream file)
{
     var buffer = new byte[file.Length];

     while (file.Read(buffer, 0, buffer.Length) != 0)
     {
     }

     if(!file.CanWrite)
         throw new ArgumentException("The specified file cannot be written.", "file");

     file.Position = 0;
     var data = Encoding.Unicode.GetBytes(value);
     file.SetLength(buffer.Length + data.Length);
     file.Write(data, 0, data.Length);
     file.Write(buffer, 0, buffer.Length);
 }

 public static void Prepend(this FileStream file, string value)
 {
     PrependString(value, file);
 }

Then
using(var file = File.Open("yourtext.txt", FileMode.Open, FileAccess.ReadWrite))
{
    file.Prepend("Text you want to write.");
}

Not really effective though in case of huge files.
Answer: using two streams, you can do it in place, but keep in mind that this will still loop over the whole file on every addition
using System;
using System.IO;
using System.Text;

namespace FilePrepender
{
    public class FilePrepender
    {
        private string file=null;
        public FilePrepender(string filePath)
        {
            file = filePath;
        }
        public void prependline(string line)
        {
            prepend(line + Environment.NewLine);
        }
        private void shiftSection(byte[] chunk,FileStream readStream,FileStream writeStream)
        {
            long initialOffsetRead = readStream.Position;
            long initialOffsetWrite= writeStream.Position;
            int offset = 0;
            int remaining = chunk.Length;
            do//ensure that the entire chunk length gets read and shifted
            {
                int read = readStream.Read(chunk, offset, remaining);
                offset += read;
                remaining -= read;
            } while (remaining > 0);
            writeStream.Write(chunk, 0, chunk.Length);
            writeStream.Seek(initialOffsetWrite, SeekOrigin.Begin);
            readStream.Seek(initialOffsetRead, SeekOrigin.Begin);
        }
        public void prepend(string text)
        {
            byte[] bytes = Encoding.Default.GetBytes(text);
            byte[] chunk = new byte[bytes.Length];
            using (FileStream readStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using(FileStream writeStream = File.Open(file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite))
                {
                    readStream.Seek(0, SeekOrigin.End);//seek chunk.Length past the end of the file
                    writeStream.Seek(chunk.Length, SeekOrigin.End);//which lets the loop run without special cases
                    long size = readStream.Position;
                    //while there's a whole chunks worth above the read head, shift the file contents down from the end
                    while(readStream.Position - chunk.Length >= 0)
                    {
                        readStream.Seek(-chunk.Length, SeekOrigin.Current);
                        writeStream.Seek(-chunk.Length, SeekOrigin.Current);
                        shiftSection(chunk, readStream, writeStream);
                    }
                    //clean up the remaining shift for the bytes that don't fit in size%chunk.Length
                    readStream.Seek(0, SeekOrigin.Begin);
                    writeStream.Seek(Math.Min(size, chunk.Length), SeekOrigin.Begin);
                    shiftSection(chunk, readStream, writeStream);
                    //finally, write the text you want to prepend
                    writeStream.Seek(0,SeekOrigin.Begin);
                    writeStream.Write(bytes, 0, bytes.Length);
                }
            }
        }
    }
}

Answer: I think the best way is to create a temp file. Add your text then read the contents of the original file adding it to the temp file. Then you can overwrite the original with the temp file.
Comment: Don't overwrite the original file, that will delete ACLs and ADSs. Use File.Replace.
Comment: I know this is old. ACL = Access Control List? ADS = ?
Answer: // The file we'll prepend to
string filePath = path + "\\log.log";

// A temp file we'll write to
string tempFilePath = path + "\\temp.log";

// 1) Write your prepended contents to a temp file.
using (var writer = new StreamWriter(tempFilePath, false))
{
    // Write whatever you want to prepend
    writer.WriteLine("Hi");
}

// 2) Use stream lib methods to append the original contents to the Temp
// file.
using (var oldFile = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
{
    using (var tempFile = new FileStream(tempFilePath, FileMode.Append, FileAccess.Write, FileShare.Read))
    {
        oldFile.CopyTo(tempFile);
    }
}

// 3) Finally, dump the Temp file back to the original, keeping all its
// original permissions etc.
File.Replace(tempFilePath, filePath, null);

Even if what you're writing is small, the Temp file gets the entire original file appended to it before the .Replace(), so it does need to be on disk.
Note that this code is not Thread-safe; if more than one thread accesses this code you can lose writes in the file swapping going on here. That said, it's also pretty expensive, so you'd want to gate access to it anyway - pass writes via multiple Providers to a buffer, which periodically empties out via this prepend method on a single Consumer thread.
Answer: prepend:
private const string tempDirPath = @"c:\temp\log.log", tempDirNewPath = @"c:\temp\log.new";

        StringBuilder sb = new StringBuilder();
        ...
        File.WriteAllText(tempDirNewPath, sb.ToString());
        File.AppendAllText(tempDirNewPath, File.ReadAllText(tempDirPath));
        File.Delete(tempDirPath);
        File.Move(tempDirNewPath, tempDirPath);
        using (FileStream fs = File.OpenWrite(tempDirPath))
        {   //truncate to a reasonable length
            if (16384 < fs.Length) fs.SetLength(16384);
            fs.Close();
        }

Answer: You should be able to do this without opening a new file. Use the following File method:
public static FileStream Open(
    string path,
    FileMode mode,
    FileAccess access
)

Making sure to specify FileAccess.ReadWrite.
Using the FileStream returned from File.Open, read all of the existing data into memory. Then reset the pointer to the beginning of the file, write your new data, then write the existing data.
(If the file is big and/or you're suspicious of using too much memory, you can do this without having to read the whole file into memory, but implementing that is left as an exercise to the reader.)
Answer: The following algorithm may solve the problem pretty easily, it's most efficient for any size of file, including very big text files:
string outPutFile = @"C:\Output.txt";
string result = "Some new string" + DateTime.Now.ToString() + Environment.NewLine;
StringBuilder currentContent = new StringBuilder();
List<string> rawList = File.ReadAllLines(outPutFile).ToList();
foreach (var item in rawList) {
    currentContent.Append(item + Environment.NewLine);
}
File.WriteAllText(outPutFile, result + currentContent.ToString());

Answer: Put the file's contents in a string. Append new data you want to add to the top of the file to that string --  string = newdata + string. Then move the seek position of the file to 0 and write the string into the file.
Answer: Use this class:
public static class File2
{
    private static readonly Encoding _defaultEncoding = new UTF8Encoding(false, true); // encoding used in File.ReadAll*()
    private static object _bufferSizeLock = new Object();
    private static int _bufferSize = 1024 * 1024; // 1mb
    public static int BufferSize
    {
        get
        {
            lock (_bufferSizeLock)
            {
                return _bufferSize;
            }
        }
        set
        {
            lock (_bufferSizeLock)
            {
                _bufferSize = value;
            }
        }
    }

    public static void PrependAllLines(string path, IEnumerable<string> contents)
    {
        PrependAllLines(path, contents, _defaultEncoding);
    }

    public static void PrependAllLines(string path, IEnumerable<string> contents, Encoding encoding)
    {
        var temp = Path.GetTempFileName();
        File.WriteAllLines(temp, contents, encoding);
        AppendToTemp(path, temp, encoding);
        File.Replace(temp, path, null);
    }

    public static void PrependAllText(string path, string contents)
    {
        PrependAllText(path, contents, _defaultEncoding);
    }

    public static void PrependAllText(string path, string contents, Encoding encoding)
    {
        var temp = Path.GetTempFileName();
        File.WriteAllText(temp, contents, encoding);
        AppendToTemp(path, temp, encoding);
        File.Replace(temp, path, null);
    }

    private static void AppendToTemp(string path, string temp, Encoding encoding)
    {
        var bufferSize = BufferSize;
        char[] buffer = new char[bufferSize];

        using (var writer = new StreamWriter(temp, true, encoding))
        {
            using (var reader = new StreamReader(path, encoding))
            {
                int bytesRead;
                while ((bytesRead = reader.ReadBlock(buffer,0,bufferSize)) != 0)
                {
                    writer.Write(buffer,0,bytesRead);
                }
            }
        }
    }
}

Answer: I came across a similar problem when attempting to append a logging file in reverse order. This algorithm will ensure the newest entry is always placed in first in-first out order, preventing the need to sort every time a new item is added.
This works for a UWP project:
using a Stack class in System.Collections.Generic
Stack<string> Text = new Stack<string>();

void PrependTextToFile(string textToPrepend, string filePath)
{
    Text.Push(textToPrepend);
    File.WriteAllLines(filePath, Text.ToArray());
}

Task PrependTextToFileAsync(string textToPrepend, StorageFile file)
{
    Text.Push(textToPrepend);
    await FileIO.WriteLinesAsync(file, Text);
}

Comment: Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it'd be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren't as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?**

C#: Prepending to beginning of a file


Stationarity and trends in ARIMA models

Question: For this question I am interested in rigorous proofs or in references explaining details.
Let us suppose we have an ARIMA process of order $(p,d,q)=(p,0,q)$:
$$A(L)X_t=B(L)\epsilon_t [1],$$
where $A$ and $B$ are polynomials in the lag operator $L$ of order $p$ and $q$ respectively. $\epsilon_t$ are i.i.d. normal variables of variance $\sigma$ and zero mean.

Would it be possible for the same choice of the parameters, i.e. A, B and $\sigma$, to have two different stationary distributions ?

To clarify the question, we can define stationary distribution for this question this way. Equation [1] can be considered a way to propagate the time series given some initial conditions. If propagating according to [1] we converge to a constant probability distribution than we call this a stationary distribution. In Markov chains we have a similar setting for example, but the stationary distribution can be not unique (unless some assumptions are verified), and dependent on the initial conditions. There are ARMA process withouth stationary distribution (for example in the presence of a unit root). My question is if there are ARMA process having more than one stationary distributions.

Would it be possible to have a limit cyclostationary distribution ?See https://en.wikipedia.org/wiki/Cyclostationary_process for definition.

For "limit cyclostationary distribution" I mean an ARMA process that, given some initial configuration, will behave in a long run as a (wide-sense) cyclostationary process, with a mean and variance changing cyclically over time.

Now let's take $d \ge 1$, so that the differentiated process $Y_t=(1-L)^d X_t$ is an $ARIMA(p,0,q)$ process. Suppose now that the $ARMA(p,q)$ process $Y_t$ has a stationary distribution. Is it true that $X_t$ will be of the form $X_t=f_t +Y_t$ where $Y_t$ is stationary and $f_t$ is deterministic and respects $(1-L)^d f_t=0$ (so that the trend must be linear, quadratic, cubic as $d$ increases)?
Comment: Thanks a lot for helping improve the question. I hope I edited it with a consistent notation. Do not hesitate to suggest other improvements.
Comment: Please motivate -1 . Bad habit of putting -1 without explanation... This habit damages stackexchange sites.
Comment: What a nice person would do is : (1) explain why the question is not well posed (considering that any question is a good question, if well posed) ; (2) wait for changes by the OP ; (3) If these changes are not performed, put a -1 . Everything else in my opinion is just unpolite .
Comment: Agreed. But maybe put a -1 for a bad question and retract the vote once the question is improved? After all, it is only logical to vote on the question as is, not as it was or will/might be. (I did not downvote.)
Comment: I tried to improve the question. I would expect than to see either further comments or a removal of the -1 ;)
Comment: The common parameterization is AR, I, MA: $(p,d,q)$, not $(p,q,d)$. Introducing a different, nonstandard ordering of parameters invites potential confusion. AR$(p,q,0)$ and AR$(p,q)$ do not seem to make sense.
Comment: This is of course reasonable, provided that it comes with an explanation/suggestion for improvement in the comments below the question. Anyway, following what you say, when I have a bit of time I will modify my question and clarify some points that came up as unclear/undefined in an answer below. For the moment, I thank you for the discussion.
Answer:
Question does not quite make sense. Stationary distributions are not identified by ARMA parameters of the series. For the same ARMA parameter $A$ and $B$ (with stationary solution), any i.i.d. $\epsilon_t$ with finite second moment would give a strictly stationary series. Different marginal distribution of $\epsilon_t$ would give different stationary distribution. For a trivial example, take i.i.d. white noise with different distributions.
What is "limit cyclostationary distribution"...? An example of cyclostationary series is seasonal ARIMA time series---e.g. the seasonal AR(1) specification
$$
(1- \phi L^{12}) X_t = \epsilon_t.
$$
In SARIMA notation, this is an SARIMA(0,0,0)$\times$(1,0,0)$_{12}$ model. Its ACF is
$\rho(12h) = \phi^h$, and zero at other lags.
No, clearly this is not true---e.g. take the unit root $(1-L) X_t = \epsilon_t$. In fact, given the way you've specified ARMA series (with not intercept), there can be no deterministic trend.
Comment: Thanks for your answer. Here some points. (1) I am considering $\epsilon_i$
normal i.i.d. variables with a variance $\sigma$. My question is if such a ARMA model can have different
stationary distributions at fixed A, B and $\sigma$ . I think no but I just wanted to be sure if there is a proof of this.
Comment: (2) The model you write is $X_t=\phi X_{t-12}+\epsilon_t$ with no intercept. So essentially there are 12 indipendent AR(1) processes.
Each process has than zero mean, which is a bit of a trivial case of a cyclostationary signal, where the expectation value $E[X(t)]$
can be non-constant and oscillate (see the wikipedia page). Can such cyclostationary signals be modelled via an ARMA process ?
Comment: (3) I am not getting your answer. If we have $A(L)X_t=B(L) \epsilon_t$ and $Y_t=X_t-k_1$ with $k_1$ constant, than $A(L)Y_t=A(L)X_t-k_2$ where the constant $k_2$ is $k_1$ times the number of non-zero terms of $A$. This shows that the intercept term causes a constant mean shift but not a trend. Further an ARIMA model with $d \ge 1$ has been defined exactly so that deterministic trends can be removed by the differentiation operation, or am I wrong? Therefore such models can contain deterministic trends.
Comment: 1) With i.i.d. normal error term, then question is trivial---Gaussian time series are characterized by the autocovariance function.
Comment: 2) Covariance-stationarity implies mean stationary. In particular, ARMA processes are mean-stationary---one can always demeaning, a general wide-sense cyclostationary process. ("Cyclostationarity" is not really time series vernacular.)
Comment: 3) If you include intercept term in the I(0) ARMA process, then sure, the I(1) process obtained by integrating can have deterministic trend. But answer to question is still no---an I(I) process is not a sum of deterministic trend plus a stationary process.Again, consider the simple unit root process. Take 0 to be the trivial "deterministic trend". Where is your stationary component Y?
Comment: Thanks again. Here my relpy. (1) To complete this answer I think one would need to show that: (1) if a stationary distrubution exists for an ARMA process, than it is
Gaussian. (2) that the autocovariance function is univocally identified from the ARMA parameters.
Comment: (2) I sent the link to the
wikipedia page for the definition of cyclostationarity, where it says that
in such a signal the covariance function also is cyclic in t. I think the answer to my question is there when you say ARMA process are always mean stationary. How one can show this ? If you have a unit root they are not mean stationary but it may be a limit example.
Comment: (3) The process you show is a good one. Xt=Xt−1+ϵt (σ2=1) is the discrete analogue of the Brownian motion. We can fix X(0)=0 and see: - Xt∼N(0,t),t>1 ; - Yt=Xt−Xt−1=ϵt and Xt−Yt=Xt−1 is non deterministic. But here I would not say that Xt has a trend, because the mean does not change over time, even if there is not a stationary distribution. But you are right to say that this phenomenon makes my claim false, as it is written.
Comment: ( as a side, referring to your original answer to point 3, the fact that there cannot be deterministic trends without intercept (after differentiating) I think is not right. Take an ARIMA(p,d=2,q) process without intercept and add $+\alpha t$ manually as a trend. Differentiating twice the new process leads to an ARMA(p,q) process without intercept. Maybe what you had in mind is that if one integrates an ARMA(p,q) without intercept one cannot build a process with deterministic trends (even if, as your example shows, one may get a non-stationary process ) )
Comment: ( I also notice that I did not answer to what I mean as "limit cyclostationary distribution", for question 2. I mean an ARMA process that has a "cyclostationary process" as a steady state. Does this make more sense ? You are right to say that this definition is not very common: it is of course a bit different than having a stationary distribution. The general idea of the question is if an ARMA process can model cyclostationary signals, as defined in wikipedia. I hope this makes the question clearer. )
Comment: Please have a look at the modified question that I tried to modify to make it clearer.

Stationarity and trends in ARIMA models


Como posso fazer uma cópia de várias tabelas em uma nova tabela usando SQL SERVER?

Question: Tenho várias tabelas com os mesmos número de colunas. e quero inserir os registros dessas tabelas em uma nova tabela. Alguém tem uma ideia? pois só consegui inserir uma e não aceita o resto de tabelas que tenho.
select  *
from DATATRAN2013_CSV A
UNION
 select  * from DATATRAN2014_CSV B
 UNION
select *from  DATATRAN2015_CSV C
UNION
select * from DATATRAN2016_CSV D

Comment: Isso é um Insert com sub consulta
Answer: Utilizando o Union, as colunas tem de ter o mesmo nome e estar na mesma ordem.
Obs: Neste caso não estará copiando, apenas juntando o resultado da seleção de várias tabelas. Para copiar para um outra tabela precisa fazer um insert com o resultado destes Unions
Comment: valeu amigo pela dica percebi isso quando eu estava tentar me matar ontem inserido isso.
Answer: Você pode inserir usando o modelo abaixo:
INSERT INTO tabelan(coluna1, coluna2, coluna3, coluna4, colunaz)
SELECT coluna1, coluna2, coluna3, coluna4, colunaz FROM tabela1
UNION
SELECT coluna1, coluna2, coluna3, coluna4, colunaz FROM tabela2
UNION
SELECT coluna1, coluna2, coluna3, coluna4, colunaz FROM tabela3
UNION
SELECT coluna1, coluna2, coluna3, coluna4, colunaz FROM tabelaz

É interessante nomear as colunas para não errar na ordem do INSERT.
Importante ressaltar que o UNION irá eliminar linhas repetidas, então caso queira manter registros duplicados entre tabelas diferentes, utilize o UNION ALL.
Comment: UNION descarta linhas repetidas (se houver).
Comment: @JoséDiz isso invalida a resposta a ponto de receber um `downvote`? É interessante dar uma lida nos privilégios quando os adquire, como por exemplo [aqui](https://pt.stackoverflow.com/help/privileges/vote-down) para utilizar o fórum de maneira correta.
Comment: @Sorack valeu amigo ajudou bastante
Answer: As sugestões desta resposta consideram que uma nova tabela deve ser criada e que as tabelas de origem estão declaradas com colunas na mesma sequência.
(1) É possível inserir uma tabela de cada vez, sem necessidade de UNION ALL:
-- código #1
SELECT coluna_1, coluna_2, ..., coluna_n
   into DATATRAN_CSV
   from DATATRAN2013_CSV;

INSERT into DATATRAN_CSV (coluna_1, coluna_2, ..., coluna_n)
  SELECT coluna_1, coluna_2, ..., coluna_n
     from DATATRAN2014_CSV;

INSERT into DATATRAN_CSV (coluna_1, coluna_2, ..., coluna_n)
  SELECT coluna_1, coluna_2, ..., coluna_n
     from DATATRAN2015_CSV;

INSERT into DATATRAN_CSV (coluna_1, coluna_2, ..., coluna_n)
  SELECT coluna_1, coluna_2, ..., coluna_n
     from DATATRAN2016_CSV;

Desta forma utiliza-se menos recursos de memória.

(2) Caso queira realizar a junção das tabelas de origem, antes de criar a nova tabela, eis outra opção:
-- código #2
with cteDATATRAN as (
SELECT * from DATATRAN2013_CSV
union all
SELECT * from DATATRAN2014_CSV
union all
SELECT * from DATATRAN2015_CSV
union all
SELECT * from DATATRAN2016_CSV
)
SELECT *
  into DATATRAN_CSV
  from cteDATATRAN;

Observe que deve utilizar o UNION ALL para obter a união completa. Se utilizar somente UNION, além do processo ficar mais lento, as linhas repetidas serão descartadas.

(3) Para ter controle absoluto, sugiro que não utilize * na lista de colunas das tabelas de origem mas sim que defina o nome das colunas:
-- código #3
with cteDATATRAN as (
SELECT coluna_1, coluna_2, ..., coluna_n
  from DATATRAN2013_CSV

union all
SELECT coluna_1, coluna_2, ..., coluna_n
  from DATATRAN2014_CSV

union all
SELECT coluna_1, coluna_2, ..., coluna_n
  from DATATRAN2015_CSV

union all
SELECT coluna_1, coluna_2, ..., coluna_n
  from DATATRAN2016_CSV
)
SELECT *
  into DATATRAN_CSV
  from cteDATATRAN;


What should I do if a new iOS version introduces possible class collisions (Apple classes with the same prefix as mine)?

Question: I'm dealing with this problem in iOS 8.3, where a new set of classes have been introduced that could potentially conflict with my classes because they use the same prefix. Should I worry? Should I use prefixes at all, or should only frameworks/libraries use them? Can I refactor all class names at once if needed?
Comment: @YvesLeBorg Thanks for the reply. I disagree with your vote - the primary question "What should I do if a new iOS version introduces possible class collisions?" is not opinion-based, if there are conflicts in new iOS versions, then there must be a solution, and a common one. This can't be the first time this has happened.
Comment: before i vote to close, here is my opinion :) : **1)** prefer prefixing to guard against the practical joke departments (in my case Apple and cocos2d) **2)** If you chose to refactor , use an IDE (like AppCode), not a toy.
Comment: not my close vote, when i came to edit out my snarky, the grace period was expired. Nonetheless, i feel everyone will have their preferred way to deal with this situation. After being 'yanked' into a forklift refactoring project a couple of times, i chose to prefix my 'app' stuff to protect my codebase.
Answer: Just go with the safer option of prefixing your classes. This will then mean you never need to worry about this problem again.
Comment: I am prefixing my classes. So I guess you are suggesting re-prefexing them. Is there an easy way to do this? Xcode doesn't seem to provide one.
Comment: Unless you've been using NS as your prefix - I don't see the need to "re-prefix" them ?
Comment: My current prefix is being used by a new set of classes Apple introduced - that's why I'm asking this question
Comment: That wasn't clear. Then you need to re-prefix them. There isn't a one click solution to this either. Out of curiosity - what are you prefixing them with currently?
Answer: Always prefix your class name with your company/app name whenever you create the class. Personally I prefer 3 characters instead of 2 characters, since Apple has the right to prefix their class name with 2 letters.
For example, if you have a class named CoreData and your company name is Foo Bar,  your app is called Rabbit, name the class "FBRCoreData" instead of "CoreData".
I suppose your best practise would be renaming your class names (all of them if possible ) with the prefix. Otherwise it may bite you again later.
Comment: I am prefixing my classes. So I guess you are suggesting re-prefexing them. Is there an easy way to do this? Xcode doesn't seem to provide one.
Comment: @mattsven Unfortunately I do not recall there is a "one click" solution in Xcode to re-prefix your class names.


How to access elements of array after using string.split in Velocity?

Question: I am using Velocity Templating Language and currently have:
#set ( $stringList = $string.split(",") )

which works fine and splits the string up using a ',' as a delimiter as expected.
My question is how do i now access each of the elements in the $stringList?
I have tried:
$stringList.get(0)
$stringList[0]
$stringList.[0]
${stringList}.get(0)

I am using Velocity in JIRA and JIRA happens to use Velocity version 1.4 which apparently doesn't have support for accessing arrays as tried above.
Any help is much appreciated.
Comment: $stringList.get(0) works for me.
Answer: Tested in Velocity 1.6.
#foreach ($element in $string.split(";"))
   $element
#end

Answer: It works when I convert the array to a List using Arrays.asList() and then use methods from List to access elements.
I add the following to the context:
context.put("arrays", Arrays.class);

In velocity template I use:
#set ( $array = $getarray.getArray() )

$arrays.asList($array).get(0)

With a String-Array as follows
new String[] {"test1", "test2", "test3", "test4"};

I get the expected output:
test1

Comment: Thanks for the suggestion centic but it doesnt seem to work. Thanks anyway.
Comment: I tried it now and it worked with the steps listed above, can you post you current code so we can see why it does not work for you?
Answer:
As of Velocity 1.6, all array references are now "magically" treated as if they are fixed-length lists. This means that you can call java.util.List methods on array references. So, if you have a reference to an array (let's say this one is a String[] with three values), you can do:
$myarray.isEmpty()

$myarray.size()

$myarray.get(2)

$myarray.set(1, 'test')

Source: http://velocity.apache.org/engine/releases/velocity-1.7/user-guide.html#methods
Answer: Its also possible to push elements into an array like this.
#set ($matchingProducts = [])
#set($bar = $matchingProducts.add($p))


Excel data validation reference spreadsheet location versus static list

Question: I'm having trouble with some Excel data validation. On one sheet, I have a list of values that contain the list that populates the validation drop-down, like this:

A1 |1.)   New Item
A2 |2.)  Miscellaneous
A3 |3.)  Change Order
A4 |4.)  Choose the item being broken out:
A5 |          Caulk NP-1
A6 |          Safety signs
A7 |          Warning lines
A8 |          Snow fence
A9 |          Drain Lead 4 lb 30"x30"
A10 |          Cant Strip
A11 |          Screws 1 5/8"
A12 |          SS Sheet Metal 24 gauge
A13 |          Sheet Metal Aluminum 040 mill finish
A14 |          Sheet Metal Aluminum .050 mill finish
A15 |          Termination Bar
A16 |          Lead Boots 2"
A17 |          Lead Boots 3"
A18 |          Modified Bitumen Smooth APP
A19 |          TREMCO ELS Mastic
A20 |          TREMCO Polyroof SF
A21 |          TREMCO Base sheet fasteners
A22 |          TREMCO BURmastic Composite
A23 |          TREMCO PowerPly Standard
A24 |          TREMCO BURmastic SF
A25 |          TREMCO PowerPly HD Base Sheet
A26 |          TREMCO PowerPly Standard FR
A27 |          TREMCO Burmesh 6"
A28 |          TREMCO Site visits
A29 |          TREMCO Reglet Sealant
A30 |          TREMCO WB Primer
A31 |          TREMCO Ice Coating
A32 |          TREMCO Tremflash tape
A33 |          TREMCO Warranty
A34 |          1/4" x 1 1/2" drive pins
A35 |          SS Roof Nails 1 1/4"
A36 |          Freight
A37 |          Auto Fuel
A38 |          PA Direct Labor Supervisor
A39 |          PA Direct Labor Sheet Metal
A40 |          PA Direct Labor Roof Coating
A41 |          Equipment Crane 45 ton
A42 |          Equipment Crane 70 ton
A43 |          Platform Hoist R&G 400 28'
A44 |          Sqeegies 24" Notched
A45 |          Dumpsters
A46 |          Porta John
A47 |          Permit
A48 |          Subcontractor RK Hydro Vac
A49 |          Subcontractor Roofing ICG
A50 |          Subcontractor Lightning Protection
A51 |          Misc
A52 |          Subtotal

When I have another sheet reference this list, the validation works properly. However, I have a VBA macro that at some point copies this other sheet into a workbook by itself to be emailed. For this and other reasons, I need the validation drop-down list on this column to not be dependent on the other sheet, so I have the macro loop through all of the cells and create a validation string that looks like this:

  1.)   New Item,2.)  Miscellaneous,3.)  Change Order,4.)  Choose the item being broken out:,          Caulk NP-1 ,          Safety signs,         Warning lines

As you can see, it's the exact same list, but it's a text string, with each selection separated by commas. It works almost like I need it to, but there is a problem - The 10 leading spaces are not working like they should in the second scenario. I have them there so that those selections are indented in the drop-down box to make it more intuitive. The 10 leading spaces are in the actual "validation list formula", but don't show up when I click the drop-down or make a selection!
Any ideas?
EDIT:
As requested, here's the actual code:
Range("A1").Value = "1.)   New Item"
Range("A2").Value = "2.)  Miscellaneous"
Range("A3").Value = "3.)  Change Order"
Range("A4").Value = "4.)  Choose the item being broken out:"
Range("A5:A350").Formula = "=""          ""&INDIRECT(""'Buy Out'!B""&MATCH(""Description"",'Buy Out'!$B:$B,0)+ROW()-3)"
Application.Calculate

' build ValidationList string for later use (this will also have to happen when misc section isn't built, so this isn't the best place for it)
Range("A1").Select
ValidationList = ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Row = 350
    If ActiveCell.Value = "          Subtotal" Or ActiveCell.Offset(3, 0).Value = "          Subtotals" Then 'end of the loop
        Exit Do
    End If

    If ActiveCell.Value <> "" Then
        ValidationList = ValidationList & "," & vbTab & ActiveCell.Value
    End If
    ActiveCell.Offset(1, 0).Select
    If ActiveCell.Row = 349 Then 'this shouldn't ever happen
        ValidationListMessedUp = True
        'MsgBox ("There appears to be a problem creating the drop-down list for the ""Addon Category/Item to Break Out"".")
    End If
Loop

'back to buy out and populate validation as dynamic formula
Sheets("Buy Out").Select
Cells.Find(What:="Addon Category/Item to Break Out", after:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate '* EH and message? "Is this job on the most recent MBO template? It does not appear to have the words "Release #" anywhere on the Buy Out tab

With Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(TotalRow - ActiveCell.Row - 2, 0)).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:= _
        "=INDIRECT(""reference!$A$1:$A$""&IFERROR(MATCH(""          Subtotal"",reference!$A:$A,0)-1,IFERROR(MATCH(""          Grand Total"",reference!$A:$A,0)-1,MATCH(""          Subtotals"",reference!$A:$A,0)-3)))"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

So the last section of this code that fills the validation with the indirect formula is the one that is working properly. Later on in the code, I populate the "static" validation list using the string. Here is that other piece:
    With Range(ActiveCell.Offset(MiscStartRow - ActiveCell.Row + 1, 0), ActiveCell.Offset(TotalRow - ActiveCell.Row + 5, 0)).Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=ValidationList
    .IgnoreBlank = False
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

Thanks so much for the help. This is getting really frustrating.
Answer: Use a vbTab
For example
With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="1,2,3," & vbTab & "          4,5"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

SNAPSHOT

Hope this is what you wanted?
FOLLOW UP
Using the above method has a drawback. DVlist cannot be more than 255 Characters.
ALTERNATIVE
Copy the list to extreme left column (Column XFD (excel 2007/2010) or Column IV (Excel 2003)) of the worksheet so that it is hidden and then use it in DV
Comment: okay, so at first that worked, but after further review, it is not. While Excel is still open, it seems to be working correctly. However, if I try to save the file and then re-open Excel, is says there are errors in the file that it must repair. When it repairs, it says it repaired the validation, and in fact has removed it...
Comment: I am unable to reproduce the issue. The file works just fine even after I close it and open it again. Can you share the exact code that you are using?
Comment: okay, I will edit the original question to include the code and the full item list populating the drop-down
Comment: There is nothing wrong with the code ;) It is the data. Your data has quotes (" ") so when you are concatenating the string, even the quotes are getting concatenated which is giving you the error. let me see If I can do something about it :)
Comment: oooooooh. wow. How about the Substitute function to replace all quotes with 2 quotes?
Comment: So do you want to check for a solution or are you removing the double quotes?
Comment: Sorry if my comments were confusing. If you can come up with a way to keep the quotes, that would be great.
Comment: let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9107/discussion-between-siddharth-rout-and-carmalize)


Evaluating vectors along paths

Question: If A = (3x$^2$-6yz)$\mathbf{i}$ + 2(y+3xz)$\mathbf{j}$ + (1-4xyz$^2$)$\mathbf{k}$ how do I evaluate
$\int$ A $\bullet$ d$\mathbf{r}$ from (0,0,0) to (1,1,1)
along the path x=t, y=t$^2$, z=t$^3$?
Comment: Check this out:
http://math.stackexchange.com/questions/680217/need-some-help-with-computing-line-integrals-for-vector-fields/680227#680227
Answer: First find out the interval of the parameter that sweeps out this path.  Technically you do this by solve the vector equations $(t, t^{2},t^{3}) = (0,0,0)$ and $(t, t^{2},t^{3}) = (1,1,1)$ but in this case it's obvious that, in the first case, $t=0$ and in the second $t=1$.
Next, find the gradient of $A$, i.e. vector of partial derivatives,
$(6x, 2y, -8xyz)$
and substitute the parameterization into this,
$(6t, 2t^{2}, -8tt^{2}t^{3})$ (note that I haven't combined terms so you can see where things came from)
Next, plug in the parameterization into $A$, which gives you $A(r(t))$, namely,
$A(r(t)) = (3t^{2}-6t^{2}t^{3}, 2(t^{2}+3tt^{3}), 1-4tt^{2}[t^{3}]^{2})$
Next form the dot-product of this with the gradient found earlier:
$(3t^{2}-6t^{2}t^{3}, 2(t^{2}+3tt^{3}), 1-4tt^{2}[t^{3}]^{2}) \cdot (6t, 2t^{2}, -8tt^{2}t^{3})$
When you compute this, find the integral of it from 0 to 1 with respect to $t$.

Evaluating vectors along paths


Role security with active directory

Question: I have to ensure the security of a asp.net website at work. They asked me to do a role based security with the active directory of my work so I could do a sitemap and give the right access at the right person.
Which class of the framework should I use? make generic identity?
Answer: It's already built into AD authentication. If you are authenticating against the AD, either via NTLM logins or an AD connected forms authentication setup then the thread identity will contain the groups the user belongs to, and the role based parts of the sitemap control will work.
Specifically you use the WindowsTokenRoleProvider. This is a one way role manager (you can't add people to groups - you have to use the AD tools for that. The use the sitemap's built in support for trimming site maps according to role.
Comment: you mind taking a look at this? it's odd as hell and I cant get any expert answers? http://stackoverflow.com/questions/13147132/active-directory-group-membership-checking-in-net-4-5
Answer: Yes, you can use a RoleManager.  Have a look at http://msdn.microsoft.com/en-us/library/ms998314.aspx
Answer: I need for every user that goes on the intranet to be looked up by the Active directory, then build the right menu depending on the roles and acces the user have.
should i use the RoleManager or a class like that?

Role security with active directory


Hypothesis testing on zero-inflated continuous data

Question: I would greatly appreciate your advice on the following problem:
I've got a large continuous dataset with lots of zeros (~95%) and I need to find the best way to test whether certain subsets of it are "interesting", ie don't seem to be drawn from the same distribution as the rest. Zero inflation comes from the fact that each data point is based a count measurement with both true and sampling zeros, but the result is continuous as it takes into account some other parameters weighted by the count (and so if the count is zero, the result is also zero).
What would be the best way to do this? I have a feeling that Wilcoxon and even brute-force permutation tests are inadequate as they get skewed by these zeros. Focussing on non-zero measurements also removes true zeros that are extremely important. Zero-inflated models for count data are well-developed, but unsuitable for my case.
I considered fitting a Tweedie distribution to the data and then fitting a glm on response=f(subset_label). Theoretically, this seems feasible, but I'm wondering whether (a) this is overkill and (b) would still implicitly assume that all zeros are sample zeros, ie would be biased in the same way (at best) as a permutation?
Intuitively, it sounds like have some kind of hierarchical design that combines a binomial statistic based on the proportion of zeros and, say, a Wilcoxon statistic computed on non-zero values (or, better still, non-zero values supplemented with a fraction of zeros based on some prior). Sounds like a Bayesian network...
Hopefully I'm not the first one having this problem, so would be very grateful if you could point me to suitable existing techniques...
Many thanks!
Comment: Thanks for pointing this out : https://doi.org/10.1007/s10651-005-6817-1
Comment: Update. So far, I've found this paper addressing a problem similar to mine: http://www.maths.otago.ac.nz/home/downloads/david_fletcher/Fletcher_et_al_2005.pdf
Comment: I'm wondering whether this extremely simplified approximation would make sense, given that zeros form the absolute majority:
1) find the proportion of zeros in each subset. 2) assume that in the subset with the smallest number of zeros all zeros are true. 3) from each subset, remove the proportion of zeros equal to the proportion of zeros in the most "zero-rich" dataset. 4) run standard non-parametric stats on this modified dataset.
Comment: The hyperlink to the paper in your first comment appears to be dead. Can you provide a citation instead?
Answer: @msp, I think you are looking at a two stage model in that attachment (I did not have time to read it), but zero inflated continuous data is the type I work with a lot. To fit a parametric model to this data (to allow hypothesis tests) you can fit a two stage but then you have two models (Y is the target and X are covariates): P(Y=0 |X) and P(Y|X;Y>0). You have to use simulation to "bring" these together. Gelmans book (and the arm package in R) shows this process for this exact model (using logistic regression and ordinary linear regression with a log link).
The other option I have seen and like better is to fit a zero inflated gamma regression, which is the same as above (but gamma as the error instead of guassian) and you can bring them together for hypothesis tests on P(Y|X). I dont know how to do this in R, but you can in SAS NLMIXED. See this post, it works well.
Comment: Yes, the two stage approach (Gelman method of two seperate models) assumes two populations, those at zero and those > 0. Regarding the hypothesis tests, can you frame them in terms of the predicted values for varying levels of the inputs and construct empirical confidence intervals related to the simulations for each? For hypothesis tests for the coefficient != 0, you need to test this seperately for both models.
Comment: @B_Miner, thanks very much for your answer, sorry don't have enough rating to vote you up... I'll have a look at the links! My only worry about conditional models is that they postulate that zeros cannot belong to the second (continuous) component, am I right? Does my setting not feel a bit more like a mixture model?  What do you think?
Comment: I've now replicated the two-stage approach proposed in the Gelman book. If subset_factor (with 25 levels) serves as subset label, the first step is fit1=glm(response~subset_factor, family=binomial); and the second step is fit2=lm(response~subset_factor, subset=response>0). I can then run simulations as they describe to obtain the distribution of fitted response values for each factor level. However, I'm still unsure how to translate this to what I need, which is (a) the probability that coefficients aren't zero and (b) significance of difference between coefficients at different factor levels.
Comment: The two stage approach (Gelman method of two seperate models) assumes two populations, those at zero and those above.
Comment: ...so would it be appropriate to simply say that if the impact of some factor level is significant (and significantly different from that of some other factor level) in either of the two models in Gelman's method then it's significant overall?
Comment: @msp: If you can fit the model shown in the link I supplied (SAS) in either SAS or R (I am sure there is an NLMIXED analog in R, especially since this model uses only fixed effects, it's just that SAS does not have any other procedure to write your own log-likelihood) you can accommodate a hypothesis test using P(Y|X) instead of separate hypothesis using the two models in the two-stage approach.
Comment: For example, I work in direct marketing and so want to use a model to test the differences between two direct mail versions. I am interested in the response rate difference (P(Y=0|X)) and the average revenue of those who order (P(Y|X; Y>0)) yes, but at the end of the day I am concerned about the expected revenue value of those that received version A versus B and can not use a simple ANOVA because of the (large amount = those that did not order) zeroes. Again, don't know your domain but hope this helps.
Comment: I work in biology, but yes - mine is a very similar problem. Will try to find an r implementation of the SAS code you mentioned. I'm also wondering if the r package cozigam is doing a similar thing. Will investigate.
Comment: I think I've found it: package gamlss provides model fitting based on several zero-inflated and adjusted continuous distributions. Thanks for your advice, B_Miner!
Comment: @B_Miner Regarding the R-code for the combined approach (zero inflated gamma regression) you can use compound poisson models with the `tweedie` and the [statmod](http://cran.r-project.org/web/packages/statmod/index.html) package. Find the distribution parameter p (`out$xi.max`) with `tweedie.profile` and then fit the GLM with `family=tweedie`, e.g. summary(glm( y ~ x, family=tweedie(var.power=out$xi.max, link.power=0)))
Answer: A similar approach to the Fletcher paper is used in marketing testing, where we can arbitrarily separate the effects of interventions (such as advertising) into (a) a change in the number buying the brand (i.e. proportion of zeroes) and (b) a change in the frequency of buying the band (sales given sales occur at all).  This is a solid approach and conceptually meaningful in the marketing context and in the ecological context Fletcher discusses. In fact, this can be extended to (c) a change in the size of each purchase.
Comment: Thanks! I'm wondering if you're aware of an existing r implementation of this?
Answer: You could treat the exact number of zeros unknown, but constrained between 0 and the observed number of zeros. This can surely be handled using a Bayesian formulation of the model. Maybe a multiple imputation method can also be tweaked to appropriately vary the weights (between 0 and 1) of the zero observations…


calling angularjs controller based method from custom directive

Question: I am using jquery steps in my angularjs app. I have used a custom directive to init the jquery plugin. Now I need to validate all input once the finish button is clicked on the final steps of the form. In order to do that I know there is a option which needs to be set called onFinished. Now how do I call my controller method in this section?
app.directive('step', [function() {
    return {
      restrict: 'EA',
      scope: {
        stepChanging: '='
      },
      compile: function(element, attr) {
          element.steps({
          labels: {finish: "SUBMIT"},
          headerTag: "h3",
          bodyTag: "section",
          transitionEffect: "slideLeft",
          stepsOrientation: "vertical",
          onFinished: function (event, currentIndex) {
             console.log("submit button has been clicked");

             $scope.validator(); //problem here

          }
        });
        return {
          //pre-link
          pre:function() {},
          //post-link
          post: function(scope, element) {
            //element.on('stepChanging', scope.stepChanging);
          }
        }
      }
    };
  }])

Comment: Are you talking about the page controller, or the controller for this directive?
Comment: @rrd  page controller. the controller which has the form. i have a method there called validator
Answer: you directive is isolated scope , it cannot access controller scope , if u want to pass functions you can use & in scope object of your directive like below
scope:{

validator:'&'

}

and in your directive pass this function as below
<step validator='validator'/>

Comment: DO you mean in my controller i can pass this function like ?
Comment: Yes , please check this question https://stackoverflow.com/questions/18378520/angularjs-pass-function-to-directive
Answer: To pass events from a directive with isolate scope to parent controller, use expression & binding.
During the directive compile phase, there is no scope for a function use.
Move the function to the postLink:
app.directive('step', function() {
    return {
      restrict: 'EA',
      scope: {
        //stepChanging: '=',
        stepChanging: '<',
        //USE expression binding
        validator: '&'
      },
      //compile: function(element, attr) {
      link: function postLink(scope,element,attrs) {
          element.steps({
              labels: {finish: "SUBMIT"},
              headerTag: "h3",
              bodyTag: "section",
              transitionEffect: "slideLeft",
              stepsOrientation: "vertical",
              onFinished: function (event, currentIndex) {
                 console.log("submit button has been clicked");

                 //$scope.validator(); //problem here
                 scope.validator();
              }
          );
        }
        /*
        return {
          //pre-link
          pre:function() {},
          //post-link
          post: function(scope, element) {
            //element.on('stepChanging', scope.stepChanging);
          }
        }*/
      }
    };
});

Usage:
<step step-changing="vm.changing" validator="validator()">
</step>

Moving forward, avoid using two-way = binding. Instead use one-way < binding. It is more efficient and provides a better path for migrating to Angular 2+.
Also avoid closing element directives with /> it causes problems with some browsers. Instead use a closing tag </step>.


How can i Debug this crystal reports formula?

Question: i have the following on a crystal report form as a formula:
IF ({REPORT_INVOICE_SUMMARY.ITEMCONCAT} <> 'Move'
    and {REPORT_INVOICE_SUMMARY.ITEMCONCAT} <> 'Daywork'
    and {REPORT_INVOICE_SUMMARY.ITEMCONCAT} <> 'Billable Repair'
    and InStr({REPORT_INVOICE_SUMMARY.ITEMCONCAT},'Non-Billable',1) = 0
    and {REPORT_INVOICE_SUMMARY.ITEMCONCAT} <> 'Turnkey Daywork') then
    {REPORT_INVOICE_SUMMARY.QUANTITY}
else
    0

how can i step through it and watch what the current REPORT_INVOICE_SUMMARY.ITEMCONCAT is ?
I really need to see the values of REPORT_INVOICE_SUMMARY.ITEMCONCAT
Comment: Did you try adding it as field to the report details?
Comment: Crystal Reports does NOT have a debugging feature like what you would expect in a proper IDE.
Answer: As CR doesn't have a debugging feature, you will need to try one of these approaches:

Build a formula one piece at a time and view the results on the canvas
Test complicated logic by returning a value for each case: If [test] Then 'A' Else If [test] Then 'B' Else 'C'
Refactor reusable logic into a custom function

In any case, a better way to structure the logic:
IF Not( {REPORT_INVOICE_SUMMARY.ITEMCONCAT} IN ['Move','Daywork','Billable Repair','Turnkey Daywork'] )
    AND InStr({REPORT_INVOICE_SUMMARY.ITEMCONCAT},'Non-Billable',1) = 0 THEN
    {REPORT_INVOICE_SUMMARY.QUANTITY}
ELSE
    0

Comment: Good to know.  In case of 'link rot', the other thread suggests to create a divide-by-zero error (1/0) at the point where you want to inspect the values of the formula's calculations.
Answer: Might be helpful if I post what I did as well.
Running Total Formaul (Basic Syntax)
dim debug as number
debug = 0

<buggy code>

formula = debug / debug   <- divide by zero  breakpoint

When run in preview you will see the variables with their current values from the formula you are trying to debug.


Unable to setup postgres on ubuntu (8.4 on 9.10)

Question: I am trying to setup postgres on ubuntu, and I cant proceed as I cant find the location of pg_hba.conf
(Postgres 8.4 on ubuntu 9.10)
What I did

setup postgres via aptitude

This gave me ...
/usr/share/postgresql/8.4# aptitude install postgresql
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
libreadline5{a} postgresql postgresql-8.4{a} postgresql-client-8.4{a} postgresql-client-common{a} postgresql-common{a}
0 packages upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/5,159kB of archives. After unpacking 18.8MB will be used.
Do you want to continue? [Y/n/?] Y
Writing extended state information... Done
Preconfiguring packages ...
Selecting previously deselected package libreadline5.
(Reading database ... 17490 files and directories currently installed.)
Unpacking libreadline5 (from .../libreadline5_5.2-6_amd64.deb) ...
Selecting previously deselected package postgresql-client-common.
Unpacking postgresql-client-common (from .../postgresql-client-common_101_all.deb) ...
Selecting previously deselected package postgresql-client-8.4.
Unpacking postgresql-client-8.4 (from .../postgresql-client-8.4_8.4.1-1_amd64.deb) ...
Selecting previously deselected package postgresql-common.
Unpacking postgresql-common (from .../postgresql-common_101_all.deb) ...
Selecting previously deselected package postgresql-8.4.
Unpacking postgresql-8.4 (from .../postgresql-8.4_8.4.1-1_amd64.deb) ...
Selecting previously deselected package postgresql.
Unpacking postgresql (from .../postgresql_8.4.1-1_all.deb) ...
Processing triggers for man-db ...
Setting up libreadline5 (5.2-6) ...

Setting up postgresql-client-common (101) ...
Setting up postgresql-client-8.4 (8.4.1-1) ...
update-alternatives: using /usr/share/postgresql/8.4/man/man1/psql.1.gz to provide /usr/share/man/man1/psql.1.gz (psql.1.gz) in auto mode.

Setting up postgresql-common (101) ...

Setting up postgresql-8.4 (8.4.1-1) ...
update-alternatives: using /usr/share/postgresql/8.4/man/man1/postmaster.1.gz to provide /usr/share/man/man1/postmaster.1.gz (postmaster.1.gz) in auto mode.

Setting up postgresql (8.4.1-1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done

tried to login as
su - postgres

Followed by
createdb mytestdb

This failed with
could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

So I though I need to enable local connections in pg_hba.conf, which I cant find. So I created a new file as
sudo vim /etc/postgresql/8.4/main/pg_hba.conf

With values
local all all ident

But I still cant login after restarting the service. What are next steps for me to take.
Answer: Looking at that output, it simply looks like the server isn't started. Just do a "/etc/init.d/postgresql-8.4 start".
Comment: Had already tried restarting etc, but tried again anyway. :). This is the outout. (I am root.) http://dpaste.de/POn6/
Answer: This usually hapen when you don't specify the host and then the client try to run against ipv6. You must to declare;
createdb mytestdb -h localhost

or
createdb mytestdb -h 127.0.0.1


retirar fundo do google chart

Question: Colegas.
Estou usando o Google Chart em um projeto, só que ao instalar ele nesse projeto, ele sobrepõe a div onde se encontra. Como eu faria para colocar transparente o fundo do Chart?
Answer: Coloca backgroundColor: 'transparent' dentro das options do gráfico.

      google.charts.load('current', {'packages':['corechart']});
      google.charts.setOnLoadCallback(drawChart);
      function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Tarefas', 'Avaliações'],
          ['Português', 11],
          ['Matematica', 2],
          ['Física', 2],
          ['Inglês', 2],
          ['Geografia',    7]
        ]);

        var options = {
          title: 'Avaliações por matérias',
          backgroundColor: 'transparent',
        };

        var chart = new google.visualization.PieChart(document.getElementById('piechart'));

        chart.draw(data, options);
      }

Comment: Obrigado TaisBevalle. Funcionou!

retirar fundo do google chart


Can't read files from BlobStore

Question: I have been trying to write and read files directly from the BlobStore, but it just doesnt work.
The issue is I open the file like file = fileService.getBlobFile(blobKey); and it doesn't throw any exception but right in the next line I call readChannel = fileService.openReadChannel(file, false); and that one throws a FileNotFoundException.
I'm confused as to why the first line did not throw the exception.
Here is the same issue
Unfortunately no one answered that question.
Answer: I haven't had any problems with writes or deletes, but I too get a FileNotFoundException when using openReadChannel(...) with an AppEngineFile.
I've tried using an AppEngineFile created from its constructor taking a complete path.  I've tried using an AppEngineFile obtained from getBlobFile(...) like you do above.  Either way, when the AppEngineFile is passed to openReadChannel(...) a FileNotFoundException is thrown.
My workaround was to let BlobstoreService.serve(...) do all the work of reading and sending the file.  I suspect that using the FileService to read from an AppEngineFile isn't supported yet (I'm using 1.6.0), so reads must be done via the BlobstoreService (serve(...), fetchData(...), BlobstoreInputStream).
Comment: I think this works in the way Blob store was meant to be used. We used to store large data files that we needed to process so I really needed to process the file. If all you need is serve the file probably this is the right way to do it. We ended up dropping the google app thing completely for this project but it would have been nice to know why the above code did not work. Thanks anyway.

Can't read files from BlobStore