I am trying to export all active layers in a QGIS project to a specified folder, below is what I get atm  Outputdir='C:/Users/DN/Downloads/Test/'   layer = iface.activeLayer()  QgsVectorFileWriter.writeAsVectorFormat( layer, Outputdir + layer.name() + ".shp", "utf-8", layer.crs(), "ESRI Shapefile", 1)   It only works when I click on the layer that I want to export, I am wondering if it's possible to write a loop to loop through all active layers in the project and export them.
I'm having trouble figuring out how to iterate over map layers. I can access the currently highlighted layer in the table of contents via iface.activeLayer() but I want my code to operate on all layers.  I don't see anything in the API that provides easy access to this functionality and couldn't find a good online example but maybe I missed something?
Database general error: 2006 MySQL server has gone away Hacking linear regression Let's say I perform linear regression on some data that produces the following $R^2$: $\text{RSS} = 1966815.13$ $\text{TSS} = 2145213.91$ $R^2 =  0.083$ Now let's say I bucket (take the average of successive equal size windows) the data and perform the exact same linear regression. This time the $R^2$ is: $\text{RSS} = 1187.56$ $\text{TSS} = 4758.32$ $R^2 =  0.75$ What have I just done here? I clearly haven't improved the explanatory power of the model over the original data, yet I've hacked the $R^2$ by averaging. What's the bias / variance argument of why this occurs? A graphical representation:  Edit: I've reduced the total variance of the data, but the bias remains unaffected. When (if ever) is this a valid statistical approach? Correlation between a nominal (IV) and a continuous (DV) variable I have a nominal variable (different topics of conversation, coded as topic0=0 etc) and a number of scale variables (DV) such as the length of a conversation.   How can I derive correlations between the nominal and scale variables? I want to delete all *.o files in a directory and its sub-directories. However, I get an error: sashoalm@aspire:~/.Workspace.OLD$ rm -r *.o rm: cannot remove `*.o': No such file or directory  On the other hand, rm *.o works, but it's not recursive. Combining  with allowframebreaks in beamer How to completely disable auto-save and versions in Mac OS X Lion? I hate the automatic saving and versioning in Mac OS X Lion.  Is there a way to completely turn it off?  (This has been asked before , but the answer and the linked article are completely wrong, so I thought I'd try again.) How does gravity work on Serenity? When the good ship Serenity is traveling in deep space, the crew experiences what looks like an Earth-normal (or Earth That Was-normal) level of gravity. Is it ever explained how the ship is able to generate artificial gravity? The ship doesn't spin, so  is out.  is a possibility, but I think the gravity in the ship pulls in a direction that is perpendicular to the direction the ship is usually traveling in, not opposite, like this method would require.   So: how does she pull it off?   Extra credit: how does she pull it off in the episode ? Serenity's engine is totally dead, to the extent where not even life support systems are online. Yet Mal still has to valiantly haul himself around on the floor to replace the compression coil, so whatever creates the artificial gravity on Serenity is clearly still going. How? Is it possible to tell a Valyrian steel sword from a very well crafted steel sword, by sight alone If I push or hit an object in space will it rotate or move along a straight line? If I push or hit an object in space (vacuum and no gravitation) in direction what is not going trough its centroid, will it rotate or move along in straight line?   I expect that on earth it will depend on what is less difficult for the object (rotation or linear movement). So the object will do some kind of combination of both movements (rotating and also moving along the direction of impulse or force).  But how could an object "decide" what to do in space, where is not resistance? Why, oh why, don't the Weasleys "conjure" up some diamonds/gold/etc, sell 'em to Muggles, and get rich? They could buy a mansion (like the Malfoys), and live there happily ever after.  I know there's  that prohibits one from conjuring food (which doesn't make much sense to me, either). Even if it applied to gold, what about all the other elements/compounds/materials? Could the law really be 'don't let a wizard conjure something if it'll make them richer'? That's totally nonsensical.  Why does Wizard society still have poor people, especially if they're talented? $\Bbb Q$-linear is equivalent to additive LaTeX: optional arguments with square brackets LaTeX is trying to add a missing $ that I don't want to the following code. Minimal working example:  \documentclass[letter,12pt]{article}  \newcommand{\monkeyBeans}[2][]{   \parbox{4in}{#1} }  \begin{document}  \parbox{4in}{$[a, b]$}   \monkeyBeans[$[a, b]$]{yo monkey}  \end{document}   If I try any of the following lines in my document instead of the call to monkeyBeans, there is no error:  \parbox{4in}{$[a, b]$}  \monkeyBeans[yo monkey]{$[a, b]$} \monkeyBeans[$(a, b)$]{yo monkey} \monkeyBeans{$[a, b]$}{yo monkey}   What is the deal with square brackets in optional arguments? Can magnets rotate infinitely? There are many videos on youtube in which people arranged magnets in circle and rotated one placing in middle of that circle on a shaft, and the magnet (magnet motor) starts madly and continues its movement. Do they really rotate infinitely? If so, do they from where they get that extra energy to move so fast and infinitely?    EDIT: This question is about real world scenario  UPDATE: I am unable to find that particular video about which i talked about -- I added them to my favourites, but they are all now deleted :( -- there are hundreds of that that kind of videos. Some example videos links I want to merge an audio file (.wav or .au format) with a video file (.mp4 format).  Please suggest me how to achieve this. I want to merge these file to new .mp4 video file. An ffmpeg command would be very welcome. How do I make Panel always transparent like the Dock in GNOME 3? I'm using Ubuntu 17.10. I want the Panel to be always transparent instead of dynamic transparency. Why is moving directories to /dev/null dangerous? Let $a\ge1$ and define the sequence $(x_n)$ recursively by: $$x_1 = \sqrt{a}$$ $$x_{n+1}= \sqrt{a+x_n}$$  Here's what I did:  Plugging in some values makes it seem as if the sequence is increasing. I first solve the equation $t=\sqrt{a+t}$, equivalently $t^2 -t -a =0$, to get an idea what's going on. The roots are $$t_{1,2}= \frac{1 \pm \sqrt{1+4a} }{2}.$$ Therefore, between the roots, that is for $$t\in \left( \frac{1 - \sqrt{1+4a} }{2}, \frac{1 + \sqrt{1+4a} }{2}\right)$$  we have $t^2-t-a \le 0 \iff t \le \sqrt{a+t}$. Here's my attempt at showing inductively that $$\forall n\in \mathbb{N}, \ x_n \le \frac{1 + \sqrt{1+4a} }{2}$$  For $n=1$, the statement is true (simple arithmetic). Suppose it's true for $n$. Consider  $$x_{n+1}= \sqrt{a+x_n}\le \sqrt{a+\frac{1 + \sqrt{1+4a} }{2}}=\frac{1 + \sqrt{1+4a} }{2},$$  because $\frac{1 + \sqrt{1+4a} }{2}$ satisfies $x=\sqrt{x+a}$.  So this establishes the sequence $(x_n)$ is bounded. Now, by induction again, I try to show it's monotonically increasing. The base case $x_1\le x_2$ is obvious. Assume (strong induction) $x_{n-1}\le x_n$ for all $n&gt;1$. But since we have $$x_1\le x_n \le \frac{1 + \sqrt{1+4a} }{2}, $$   then $x_n$ lies in the appropriate interval, so $x_n \le \sqrt{a+x_n}=x_{n+1}.$  Is this proof correct? Can the condition on $a$ be relaxed to $a&gt;0$? Maybe even small negative $a$? And could someone provide me with another proof of convergence of $x_n$? I absolutely hate this one! I want to write applications for Ubuntu. I do not know much about programming but I want develop for Ubuntu. I am trying to learn Python right now. What do you think is the best way to develop apps for Ubuntu? Can you point me to some resources that can help me get started with developing for Ubuntu?  Related . This is a  about DoS and DDoS mitigation.   I found a massive traffic spike on a website that I host today; I am getting thousands of connections a second and I see I'm using all 100Mbps of my available bandwidth.  Nobody can access my site because all the requests time out, and I can't even log into the server because SSH times out too!  This has happened a couple times before, and each time it's lasted a couple hours and gone away on its own.  Occasionally, my website has another distinct but related problem: my server's load average (which is usually around .25) rockets up to 20 or more and nobody can access my site just the same as the other case.  It also goes away after a few hours.  Restarting my server doesn't help; what can I do to make my site accessible again, and what is happening?  Relatedly, I found once that for a day or two, every time I started my service, it got a connection from a particular IP address and then crashed.  As soon as I started it up again, this happened again and it crashed again.  How is that similar, and what can I do about it? Centering in the \align* environment