I require a data structure that has a capacity, but also that allows adding an item from either the front or the back. Each time an item is added, one item must be removed from the opposite end. My first thought was that this sound very similar to a Deque.   Is there an existing data structure that provides this functionality, or do I have to create it myself? If it does exist, does the .Net library have an implementation?  Thanks
I have a Queue&lt;T&gt; object that I have initialised to a capacity of 2, but obviously that is just the capacity and it keeps expanding as I add items.  Is there already an object that automatically dequeues an item when the limit is reached, or is the best solution to create my own inherited class?
What is the preferred way to remove spaces from a string in C++? I could loop through all the characters and build a new string, but is there a better way? How can I download an APK file from the Play Store? I can't download apps from the Play Store on my Android device (maybe due to a network issue), so I'm wondering how could I download the APK file of an app on my PC from ? is piped ls the same as ls -1? ls returns output in several columns, whereas ls|cat returns byte-identical output with ls -1 for directories I've tried. Still I see ls -1 piped in answers, like ls -1|wc -l. Is there ever a reason to prefer ls -1? Why does ...|cat change the output of ls? Prove that lim $(\sqrt{n^2+n}-n) = \frac{1}{2}$ Here's the question: Prove that $\lim_{n \to \infty} (\sqrt{n^2+n}-n) = \frac{1}{2}.$  Here's my attempt at a solution, but for some reason, the $N$ that I arrive at is incorrect (I ran a computer program to test my solution against some test cases, and it spits out an error). Can anyone spot the error for me?  $\left|\sqrt{n^2+n}-n-\frac{1}{2}\right| &lt; \epsilon$  $\Rightarrow \left|\frac{n}{\sqrt{n^2+n}+n} - \frac{1}{2}\right| &lt; \epsilon$  $\Rightarrow \frac{1}{2}-\frac{1}{\sqrt{1+\frac{1}{n}}+1} &lt; \epsilon$  $\Rightarrow \frac{1}{\sqrt{1+\frac{1}{n}}+1} &gt; \frac{1}{2} - \epsilon = \frac{1-2 \epsilon}{2}$  $\Rightarrow \frac{1}{\sqrt{1+\frac{1}{n}}} &gt; \frac{1-2 \epsilon}{2}$  $\Rightarrow \frac{1}{\sqrt{\frac{1}{n}}} &gt; \frac{1-2 \epsilon}{2}$  $\Rightarrow \sqrt{n} &gt; \frac{1-2 \epsilon}{2}$  $\Rightarrow n &gt; \frac{4 {\epsilon}^2-4 \epsilon +1}{4}$ Will Stack Exchange 2.0 websites stay free of ads for the next 2 years? Explanation of method for showing that $\frac{0}{0}$ is undefined (This was asked due to the comments and downvotes on this  answer. I am not that good at maths, so was wondering if I had made any basic mistakes)  Ignoring limits, I would like to know if this is a valid explanation for why $\frac00$ is undefined:     $x = \frac00$    $x \cdot 0 = 0$        Hence There are an infinite number of values for $x$ as anything multiplied by $0$ is $0$.   However, it seems to have got comments, with two general themes.  Once is that you lose the values of $x$ by multiplying by $0$.  The other is that the last line is:      $x \cdot 0 = \frac00 \cdot 0$   as it involves a division by $0$.  Is there any merit to either argument? More to the point, are there any major flaws in my explanation and is there a better way of showing why $\frac00$ is undefined? If shuffle-playing playlist &times;100 resulted in [10 13 10  3  2  2] different songs being repeated [1 2 3 4 5 6] times, what is the estimate for the total number of songs? (assuming shuffle play was completely random)  Update: (R code)  k &lt;- 50 # k number of songs on the disk indexed 1:k n &lt;- 100 # n number of random song selections m &lt;- 20 # m number of repeat experiments colnum &lt;- 10 mat &lt;- matrix(data=NA,nrow=m,ncol=colnum) df &lt;- as.data.frame(mat) for(i in 1:m){   played &lt;- 1+floor(k*runif(n)) # actual song indices (1:k) selected    freq &lt;- sapply(1:k,function(x){sum(played==x)})   # = number of times song with index x is being played   histo &lt;- sapply(1:colnum,function(x){sum(freq==x)});   for(j in 1:colnum){    df[i,j] &lt;- histo[j]   } } df   Resulting in: e.g. 20 distributions (V1=number of single plays, V2=number of double plays, etc):     V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1  15 13 11  1  2  2  0  0  0   0 2  15 12 10  1  4  0  1  0  0   0 3  12 14  7  6  3  0  0  0  0   0 4  17 16  6  4  2  0  1  0  0   0 5  17 10 12  5  0  0  1  0  0   0 6  13 15 11  6  0  0  0  0  0   0 7  10 14  9  3  2  1  1  0  0   0 8  12 17  5  6  3  0  0  0  0   0 9   9 19  8  3  1  2  0  0  0   0 10 13  9 11  6  1  0  1  0  0   0 11 16  9 12  5  2  0  0  0  0   0 12 15  9 11  6  2  0  0  0  0   0 13 19  9  7  4  4  1  0  0  0   0 14 17 11  4  7  3  1  0  0  0   0 15 11 20  8  1  3  1  0  0  0   0 16 14 12 10  5  0  2  0  0  0   0 17  9 12  8  7  3  0  0  0  0   0 18 10 15  9  4  2  0  1  0  0   0 19 14 11 12  7  0  0  0  0  0   0 20 16 14 11  3  1  1  0  0  0   0   Now I need to get from here to the Poisson modelling--my R is a bit rusty (?lmer)...--Any help would be appreciated...  Attempted Poisson modelling: disappointing fit?!  plot(1:colnum,df[1,1:colnum],ylim=c(0,30),    type="l",xlab="repeats",ylab="count") for(i in 1:m){   clr &lt;- rainbow(m)[i]   lines(1:colnum,df[i,1:colnum],type="l",col=clr)   points(1:colnum,df[i,1:colnum],col=clr) }  df.lambda=data.frame(lambda=seq(1,5,0.1),ssq=c(NA));df.lambda for(ii in 1:dim(df.lambda)[1]){   l &lt;- df.lambda$lambda[ii]       ssq &lt;- 0       for(i in 1:20){         for(j in 1:10){           ssq &lt;- ssq + (df[i,j] - n*dpois(j,l))^2         }       }       print(ssq)       df.lambda$lambda[ii] &lt;- l   df.lambda$ssq[ii] &lt;- ssq     }     df.lambda     lambda.est &lt;- df.lambda$lambda[which.min(df.lambda$ssq)] lambda.est # 2.4 points(x &lt;- 1:10, n*dpois(1:10,lambda.est),type="l",lwd=2)  100*dpois(1:10,3) n/lambda.est   the estimated lambda stays around 2.3, with an n estimate of around 43; the fitted curve seems very discrepant, and seems to worsen with rising n !?  Doesn't this have to do with the fact, that our repeats are different from the 'classical' Poisson distributions: it's not just ONE event that repeats itself x number of times, but the sum of repeats of different items (songs)?! Testing equality of coefficients from two different regressions This seems to be a basic issue, but I just realized that I actually don't know how to test equality of coefficients from two different regressions. Can anyone shed some light on this?   More formally, suppose I ran the following two regressions:  $$ y_1 = X_1\beta_1 + \epsilon_1 $$ and  $$ y_2 = X_2\beta_2 + \epsilon_2 $$ where $X_i$ refers to the design matrix of regression $i$, and $\beta_i$ to the vector of coefficients in regression $i$. Note that $X_1$ and $X_2$ are potentially very different, with different dimensions etc. I am interested in for instance whether or not $\hat\beta_{11} \neq \hat\beta_{21}$.   If these came from the same regression, this would be trivial. But since they come from different ones, I am not quite sure how to do it. Does anyone have an idea or can give me some pointers?   My problem in detail: My first intuition was to look at the confidence intervals, and if they overlap, then I would say they are essentially the same. This procedure does not come with the correct size of the test, though (i.e. each individual confidence interval has $\alpha=0.05$, say, but looking at them jointly will not have the same probability). My "second" intuition was to conduct a normal t-test. That is, take   $$ \frac{\beta_{11}-\beta_{21}}{sd(\beta_{11})} $$  where $\beta_{21}$ is taken as the value of my null hypothesis. This does not take into account the estimation uncertainty of $\beta_{21}$, though, and the answer may depend on the order of the regressions (which one I call 1 and 2).   My third idea was to do it as in a standard test for equality of two coefficients from the same regression, that is take  $$ \frac{\beta_{11}-\beta_{21}}{sd(\beta_{11}-\beta_{21})} $$   The complication arises due to the fact that both come from different regressions. Note that   $$ Var(\beta_{11}-\beta_{21}) = Var(\beta_{11}) + Var(\beta_{21}) -2 Cov(\beta_{11},\beta_{21}) $$ but since they are from different regressions, how would I get $Cov(\beta_{11},\beta_{21})$?  This led me to ask this question here. This must be a standard procedure / standard test, but I cound not find anything that was sufficiently similar to this problem. So, if anyone can point me to the correct procedure, I would be very grateful! Background on color perception:  Due to the nature of the human eye and visual processing by the brain, there's an optical illusion that the same color will look different depending on the background.   It is known as the , illustrated below — center rectangles are identical:   Source:   An illustration  makes the effect of the background's color even more obvious:     Source:   (Note how the two upper-most colors in the second image appear the same, but are actually completely different.)    What about web design?  My question pertains to web design, specifically in this case, the color of link text on different backgrounds.  For a given color of text, how can one find the complementary color to make it appear the same on a certain background?    Let's take a look at an example for this question:  Consider my example below, with yellow text #FFF000 on the following backgrounds:    white #FFFFFF, black #000000, and grey #555555.          As expected, doesn't look the same at all. ()  How can we make it look the same on all three? Clearly, the text on the white background needs to be a darker yellow, and the one on the grey needs hue/tone adjustments. (The surrounding text will also affect it — but that's likely harder to account for.)  Can this perfect color somehow be calculated, based on the Hex, RGB or another system? That's where the crux of this question lies, as it would be much more efficient than manually approximating. What would you call a word that doesn't exist in or translate well into another language? Variablity in cv.glmnet results I am using cv.glmnet to find predictors. The setup I use is as follows:  lassoResults&lt;-cv.glmnet(x=countDiffs,y=responseDiffs,alpha=1,nfolds=cvfold) bestlambda&lt;-lassoResults$lambda.min  results&lt;-predict(lassoResults,s=bestlambda,type="coefficients")  choicePred&lt;-rownames(results)[which(results !=0)]   To make sure the results are reproducible I set.seed(1). The results are highly variable. I ran the exact same code 100 times to see how variable the results were. In the 98/100 runs had one particular predictor always selected (sometimes just on its own); other predictors were selected (co-efficient was non-zero) usually 50/100 times.  So it tells me that each time the cross-validation is running it's going to probably select a different best lambda, because of the initial randomization of the folds matter. Others have seen this problem () but there isn't a suggested solution.  I am thinking that maybe that one which shows up 98/100 is probably pretty highly correlated to all the others? The results do stabilize if I just run LOOCV ($\text{fold-size} = n$), but I am curious why they are so variable when $\text{nfold} &lt; n$. Run system commands from QML App I want to run a system command from inside my application. It's suppose to run a command on a remote server using SSH. But that's not really the point. The point is that I don't know how to run any kind of command from the app. I asked in the mail list and they referred me to build a QML extension using C++. But I don't know C++ and it seems that I have to learn so much only to run a simple command.  In Python (as in PHP) it's easy to run a system command. Is there any other way of doing it in my Touch app, or is there someone that could help me even more? Or perhaps have a better solution to my problem? If I wanted to just view, sort, and organize (via tags or folders or both), what programs are geared toward doing this quickly?  I know I could do this in most any photo editor, but it's not ideal for reviewing hundreds of images. I've also seen people use the image previewers built into their computer's OS, but that can't be the best option either.  What program would you suggest instead?  Extra info on the program is appreciated, i.e. OS requirements and cost. Find a plane that passes through a point and is perpendicular to 2 planes Does app review rejection list all issues? Our app was rejected recently with reason Google+ signin, which we understood is not according to Apple policy and need to fix.  While discussing about this issue we came across an interesting question with Apple review process, does Apple review team list all issues (if more than one exists) while rejecting app (or) would they stop reviewing other areas as soon as they found an issue (in our case Google+ signin)? Do I need a transit visa to collect and re-check my luggage at Istanbul Ataturk airport? I'm Egyptian and flying to Cairo from Tbilisi, via Istanbul. The first flight Tbilisi-Istanbul is on Atlasjet, then from Istanbul to Cairo I am flying on Egyptair. For that, I have to recheck in at Istanbul to my Egyptair flight  Will I need to pass passport control at Istanbul airport to collect my bags and check in on Egyptair? Will I need a transit visa for that? Or it can be all done through neutral zone? Can you break up your Attack action for a bonus action? You can do it to move:     If you take an action that includes more than one weapon attack, you can break up your movement even further by moving between those attacks. For example, a fighter who can make two attacks with the Extra Attack feature and who has a speed of 25 feet could move 10 feet, make an attack, move 15 feet, and then attack again. (PHB 190)   It would be necessary for the Great Weapon Master feat:     On your turn, when you score a critical hit with a melee weapon or reduce a creature to 0 hit points with one, you can make one melee weapon attack as a bonus action   As a level 17 Fighter, if I can not place a bonus action between attacks, there are two possibilities:   I have to wait until I finished all 4 attacks of the action, to make another attack as a bonus action the bonus action attack is wasted unless the kill or crit happens on the 4th attack   So can I take a bonus action in the middle of the attacks of an action? There is a restriction on setting your birthday:     Oops! There was a problem updating your profile:   - Birthday must be after 1920/01/01   I realize the number of 90 year old users is small, but shouldn't the restriction be a bit more relaxed, such as larger than any ?  Either 120 or 150 seems appropriate.  For example, my grandfather turns 90 next year (and just barely misses the current cutoff), but I can't imagine he's the only one around that age who is computer literate and still active enough to be interested in (the increasingly broad range of) SE sites.  I don't think he has contributed yet (mostly because of the comment restriction, I'd see him commenting before asking or answering), but I have emailed him with links that I know he's read.  Incidentally, the error message is wrong: birthday must be after 1919/12/31 and using the next day is accepted. Small snap loop devices visible in gnome-disk-utility OR what is the function of snap ubuntu-core I just realized using gnome-disk-utility (3.18.3.1) that my 16.04 installation is featuring several small loop devices.  In detail:   78 MB Loop Device (/var/lib/snapd/sn_ntu-core_352.snap -> /dev/loop0) 76 MB Loop Device (/var/lib/snapd/sn_ntu-core_216.snap -> /dev/loop1) 79 MB Loop Device (/var/lib/snapd/sn_ntu-core_423.snap -> /dev/loop2) 705 KB Loop Device (/var/lib/snapd/snaps/tpad_12.snap -> /dev/loop3) 684 KB Loop Device (/var/lib/snapd/snaps/tpad_11.snap -> /dev/loop5) 705 KB Loop Device (/var/lib/snapd/snaps/tpad_13.snap -> /dev/loop6)   Image showing gnome-disk-utility    My questions are as follows:   What are those loop devices used for? Is that an expected behaviour in 16.04? Can  I remove them? And if so - how (just by unmounting)? Is there any risk in removing the 2 installed snaps mentioned below (tpad and ubuntu-core)   UPDATE  Installed snaps  According to snap list I do have   tpad (1.8.1) ubuntu-core (16.04.1)   installed. I remember I did tinker with snaps for a short time when  I realized this option - but am pretty unsure if  I  installed those 2 snaps - or if they are pre-/auto-installed.  tpad is a Terminal text editor with GUI-like user interface  I  did install manually, as  I don't use it  I removed it now via sudo snap remove tpad. As a result the 2 loop devices pointing to tpad are gone in gnome-disk-utility.  So - at the current point  I am still having 1 snap installed called ubuntu-core and I don't know what it is used for. The summary of this particular snap is   The ubuntu-core OS snap I'm just trying to review basic terminal commands. Having said that, how do I create a text file using the terminal only?