I am trying to read a text file and create a string. I am using following code:   String FILENAME = "file.txt";  File file = getApplicationContext().getFileStreamPath(FILENAME);   int size = (int) file.length();  System.out.println("size: "+size);  byte[] bytes = new byte[size];   BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));  buf.read(bytes, 0, bytes.length);  buf.close();   System.out.println("buf string: "+new String(bytes));   size in this case is 5295164. in the last line of code, i get following exception:   FATAL EXCEPTION: main  java.lang.OutOfMemoryError      at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)      at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)      at java.lang.StringBuilder.append(StringBuilder.java:216)      at se.egretails.ssapp.MyActivity$4.onClick(MyActivity.java:461)      at android.view.View.performClick(View.java:4084)      at android.view.View$PerformClick.run(View.java:16966)      at android.os.Handler.handleCallback(Handler.java:615)      at android.os.Handler.dispatchMessage(Handler.java:92)      at android.os.Looper.loop(Looper.java:137)      at android.app.ActivityThread.main(ActivityThread.java:4812)      at java.lang.reflect.Method.invokeNative(Native Method)      at java.lang.reflect.Method.invoke(Method.java:511)      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)      at dalvik.system.NativeStart.main(Native Method)   How should i solve this? Thanks in advance.
If you have a java.io.InputStream object, how should you process that object and produce a String?    Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for example I can write that to a log file.  What is the easiest way to take the InputStream and convert it to a String?  public String convertStreamToString(InputStream is) {     // ??? }
Can you take different archetype options at different levels? Once you've picked a subclass option at level 3, could you later take a different subclass option, or do you lock into a specialty at level 3 and then run with it for the rest of that class' progression?  For example, as a rogue, if you took the "Thief" archetype at level 3, giving you access to Fast Hands and Second Story Work, could you then take the "Assassin" archetype to give you the specific benefits that archetype gives instead of the "Thief" ones?  The  seems to imply that you couldn't:     At 3rd level, you choose an archetype that you emulate in the exercise of your rogue abilities: Thief, detailed at the end of the class description, or one from another source. Your archetype choice grants you features at 3rd level and then again at 9th, 13th, and 17th level.   but I'd like a more certain answer, especially one that refers to archetypes in general. Also I'm not ashamed to admit I'd prefer a source with some authority that tells me you can mix and match, but I am looking for the truth of the rules when all is said and done...   Different to  because the no on that demonstrates that you can't re-take a level of the same class. Taking different features for different levels is not the same thing, and would work differently. Similar to  but that one was specific to monks - which is why it didn't show up on any searches I did, and why it wouldn't on the searches of others. This question is specific enough to be clear and precise, but broad enough to be useful to others who aren't in the exact same situation/using the same class. Inspecting standard container (std::map) contents with gdb Supposing to have something like this:  #include &lt;map&gt; int main(){     std::map&lt;int,int&gt; m;     m[1] = 2;     m[2] = 4;     return 0; }   I would like to be able to inspect the contents of the map running the program from gdb. If I try using the subscript operator I get:    (gdb) p m[1] Attempt to take address of value not located in memory.   Using the find method does not yield better results:  (gdb) p m.find(1) Cannot evaluate function -- may be inlined   Is there a way to accomplish this? Terminating with Master's after several years in a PhD program. How to indicate on CV/Resume? I am not happy with my PhD program, and after several years I am graduating with a master's this month. I earned the M.S. along the way as a PhD student, but have never formally requested it before this semester. What is the best way to indicate this situation on a CV or resume? I don't want to put just M.S. because then it looks like it took me a really long time to get a master's and I can't put that I am a PhD student because I no longer am.  Right now, I am thinking something like  M.S. in &lt;field&gt;, &lt;University&gt;, May 2016 PhD student in &lt;field&gt;, &lt;University&gt;, Aug. 2011 - May 2016 B.S. in &lt;field&gt;, &lt;Undergrad University&gt;, Aug. 2007 - May 2011   Would that be clear what's going on? Alternatively, should I list PhD above M.S. even though I didn't complete it? Should I list both M.S. and PhD in same line since it is the same university and span of time? Answers no longer sorted by score/votes Can you retrain the Magic Initiate spell using the Spellcasting feature? got me thinking about the mechanics of the Magic Initiate feat when you have class levels in the class into which you were inducted.    Among the classes you can pick with this feat are the Bard, Sorcerer, and Warlock, which know a limited number of spells and all have the same statement under Spells Known.     Additionally, when you gain a level in this class, you can choose one of the [class] spells you know and replace it with another spell from the [class] spell list , which must also be of a level for which you have spell slots.   The term "learning" is used both to describe new spells acquired on level-up and the spell acquired through the feat. This would seem to indicate your Magic Initiate spell counts among the spells you know, and is thus eligible for retraining if you learned it as a spell of your class.  An odd change in wording occurs during the Magic Initiate feat description (emphasis mine):     In addition, choose one 1st-level spell from the same list. You learn that spell and can cast it at its lowest level.   This generalization in describing the learned spell's level seems to imply that there exists a scenario where it would not be appropriate to restrict the spell to being cast as a 1st-level spell.  Could one of the charisma casters retrain Magic Initiate into a higher level spell, which they could then cast once per long rest without using a slot?  This would turn an otherwise unexciting feat into, effectively, a Mystic Arcanum for Bards and Sorcerers. This seems too powerful to be intentional,  but the feat description appears to have gone out of its way to permit it. Topology: Proof that a finitely generated cone is closed Crick’s Central Dogma — Counter Cases where instance variables get initialized Is there a way to see questions with a certain tag from all Stack Exchange sites? For example, I see there are questions with the  tag on Stack Overflow, but there are also such questions on Super User, Unix/Linux, and other sites in the network.  Is there a way to follow a tag across all of the Stack Exchange sites, so that one can see the global activity of a topic without visiting all the sites separately? I want to monitor the output of a command and whenever it contains a certain string I want to run another command.  Example: when command1 outputs 1234 I want to run command2 Passing HTML to template using Flask/Jinja2 Dual Booting win 10 and Ubuntu 18.04 on two separate physical ssds I have gotten as far as to create the bootable usb, booting into that bootable usb and getting to the install options however i quit because I had some concerns.  I currently have a Samsung 850 evo 1tb that has win 10ninstalled. I want to dual boot with Ubuntu 18.04 by installing it on a brand new unformatted uninitialized Samsung 860bevo 250gb. Should i format the brand new ssd as a new volume in win 10 and then proceed with the Ubuntu install on this volume. What else should i do? Im a first time Ubuntu user and installer.  Any and all help is appreciated. If $A$ and $B$ are square matrices such that $AB = I$, where $I$ is the identity matrix, show that $BA = I$.    I do not understand anything more than the following.   Elementary row operations. Linear dependence. Row reduced forms and their relations with the original matrix.   If the entries of the matrix are not from a mathematical structure which supports commutativity, what can we say about this problem?  P.S.: Please avoid using the transpose and/or inverse of a matrix. Hide files from root in ubuntu I have a finite field $\mathbb{F}_{27}$. I need to find an element of order 13. I know that multiplicative group of this field is cyclic with order 26. So I want to find a generator $g$ of this cyclic group, then $g^2$ will have order 13. Also I know that all elements of this field can be represented by polynomials from $\mathbb{F}_3[t]$, where t is root of irreducible polynom $x^3-x-1$.  Probably we can find generator of $\mathbb{Z}_{26}$ and than build an isomorphism to $\mathbb{F}_{27}\setminus 0$.  Anyway I don't know were to start.  Thanks! Why are hexadecimal numbers prefixed with 0x? Goal: I have a function $f(x,y)=z$ (two variables for illustration only) which I know almost nothing about--it has a compact domain which I can determine, it is non-negative, and bounded above.  My goal is to find the maximum value $f(x,y)$ takes on its domain.  I can query the function and I know the values at a few points: $f(x_1, y_1)=z_1, f(x_2, y_2)=z_2,..., f(x_n, y_n)=z_n$.  Optimization via Linear Regression:  I have used linear regression (and related methods like the lasso) to model functions like this in the past; this is the method that I am very comfortable with.  Typically, I might try to find a polynomial (of degree $k$) which relatively accurately models the data. The end result would be to say that:   $$f(x,y)\approx \beta_1 + \beta_2 x + \beta_3 y + \beta_4 x^2 + \beta_5 xy + \beta_6 y^2 + ... + \beta_{m}y^{k}.$$  Determining the coefficients is done by solving the .  The "best degree" for the polynomial might be determined using $k$-fold cross validation.  Once the "best" polynomial has been determined, one can choose any of a number of methods to optimize it (Newton's method, gradient descent, hill climbing, etc).  Then, if all goes well, the optimal value on the polynomial corresponds to an optimal value of $f(x,y)$.  Bayesian Optimization:  Recently, I was describing this technique (linear regression) to a colleague who asked: "What is the difference between that and Bayesian Optimization?"  I've been attempting to answer this question for the last couple days, and so far I don't have anything really conclusive.  After reading , trying to read  and getting stuck reading  I think I understand the following about BO:   Start with a prior (a guess as to what family of functions the black box belongs to... or at least some family of functions which you believe might be able to describe $f$ well).  It looks using a  as a prior is popular. Specify whatever is needed to build your prior (for GP this is a covariance function). As you go along, you maintain two evolving functions, a "mean" function $m(x,y)$ and a "confidence interval" function $c(x,y)$.  Basically, you can predict the value at any point by evaluating $m(x,y)$ and you are confident that $f(x,y)\in [m(x,y)-c(x,y), m(x,y)+c(x,y)]$. Bayesian optimization provides a systematic way of updating/exploiting the model by alternatively selecting points where the confidence interval is wide (you are very uncertain about the value) or at optimal points on the model $m(x,y)$.   My Question: Is it fair/correct to say that the major difference between Bayesian Optimization and simply optimizing the linear regression model is that Bayesian Optimization provides the systematic way of sampling with the goal of optimizing the model and reducing uncertainty whereas the linear regression model ignores the idea of uncertainty and doesn't explicitly provide a means of updating the model?  Said another way, is the linear regression model an example of what might be a "mean" function $m(x,y)$ in Bayesian Optimization?  If I stick with linear regression, specify how to compute the uncertainty, and provide a means of updating/improving the model (exploit/explore) am I just doing Bayesian Optimization (without calling it that)?  Background: My background is in pure mathematics (graph theory) but my new job has me working with a lot of data (so I'm self learning statistics).  With that in mind, my statistics vocabulary is somewhat limited (so I appreciate answers that either avoid technical terminology or briefly explain any technical terminology used)--for example, Monday was the first time I heard/read the word "prior" used in a stats sense and I'm still not 100% sure I understand that correctly. Divergence of $\frac{ \hat {\bf r}}{r^2} \equiv \frac{{\bf r}}{r^3}$, what is the 'paradox'? I just started in Griffith's Introduction to electrodynamics and I stumbled upon the divergence of $\frac{ \hat r}{r^2} \equiv \frac{{\bf r}}{r^3}$, now from the book, Griffiths says:  Now what is the paradox, exactly? Ignoring any physical intuition behind this (point charge at the origin) how are we supposed to believe that the source of $\vec v$ is concentrated at the origin mathematically? Or are we forced to believe that because there was a contradiction with the divergence theorem? Also how would the situation differ if $\vec v$ was the same vector function but not for a point charge? Or is it impossible? Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc PHP Session data not being saved I have one of those "I swear I didn't touch the server" situations. I honestly didn't touch any of the php scripts. The problem I am having is that php data is not being saved across different pages or page refreshes. I know a new session is being created correctly because I can set a session variable (e.g. $_SESSION['foo'] = "foo" and print it back out on the same page just fine. But when I try to use that same variable on another page it is not set! Is there any php functions or information I can use on my hosts server to see what is going on?  Here is an example script that does not work on my hosts' server as of right now:  &lt;?php session_start(); if(isset($_SESSION['views']))     $_SESSION['views'] = $_SESSION['views']+ 1; else     $_SESSION['views'] = 1;  echo "views = ". $_SESSION['views']; echo '&lt;p&gt;&lt;a href="page1.php"&gt;Refresh&lt;/a&gt;&lt;/p&gt;'; ?&gt;   The 'views' variable never gets incremented after doing a page refresh. I'm thinking this is a  problem on their side, but I wanted to make sure I'm not a complete idiot first.  Here is the phpinfo() for my hosts' server (PHP Version 4.4.7):