Any suggestions for a good undergraduate introductory textbook to statistics?

Question: I am hoping you can give me some suggestions. I am teaching in a very diverse (made of minority groups) college and the students are mostly Psychology majors. Most students are fresh from high school but some of them are older returning students above 40. Most of the students have motivational problems and aversion to math. But I am still looking for a book that covers the basic curriculum: from descriptive to sampling and testing all the way to ANOVA, and all in the context of experimental methods. The department requires me to use SPSS in class, but I like the idea of building the analysis in a spreadsheet such as excel.
p.s. the other teachers use a book that I don't like because of the extensive reliance on computational formulae. I find using these computational formulas - rather than the more intuitive and computationally intensive formula that is consistent with the rational and basic algorithm- unintuitive, unnecessary and confusing. This is the book I refer to Essentials of Statistics for the Behavioral Sciences, 7th Edition Frederick J Gravetter State University of New York, Brockport Larry B. Wallnau State University of New York, Brockport ISBN-10: 049581220X
Thank you for reading!
Comment: Closely related: http://stats.stackexchange.com/questions/421/what-book-would-you-recommend-for-non-statistician-scientists
Answer: Statistics, by Freedman, Pisani, & Purves, originated from a popular and successful course taught at U.C. Berkeley.  I have used it as an intro stats text for undergraduates, have borrowed some of its ideas when teaching graduate stats courses, and have given away many copies to colleagues and clients.  There are many reasons for its popularity:

Its narrative and its problems are driven by real case studies and actual data of obvious importance, rather than the made-up drivel found in so many texts.  These are truly interesting and memorable, including the Salk polio vaccine trials, the 1936 Literary Digest poll debacle, the Berkeley graduate student discrimination lawsuit (hinging on Simpson's Paradox), Fisher's criticism of Mendel's pea results, and much more.
It has extensive problems at three levels: at the end of each chapter subsection (of which there are hundreds), at the end of each chapter (over 30), and at the ends of major groups of chapters (about 4, I recall).  These problems require minimal or no mathematics: they focus on potential misunderstandings that the authors, in their extensive experience, have found to arise among students.
It focuses on statistical ideas and reasoning rather than mathematics.
It uses (almost) no mathematical formulas.  Quantitative relationships are usually expressed graphically and in words.  (They are so clearly conveyed that when I first read this book, as a math graduate student entirely ignorant of statistics, I was able to reproduce all the underlying mathematical theory with no trouble.)
It covers most of the traditional material, including the Binomial and Normal distributions, confidence intervals, z tests, t tests, chi squared tests, regression, and the minimum amount of probability and combinatorics needed to understand these.

Some potential drawbacks would include:

No treatment of Bayesian statistics.  This will make this book outmoded within a decade.
No treatment of ANOVA (psychology students might miss this the most).
No discussion of computing.

I believe the latter two are not critical: a good instructor can easily supply the ANOVA material and can teach as much or little computing as they might wish.  Whether the omission of Bayesian statistics is important will depend on the instructor's tastes and aims.
Finally, I should note that although the mathematical demands are as small as one could possibly imagine, my pre- and post-testing of students indicates that people who come to the book with a disposition and habit of thinking quantitatively still get much more out of it than those who do not.  Most of my students performed badly on pretests of mathematical knowledge (90% got failing grades), but those who also performed badly on pretests of critical thinking (Shane Frederick's Cognitive Reflection Test) exhibited markedly less improvement during the semester than others did.  The pre and post tests both included the full 40-item CAOS test of fundamental concepts any introductory college-level stats course ought to include.  The students in this class have consistently exhibited twice as much improvement as that reported in the CAOS literature; the students with poor cognitive reflection scores improved only an average amount (or failed to complete the course).  I haven't the data to assign causes to this extra improvement, but suspect the textbook deserves at least some of the credit.
Comment: whuber, based on your contributions to this site, I am convinced your students (if you are still teaching) are very lucky.
Answer: I read Freedman (almost the entire book) and OpenIntro Statistics (more than a third). Both of these books are quite good.
I eventually found the book that came close to what I was looking for: Learning Statistics with R: A tutorial for psychology students and other beginners by Danielle Navarro. It is freely available online (legally) and you can also order a print version for about US $30 (see the book page for details).
The main pros of this book are:

R implementations embedded in text as topics are introduced. R has built-in functions for most of the methods
explained in the book. Where R doesn't have a built-in, the author
has written her own function for it and made it available on CRAN
under her lsr library, so your learning is quite complete. I
personally found this to be the biggest plus point of this book.

The book is more comprehensive than Freedman and OpenIntro. Along
with the basics, it covers topics like Shapiro-Wilk test, Wilcoxon test,
Spearman correlation, trimmed means and a chapter on Bayesian statistics, to name a few.

The motivation behind each topic is explained clearly. There is also a good amount of history behind the topics, so you get to appreciate how a method was arrived at.

The book was written iteratively with feedback from readers and I believe   the author is still improving upon the book.

The only drawback is that the hard copy version is large and heavy!
Comment: +1 Thank you for a thoughtful and informative contribution!
Comment: Thank you for your kind words. That is the greatest compliment I have got recently coming from one of the top contributors to this site!
Answer: Thom Baguley, an outgoing editor of The British Journal of Mathematical and Statistical Psychology, published Serious Stats book that you could find useful. It relies on R rather than SPSS, though.
I am suspicious of the books that are in their 7th edition. In my teaching experience, it means that the sections and problems were reshuffled so that the students would have to buy the latest edition to generate the cash flow for the publisher and royalties for the authors keep up with the course. Few serious, research level monographs have undergone a second edition by their authors, and any higher number is obviously an outlier. (Kendall's Library of Statistics is a notable exception, but I cannot really think of any other book that I know that would be in its third edition.)
In my very strong opinion, Excel is a good tool for statistical analysis only when used by a Ph.D. statistician. Teaching undergraduate statistics with it will likely have disastrous consequences, and teaches little statistics as compared to using a modern package like R or Stata. Just try to produce a standardized residual vs. leverage regression plot in Excel, and compare it to one-liners in these packages. Stat majors would need to know the theory, so they would need to build these plots from scratch, but still using a statistical package rather than copy/paste the formulae around in Excel. Non-major undergrads need to get the feel for data analysis, and Excel obscures it, at best.
Comment: Another exception that proves the multi-edition rule is [Freedman, Pisani, & Purves](http://books.wwnorton.com/books/978-0-393-92972-0/) which is in its fourth edition. Somewhere (perhaps in the instructor's manual, maybe the preface) they note that the material is largely unchanged from the first, published some 35 years ago, but that instructors have asked for updated datasets. Thus it's possible to teach from any edition if you like--and old editions are widely available at hugely discounted prices. (I bought my first copy for 25 cents.)
Comment: I can think of several good books that are in high editions; they aren't research monographs, they are textbooks, but that's what is being asked for.

e.g. Tabachnick and Fidell is in its 6th edition
Comment: Tabachnik was on the very bottom of my list of multivariate books (http://www.amazon.com/Multivariate-statistics-books/lm/R3312L94GKFZD1). I see a niche for this particular book to be researchers who want to apply a method like discriminant analysis once, follow the formulae and be done with it and not touch statistics with a ten-feet pole until a dire need arises. But I would not recommend it; again, the age of taking a formula and implementing it in Fortran is way over, and with more convenient tools, modern books can afford looking more into understanding the methods and how they work.
Comment: Thank you for taking the time to expand on your original comment! The book may be too hard for these students, and it will take a long time until the exam copy arrives. About Excel, I think excel is useful for viewing the application of the formula to the data, not as a tool of analysis.
Answer: Statistics Unplugged is a great book for introductory statistics. The author first introduces the logic of the statistical test and later gives the mathematical formula. This approach helps in digesting the new concepts. There are several examples throughout the book which are presented in the form of a problem required to be solved rather than a hypothetical statement and mathematical steps.
Answer: How about The Statistical Sleuth by Ramsey and Schafer?
I think this book gets at some important points without either a) Too much math or b) dumbing things down.
I would suggest that an intro stats course for psychology and other social science types should emphasize how not to go wrong too much. A survey of methods would also be a good thing for undergrads to get.
Answer: Check out the introductory statistics book, Making Sense of Data through Statistics: An Introduction (2014) by Dorit Nevo.  It is written in an extremely accessible manner and is meant for undergraduate or graduate students in business and in the social sciences.  The textbook makes use of examples meaningful to today's students and is accompanied with Excel worksheets providing hands-on experience that reinforces the statistical concepts and techniques covered.  Instructors  are provided with supplementary teaching materials, including PPT lecture slides for each chapter, a Solutions Manual for all Unit Exercises and End-of-Chapter Practice sets, and a Test Bank.  The book is sold in digital format only (.pdf), allowing for the very reasonable price of $19.95.  Educators may register for free access to the book and teaching materials by signing up at the Legerity Digital Press Educator Preview portal.
Answer: Here is a list of books. Puzzles/riddles are a great way to instil an interest in what mathematics/statistics can do. Real life examples help too.
Comment: BTW, in reviewing this list I notice it focuses on *probability* exclusively.  Probability is not the same as statistics!
Comment: I added the post notice because answers that rely solely on a link are likely to become invalid in the future when the link rots. At least summarize or highlight some of the books on the list.  Are you familiar with any of them?
Answer: I have been a TA, observer, or student in a lot of courses involving quantitative methods for psychology, with SPSS as the main program. In all cases it has seemed to me that students have gravitated towards Field (2013), irrespective of whether the course coordinator has mentioned this book or not. In numerous cases students have ignored a recommended textbook and read Field's textbook instead.
I'm not properly competent to assess the rigour of the explanations in the book, and nor am I aware of any research on learning outcomes. However, I can say that this book is comprehensive, cheap (where I'm from anyway), and popular with students. The author's writing style relies a great deal on personal anecdotes, which will grate with some readers. However, I've found that at least as many students enjoy it. I seemed to run into a lot of typos and other issues in the early editions, but by the fourth edition most of these seem to be weeded out.
So, Field (2013) is my recommendation, since:

I've seen psychology students engage with it and enjoy reading it.
Even if you recommend another book, it's quite likely that some students will use Field (2013) anyway. This can then create administration issues within your course.
The book is popular and the author is still relatively young, so it's likely that there will be further editions and improvements.
If you later decide that you want to use R instead, you can transition pretty seamlessly to Field, Miles, and Field (2012), which uses most of the same examples. @jeremy-miles is a frequent contributor to this site.

Field, A. (2013). Discovering statistics using IBM SPSS statistics. Sage.
Field, A., Miles, J., & Field, Z (2012). Discovering Statistics Using R. Sage.
Comment: See the comment of @whuber in a thread discussing inaccurate and misleading advice in this book "Skimming pages here and there in the SPSS book provides insight into some of the really confused questions we get on this site: I think they must come from readers of that book. It is full of errors, misinformation, and outright confabulation."  http://stats.stackexchange.com/questions/157217/transforming-data-all-variables-or-just-the-non-normal-ones/157227#157227
Comment: The author's sense of humour divides people drastically. Juvenile, gross and disgusting are some of the negative verdicts.
Answer: Statistics for College Students and Researchers: Grasping the Concepts, Paperback 2010,  ISBN-13 : 978-1453604533 is perhaps the easiest and most comprehensive stat book for college students. "grasping the concepts and the logic of Statistics. Formulas do not lead to understanding, they actually prevent it. This book takes you through elementary, intermediate and advanced Statistics with only five simple formulas! Descriptive and inferential Statistics. t-test, one-way analysis of variance (ANOVA), two-way ANOVA, repeated measures, factorial designs unlimited, complex split-plot designs.". Unbelievable? Yes... I got the book, the description at amazon is correct. The author is a psychologist/medical anatomist, so examples come from these areas. Apparently these are his lectures. Concepts are developed through funny stories. Yes, five simple formulas all the way through ANOVA. ANOVA summary tables become redundant, although all example cases use them.
Answer: http://onlinestatbook.com/index.html is a very nice source with simulations and videos


Saved video to server from iPhone wont play back via URL in MPMovieVideoController

Question: I have saved a video file at medium quality from the iPhone to Google App Engine. The video plays back fine on the web using the given URL.
http://www.getsplash.com/t/video/wa6Rbzq74WOB
This file will not play back on iPhone, I just get a black screen. I've been able to play other .mov sample files from the web just fine so its not the Objective-C as far as I know. I'm wondering if the encoding that the iPhone stores the video at is not compatible with pulling it back in via a URL?
I've tried adding an extension to the URL above and changing the content type to video/quicktime to no avail.
<code>self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.getsplash.com/t/video/wa6Rbzq74WOB"]];
moviePlayerController.view.frame = CGRectMake(0, 51, 320, 240);
[scrollView addSubview:moviePlayerController.view];
[moviePlayerController play]
</code>
Comment: When testing that my hosted video is or isn't working I use this to make sure my objective-c code is working: http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_640x360.m4v
Comment: The code is working, I can run with other URLs. If I take my video from the above link (which was saved from the iPhone using Medium quality setting) and in Quicktime save it for playback on iPod/iPhone, then put it on the server, it works fine. I'm baffled that the video I save from the iPhone cannot play back on the iPhone from my URL. One would think ...
Answer: Putting the answer here. The solution turned out to be adding ".m4v" to the end of the file URL and that enabled the MoviePlayerController to play it back. I thought relying on file extensions alone was a windows downfall, not something Apple relied on. We also ended up moving from Google Cloud Storage to AWS which has many more controls for types and security.
Answer: What exact model of iPhone are you testing on?  The video is encoded with the Baseline 3.0 profile, which won't work on older models like the 3 and 3GS, I believe.
Comment: Testing on an iPhone 4 and iPhone 4s. The app is intended for 4 and above and iOS 5.0+


Finding a orthogonal matrix that fits $f(S(x,y,z)^t) = ax²+bx²+cx²$

Question:
Consider the function $$ f(x, y, z) := x^2 + y^2 + z^2 - \sqrt{2} x y + \sqrt{2} y z $$ Find an orthogonal $3 \times 3$ matrix $S$ and $\alpha, \beta, \gamma \in \Bbb R$ with $$f(S(x, y, z)^t) = \alpha x^2 + \beta y^2 + \gamma z^2$$ Note: First write $f$ in the form $f(x) = (Ax) - x$ with asymmetrical $3 \times 3$ matrix $A$.

I tried and came to following representation for the function as matrix:
\begin{equation}
A=
  \begin{pmatrix}
   1 & -\frac{1} {\sqrt2} & 0\\
   -\frac{1} {\sqrt2} & 1  & \frac{1} {\sqrt2}\\
   0 & \frac{1} {\sqrt2} & 1\\
  \end{pmatrix}
\end{equation}
\begin{matrix}
(A⋅x)^t⋅x = x^2+y^2-\sqrt{2}⋅x⋅y+z^2+\sqrt{2}⋅y⋅z
\end{matrix}
This looked good to me. Now, I wanted to calculate the eigenvectors for this :
$$
u_{1} = \left(\begin{matrix}
-1 \\
-\sqrt{2} \\
1
\end{matrix}\right), u_2=\left(\begin{matrix}
1 \\
0 \\
1
\end{matrix}\right), u_3=\left(\begin{matrix}
-1 \\
\sqrt{2} \\
1
\end{matrix}\right)
$$
However, when I use these vectors as my matrix S, it is not symetric and $$S^TS \neq E$$ So, what should I do instead. According to ChatGPT the values α, β, γ are the eigenvalues (0, 1, 2). But as it is right now, I don't think this is correct. I am not really going anywhere since then, so I wanted to ask what to do now/instead.
$$ \ $$
Thank you!
Comment: You need to normalize your eigenvectors.
Comment: Where does this come from?
Answer: Your approach is esentially correct: $S$ is the change of basis matrix from the basis $\{u_1,u_2,u_3\}$ to the standard basis. However, note that $S$ is orthogonal iff the basis $\{u_1,u_2,u_3\}$ is orthonormal. Hence, since your $u_i$'s are already orthogonal, the last thing that you need to do is normalize the basis of eigenvectors $\{u_1,u_2,u_3\}$, i.e., taking $u_i/\lVert u_i\rVert$ instead of $u_i$.
Comment: Hey, so I did normalize it. How can I check whether it's right or not. If I add it to (Ax)^t x for A, I don't get the eigenvalues as coefficients. Is it still correct? My values are like -1/2 and 0 and 1/2
Comment: Well, after normalization you will see that $S^T = S^{-1}$, so $S^T A S = S^{-1} A S$, which will be equal to a diagonal matrix with diagonal entries $\alpha,\beta,\gamma$, the eigenvalues of $A$.


How to download jar file?

Question: I guess this might be a quiet stupid question but this is the first time I want to bring an external jar file ile to Eclipse and I just don´t know how to download it. I want to import: "nl.flotsam.xeger.Xeger"
I found this link but I don´t understand how to download it.. https://code.google.com/p/xeger/source/browse/trunk/src/main/java/nl/flotsam/xeger/Xeger.java?r=4
Comment: The jar in the 'Downloads' tab of the bar doesn't have what you want?
Comment: well yeah .. I thought this might be a stupid question but this is really all I needed. Thanks a lot!
Answer: Right click on your project folder in eclipse -> build path -> configure build path.
Select "Library" tab, click on "Add External Jars" button and select your jar

How to download jar file?


Relative Frobenius and absolute Frobenius

Question: Let $X$ is a scheme over a scheme $S$ of characteristic $p$. Let $F: X\to X^{(p)}$ be the relative Frobenius and let $W: X^{(p)}\to X$ be the natural map in fibre product. We know $W\circ F$ is the absolute Frobenius on $X$ by definition. What about $F\circ W$? Is is the absolute Frobenius on $X^{(p)}$ and why?
Comment: Have you tried writing down an example, say for $S=\operatorname{Spec} \Bbb F_q$ and $X=\Bbb A^1_S$?
Comment: @KReiser Yes. For easy case, like you mentioned I can figured out. But how can I prove for arbitrary schemes?
Answer: sorry for joining the party so late! yes this is quite tricky to write down, but follows from the universal property of the relative Frobenius $F_{X}$. For any morphism $f: X\rightarrow Y$ over $S$ we have a commutative square:
$\require{AMScd}$
\begin{CD}
X^{} @>F_X>> X^{(p)}\\
@Vf VV @Vf^{(p)} VV\\
Y^{} @>F_Y>> Y^{(p)}
\end{CD}
For a proof see here, basically follows from definition and the fact that any ring hom $\phi$ is somehow "Frobenius equivariant", i.e. $\phi(a^p)=\phi(a)^p.$
Now replacing $X$ by $X^{(p)}$and $X^{(p)}$ by $X^{(p^2)}$ you get the diagram (you can do that because $X^{(p)},X^{(p^2)}$ are still by def. schemes over $S$).
\begin{CD}
X^{(p)} @>F_X^{(p)}>> X^{(p^2)}\\
@Vf VV @Vf^{(p)} VV\\
Y^{} @>F_Y>> Y^{(p)}
\end{CD}
Now in the lower row set $Y=X$ and $f=W$ following your definitions. Then you get
\begin{CD}
X^{(p)} @>F_X^{(p)}>> X^{(p^2)}\\
@VW VV @VW^{(p)} VV\\
X^{} @>F_X>> X^{(p)}
\end{CD}
Now observe $W^{(p)}F_X^{(p)}$ is the absolute Frobenius on $X^{(p)}$ by definition. By commutativity of the diagram, this is the same as $F_XW$


Redireccionar ASP NET

Question: Como posso redireccionar a página que me encontro através de um inputButton html no ASP NET WEB FORMS
o código do meu button:
 <input id="ButtonD" style="width: 169px" type="button" value="D"  />

Comment: pq tu não utiliza um  ? ou um asp:button, que tem o evento onClick. No evento onClick tu iria executar o código: `Response.Redirect("url");`
Answer: Você pode atribuir uma função
Atribuindo ao OnClientClick event para chamar uma função JavaScript em um asp:Button:
<asp:Button ID="ButtonD" runat="server" Text="Button" onclientclick='redirect()' />

Ou no input type="button":
<input id="ButtonD" style="width: 169px" onclick="redirect()" type="button" value="D"  />

JavaScript:
function redirect() {
  location.href = 'page.aspx';
}

Você também pode vincular por ID
jQuery(se for input type="button"):
$("#ButtonD").click(function(){
   location.href = 'page.aspx';
});

jQuery(se for asp:Button):
$("#<%= TextBox1.ClientID %>").click(function(){
  location.href = 'page.aspx';
});

Referência: link SOEN
Answer: Adicione:
Response.Redirect("sua url destino");

No evento Click do botão que você criou.

Redireccionar ASP NET


Trying to build a ReactNative iOS app and getting errors on Macbook Pro with M1 Apple Chip

Question: I'm able to successfully run the starter "AwesomeProject" react-native app on both iOS and Android.
I have a private repo project that was built by an outsourced team that I'm trying to get running on my local Macbook Pro with an M1 Chip.  The team claims they are able to get the project running on a normal Macbook Pro (without the M1 chip).
I'm unable to build the project on iOS and get the following error:

The following build commands failed:  SwiftEmitModule normal arm64
Emitting\ module\ for\ Charts (in target 'Charts' from project 'Pods')
(1 failure)

When I try to run the Android app I'm able to get it to run on the Android Device simulator but get the following errors from

ERROR  Error: token is not a valid string
ERROR  Invariant
Violation: Module AppRegistry is not a registered callable module
(calling runApplication). A frequent cause of the error is that the
application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
ERROR
Invariant Violation: Module AppRegistry is not a registered callable
module (calling runApplication). A frequent cause of the error is that
the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

I'm not sure how to further debug these issues.  I followed some of the debugging I saw with M1 Macbooks and React-Native like using "brew" to install cocoapods and then always using "alias pod='arch -x86_64 pod'" for the pod command.  I see lots of other hacks to make react-native work on M1 like this article: https://goxotech.medium.com/apple-m1-react-native-was-not-exactly-what-we-thought-but-that-is-not-an-issue-6c8d359926df
Answer: try adding this in your PodFile
<code>post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
        config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
end
</code>


Prevent Delphi 10.2 from auto adding properties to TForm

Question: I have a codebase that I'm working on that is written to work in both Delphi 5 and Delphi 10.2, until we get everything converted to D10.
Whenever I open a DFM file in 10.2 and save it, it automatically adds a DesignSize property to the TForm. This property doesn't exist in D5, so I get errors every time I open the same DFM in D5.
Is there any way to prevent D10 from auto-updating the DFM? Or is this not possible?
Comment: @Uwe Thats a pretty good idea. The only issue with that I can think of is having to make it writable when making changes to dfm, which isn't done so often.
Comment: What about making the DFM read-only?
The DesignSize property is only written, when you have some child component set to Align = alNone and Anchors <> [akLeft, akTop]. Perhaps you can avoid this combination.
Comment: @UweRaabe: That combination is difficult to avoid! I use it all the time to make dialog boxes behave well when resized.
Answer: You could clear them out using a utility when needed. The JVCL includes a utility called DFM Cleaner that does this. In ends up in $(JVCL)\DevTools after JVCL is installed.

DFMCleaner is a tool to remove unsupported properties from DFMs. If
  you save a dfm file in one version of Delphi and want to use it in an
  earlier version, chances are there are some unsupported properties in
  it, generating an error when the form is opened in Delphi. What's even
  worse, if the dfm is part of a design-time package, Delphi will
  install the package without errors but when you try to access the form
  at design-time (f ex if the form is used by a property editor), Delphi
  generates an AV instead.


InnoDB options crashing mysql start AND mysql tuning

Question: I have an innodb on a Ubuntu 10.10 server running on an ESXi platform. I have dedicated 8 CPUs, 32 Gigs of ram, and files stored in a Raid 5 HP SAN of SAS 10k rpm disks. I'm expecting FAST queries! However: select count('x') takes 45 seconds for 75 million rows! So, I dug into tuning this beast:
1) Some of my settings cause mysql to bomb out with "Unknown variable" errors. These are:
innodb_file_format = barracuda
innodb_read_io_threads = 6
innodb_write_io_threads = 6
innodb_io_capacity = 1000

2) The rest of my settings that do not crash mysql but are probably not optimized..
skip_name_resolve
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_buffer_pool_size = 24G
innodb_log_files_size = 1G
innodb_log_buffer_size = 8M
innodb_flush_method = O_DIRECT
innodb_flush_log_at_trx_comit = 1

key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 32
query_cache_limit = 1M
query_cache_size = 0

Is there any additional tuning that you would recommend on these settings? Any additional settings that I am missing?
Thanks for the support!
Answer: innodb_file_format = barracuda
innodb_read_io_threads = 6
innodb_write_io_threads = 6
innodb_io_capacity = 1000

These setting are MySQL 5.5 specific. If you are using MySQL 5.5 against data that was wriiten in a MySQL 5.0/5.1, you need to run the old version of MySQL, mysqldump everything out, and reload the data into mysql again. The barracuda format is another InnoDB File Format. You must migrate out from the previous version of MySQL and InnoDB. I wrote something on this awhile back.
To double check the file format, do "SHOW VARIABLES LIKE 'innodb_file_format';" You should see Antelope.

Once you get this issue straightened out, crank up the other variables to this
innodb_read_io_threads = 64
innodb_write_io_threads = 64
innodb_io_capacity = 20000

After all, you have 8 CPUs.

MyISAM Tuning Options
InnoDB Tuning Options
InnoDB Specific Tuning
InnoDB and MyISAM Cache Configuration Forecasting


Quadratic inequality proof.

Question: I recently encountered a quadratic equations property that
$ax^2+bx+c>0$  $  \forall$   $x\in \Re \Rightarrow D<0$ $and$ $a>0$
and $ax^2+bx+c<0$  $  \forall$   $x\in \Re \Rightarrow D<0$ $and$ $a<0$.
Now, i tried to prove it algebraically and through graphs. Its clear that the equation seems much simple by just making a parabola and as $D<0$ the parabola never touches the $x$ axis and hence the two equations follow.
Can there be any algebraic proof the relation mentioned above.
Comment: How is the discriminant related to the roots? Once you have that in mind, the first question is easily answered. For the second, use continuity and look at the limit as $x$ goes to infinity
Answer: We suppose $a \neq 0$, otherwise it is not a quadratic equation.
$$ax^2+bx+c>0,\forall x \in \mathbb{R} \Rightarrow ax^2+bx+c\neq0,\forall x \in \mathbb{R}\Rightarrow D<0$$
Also $\lim_{x\to \infty}ax^2+bx+c=\frac{a}{|a|}\infty$. So :
$$ax^2+bx+c>0,\forall x \in \mathbb{R} \Rightarrow \lim_{x\to \infty}ax^2+bx+c =+\infty \Rightarrow \frac{a}{|a|}=1 \Rightarrow a>0$$
Finally : $$ax^2+bx+c>0,\forall x \in \mathbb{R} \Rightarrow D<0 \space \text{and} \space a>0$$
You can do the same kind of reasonning for the second inequality.
Answer: For $a>0$ we have:
$$
ax^2+bx+c>0 \quad \iff \quad x^2+\frac{b}{a}+\frac{c}{a}>0
$$
so:
$$
x^2+\frac{b}{a}>-\frac{c}{a}
$$
$$
x^2+\frac{b}{a} +\left(\frac{b}{2a} \right)^2>-\frac{c}{a}+\left(\frac{b}{2a} \right)^2
$$
$$
\left(x+\frac{b}{2a} \right)^2>-\frac{c}{a}+\left(\frac{b}{2a} \right)^2
$$
that is always verified ( since The LHS is a square) if
$$
-\frac{c}{a}+\left(\frac{b}{2a} \right)^2<0
$$
i.e.
$$
\frac{b^2-4ac}{4a^2}=\frac{\Delta}{4a^2} <0
$$
and since $4a^2>0$ we have $\Delta<0$.
You can do the same for the other case.

Quadratic inequality proof.


What does the prefit parameter in sklearn's SelectFromModel do?

Question: I'd like to use sklearn's SelectFromModel to do feature selection. However, I'm not quite sure I understand the difference between prefit=True and prefit=False. According to the documentation:
Whether a prefit model is expected to be passed into the constructor directly or not.
If True, transform must be called directly and SelectFromModel cannot be used with cross_val_score, GridSearchCV and similar utilities that clone the estimator.
Otherwise train the model using fit and then transform to do feature selection.

I don't really understand what this means.
Answer: The prefit parameter of SelectFromModel indicates if the provided estimator has already been fit to data. If the parameter is set to True, the transform() method can be called directly to transform the data according to the most important features:
from sklearn.datasets import make_classification
from sklearn.feature_selection import SelectFromModel
from sklearn.linear_model import LogisticRegression

X, y = make_classification(n_classes=2, n_samples=100, n_features=5)

log_reg = LogisticRegression()
log_reg.fit(X, y)

selector = SelectFromModel(estimator=log_reg, prefit=True)

X_selected = selector.transform(X)

Alternatively, one can also choose to pass an estimator that has not been fitted to any data yet. In this case, SelectFromModel needs to first complete this step as well:
X, y = make_classification(n_classes=2, n_samples=100, n_features=5)

selector = SelectFromModel(estimator=LogisticRegression)

X_selected = selector.fit_transform(X)

The reason behind such a design is to make SelectFromModel compatible for use in data transformation pipelines, e.g. in cross-validation or grid search for hyperparameter tuning. Since in such pipelines a different subset of data points may be passed to the estimator in each iteration, it needs to be re-fit to each subset. This is also the reason why a SelectFromModel object with prefit=True cannot be used with e.g. cross_val_score or GridSearchCV.
Contrariwise, if SelectFromModel is not used in such pipelines and a fitted model is already available, setting prefit=True avoids re-fitting the estimator unnecessarily and saves computational resources.


How to implement backdrop like this one in android studio?

Question: Good morning .
i have this design here in figma and i want to turn it into code in android studio :
The design in figma
how i can do this  and what is the name of the library of this layout . i tried backdrop layout but it didn't work
Answer: Design a layout file for bar which contains rating, rate button and metascore. Add corner radius to its background (Top Left and Bottom Left). You can use cardview library. Use this layout in your original fragment. And set elevation. Front layers elevation should be bigger than back layer. Lowest elevation is 0 dp, biggest is 24 dp.
You can learn elevation more from this link :


What is the difference between spatial dependence and spatial (auto)correlation?

Question: It seems to me that in literature these terms are used synonymously.
Does spatial autocorrelation strictly refer to linear dependence, or does spatial autocorrelation refer to the set of measures of spatial dependence (moran's i,...)?
Do you know of any precise definition of both terms?
Thank you very much
Comment: It may be too much to expect universal agreement.  In specific cases, authors will clearly distinguish particular mathematical forms of spatial correlation from statistical dependence, but there is a well-established tradition of doing just the opposite.  *E.g.,* Noel Cressie (in *Statistics for Spatial Data*, 1991) writes "...correlated ( i.e., cannot be modeled as statistically independent)" [p. 3].  Therefore you should anticipate that several different answers to this question are possible.  Perhaps you have a specific subset of the "literature" in mind?
Comment: For me, spatial dependence is a characteristic of the data generating process (DGP), see @Emre, and spatial correlation is a characteristic of the pattern/configuration of your observations (empirical). So, it is expected that a spatially dependent DGP will result in spatially correlated values.
Comment: From my point of view it would be fair to say that spatial heterogeneity and spatial autocorrelation are special cases of spatial dependence. I found, however, no one in lterature who shares my opinion :)
Answer: Correlation is a specific type of dependence--first order--thus dependence subsumes correlation. Furthermore, two random variables can be dependent without being correlated. Basic examples:
Auto-correlation: $R_X(\mathbf x_1, \mathbf x_2) = h_1(\| \mathbf x_1 - \mathbf x_2 \|)$
Cross-correlation: $R_{XY}(\mathbf x, \mathbf y) = h_2(\| \mathbf x - \mathbf y \|)$
Dependence: $f_{XY}(\mathbf x, \mathbf y) \neq f_X(\mathbf x) f_Y(\mathbf y)$
Comment: $h_1$ and $h_2$ are appropriate scalar functions, $f$ is a pdf, and $R$ is the correlation function, $X$ and $Y$ are random variables, $\mathbf{x}$ and $\mathbf{y}$ are vectors.
Comment: What do $R$, $h_1$, $h_2$, and $f$ *mean*?


Invoke-WebRequest : Unauthorized - The request requires user authentication

Question: I am hitting this url
https://webadmin.td90.centile-dev.com/restletrouter/v1/service/Login
Then i am getting the session and passing into the url below
https://myistra.td90.centile-dev.com/restleroute/v1/3rdParty/AdmtiveDomain.
Problem
Output
<code>Invoke-WebRequest : Unauthorized
The request requires user authentication
You can get technical details here.
Please continue your visit at our home page.
At C:\Users\administrator\Documents\CDR.ps1:20 char:213
+ ... 'Session' | Invoke-WebRequest -Uri ("https://myistra.td90.centile-
   dev ...
 +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo          : InvalidOperation:
(System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
thirdParty_SESSIONID=969514241160310577; _ac958=http://10.20.100.190:8078
</code>
Here is my code
<code>$user = "SuperGabriel"
$pass = "SuperGabriel@2019"
$pair = "$($user):$($pass)"

$encodedCreds =

$basicAuthValue = "Basic $encodedCreds"

$PartOneHeaders = @{
"Authorization" = $basicAuthValue
"X-Application" = "3rdParty"

}

#test
$Headers =@{
"X-Application" = "3rdParty"
"Cookie"= "thirdParty_SESSIONID=7353595784495763113;"
}

$PartOneWebRequest = Invoke-WebRequest -Uri https://webadmin.td90.centile-
dev.com/restletrouter/v1/service/Login -Headers $PartOneHeaders -
ContentType "application/json" -Method POST -SessionVariable 'Session' |

Invoke-WebRequest -Uri ("https://myistra.td90.centile-
dev.com/restleroute/v1/3rdParty/AdmtiveDomain" )  -Headers $Headers -
Method Get
</code>
I have echoed everything out to make sure i am getting the right information and passing it into the right places.
I have tested the call in postman and it works.
Expected results
<code>[
{
    "restUri": "v1/3rdParty/AdmtiveDomain/0.",
    "alias": "TopLevelAdmtiveDomain",
    "rootModel": "AdmtiveDomain",
    "domainName": "Top-Level",
    "admtiveDomainID": "0."
},
{
    "restUri": "v1/3rdParty/AdmtiveDomain/0.106.",
    "alias": "AdmtiveDomainSpecific",
    "rootModel": "AdmtiveDomain",
    "domainName": "acd-00",
    "domainType": "Enterprise",
    "admtiveDomainID": "0.106."
}
]
</code>
Comment: You're not giving `$encodedCreds` a value.. Plus.. Are all these new line breaks in the code by accident? What is supposed to be there after the pipe symbol (`'Session' |`)
Answer: <code>[System.Uri]$Uri = "https://webadmin.td90.centile-dev.com/restletrouter/v1/service/Login" # Add the Uri
[System.Uri]$Uri_Get = "https://webadmin.td90.centile-dev.com/restletrouter/v1/3rdParty/AdmtiveDomain"

$ContentType = "application/json" # Add the content type
$Method = 'POST' # Add the method type

$user = "SuperGabriel"
$pass = "SuperGabriel@2019"
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
    # Add name and value of headers
    "Authorization" = $basicAuthValue
    "Cookie" = "thirdParty_SESSIONID=6335513255659796064"
    "X-Application" = "3rdParty"
}
$Headers_Get = @{
    # Add name and value of headers

    "Cookie" = "thirdParty_SESSIONID=4436753218874838616; thirdParty_SESSIONID=6335513255659796064;"
    "X-Application" = "3rdParty"
    "Host" = "webadmin.td90.centile-dev.com"
    "Content-Type"= "$ContentType"
}

$Headers_Get2 = @{
    # Add name and value of headers

    "Cookie" = "thirdParty_SESSIONID=1312545750448673312"
    "X-Application" = "3rdParty"
    "Host" = "webadmin.td90.centile-dev.com"
    "Content-Type"= "$ContentType"
}
# Splat the parameters
$props = @{
    Uri         = $Uri
    Headers     = $Headers
    ContentType = $ContentType
    Method      = $Method
}
$props_Get = @{
    Uri         = $Uri_Get
    Headers     = $Headers_Get
    ContentType = $ContentType
    Method      = "GET"
}

try
{

$Result= Invoke-RestMethod @props  -SessionVariable sess -OutFile C:\output.json
echo  $Result

$Result1= Invoke-RestMethod @props_Get  -OutFile C:\"$DateStr".json -WebSession $sess
echo  $Result1

}
catch [System.Net.WebException]
{
    $res = $_.Exception.Response
    echo $res
}
</code>
Will work as per your request.

Cheers..


How can I notify an application of a programmatically set scrollbar value?

Question: My code involves standard Scroll Bar control and it happens that I need to change its value programmatically in some cases. I do this using SetScrollInfo function, as in this example:
void setScrollBarValue( HWND scrollBar, int value )
{
    SCROLLINFO si = { sizeof( SCROLLINFO ); }
    si.fMask = SIF_POS;
    si.nPos = value;
    ::SetScrollInfo( scrollBar, SB_CTL, &si, true /* redraw */ );
}

This appears to work fine (the thumb of the scrollbar moves around) but it fails to notify the rest of the application of the new scrollbar value. For instance, an edit control which uses the scroll bar (much like in the Windows notepad application) fails to scroll around because it doesn't get notified about the new scrollbar value.
In case it matters: the scrollbar I'm modifying is not in the same process as the above
setScrollBarValue function.
Does anybody know how to achieve this?
Edit: I found out how to do this with default window scrollbars (those of type SB_VERT or SB_HORZ). I can send the WM_HSCROLL and WM_VSCROLL to the window like this:
::SendMessage( windowContainingScrollBar,
               WM_HSCROLL,
               MAKEWPARAM( SB_THUMBPOSITION, si.nPos ), NULL );

However, in my case the scroll bar has a window handle of its own (it has the type SB_CTL). This means that I don't know the orientation of the scroll bar (so I cannot tell whether to send WM_HSCROLL or WM_VSCROLL) and I don't know what window to send the message to.
Answer: Try sending the WM_VSCROLL message after calling SetScrollInfo().
Comment: I looked into this, but my scrollbar is a distinct window (hence I'm passing `SB_CTL`); which window would I send `WM_VSCROLL` to? And what would the WPARAM argument look like? I guess it should be `SB_THUMBPOSITION` but how can I know the position of the thumb after scrolling? The same as I set `si.nPos` to in my example?
Comment: Send the message to the control itself. If it doesn't handle it, it will automatically get passed on to its parent windows. Or you could just send it directly to its parent window.
About the parameters: use GetScrollInfo() to get the params - it's required to call GetScrollInfo() after SetScrollInfo() since the control can adjust the params.
Comment: Thanks about the GetScrollInfo() hint! I got it working now (except that I don't know how to determine the orientation of a `SB_CTL` scrollbar, but that's a separate SO question). :-)


Como usar Scope_Identify para retornar id .NET

Question: Estou desenvolvendo uma aplicação e preciso que quando o sql faça o insert retorne o valor do id que foi inserido, estou usando o seguinte comando
SqlCommand cmd = new SqlCommand("insert into solicitacoes (assunto, mensagem, endereco, anexo, status, id_Departamento) values ('" + valorcadastro.assunto + "', '" + valorcadastro.mensagem + "', '" + valorcadastro.endereco + "','" + valorcadastro.anexo + "','Inicial', 0)", con);
            cmd.ExecuteNonQuery();

Eu pesquisei em alguns tutoriais e achei a função Scope_Identify mas como devo implementar no meu código?
Answer: SCOPE_IDENTITY é uma função de SQL Server. Precisas da função equivalente para MySQL, last_insert_id:
SqlCommand cmd = new SqlCommand("insert into solicitacoes (assunto, mensagem, endereco, anexo, status, id_Departamento) values ('" + valorcadastro.assunto + "', '" + valorcadastro.mensagem + "', '" + valorcadastro.endereco + "','" + valorcadastro.anexo + "','Inicial', 0);SELECT last_insert_id()", con);

cmd.ExecuteNonQuery();
int ultimoRegistro = cmd.ExecuteScalar();

Nota que precisas de usar ExecuteScalar em vez de ExecuteNonQuery para obter o valor retornado pela BD.
Ou então, se usares a classe MySqlCommand, podes aceder à propriedade LastInsertedId.
Nota que o teu comando está aberto a ataques por injecção de SQL. Devias usar queries parameterizadas:
var cmd = new SqlCommand("insert into solicitacoes (assunto, mensagem, endereco, anexo, status, id_Departamento) values ('@assunto', '@mensagem', '@endereco','@anexo','Inicial', 0);SELECT last_insert_id()", con);

cmd.Parameters.AddWithValue("@assunto", valorcadastro.assunto);
cmd.Parameters.AddWithValue("@mensagem", valorcadastro.mensagem);
cmd.Parameters.AddWithValue("@endereco", valorcadastro.endereco);
cmd.Parameters.AddWithValue("@anexo", valorcadastro.anexo);

Comment: @Marconi [Funciona em MySql](http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id)
Comment: @Marconi ele deve ter visto tutoriais de SQL Server. Mas tagou a pergunta com `MySql`.
Comment: Que eu saiba não tem nenhum mecanismo ANSI SQL pra gerar chaves automaticamente; tem que fazer essa lógica RDBMS por RDBMS mesmo, a menos que você tope e.g. usar UUIDs como chaves, em qual caso eles podem ser gerados pelo próprio aplicativo.
Comment: Um pequeno alerta, penso que se houver escritas concorrentes a usar a mesma connection pode haver problemas. Pelo seguro o melhor é abrir sempre uma nova ligação ao executar um comando deste tipo e fechar de seguida.


Delete directory regardless of 260 char limit

Question: I'm writing a simple script to delete USMT migration folders after a certain amount of days:
## Server List ##
$servers = "Delorean","Adelaide","Brisbane","Melbourne","Newcastle","Perth"

## Number of days (-3 is over three days ago) ##
$days = -3

$timelimit = (Get-Date).AddDays($days)

foreach ($server in $servers)
{
    $deletedusers = @()
    $folders = Get-ChildItem \\$server\USMT$ | where {$_.psiscontainer}
    write-host "Checking server : " $server
    foreach ($folder in $folders)
    {
        If ($folder.LastWriteTime -lt $timelimit -And $folder -ne $null)
        {
            $deletedusers += $folder
            Remove-Item -recurse -force $folder.fullname
        }
    }
        write-host "Users deleted : " $deletedusers
        write-host
}

However I keep hitting the dreaded Remove-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I've been looking at workarounds and alternatives but they all revolve around me caring what is in the folder.
I was hoping for a more simple solution as I don't really care about the folder contents if it is marked for deletion.
Is there any native Powershell cmdlet other than Remove-Item -recurse that can accomplish what I'm after?
Answer: I often have this issue with node projects. They nest their dependencies and once git cloned, it's difficult to delete them. A nice node utility I came across is rimraf.
npm install rimraf -g
rimraf <dir>

Comment: Great! the robocopy solution worked partially, it removed some files but not everything.  This rimraf works flawlessly. Thanks @Andy a lot!
Answer: Just as CADII said in another answer: Robocopy is able to create paths longer than the limit of 260 characters. Robocopy is also able to delete such paths. You can just mirror some empty folder over your path containing too long names in case you want to delete it.
For example:
robocopy C:\temp\some_empty_dir E:\temp\dir_containing_very_deep_structures /MIR

Here's the Robocopy reference to know the parameters and various options.
Comment: I can confirm that this solution works and it's the one I've used when I came across the same problem.
Comment: Thank you so much for this!  I've been trying to find a tool to delete borked folders names for years.
Comment: This should be the answer.. its clean and lean no third party tools used
Comment: This worked for me but I had to add a removal step after robocopy mirrored it (Remove-Item). I was left with E:\temp\dirname with the empty dir contents. Thank you very much. I've been trying to figure this out for a while now!!!
Answer: I've created a PowerShell function that is able to delete a long path (>260) using the mentioned robocopy technique:
function Remove-PathToLongDirectory
{
    Param(
        [string]$directory
    )

    # create a temporary (empty) directory
    $parent = [System.IO.Path]::GetTempPath()
    [string] $name = [System.Guid]::NewGuid()
    $tempDirectory = New-Item -ItemType Directory -Path (Join-Path $parent $name)

    robocopy /MIR $tempDirectory.FullName $directory | out-null
    Remove-Item $directory -Force | out-null
    Remove-Item $tempDirectory -Force | out-null
}

Usage example:
Remove-PathToLongDirectory c:\yourlongPath

Comment: FYI : in Windows 10 with build numbers 14393 (Anniversary update) the path limit bug in .NET has been fixed. You need to enable long path support in the local policies and you can do anything you want with long paths without having to resort to P/Invoke or robocopy
Comment: This works like a dream. And there was me for months using subst z: myLongPath
Comment: This is the only solution on this page that worked for me.  Thanks!
Comment: What about if the directories are in Windows Server 2016?
Answer: This answer on SuperUser solved it for me: https://superuser.com/a/274224/85532
Cmd /C "rmdir /S /Q $myDir"

Comment: This answer has worked some times in the past for me, but failed in removing my `node_modules` folder. For that case I resorted to [this other answer](http://stackoverflow.com/a/33692148/419956) as I hade node installed in that case anyways.
Comment: Didn't work for me either. It also risks failing with dirs with spaces deleting the wrong stuff (though that would be fixable)
Answer: I learnt a trick a while ago that often works to get around long file path issues.  Apparently when using some Windows API's certain functions will flow through legacy code that can't handle long file names.  However if you format your paths in a particular way, the legacy code is avoided.  The trick that solves this problem is to reference paths using the "\\?\" prefix.  It should be noted that not all API's support this but in this particular case it worked for me, see my example below:
The following example fails:
PS D:\> get-childitem -path "D:\System Volume Information\dfsr" -hidden

Directory: D:\System Volume Information\dfsr

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a-hs        10/09/2014  11:10 PM     834424 FileIDTable_2
-a-hs        10/09/2014   8:43 PM    3211264 SimilarityTable_2

PS D:\> Remove-Item -Path "D:\System Volume Information\dfsr" -recurse -force
Remove-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260
characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ Remove-Item -Path "D:\System Volume Information\dfsr" -recurse -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : WriteError: (D:\System Volume Information\dfsr:String) [Remove-Item], PathTooLongExcepti
on
+ FullyQualifiedErrorId : RemoveItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand

PS D:\>

However, prefixing the path with "\\?\" makes the command work successfully:
PS D:\> Remove-Item -Path "\\?\D:\System Volume Information\dfsr" -recurse -force
PS D:\> get-childitem -path "D:\System Volume Information\dfsr" -hidden
PS D:\>

Comment: I get no errors, but it also doesn't remove the folder.
Comment: This worked for me prefixes, win 10 powershell 5.1. Like this Remove-Item -Recurse -Force -Path "\\?\$($_.FullName)"
Comment: That's a great trick. I'll have to give it a go. I'm not usually doing anything too exotic when I run up against the limit, mainly just parsing a folder structure or removing files etc. Thanks!
Comment: Deletes folder with long paths on PS 5.1 but doesn't delete it on PS 7.1 (no error) (on Windows Server 2019)
Comment: PS 7.1 (core) is able to delete the folder without the prefix. (on Windows Server 2019)
Answer: If you have ruby installed, you can use Fileman:
gem install fileman

Once installed, you can simply run the following in your command prompt:
fm rm your_folder_path

This problem is a real pain in the neck when you're developing in node.js on Windows, so fileman becomes really handy to delete all the garbage once in a while
Comment: It's a good answer for a specific situation but they were production servers at the time unfortunately, no ruby!
Comment: Ridiculous that I have to install Ruby, then the devkit, then a gem to delete a folder, but this did get the job done.
Comment: this was awesome.  It deleted a HUGE tree in a fraction of a second.  Thank you, thank you, thank you.
Answer: This is a known limitation of PowerShell.  The work around is  to  use dir cmd (sorry, but this is true).
http://asysadmin.tumblr.com/post/17654309496/powershell-path-length-limitation
or as mentioned by AaronH answer use \?\ syntax is in this example to delete build
dir -Include build -Depth 1 | Remove-Item -Recurse -Path "\\?\$($_.FullName)"

Comment: `dir` seems to be failing too.
Comment: I was hoping to not have to do that, but the more I read the more it looks like there is no alternative.  Thanks for the link
Comment: Best answer here: https://stackoverflow.com/a/33692148/1657465
Answer: If all you're doing is deleting the files, I use a function to shorten the names, then I delete.
    function ConvertTo-ShortNames{
    param ([string]$folder)
    $name = 1
    $items = Get-ChildItem -path $folder
    foreach ($item in $items){
        Rename-Item -Path $item.FullName -NewName "$name"
        if ($item.PSIsContainer){
            $parts = $item.FullName.Split("\")
            $folderPath = $parts[0]
            for ($i = 1; $i -lt $parts.Count - 1; $i++){
                $folderPath = $folderPath + "\" + $parts[$i]
            }
            $folderPath = $folderPath + "\$name"
            ConvertTo-ShortNames $folderPath
        }
        $name++
    }
}

I know this is an old question, but I thought I would put this here in case somebody needed it.
Comment: This is what works well for node_modules folders on Windows machines.
Comment: Savior. Thank you!
Comment: "in case somebody needed it." just put it in.. Very good solution btw.  ( :
Answer: There is one workaround that uses Experimental.IO from Base Class Libraries project. You can find it over on poshcode, or download from author's blog. 260 limitation is derived from .NET, so it's either this, or using tools that do not depend on .NET (like cmd /c dir, as @Bill suggested).
Answer: For my Robocopy worked in 1, 2 and 3

First create an empty directory lets say c:\emptydir
ROBOCOPY c:\emptydir c:\directorytodelete /purge
rmdir c:\directorytodelete
Answer: Combination of tools can work best, try doing a dir /x to get the 8.3 file name instead. You could then parse out that output to a text file then build a powershell script to delete the paths that you out-file'd. Take you all of a minute.  Alternatively you could just rename the 8.3 file name to something shorter then delete.
Answer: This is getting old but I recently had to work around it again. I ended up using 'subst' as it didn't require any other modules or functions be available on the PC this was running from. A little more portable.
Basically find a spare drive letter, 'subst' the long path to that letter, then use that as the base for GCI.
Only limitation is that the $_.fullname and other properties will report the drive letter as the root path.
Seems to work ok:
$location = \\path\to\long\
$driveLetter = ls function:[d-z]: -n | ?{ !(test-path $_) } | random

subst $driveLetter $location
sleep 1
Push-Location $driveLetter -ErrorAction SilentlyContinue
Get-ChildItem -Recurse

subst $driveLetter /D

That command is obviously not to delete files but can be substituted.
Answer: PowerShell can easily be used with AlphaFS.dll to do actual file I/O stuff
without the PATH TOO LONG hassle.
For example:
Import-Module <path-to-AlphaFS.dll>

[Alphaleonis.Win32.Filesystem.Directory]::Delete($path, $True)

Please see at Codeplex: https://alphafs.codeplex.com/ for this .NET project.
Answer: I had the same issue while trying to delete folders on a remote machine.
Nothing helped but... I found one trick :
# 1:let's create an empty folder
md ".\Empty" -erroraction silentlycontinue

# 2: let's MIR to the folder to delete : this will empty the folder completely.
robocopy ".\Empty" $foldertodelete /MIR /LOG+:$logname

# 3: let's delete the empty folder now:
remove-item $foldertodelete -force

# 4: we can delete now the empty folder
remove-item ".\Empty" -force

Works like a charm on local or remote folders (using UNC path)
Answer: Adding to Daniel Lee's solution,
When the $myDir has spaces in the middle it gives FILE NOT FOUND errors considering set of files splitted from space. To overcome this use quotations around the variable and put powershell escape character to skip the quatations.

PS>cmd.exe /C "rmdir /s /q <grave-accent>"$myDir<grave-accent>""
Please substitute the proper grave-accent character instead of <grave-accent>
 SO plays with me and I can't add it :). Hope some one will update it for others to understand easily
Answer: Just for completeness, I have come across this a few more times and have used a combination of both 'subst' and 'New-PSDrive' to work around it in various situations.
Not exactly a solution, but if anyone is looking for alternatives this might help.
Subst seems very sensitive to which type of program you are using to access the files, sometimes it works and sometimes it doesn't, seems to be the same with New-PSDrive.
Answer: Any thing developed using .NET out of the box will fail with paths too long. You will have to move them to 8.3 names, PInVoke (Win32) calls, or use robocopy


what is difference between data center manager and data center administrator

Question: can anyone bring out the difference between what is expected from a Data Center Manager and a Data Center Administrator?
Comment: I suspect it depends on who's paying them.  Employers usually get to define roles; sysadmin Q&A sites, not so much.
Comment: This isn't a bad question, but it's not a good question for Server Fault -- Like MadHatter said the title applied to a given role varies pretty widely depending on where you work. [Brent's answer](http://serverfault.com/a/465890/32986) covers the general division though - In a place that has both titles one is usually "management" and the other is a grunt that actually does the work.
Comment: To add to @voretaq7 you may have better luck with posting this question on [Workplace.SE](http://workplace.stackexchange.com/faq), but check their FAQ first to make sure it is acceptable.
Answer: Titles vary by every place you might work...
Regardless, the DC Manager is probably responsible for the entire data center, has multiple supervisors and others below them.  May only be responsible for certain aspects of the DC such as only cabinets and servers, or could actually be responsible for the entire facility, much like a General Manager type of position.  Again this all varies.
The DC administrator is someone who would report to one of the aforementioned supervisors or managers.  This person is often responsible for actually making changes to things, monitoring devices and deploying new stuff.
Again, this all varies across the board but should give you a good separation of responsibilities from a general view point.


Drupal 8 YAML Form Module: How do I change the value of a Hidden element?

Question: A few days ago I asked a question about Drupal 8 YAML Form Module: Populate Select Element. I found a solution that it works fine for me.
But now I've got a new doubt. I would like to change the value of a Hidden element and depending of this value, to show some elements in the form or not. I'm trying to implement the hook hook_yamlform_element_info_alter(array &$elements) and I do $elements['hidden_element_name']['#value'] = 'New value of the hidden element' but it doesn't work.
Any ideas? Thanks in advance!
Answer: Here is the solution: How do I change the value of a Hidden element?
Basically, I've implemented hook_form_FORM_ID_alter() and I do:
$form['elements']['hidden_element_name']['#value'] = 'New value of the hidden element';

I hope it helps someone!


How can I give permissions to a user to be able to use the "Performance" monitor in W2003?

Question: I have a user that needs to be able to access the Performance counters tool in one of my servers, but I can't make him an admin.
Is there a way to grant him this permission?
Thanks!
Daniel
Answer: Sure, add him to the Performance Monitors users group on that machine.  Use the computer management snap in, navigate to local users and groups, groups, and add him there.


Estrutura GRID - Alinhamento

Question: Não entendo pq não consigo alinhar eles ao centro (eu não coloquei nenhum valor dentro de main), se puderem me explicar este conceito, ainda está confuso na minha cabeça.
meu css está assim:
main .container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    max-width: 800px;
    justify-content: center;
}

main .bikeimg > img {
    width: 100%;
}

meu html está assim:

Bicicletas Feitas a Mão

A Nimbus Stark é a melhor Bikecraft já criada pela nossa equipe. Ela vem equipada com os melhores acessórios da marca.

                Ver Mais

Vantagens Bikcraft

Motor Elétrico

Permite você viajar distâncias inimagináveis com sua bike.

40 km/h

A mais rápida bicicleta elétrica disponível hoje no mercado.

Rastreador

Rastreador e sistema anti-furto para garantir o seu sossego.

Preciso deixar a grid alinhada ao centro.
Comment: Os itens estão alinhados no `container`, mas o `container` não  está alinhado na tag `main`. O `container` começa na esquerda da tag `main` e aumenta até os `800px` que você especificou. Para o `container` ficar centralizado você tem que especificar isso na tag `main` (ou só dê um `margin: auto` no seu `container` [Veja](https://pt.stackoverflow.com/questions/206514/qual-a-diferen%C3%A7a-entre-margin-0-auto-e-margin-auto))
Comment: Entendi, Valeuzão!
Answer: certifique-se de max-width não está intervindo em justify-content. Sugiro postar o código das duas classes e o uma printscreen do resultado final para ajudar na solução.
tente adicionar align-items: center; ao container.
Comment: Sua resposta pode ser melhorada adicionando informações fundamentais. Basta [edit] para adicionar mais detalhes, como citações ou documentação para que outras pessoas possam confirmar que sua resposta está correta. Você pode encontrar mais informações sobre como escrever boas respostas [na Central de Ajuda](/help/how-to-answer).

Estrutura GRID - Alinhamento


Linux server with Samba 4 as DC, filserver and netatalk (AFP for OS X)

Question: I have an Ubuntu 12.04 server with samba 4.0.6 and netatalk 3.0.4. Samba is DC and fileserver. All with ACL and ext4 with acl filesystem. I managed to get the ubuntu server to join the domain with centrifydc trough changing the hostname in /etc/hostname
Seems like ACL is complicated in an mixed environment. I have therefore not got it to work as it should (OS X with AFP don't read ACL as windows and don't get write permissions to files and folders).
I guess the easiest solution would be to just skip ACL and use unix filegroups. But how do I do that on samba 4?
I have removed acl (from linux terminal) and got AFP connections to work as I will, but then I dont' get access with smb (seems like samba 4 just recognizes ACL?).
Answer: You could try whether "map acls = mode" in afp.conf helps with AFP permissions when dealing with ACLS.
Comment: Did this. Also I will mention that the ugly "hack" to get join AD with Centirfy DC broke after some days. I'm now using winbind 4 (http://serverfault.com/questions/527332/ubuntu-12-04-samba-4-and-winbind), and it seems like it is all working now.
Comment: Thanks! Not found time to try it yet, but I will. Unfortunately limited functionality of winbind 4 keeps us from using AFP on same server as samba 4.
Answer: Use Samba3 for the file server and use Samba4 only as an AD DC?
Comment: On same server? I've found out that winbind 4 has limited functionality, so probably the best solution would have been to have 2 servers. In this case we probably will be stuck with smb until winbind 4 gets better.
Comment: I think having 2 servers may make life a little easier for you.


Combine two views on one page

Question: I have 2 custom views(block types) 'view_A' and 'view_B', one shows content the other shows orders. I need to cobmine them in a single page displaying in 2 different tables. Really dosen't make sense to bundle events and orders in one table.
I tried creating a page, but I can't select 'block' for the context type. I can only select nodes. What's the best way using the UI in Drupal 7 to do this?
Answer: A simpler way can be:
Current Setup:

View A (show content)
View B (show orders)

Steps:

Create a new "page display" of the View A and set the path and menu if you have to.

2 a. Then on the view header or footer (depending if you want the View B before or after View A) add a global view area that will show the View B when viewing View A page.

2 b. Select from your existing views the View B

2 c. Apply the change to the current display and you are done.
Comment: When I check off "Global view area" and hit Apply, I get "Changes cannot be made to a locked view."  What is this and how can I get around it?
Comment: That message indicate that the view is lock by other user or session in the edit mode. This usually have a message in top saying to "break" the lock.
Answer: You could just make a blank page with a custom path (i.e. /my-empty-page) and no content.
Then in the structure>blocks menu assign the blocks to the content region and set them to only show up on the URL for the page you just made?
Answer: You can use the Views Field View as well. So you create 2 separate views and then decide which one do you want to place in which region i.e header or footer and based on that add the  Global: View (Views field view) from the global section.
The only difference which I know from the above method is this module allows you to pass arguments as well from the parent view and has token integration as well.
Comment: Could we apply this method with this question?
http://drupal.stackexchange.com/questions/79096/need-you-advice-how-to-build-this-website-has-the-same-views

Combine two views on one page


Factorise the number $5^{2015} - 1$ into three positive factors such that each is greater than $5^{200}$

Question: Factorise the number $5^{2015} - 1$ into three positive factors such that each is greater than $5^{200}$
I don't really know how to do this. Is inequality involved?
Bonus question: can the same be done for $5^{2017} - 1$
Comment: I could post a variant of [this](http://math.stackexchange.com/a/1865896/11619), but that would make this a duplicate :-). 2015 has a friendlier factorization than 1985, so it seems to me (see lhf's answer) that cyclotomic tricks will suffice. OTOH, if you want three factors $>5^{400}$, then Aurifeuillian is the way to go. And, no, I don't see a way to use Aurifeuillian factors with $5^{2017}-1$.
Answer: Look at the factorization of $x^{2015}-1$ into cyclotomic polynomials:
$$
x^{2015}-1 = \Phi_{1} \Phi_{5} \Phi_{13} \Phi_{31} \Phi_{65} \Phi_{155} \Phi_{403} \Phi_{2015}
$$
and write
$$
5^{2015} - 1 = ABC
$$
with
$$
A=(\Phi_{1} \Phi_{5} \Phi_{13} \Phi_{31} \Phi_{65} \Phi_{155})(5),
\quad
B=\Phi_{403}(5),
\quad
C=\Phi_{2015}(5)
$$
You still need to check that $A,B,C > 5^{200}$. The degrees of the polynomials are $215,  360, 1440$, which is a good indication (but not proof) that this is true.
You cannot do this trick for $2017$ because $2017$ is prime and
$$
x^{2017}-1 = \Phi_{1} \Phi_{2017}
$$
(but of course this does not mean that $5^{2017}-1$ cannot be factored)
Comment: See also http://math.stackexchange.com/questions/2221051/growth-of-cyclotomic-polynomials.


Data analysis mess! Huge data set, 2 factors with 2 levels each, but the levels are the same

Question: To explain the hypothess a little bit: The factors would be emotional words and neutral words; the levels of both factors are left and right visual hemifields. The data is the participants response time in milliseconds. I can explain our hypothesis: We predict a decrease in reaction time for the emotional words as compared to the neutral words; I guess we are expecting a decrease in response time when the stimuli is presented in the right visual hemifield... thats why each factor has the same levels (left/right visual hemifield)
I guess my main problem is that I don't understand how to identify the rows as the response variable... how can I make this dataset easier to run a statistical test on? I originally thought I would have to do ANOVA, but I realize that since each participant was assessed multiple times (with different words displayed on different sides of screen during lexical decision study) my data isn't independent so ANOVA would not be the appropriate test? I'm just not sure, I've tried entering it so many times in both excel and SPSS, I've even tried creating regression models in R... I'm not entirely sure they make sense though. I just need ANY KIND OF help or suggestions on what's the most sensible thing to do with this messy, long dataset.
The data: https://docs.google.com/spreadsheets/d/1czrXmJuxvwalDwNDLHIvt64QqNb8cSTahEEK8DIiQPM/edit?usp=sharing
There's multiple "sheets", because I tried too many times entering it in different ways for it to make sense. The second sheet is what I've mainly been working with.. It's the same dataset, I just tried to clean it up.. please help!!
Comment: Welcome to CrossValidated. Please avoid sensationalizing titles; instead ask a specific question. You can edit your question to improve the title.
Answer: The most straightforward way to organize data like these is to have 1 row per observation. Each row would then have data in columns for: the response time, the neutral/emotional category, the right/left category, and an ID for the individual tested. That data format then fits quite nicely into standard statistical software programs. You just let the software know which column contains the response values and which columns contain the corresponding predictor-variable values, based on the syntax expected by the software.
You are correct that you should take into account the multiple tests performed on the same individual. One way to do this is to treat the individuals as random effects, in which the variability among the individuals in response times is modeled. The best way to proceed then depends on how you expect the individuals to differ in terms of response times.
For example, if you think that individuals will differ in terms of baseline response times (some are just faster than others) but that right/left and neutral/emotional differences around those baseline times will be the same, then you could include a random-effect term for the intercept in your model. If you think that individuals might have a wide distribution with respect to right/left or neutral/emotional differences in response times, you could also include random-effect terms for the coefficients of those predictor variables, too. This page shows how to specify these types of random effects for one popular package in R.
This sounds like the type of project that is being done at an academic institution. If so, it would be wise to consult with local statistics experts, who might better be able to identify particular issues and approaches related to your study and its data than we can remotely on this site.


php: How to add generically values to a multidimensional array without incrementing the count

Question: I have this...
$routes = array();
loop starts...
    $routes[]['location1'] = MyValue1
    $routes[]['location2'] = MyValue2
    $routes[]['distance'] =  MyValue3
...loop ends

What I want is this...
Array
(
    [0] => Array
        (
            [location1] => MyValue1
            [location2] => MyValue2
            [distance] => MyValue3
        )

    [1] => Array
        (
            [location1] => MyValue1
            [location2] => MyValue2
            [distance] => MyValue3
        )
}

But what I get is this...
Array
(
    [0] => Array
        (
            [location1] => MyValue1
        )

    [1] => Array
        (
            [location2] => MyValue2
        )

    [2] => Array
        (
            [distance] => MyValue3
        )

    [3] => Array
        (
            [location1] => MyValue1
        )

    [4] => Array
        (
            [location2] => MyValue2
        )

    [5] => Array
        (
            [distance] => MyValue3
        )
}

What is the correct syntax to use? Or do I need to add some kind of counter to count the iterations through the loop using something like $routes[$a]['distance'] etc.?
Answer: The simplest way is to build your sub-array, then add it in a single assignment:
$routes = array();
loop starts...
    $routes[] = array (
        'location1' => MyValue1,
        'location2' => MyValue2,
        'distance' =>  MyValue3
    );
...loop ends

Every time you do anything with $routes[], you add an element to $routes. So, you must either do the above or keep track of the index you are working with.
Comment: I was just testing it... gimme a second! :)
Answer: This can work too:
$routes=Array(
"0"=>Array
(
        'location1' => 'MyValue1',
        'location2' => 'MyValue2',
        'distance' => 'MyValue3'
),
"1"=>Array
    (
        'location1' => 'MyValue1',
        'location2' => 'MyValue2',
        'distance' => 'MyValue3'
    )
);

Comment: Very true - the problem with this solution, however, is that I don't know how many iterations the loop will go through. I was hoping to avoid adding a messy loop counter and I knew there would be a simple, generic `$arr[] = value` type answer.


How to implement Kafka DLQ in asp.net

Question: How can I create kafka DLQ for consumer using asp.net core
<code>            var kafkaConfig = new ConsumerConfig
            {
                GroupId = _configuration["ConsumerGroup"],
                BootstrapServers = _configuration["KafkaServer"]
            };

            using (var consumer = new ConsumerBuilder<int, string>(kafkaConfig).Build())
            {
                consumer.Subscribe(_configuration["Topic"]);

                try
                {
                    while (!stoppingToken.IsCancellationRequested)
                    {
                        try
                        {
                            var consumeResult = consumer.Consume(stoppingToken);
                            Console.WriteLine($"Consumed message '{consumeResult.Value}' at: '{consumeResult.TopicPartitionOffset}'.");

                            if (!TryConsume(consumeResult, stoppingToken))
                            {
                                await _retryQueueProducer.RetryAsync(consumeResult);
                            }
                        }
                        catch (ConsumeException e)
                        {
                            Console.WriteLine($"Error occured: {e.Error.Reason}");
                        }
                    }
                }
                finally
                {
                    // Ensure the consumer leaves the group cleanly and final offsets are committed.
                    consumer.Close();
                }
            }
</code>
above one is sample code
How to show the failed messages values in DLQ
Comment: Please clarify what is `_retryQueueProducer`
Answer: You know how to use a Producer, and you know how to write a try catch.
That's all you need. Catch exception from a consumed record, and then use a producer to send to a new topic, you now have a DLQ.
Write a new consumer to subscribe to the DLQ.
You should create the actual topic outside of your code.
Comment: Can you please give me some code sample?
Comment: You already have sample code in your question. I don't know what `_retryQueueProducer` is, but seems like it's sending data to another topic when your consumer fails
Comment: ok thank you one more question I have. Do I need to create separate topic name to save DLQ messages(along with the producer topic and consumer topic)
Comment: A DLQ is a completely separate topic, yes. Technically, DLT (dead letter topic)

How to implement Kafka DLQ in asp.net


How to condense an SATB choir section with mixed dynamics, voices & hairpins

Question: The score I'm working on has a four-part SATB choir, thus:

For space-conservation reasons I usually condense my choir parts down to a SA/TB grand staff. But this choir section has different dynamics and hairpins and voices starting at different times, so I'm not sure how best to condense it into two staves, if that's even possible. Obviously the T/B would take the bass staff and the A would be on the treble staff, but how would I notate the soprano's dynamics & hairpins in a way that doesn't conflict with the alto's?
Any advice, especially from someone with arranging/engraving experience, would be appreciated.

Here is my current attempt at condensing the staves, complete with all necessary text (lyrics, div. instructions, etc.) – apologies for the small size, it's the best I could do given the layout:
Answer: One way is to place any expression markings relative to that voice's placement on the staff. In other words, markings relating to the soprano and tenor lines should go above their respective staves, since they are the higher voices. Meanwhile, markings for the alto and bass should go below their respective staves.
For example (with apologies for any incorrect pitches and/or markings due to looking at an incomplete score):

With complex scores the notation can get pretty dense, but this seems relatively common in my experience as an analyst and engraver.
Comment: @Walter Yes, your new examples look great!
Comment: @Walter be careful of the alto *divisi.*  Because the noteheads have no stems, you probably have to add some text like *alti divisi* or a square bracket to the first divided notes, or both.  I see you have that in your first example. It's probably not necessary to label the soprano entrance, but it doesn't hurt unless it causes crowding. The labels on the men's entrance seem redundant to me; there's no ambiguity without them.
Comment: Thanks for the reply and the example! Yours doesn't look too dissimilar from my first attempt. I've edited it and updated the OP with it; would you mind taking a look and letting me know what you think of it?
Comment: @phoog Great point; I didn't see that there wasn't a rest for the soprano line!
Comment: @phoog I thought of adding a square bracket, but I figured that since the "alto div." is clearly labeled and the soprano starts later, it wouldn't be ambiguous enough to need it. I'll try adding it then (soon as I figure out how to do that in Sibelius, heh).
Comment: @Walter with the rest above, and the *alto div.* label, the bracket is probably superfluous.  The "soprano" label does seem to help eliminate ambiguity, though after the "unison" instruction for the alto it may also be unnecessary.


Set the number of threads created by JVM when initializing it through JNI

Question: Is there a way to set a limit for the number of threads created by JVM when starting it through JNI?
I would like to set a maximum limit for the number of threads created if it is possible.
Comment: What JVM thread pool?
Comment: Why? How do you know how many threads the JVM needs to work correctly?
Comment: @EJP I edited the question
Answer:
Is there a way to set the size of the JVM thread pool ...

A JVM doesn't have a thread pool.

Is there a way to set a limit for the number of threads created by JVM when starting it through JNI?

No.
If you want to restrict the number of threads created, you could possibly implement this using a custom SecurityManager.   For example: https://stackoverflow.com/a/17536809/139985
Or possibly at the OS level using UNIX ulimit -T or similar.
But if you can trust the Java code that you are running in the "child" JVM, it is better to get it (i.e. the developer) to use a Java SE library (e.g. an ExecutorService with a bounded thread-pool) or a third party thread-pool implementation.
Answer: JVM doesn't have thread pool, the threads are created and managed by the code - the VM could only kill them on exit. Clearly such restricted app will not work if you don't give it all threads that it needs. How would you choose which thread is critical for the application and which is not? It doesn't make sense.
You can set resources that a particular process can use on the OS level, but it is rather for stopping some ill performing process from killing your system.
As @StephenC said there is a way to block the creation of new Threads in a JVM using custom SecurityManager - this could be handy in some scenarios - eg. if you have some application that runs untrusted code from clients - you can restrict the clients to not create new threads.
Comment: Thanks for the explanation. I am coming from a C++ background and that's why the confusion.


Are light peer review requests allowed here?

Question: I ask this because I frequently find myself flat out of luck googling for an elegant solution and end up rolling my own extensions to accomplish whatever tasks that Magento can't accommodate out of the box.
It's very possible that some of the things I make aren't considered "best practice" and better solutions do exist somewhere out there.  The reviews that I'm speaking of wouldn't necessarily be code reviews, but rather concept reviews.  I think that such topics would be general enough to benefit a lot of folks that encounter the same problems.
As a concrete example:

Target Version:

Magento 1.7.02 Community Edition

Problem Synopsis:

Adding a block class that doesn't descend from Mage_Page_Block_Template_Links_Block to a Mage_Page_Block_Template_Links block may result in non-compliant HTML generation unless the block class wraps its own output in <li> tags.

Additional Info:

I encountered this yesterday when adding a search bar in a link list.

Proposed Solution

I resolved this by providing my own MyCompany_Page_Block_Template_Links template in the theme that I am building that handles the case of block classes that are not of type Mage_Page_Block_Template_Links_Block.

Related Code

< code here >

Question

Is there a better way to accomplish this?

Determining whether a question is "recommend opinion based X" versus "recommend industry accepted best practice" should be quite distinct in these cases.
Thoughts?
Answer: I depends on how you ask the questions.
if your question starts with "what's the best way to..." then it might be opinion based since in a lot of cases there is no best way or there are multiple ways that are equally valid to do a thing.
If your question looks like "I have to do.... I tried it to do like this....it seams to work, but it doesn't look clean to me. Are there alternatives?" it may be a valid question.
SE encourages you to post what you tried so far so other people can reproduce your issue.
Answer: If you just search for feedback, the magento reddit is always a good place.


Multi-language search matching

Question: Suppose we have the name written in any none-latin letters - languages, like Arabic, Hebrew, Chinese, Japanese etc.
How could a search engine match between the original name and the English spelling of the same name. and vice versa?
Something like the name 拓海 in Japanese and the English spelling Takumi.
what is the algorithm/technique used to do this ?
Comment: Won't the search engine just [translate it](http://translate.google.com/#auto|en|%E6%8B%93%E6%B5%B7) and then search for both keywords. I am not sure I understand what your asking.
Comment: See [this](http://stackoverflow.com/questions/4203299/sorting-multi-locale-strings-in-java) post. There is something about multi-language sorting
Comment: That's why i said "name" not "word". the same pronouncing written in different languages.... and cannot be translated !
Comment: But if you click my link it seems that translating the name is not an issue. Google Translate can translate the name.
Comment: mmm,so do you think, they just convert the name into the equivalent pronounced characters in the other language ?
Answer: good day.
you have to do following:
classificate each lang in the world on the same symbols:
all langs:

Engish [26 letters] a b c d e f g ...
Russian [33 letters] a б в  г д е ....
Chinese [x letters]  ....
Ukrainian [x letters] a б в г д ..... i
Japanese [x letters] ...
.................

finally you will be have rules between any symbols spelling in any langs.
Some langs, for instance, Hindi, Chinese and etc not will be have any rules. you should be create your own rules(based on transcription of this langs).
algo:
[w][e][п] = wep
e  e  r
e - eng
r - rus
transcription[п] = p
Answer: Search engines (like Google) probably has huge amount of data sets (corpus), each corpus in different languages.
When you want to translate a word in one language to other language, it can be done by searching the word in the corpus in the first language, and return the compatible word in the corpus of the second language. (same technique for names)
That's the basic idea.
You better read about the NLP field here for some background:
http://en.wikipedia.org/wiki/Natural_language_processing

Multi-language search matching


Finding the next term in a sequence.

Question: So this came up in a math competition some of students participated in over the weekend.  Expected highest level of mathematics is calculus 1.
Let $a_n$ be an arithmetic sequence, $b_n$ be a geometric sequence and suppose that $c_n=a_n-b_n$.  The first four terms of $c_n$ are $2, 8, 6, 20$.  Find $c_5$.
My students had two minutes and no calculator to answer this... I've played with this a bit and think that partial sums is probably the direction to go if this is going to be a 2 minute problem but I'm stuck!  I've gotten to a couple spots that I think are along the right direction but perhaps I'm not thinking about this correctly.  Here's what I know:
$c_5=S_5-S_3-c_4$
So if I could find the partial sum at 5 I've got this... The other idea that I have is that the common ratio of the geometric series is $(-b_2)/(b_1)$ (I believe) but I'm still fairly at a loss as how to get our next term.  Some help would be appreciated!
Comment: Hi Ben - I think I've hit upon the "intended" solution (which took me over two minutes). If we write $a_{n+1} - a_n - (b_{n+1} - b_n) = c_{n+1} - c_n$, then we can rewrite as $d - b_n(r - 1) = c_{n+1} - c_n$. From this we can solve for the geometric progression $b_n$ of ratio $r$, and then the arithmetic progression $a_n$ of difference $d$.
Answer: Let $d$ denote the common difference of the arithmetic sequence and $r$ denote the common ratio of the geometric sequence.  Then:
\begin{align*}
  c_1 &= a_1 - b_1\\
  c_2 &= a_2 - b_2\\
    &= (a_1 + d) - (b_1r)\\
  c_3 &= a_3 - b_3\\
    &= (a_1 + 2d) - (b_1r^2)\\
  c_4 &= a_4 - b_4\\
    &= (a_1 + 3d) - (b_1r^3)
\end{align*}
And you want to find this value:  $c_5 = a_5-b_5 = (a_1+4d) - (b_1r^4)$.
We have this system:
\begin{align*}
  2 &= a_1 - b_1\\
  8 &= a_1 + d - b_1r\\
  6 &= a_1 + 2d - b_1r^2\\
  20 &= a_1 + 3d - b_1r^3
\end{align*}
It's mildly unpleasant but it's four equations with four variables, and there is indeed a unique solution.  Can you take it from here?
Comment: Yeah, we certainly went this way initially and came to this system as well.  Our (the faculty at my school who've been working this) are trying to see if there is an easier way - so that this is solvable in the 2 minute timespan.  Maybe this is it?  Thanks for your response.
Comment: @ArchisWelankar, I don't know.  But I do know that math competitions that take place over weekends aren't supposed to be easy.  By that same token there is likely some sort of trick to make this easier/quicker.
Answer: I don't think my solution can be calculated within two minutes, but it is pretty straightforward and can be calculated fast too. Let $a_i = x+(i-1)\cdot y$. Since $b_i = a_i-c_i$, we have $$b_2^2 = b_1b_3\implies (x+y-8)^2=(x-2)\cdot(x+2y-6)\implies y^2-12y+52=8x$$
$$b_3^2=b_2b_4 \implies (x+2y-6)^2=(x+y-8)(x+3y-20)\implies y^2+20y-124=-16x$$
Multiplying the first equation by $2$ and adding the second equation, $$3y^2-4y-20=0\implies y=-2,x=10\ \ \text{or} \ \ \ y=\frac{10}{3}, x=\frac{26}{9}$$
The first case is not what we are looking for because it gives $b_2=b_3=0$, so the second case must be true.
Hence, we can get $a_5=x+4y=\frac{146}{9}$. Further, $$b_1=a_1-c_1=\frac{8}{9}, b_2 = a_2-c_2 = -\frac{16}{9}\implies b_5 = \frac{128}{9}$$ Thus, $$c_5=a_5-b_5=\frac{18}{9}=2$$
Comment: Can you clarify why $b^2_3=b_2b_4?$ I'm just not seeing it sorry.
Comment: Because $b_2,b_3,b_4$ is a geometric series, $b_3=b_2\cdot z$ and $b_4=b_2\cdot z^2$ for some $z$, hence $b_3^2=b_2b_4=b_2^2z^2$.

Finding the next term in a sequence.


Java DatagramSocket not receiving packets

Question: I have made a simple program to send and receive a packet from a SA:MP server, which contains information about the specified server. This works correctly when I send the packet with a program called "Packet Sender", but my Java program just doesn't want to work. This is the code I am currently using:
<code>        DatagramSocket dataSocket = new DatagramSocket(iPort);
        dataSocket.setSoTimeout(iTimeout);
        byte[] bytepacket = szPacket.getBytes(Charset.forName("UTF-8"));
        byte[] buf = new byte[256];
        DatagramPacket recpacket = new DatagramPacket(buf, buf.length);
        DatagramPacket packet = new DatagramPacket(bytepacket, bytepacket.length, address, iPort);
        packet.setData(bytepacket);
        packet.setAddress(address);
        packet.setPort(iPort);
        dataSocket.connect(address, iPort);
        socketConnected = true;
        System.out.println("Local port: " + dataSocket.getLocalPort());
        System.out.println("Local IP: " + dataSocket.getLocalAddress());
        System.out.println("Remote port: " + dataSocket.getPort());
        System.out.println("Remote IP: " + dataSocket.getInetAddress());
        System.out.println("Recieve Timeout: "+iTimeout+" milliseconds.");
        dataSocket.send(packet);
        System.out.println("Sent packet: "+ packet.getData());
        dataSocket.receive(recpacket);
        String recieved = new String(recpacket.getData(), 0, recpacket.getLength());
        System.out.println("Recieved packet: "+ recieved);
        dataSocket.close();
        dataSocket.disconnect();
</code>
This is my debug:
<code>Packet: SAMPÀßµai
Local port: 7777
Local IP: /192.168.0.103
Remote port: 7777
Remote IP: samp.lawlessrp.com/18.104.22.168
Recieve Timeout: 5000 milliseconds.
Sent packet: [B@76dd3333
java.net.SocketTimeoutException: Receive timed out
at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method)
at java.net.DualStackPlainDatagramSocketImpl.receive0(Unknown Source)
at java.net.AbstractPlainDatagramSocketImpl.receive(Unknown Source)
at java.net.DatagramSocket.receive(Unknown Source)
at lillyramcharan.blacksirrah239.tracker.main.<init>(main.java:199)
at lillyramcharan.blacksirrah239.tracker.launch.init(launch.java:17)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
</code>
In the debug "Packet" is the packet before it is converted into bytes. It is also missing one character due to it being an invalid ascii character (represented as CANCEL).
Here is a screenshot of the program I mentioned earlier, sending and returning the packet:
http://puu.sh/6gRd5.png
EDIT:
I have already tried disabling my firewall/allowing javaw (it is an applet) through my firewall, as well as packets with the port 7777 and 55056.
Any help would be appreciated!
Thanks
Comment: You talk about two different ports, yet your code uses exactly one. What port are you sending to on the server, and what port is the server sending the reply to, exactly?
Comment: SAMP uses port 7777, so that is the port I was sending to/from.
Comment: why you use packet.setData, packet.setAddress methods? data and address and other data already defined in new DatagramPacket(bytepacket, bytepacket.length, address, iPort). Isn't it?
Answer: There is nothing obviously wrong with your code, so you need to do some investigation.
For example, find and install a packet logger and use it to see if the packet is actually being send over the wire and if a reply packet is coming back from the server.

Actually, there is a possible clue in the output messages:
<code>    Local IP: /192.168.0.103
    Remote IP: samp.lawlessrp.com/220.127.116.11
</code>
You have set up your program to listen on the IP address 192.168.0.103.  That is a private IP address.  But you are trying to talk to 18.104.22.168, which is a (notionally) public IP address.  If 184.108.40.206 is not in your organization's network(s), the chances, it won't know how to route packets to your address ... and they will get silently dropped.
Comment: Thanks for the help, I ended up fixing it by changing the charset from UTF-8 to US-ASCII and it worked :-)


Java regex expressions

Question: I'm using Java 1.7 and want to write some code to detect the presence of a string within another string.
The incoming string will either be one of the the below 2 values:
 - "Install build"
 - "Install my build"
I need to check occurence in a string for 2 possible values. I know I can use an if else but I thought a pattern match would be better as there could be future new values also.
My code is:
<code>    String pattern = "(Install)(.*)(build)";
    String option = "Install build"; //see if this matches

    Pattern r = Pattern.compile(pattern);
    Matcher matcher = r.matcher(option);

    if (matcher.find()) {
        System.out.println("Match found");
    } else {
        System.out.println("Match not found");
    }
</code>
Any help would be great.
Comment: @MeRose, Please read a [Guide to Code Review for Stack Overflow users](http://meta.codereview.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users). The code should be working before posting at [Codereview.se]
Comment: Maybe going to http://codereview.stackexchange.com/ ?
Comment: [A good place to test regular expressions](http://www.regexpal.com/)
Comment: @holroy: OP's code is a working one. He just wants to get rid of if-else.
Answer: Regexp is a powerful tool when it comes to deal with String that have an unknown formating (i.e. counting occurences of a certain pattern, or capture unknown subparts of a string, etc).
In your case, using Regexp does not make much sense since you already know every single String possibility.
Answer: This seems to work:
<code>Install(?: my)? build
</code>

Java regex expressions