I want to use regex to replace the lowercase letter of every word within a string of words, with an uppercase, ie change it to title case such that str_val="This is the best sauce ever"  becomes "This Is The Best Sauce Ever". Here is my code  function (str_val) {    let reg_exp = /\s\w/g;    let str_len = str_val.split(' ').length;     while (str_len){       str_val[x].replace(reg_exp, reg_exp.toUpperCase());       x++;       str_len--;    }    return str_val; }   How do I solve this with regex?
Is there a simple way to convert a string to Title Case? E.g. john smith becomes John Smith. I'm not looking for something complicated like , just (hopefully) some kind of one- or two-liner.
The canonical way to return multiple values in languages that support it is often . Option: Using a tuple Consider this trivial example: def f(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return (y0, y1, y2)  However, this quickly gets problematic as the number of values returned increases. What if you want to return four or five values? Sure, you could keep tupling them, but it gets easy to forget which value is where. It's also rather ugly to unpack them wherever you want to receive them. Option: Using a dictionary The next logical step seems to be to introduce some sort of 'record notation'. In Python, the obvious way to do this is by means of a dict. Consider the following: def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return {'y0': y0, 'y1': y1 ,'y2': y2}  (Just to be clear, y0, y1, and y2 are just meant as abstract identifiers. As pointed out, in practice you'd use meaningful identifiers.) Now, we have a mechanism whereby we can project out a particular member of the returned object. For example, result['y0']  Option: Using a class However, there is another option. We could instead return a specialized structure. I've framed this in the context of Python, but I'm sure it applies to other languages as well. Indeed, if you were working in C this might very well be your only option. Here goes: class ReturnValue:   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return ReturnValue(y0, y1, y2)  In Python the previous two are perhaps very similar in terms of plumbing - after all { y0, y1, y2 } just end up being entries in the internal __dict__ of the ReturnValue. There is one additional feature provided by Python though for tiny objects, the __slots__ attribute. The class could be expressed as: class ReturnValue(object):   __slots__ = [&quot;y0&quot;, &quot;y1&quot;, &quot;y2&quot;]   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  From the :  The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.  Option: Using a  (Python 3.7+) Using Python 3.7's new dataclasses, return a class with automatically added special methods, typing and other useful tools: @dataclass class Returnvalue:     y0: int     y1: float     y3: int  def total_cost(x):     y0 = x + 1     y1 = x * 3     y2 = y0 ** y3     return ReturnValue(y0, y1, y2)  Option: Using a list Another suggestion which I'd overlooked comes from Bill the Lizard: def h(x):   result = [x + 1]   result.append(x * 3)   result.append(y0 ** y3)   return result  This is my least favorite method though. I suppose I'm tainted by exposure to Haskell, but the idea of mixed-type lists has always felt uncomfortable to me. In this particular example the list is -not- mixed type, but it conceivably could be. A list used in this way really doesn't gain anything with respect to the tuple as far as I can tell. The only real difference between lists and tuples in Python is that lists are , whereas tuples are not. I personally tend to carry over the conventions from functional programming: use lists for any number of elements of the same type, and tuples for a fixed number of elements of predetermined types. Question After the lengthy preamble, comes the inevitable question. Which method (do you think) is best? Deriving curvature formula How do you derive the formula for unsigned curvature of a curve $\gamma (t) = (x(t), y(t)$ which is not necessarily parameterised by arc-length.   The formula given is $$|\kappa (t)| = \left|\frac{x'' y' - y'' x'}{((x')^2 + (y')^2)^{3/2}}\right|$$  All the definitions of curvature in my notes give it in terms for an arc-length parameterisation $T'(s) = \kappa(s) N(s)$. This is apparently meant to be 'easily derivable', am I missing something? Reference to the Table of Contents page I thought that someone must have asked this, but my searches didn't find it.  I am looking to refer back to the table of contents from places in my document. How can I do this? Prove that $\liminf x_n = -\limsup (-x_n)$ How can we prove that $\liminf x_n = -\limsup (-x_n)$?  The definitions we are using are $\limsup x_n = \lim\limits_{n\to\infty} \sup\{x_k; k\ge n\}$ $\liminf x_n = \lim\limits_{n\to\infty} \inf\{x_k; k\ge n\}$ How do I disable network manager permanently? I'm using Ubuntu 18.04.1 LTS. I want to disable network manager on an Ubuntu machine, because (1) I don't need it, (2) I prefer having hardcoded configuration, and (3) network manager regularly causes issues by changing the DHCP configuration. I tried to follow :  Stop network manager sudo systemctl stop NetworkManager.service  Disable network manager (permanently) to avoid it restarting after a reboot sudo systemctl disable NetworkManager.service   Despite this, the network manager is back again every time I reboot the machine. How can I make it go away? I'm trying to prove that  $$ \left| \frac{1}{x}-\frac{1}{y} \right| $$  is a metric on $X = \mathbb R^+$.  The properties of non-negativity and symmetry are obvious (do I actually even need to prove them?), but the tricky one is, as usual the inequality property, i.e.  $$ d(x,z) \le d(x,y) + d(y,z) \text{ for any } z \in X. $$  So, ok, I have that  $$ d(x,z) \le d(x,y) + d(y,z) \\ \iff \left| \frac{1}{x}-\frac{1}{z} \right| \le \left|\frac{1}{x} - \frac{1}{y} \right| + \left|\frac{1}{y} - \frac{1}{z} \right| \\ \iff \left| \frac{1}{x} \right|- \left| \frac{1}{z} \right| \le \left| \frac{1}{x}-\frac{1}{z} \right| \le \left|\frac{1}{x} - \frac{1}{y} \right| + \left|\frac{1}{y} - \frac{1}{z} \right| $$  ...and that's about as far as I've gotten–which is to say, not very far. I also tried multiplying both sides by $ \left| \frac{1}{x}-\frac{1}{z} \right| $, but that wasn't very fruitful. If someone could point me in the right direction, it'd be greatly appreciated. Thanks. Can you cast a spell learned from the Magic Initiate feat using spell slots? Say I play a wizard who learns cure wounds by taking the Magic Initiate feat. Could I cast that spell using the Wizard's spell slots? Sinking and Sourcing Current to and from a PIC24F Output Pin Sinking and sourcing current refers to current going into and out of the MCU (respectively), right? If you configure a GPIO pin as an output, why would current ever go into the pin (since it's configured as an OUTPUT)? I suppose it depends what the output circuit looks like, if it's tied to the voltage supply rail or ground... maybe I just answered my own question...? Why doesn't [Required] work for me? MVC3 "I cannot seem to find it" Why do some Debian packages have a "+deb7u2" suffix? I figured the "7u2" part stood for "Debian 7.2" (aka "wheezy"). But I'm wondering if anybody knows the official answer as to why some packages have it and others do not.  Example:   The only time "+deb7u2" is appended to the version is when the package gets put in the "stable" release. Does this mean that's a "tag" to indicate a checkin to stable from another repo? I have noticed that when I leave comments on a question and someone votes it up, I do not get a notification. If the upvote count would at least be more than 5, I would expect to be notified since that leads to a badge. underbrace matrix inside brackets I would like to put an underbrace below the matrix like this:  $$\left(\underbrace{ \left[\begin{array}{ccc}     a&amp;b&amp;c\\     d&amp;e&amp;f\\     g&amp;h&amp;i \end{array}\right]}_{A} \left[\begin{array}{c}     x_1\\     x_2\\     x_3 \end{array}\right]\right)$$     But I don't want the outer brackets \left( and \right) to stretch vertically. I want them to remain as if there was no underbrace. How to achieve that behaviour? Opt out of moderator election notifications I would like to create some kind of feature matrix with available classes in columns and implemented features as rows. Problem is, that the class names are quite long.  Rotating them by 90° simply looked quite silly, so am looking for alternate ideas.  The only idea I had so far was to write the heading text horizontally with a arrow (or similar) matching the "heading row" with a column. But frankly I have no idea how to do something like this in latex.  An minimal example of my naive approach looks like this.  \documentclass{beamer}  \usepackage{tabularx}  % I am actually using a custom theme % The space ``wasted'' is similar for PaloAlto though \usetheme{PaloAlto}  \begin{document} \frame {   \frametitle{Comparision of boost implemented graph classes}   \begin{tabularx}{\textwidth}{X c c c}     %     % Column Headers, first column is empts     %     & \rotatebox{90}{adjacency\_list}     & \rotatebox{90}{adjacency\_matrix}     & \rotatebox{90}{compressed\_sparse\_row\_graph}      \     %     % Rows, I suspect I need about 10     % Class               adjlist          adjmatrix     csrg     \hline      AdjacencyGraph        & Yes            & No          & Yes \\     Interface \#2         & Yes            & No          & Yes \\     Interface \#3         & Yes            & No          & Yes \\     Interface \#4         & Yes            & No          & Yes \\     Interface \#5         & Yes            & No          & Yes \\     Interface \#6         & Yes            & No          & Yes \\     Interface \#7         & Yes            & No          & Yes \\     Interface \#8         & Yes            & No          & Yes \\     Interface \#9         & Yes            & No          & Yes \\     % Rest omitted   \end{tabularx} } \end{document}    If its important: I am doing this for a presentation with beamer. 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? Very specific paragraph shape Where is the known_hosts file for OpenSSH for Windows? I have two large external drives with about 2.5 TB of data. About half the storage is images and videos that I want to put on a new NAS drive/device. I don’t want to carry over junk, duplicates and non photo/video files.   I am hoping Lightroom can help scour the mounds of folder structures on these drives and copy images/videos the new drive that I want to catalogue and keep clean as a working platform for all images and video. Once completed I plan to format the original drives and copy the cleaned-up content back to them as part of a backup strategy.  Can Lightroom help? If so, how? If not, is there some other application for Mac OS X that I can use for help with this? One problem I had with my original attempt is I wasn't sure how to move images and rename folders to get the new drive contents to make sense, so I formatted it and am looking to try again.  (steps for this operation would be helpful) I am wondering if the mass density profile $\rho(\vec{r})$ has been characterized for atomic particles such as quarks and electrons. I am currently taking an intro class in quantum mechanics, and I have run this question by several professors. It is my understanding from the viewpoint of quantum physics a particle's position is given by a probability density function $\Psi(\vec{r},t)$. I also understand that when books quote the "radius" of an electron they are typically referring to some approximate range into which an electron is "likely" to fall, say, one standard deviation from the expectation value of its position or maybe $10^{-15}$ meters.  However it is my impression that, in this viewpoint, wherever the particle "is" or even whether or not the particle "had" any position to begin with (via the Bell Inequalities), it is assumed that if it were (somehow) found, it would be a point mass. This has been verified by my professors and GSIs. I am wondering if its really true.  If the particle was truly a point mass then wherever it is, it would presumably have an infinite mass density. Wouldn't that make electrons and quarks indistinguishable from very tiny black holes? Is there any practical difference between saying that subatomic particles are black holes and that they are point masses? I am aware of such problems as Hawking Radiation although at the scales of the Schwarchild radius of an electron (back of the envelope calculation yields $\tilde{}10^{-57}$ meters), would it really make any more sense to use quantum mechanics as opposed to general relativity?  If anyone knows of an upper bound on the volume over which an electron/quark/gluon/anything else is distributed I would be interested to know. A quick Google Search has yielded nothing but the "classical" electron radius, which is not what I am referring to.  Thanks in advance; look forward to the responses.