How do I get items of a field of type list?

Question: I have created a list field with 10 items(allowed values). Now I want to get that 10 items programmatically. How do I get them?
Answer: Better create a vocabulary of taxonomy terms populated with your items.Then you can use taxonomy_get_tree() function to retrieve all those items
Comment: There's a working function implemented [here](http://www.tylerfrankenstein.com/user/4/return-drupal-cck-integer-field-allowed-values-list-array) that does the same thing
Comment: I can't change the field. There are many submitted nodes having this field.
Comment: The data is on the field_config table. Identify the row  by checking the value given for that select list from field_config.field_name column and use sql like this "select field_config.data from field_config WHERE id =field_config.id value". The allowed values will be the array ['settings']['allowed_values']


Which distribution in this case?

Question: Let's say I am taking a sample size of n=1000 of a country population, and every one of them decides with '1' (for a specifc political party) or with '2' (for another political party).
Which distribution is given if I want to calculate the confidence interval for a proportional value pi?
Comment: @Kevin taking a large sample doesn't make the *sample* normally distributed. The distribution the sample was drawn from will be the same no matter what sample size you draw. It's the distribution of a (standardized) mean that might be argued to be approaching the normal.
Comment: Since you have a large random sample, you can assume it is normally distributed with mean $\hat{p}$. You'll need to estimate the standard error of this distribution to create a confidence interval.
Comment: See https://en.wikipedia.org/wiki/Binomial_distribution and https://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval
Comment: Agreed, I meant to say the sample proportion (instead of "it") - thanks!
Comment: If your question has been answered to your satisfaction, you can accept an answer by clicking the check mark under the voting arrows.
Answer: Try the Bernoulli distribution. This is a distribution that has only two values, which in this case you would designate 1 and 2, and  a single parameter, which dictates the probability of the outcome designated "success". Finding a confidence interval for this parameter is a well-studied topic.

Which distribution in this case?


Rstudio Automatically use input file name in read.csv when using write.csv & two headers

Question: Currently I use a script to edit columns of a dataset.
I click run on Rmarkdown, and my first line of code is
Data <- read.csv(file.choose(), sep = "," ,header = T , skip = 2)

This skips the first 2 lines and gives the third line a header for the file that I select after clicking run. When the script finishes, the last line of code is
write.csv(Data, "FileName.csv", row.names=FALSE)

This removes all the row names that were given numerical values on the left, and saving a FileName.csv in my working directory.
My question is if I do a read.csv of a certain file that I pick, for example, the file name is "FileName.csv", is there a way to use that name that I picked the same name as the file that I use
write.csv

and it would give out the name FileName on my working directory without manually writing it. Also is there a way to add back the other first 2 lines that I skipped when doing write.csv
Answer: You can save the filepath/filename into a variable and use that variable in both read.csv and write.csv:
myfile <- file.choose()
data <- read.csv(file=myfile, ...)
   ... lots of code...
write.csv(data, file=myfile)

Answer: I'd comment if I could as I am not sure this is a full answer, but I guess you could just use:
Data <- read.csv(file.choose(), skip=2))
FileName <- basename(file.choose())
write.csv(Data, FileName, row.names=FALSE)

Answer: You can capture the filename from file.choose and save the skipped lines to write out later.
## Capture file name
FileName = file.choose()

# Capture skipped header lines
IN=file(FileName, open="r")
Header=readLines(IN, 2)
Input <- read.csv(IN)          # No need to skip lines now
close(IN)

## Whatever processing

## Output
OUT = file(FileName ,open="w")
writeLines(Header, OUT)
write.csv(Input, OUT,  row.names=FALSE)
close(OUT)


Calculate this limit as x goes to infinity

Question: What is the following limit?
$$
\lim_{x \to \infty}
{\displaystyle{\large\left(1 + x\right)\left(1 + 1/x\right)^{2x} - x\,{\rm e}^{2}}
\over \displaystyle{\large{\rm e}^{2} - \left(1 + 1/x\right)^{2x}}}
$$
Thanks.
Comment: I think you're supposed to show what you've done so far.
Comment: Welcome !!!. You are a new user. M.SE people think you must show what did you try to get the answer and/or where you stop to see the road to the answer. In that way they can provide you with several alternatives.
Comment: This is a nice hard limit to do; the limit exists ($\frac{1}{6}$ seems to be the answer) but none of the usual tricks nail it.
Answer: Define the numerator and the denominator of the limit as:
$$a(x):={\large\left(1 + x\right)\left(1 + 1/x\right)^{2x} - x\,{\rm e}^{2}}$$
$$b(x):={\large{\rm e}^{2} - \left(1 + 1/x\right)^{2x}}$$
Then
$$A(t)=a(1/t)={\large\left(1 + (1/t)\right)\left(1 + t\right)^{2/t} - (1/t)\,{\rm e}^{2}}$$
$$B(t)=b(1/t)={\large{\rm e}^{2} - \left(1 + t\right)^{2/t}}$$
We can now expand $A(t)$ and $B(t)$ at $t=0$ ($x=\infty$):
$$A(t)=\frac{{\rm e}^{2}}{6}t+O(t^2)$$
$$B(t)={\rm e}^{2}t+O(t^2)$$
Thus
$$\lim_{x \to \infty}\frac{a(x)}{b(x)}=\lim_{t \to 0}\frac{A(t)}{B(t)}
=\lim_{t \to 0}\frac{\frac{{\rm e}^{2}}{6}t}{{\rm e}^{2}t}=\frac{1}{6}$$
It is exactly as what Mark Fischler predicted.
Comment: I really like that trick of converting the problem to limit at zero: "We can now expand A(t) and B(t) at t=0 (x=∞)"


How to do menu rebuild when having PHP Fatal error?

Question: I have been trying to get the command menu_rebuild(); to work on drush. However, I keep getting this error:

I, of course, think I installed Drush correctly. However, I can't be 100% certain since I've never used Drush before.
The reason why I am trying to run this command is because my admin menu is giving me problems. Whenever I install new modules, the settings pages corresponding to those modules are missing. Yet, they are installed and working according to Drupal.
Comment: Just to be sure, you have tried `drush cc all` first right? You may also want to see if [this](http://drupal.stackexchange.com/questions/58618/how-do-i-call-the-menu-rebuild-function-in-drupal-7#124596) helps.
Answer: Make sure you're running drush in your web root and drush status is showing Drupal bootstrap: Successful.
Then try the following steps:

drush cc all to clear the caches or clear cache tables manually, e.g.:
echo "SHOW TABLES LIKE 'cache%'" | $(drush sql-connect) | tail -n +2 | xargs -L1 -I% echo "DELETE FROM %;" | $(drush sql-connect) -v

try rebuild menu again: drush eval 'menu_rebuild();'
try rebuild your Drupal registry via:
drush -y dl registry_rebuild
drush rr

consider disabling caches

In case your drush status doesn't show Drupal bootstrap as Successful, you either running it outside of your Drupal webroot or your db credentials are not configured properly in settings.php, or you've some missing/corrupted files which prevents from bootstrapping your Drupal core.
If you're using multisite, then don't forget to specify your profile by either running inside sites/X dir or make sure you're specifying the right --uri parameter, e.g.: drush -l http://myprofile status (see: drush topic core-global-options for proper syntax).
If you still having the issue, try: drush -vd status to troubleshoot the source of your problem.
Comment: Well, when I run drush status "Drupal bootstrap: successful" doesn't come out. So is this where my error is? I tried drush cc all either way and still gave me the same error.
Answer: Turns out that the Backup and Migrate module we had installed was causing the issue. Why? I'm not entirely sure but the problem is gone now that we removed it.


AKS authentication through VM with user managed identity asking for code verification

Question: I have a VM with a user assigned managed identity.  The cluster has Azure RBAC enabled and the VM identity  has contributor role assigned to the cluster.
I login with az login --identity successfully and also az aks get credentials ...
When I try to use kubectl I get the message
o sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code...
How can I configure things to access AKS without interactive code verification in this case?
Answer: you need to pull admin credentials:
az aks get-credentials \
  --admin \ # to pull admin credentials
  -n xxx \
  -g yyy

alternatively you can use kubelogin to convert az cli token to regular credentials:
az aks install-cli # this will install 'kubelogin' as well
az aks get-credentials -n xxx -g yyy
kubelogin convert-kubeconfig -l azurecli

Comment: I  was struggling with it some hours and your answer resolved my issue. The nessasary part was to ask for `--admin` flag. Without it I end up with `Error from server (Forbidden): nodes is forbidden: User "" cannot list resource "nodes" in API group "" at the cluster scope`


Is this sum $\sum_{k=1}^{\infty}\left({1\over kx}+{1\over kx-1}+{1\over kx-2}+\cdots+{1\over kx-x+1}-\ln{k+1\over k}\right)=\gamma+\ln{x}$ correct?

Question: Given that:
$\mbox{A well-known Euler's sum is}\displaystyle\quad%
\sum_{k = 1}^{\infty}\left[{1\over k} - \ln\left(k + 1 \over k\right)\right] =
\gamma\label{1}\tag{1}
$
The generalised of \eqref{1} is:

$$
\sum_{k = 1}^{\infty}\left[{1 \over kx} + {1 \over kx - 1} +
{1 \over kx - 2} + \cdots + {1 \over kx - x + 1} -
\ln\left(k + 1\over k\right)\right] = \gamma + \ln\left(x\right)\label{2}\tag{2}
$$

Where $\gamma$ is Euler's constant and $x \geq 1$.
Is the sum of \eqref{2} correct ?
Comment: It's not even correct for $x=1$.
Comment: Note that $$\log(x)=\sum\limits_{k=1}^\infty \left[\sum\limits_{j=1}^{x-1}\frac{1}{kx-j}-\frac{x-1}{kx}\right]$$
Comment: @Raskolnikov Not true at all. when $x=1$ the LHS becomes simply $$\sum_{k=1}^{\infty}\left({1\over k}-\ln{k+1\over k}\right)$$ which is the OP's identity already stated
Comment: Sorry, let me check again
Comment: Numerically, this seems correct, at least for $x=1$ and $x=2$. Now, some work is needed to define this for non-integer values of $x$
Comment: Where is this conjecture from
Comment: $(2)$ came from $(1)$ base on an observation I made.
Comment: The formula given by @Brevan Ellefsen has a nice interpretation as the rearrangement R(x,1) (x positive terms, 1 negative term) of the null harmonic series
log(1) = (1-1)+(1/2-1/2)+(1/3-1/3)+...
In general, the rearrangement R(p,q) converges to log(p/q).
$$
\log\left(\frac{p}{q}\right)=\sum_{i=0}^\infty \left(\sum_{j=pi+1}^{p(i+1)}\frac{1}{j}-\sum_{k=qi+1}^{q(i+1)}\frac{1}{k}\right)
$$
Comment: See, for example, how to build log(3/2) http://oeis.org/A166711
Answer: I'm assuming that $x$ is a positive integer. Note that $$\sum_{m=0}^{x-1}\frac{1}{kx-m}=H_{kx}-H_{x\left(k-1\right)}$$ where $H_{l}$ is the $l$-th harmonic number and since $$\lim_{n\rightarrow\infty}\left(H_{n}-\log\left(n\right)\right)=\gamma$$ we have $$\lim_{N\rightarrow\infty}\left(\sum_{k=1}^{N}\left(\sum_{m=0}^{x-1}\frac{1}{kx-m}-\log\left(\frac{k+1}{k}\right)\right)\right)$$ $$=\lim_{N\rightarrow\infty}\left(\sum_{k=1}^{N}\left(H_{kx}-H_{x\left(k-1\right)}-\log\left(k+1\right)+\log\left(k\right)\right)\right)$$ $$=\lim_{N\rightarrow\infty}\left(H_{Nx}-\log\left(N\right)\right)=\lim_{N\rightarrow\infty}\left(H_{Nx}-\log\left(Nx\right)+\log\left(x\right)\right)=\color{red}{\gamma+\log\left(x\right)}.$$
Comment: @BrevanEllefsen It is a telescopic sum.
Comment: How did you go from $$\lim_{N\rightarrow\infty}\left(\sum_{k=1}^{N}\left(H_{kx}-H_{x\left(k-1\right)}-\log\left(k+1\right)+\log\left(k\right)\right)\right)$$ to $$=\lim_{N\rightarrow\infty}\left(H_{Nx}-\log\left(N\right)\right)$$


Determine the velocity of the skater when they reach the point at the bottom of the halfpipe

Question: A skateboarder with a mass of $75$ kg rolls down a parabolic halfpipe (with shape described by the function $y = 0.2 x^2$). When the skateboarder is at a point $h_1 = 3$m above the ground, their velocity $v_1 = 3.0$ m/s. Neglecting friction, determine the velocity $v_2$ of the skater when they reach the point at the bottom of the halfpipe
My working out:
$$mgh = mv^2/2$$
\begin{align}
v & = \sqrt{2gh}\\
  & = \sqrt{9.8 \times 3 \times 2} \\
  & = 7.67 \text{m/s}\\
\end{align}
Is my working out and answer correct?
Comment: you appear to be ignoring the initial kinetic energy
Answer: Your answer would be correct if the skateboarder started out stationary when they are 3m from the ground. But they aren't stationary - they have an initial speed of 3 m/s.
So your energy equation should be:
$\frac{1}{2}mv_1^2 + mgh = \frac{1}{2}mv_2^2$
You know $v_1=3$ and $h=3$ so you can solve to find the value of $v_2$.
Comment: isnt h = -3 since the skateboarder is going downhill? Also is g = negative 9.8 when substituting into the above equation u wrote up?
Comment: You can make g and h negative if you like - that is a matter of convention. Key point is that the product gh must be positive, so that $v_2 > v_1$ i.e. the skateboarder is speeding up as they go downhill.
Answer: When we know that:
$$\text{E}_{\space\text{initial}}=\text{E}_{\space\text{k}}+\text{E}_{\space\text{p}}=\frac{\text{m}_{\space\text{initial}}\cdot\text{v}_{\space\text{initial}}^2}{2}+\text{m}_{\space\text{initial}}\cdot\text{g}_{\space\text{initial}}\cdot\text{h}_{\space\text{initial}}\tag1$$
And when he is at the bottom:
$$\text{E}_{\space\text{final}}=\text{E}_{\space\text{k}}=\frac{\text{m}_{\space\text{final}}\cdot\text{v}_{\space\text{final}}^2}{2}\tag2$$
Now, when we know that:

$$\text{g}_{\space\text{initial}}=\text{g}\tag3$$
$$\text{m}_{\space\text{initial}}=\text{m}_{\space\text{final}}=3x\tag4$$
$$\text{v}_{\space\text{initial}}=\text{h}_{\space\text{initial}}=x\tag5$$

So, you can write:
$$\frac{3x\cdot x^2}{2}+3x\cdot\text{g}\cdot x=\frac{3x\cdot\text{v}_{\space\text{final}}^2}{2}\space\Longleftrightarrow\space\text{v}_{\space\text{final}}=\pm\sqrt{x}\cdot\sqrt{x+2\cdot\text{g}}\tag6$$


How can I move storage from one file system to another filesystem?

Question: I'm on a Linux EC2 machine and I'm getting an error that my storage space is full.
  Error writing to connection:  No space left on device

I used df and I can see that I have plenty of space in some of my filesystems.
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs         8202604      60   8202544   1% /dev
tmpfs            8213188       0   8213188   0% /dev/shm
/dev/xvda1       8123812 8023744         0 100% /

I'm on a t2.xlarge. Is it possible to make more space available in xvda?
Comment: You have "plenty of space" on a `tmpfs` and a `devtmpfs` fs mount...clear up data on `/`
Comment: Can I move files from `xvda1` to these other file systems?
Comment: @Lenniey they're both ramdisks, they can't be used to extend the real disk
Comment: @Chopper3 I know, that's why I put the " around plenty of space and to clear up data on /, wasn't clear enough, obviously
Comment: @goollan I didn't want to sound condescending. No you can't extend your root filesystem or move data to them, as they are not "normal" filesystems. You either have to add more storage to your instance or clear up space on your root filesystem
Answer: When using GNU coreutils df, get in the habit of filtering by file system type: df -t xfs -h.  Or maybe you are using ext4 or other file systems. This ignores in memory types that are not permanent storage, like tmpfs.

Create new disks (EBS volumes in the case of AWS), create LVM volumes and file systems on them.  Then migrate onto the new mount points (/srv or somewhere under /var perhaps) by copying data. You can then do neat tricks like booting an image with upgraded software, then swing the existing disk over to the new instance.
Or, you could expand the existing disk and the file system on it. However, that ties your data to your operating system volume.
Comment: The advantage of one larger disk vs two smaller disks is effectively higher IOPS, as the OS isn't really going to be using the disk all that much.
Comment: I mentioned a data mounts scheme for administrative convenience first, not necessarily performance. Also, you can boot the OS from spindles and put the data on faster solid state LUNs if you like.


Mifare ultraligtht and APDU commands

Question: I am looking for a list over various APDU commands, supported by the mifare ultralight cards,
I have tried to search for how to lock bytes, making them permanently readonly, but so far unable to find anything, is it even possible to set any of these blocks to readonly, or is there even a permanently reset card to 0 ?
thanks again
Answer: All the information you are looking for are in the document "NFC Forum Type 2 Tag Operation Specification 1.1"
Here is a copy:
http://apps4android.org/nfc-specifications/NFCForum-TS-Type-2-Tag_1.1.pdf
In general, if you are looking for technical details, try the NFC Forum specifications first. You'll find pretty much everything NFC related in them.
Answer: I am not sure whether by using APDU command you mean 'command' or 'ISO/IEC 7816-4' APDU command.
But Mifare ultraligtht does not support ISO/IEC 14443-4 so they cannot support 'ISO/IEC 7816-4/smartcard' APDU.
See this Mifare family comparison table to see which Mifare support APDU: http://cache.nxp.com/documents/line_card/MIFARE_ICs_939775017001_v9_HR.pdf
As said in another message, have a look at NFC Type 2 (http://apps4android.org/nfc-specifications/NFCForum-TS-Type-2-Tag_1.1.pdf).
Or have a look at one of the Mifare Ultralight datasheet: http://cache.nxp.com/documents/data_sheet/MF0ICU2.pdf.

Mifare ultraligtht and APDU commands


Property of a plane domain in $\mathbb{C}$

Question: A plane domain $D$ has the property that each point $z$ of $C \setminus D$ is contained in some unbounded, connected subset $A_z$ of $C \setminus D$.  Prove that $D$ is simply connected.
A domain is an open connected set.
A domain $D$ is said to be simply connected if every closed, piecewise smooth path is homologous to 0 in $D$.
My first idea was to consider a point $z_0 \in C\setminus D$.  Then $z_0 \in A_{z_0}$. This means that for any path $\gamma \in D$ we have $n(\gamma, z_0)=0$.  I'm not sure where to go from here, and I'm also worried since I barely used any of the assumptions.
Comment: Let $D$ be the union of the unit disk centered at $-2$ and the unit disk centered at $2$.  $D$ is clearly disconnected, but $\mathbb{C} \setminus D$ is both unbounded and connected.  What are you missing in the definition or problem statement?
Comment: A domain $D$ is a open, connected set.  So your example doesn't work.
Comment: Ah.  A definition.  Are open, connected sets bounded?
Comment: Yes, at least the ones I keep thinking about are.
Comment: Is the set $-1 < \Re(z) < 1$ open and connected?
Comment: I'm assuming that $\R(z)$ means real part of $z$?  If so, that's a band that is symmetric about the y-axis.  It's connected, open, and not bounded.
Comment: Do you believe in the 1-point compactification of $\mathbb{C}$?  If so, does this connect all the $A_z$ through the point at infinity?  (They're incident to it since they're all unbounded.)
Comment: If so, the boundary of $D$ is homeomorphic to a circle on the Riemann sphere...
Comment: What you are discussing is far beyond the scope of what I've studied so far in Complex.
Comment: What sorts of tools are you getting to?
Comment: The most advance tool I have is the discussion of cycles and the global cauchy integration formula/theorem.
Comment: If there were a bounded connected piece of $\mathbb{C} \setminus D$, call it $B$, and a $z_0 \in B$, then there would be a path in $D$ (since $D$ is connected) completely encircling $z_0$.  This loop would not contract to 0 because it cannot contract through $B$, nor can it contract through infinity to collapse "on the other side".  For $A_z$s as given, any such loop must pass through the point at infinity, which they cannot.  The set of all paths in $D$ therefore contains no uncontractible loops.
Comment: Let me make sure I understand.  We haven't delved into discussions of paths going to infinity.  So we suppose to the contrary that abounded $B$ would exist and that $z_0$ is in $B$.  Then we can find a path $\gamma$ in $D$ such that $z_0$ is interior to this path.  I'm not sure how to incorporate the unboundedness of $A_{z_0}$.
Comment: If $A_{z_0}$ is unbounded, there is a path connecting $z_0$ to infinity lying in $A_{z_0}$.  Can the loop cross this path?
Comment: Well no.  So basically it's as if there is a path just jetting out in one direction since $A_{z_0}$ is connected.
Comment: Yup.  Is that enough to get you rolling?  I.e., there are no loops in $D$, since those would encircle a $z_0$.  But that $z_0$ is connected to $\infty$ by a path in $A_{z_0}$ which would be crossed by the assumed loop, so the loop does not exist.  Thus every loop in $D$ is contractible to $0$.
Comment: We haven't mentioned contractability.  But this is enough to get me started.  Thanks.
Comment: The statement you are trying to prove is equivalent to the Jordan curve theorem.  It cannot be proved using the elementary geometric arguments described in the comments, but there is probably a way to do it using the Cauchy integral theorem.
Answer:
A domain $D$ is said to be simply connected if every closed, piecewise smooth path is homologous to $0$ in $D$.

That means your first idea is effectively the solution, you just need to recognise that, and write it up properly.
Let $\gamma$ be a piecewise smooth closed path in $D$. Then for every $z_0\notin D$, the winding number $n(\gamma,z)$ is constant on the connected set $A_{z_0}$. Since $A_{z_0}$ is unbounded, there are points $w\in A_{z_0}$ with $\lvert n(\gamma,w)\rvert < 1$. [I leave out a few steps now ...] Therefore $\gamma$ is homologous to $0$ in $D$. Since $\gamma$ was arbitrary, $D$ is simply connected.


Get a contextual filter for a View in Drupal 8

Question: I'm converting a module from D7 to D8 for a client. Some of the code is working programmatically with views - something I haven't done that much in D7, since I just write my own queries.
In the code is this line:
$contextual_filter = method_exists($view, 'get_items') ? $view->get_items('argument', $display->id) : 0;

I need to convert this to D8, but I'm not sure entirely what I'm working with here.
What I do know:

In D8, $view is an object of type Drupal\views\ViewExecutable
In D8, there is no get_items() method, nor a getItems() method on ViewExecutable
ViewExecutable has a property, args, and also a property argument

My questions:

How can I get the items from ViewExecutable
How can I get the contextual filter from ViewExecutable
Do I even need to do #1 to get #2?

Further down the code, I can see that $contextual filter is used as follows:
'contextual_filter' => !empty($contextual_filter) ? 1 : 0

So it would appear I'm just trying to get a boolean indicating whether or not a contextual filter exists.
Can anyone who has worked more with D7 Views more than I give me some insight as to what is happening with this code, and ideally how I can update it to D8? (Though insight as to what is happening in D7 may be enough for me to figure it out in D8).
Answer: In D8 the settings of a view are stored in a configuration entity. You can load the entity with View::load() or get it from the view executable directly and then load a display and check the contextual filters (stored in the key arguments of the display options):
$storage = $view->storage;
$display = &$storage->getDisplay('default');
$arguments = $display['display_options']['arguments'];

'contextual_filter' => !empty($arguments) ? 1 : 0


Removing finitely many points from a connected manifold (dimension greater then 2) remains connected?

Question: I think yes. Here is my approach.
As we know manifolds are locally Euclidean, Suppose we remove a point say $p$ from the manifold M then $p$ has a neighbourhood say U which is homeomorphic to an open subset V of $R^{n}$, let $\phi$ be the homeomorphism between them. Then, Consider any continuous map,
$ f: V-\phi(p) \rightarrow \{0,1\}$ where {0,1} has the discrete topology.
Then, it suffices to show that the map $f$ is constant.
Suppose $f$ is not constant then $\phi^{-1}(0)$ and $ \phi^{-1}(1)$ are not empty open sets in $V-\phi(p)$ more precisely $V-\phi(p)=\phi^{-1}(0) \cup \phi^{-1}(1)$. So, $\phi^{-1}(0)$ is a non trivial clopen set. Hence a contradiction.
And f is constant.
Now, $U$ is connected. I don't know how's to proceed and extend it to the whole manifold?
Thanks for any help!
Answer: Hint: Things get much easier if you use that a manifold is connected if and only if it is path connected.


What the function data.groupby(cuts).outcome.agg does in the pandas library?

Question: please, I can't understand what this function does.
here is the code context:
    #group outcomes into bins of similar probability
    bins = np.linspace(0, 1, 20)
    cuts = pd.cut(prob, bins)
    print(cuts)
    binwidth = bins[1] - bins[0]

    #freshness ratio and number of examples in each bin
    cal = data.groupby(cuts).outcome.agg(['mean', 'count'])
    print(cal['count'])
    print(cal['mean'])
    cal['pmid'] = (bins[:-1] + bins[1:]) / 2
    cal['sig'] = np.sqrt(cal.pmid * (1 - cal.pmid) / cal['count'])

    #the calibration plot
    ax = plt.subplot2grid((3, 1), (0, 0), rowspan=2)
    p = plt.errorbar(cal.pmid, cal['mean'], cal['sig'])
    plt.plot(cal.pmid, cal.pmid, linestyle='--', lw=1, color='k')
    plt.ylabel("Empirical Fraction")

Comment: Do they not provide documentation for their APIs?
Answer: data is a DataFrame containing a column named outcome. The salient part of your code is:
cal = data.groupby(cuts).outcome.agg(['mean', 'count'])

What this does is, in order:

Group your data based on the entries in the "cuts" column (further reference).
Fetch the SeriesGroupBy corresponding with the "outcome" column.
Create a DataFrame with two columns, "mean" and "count", applied to each group in your SeriesGroupBy (see e.g. here).
Assign that to the cal variable.


How to select all tables based on the inserted data in sql server

Question: problem : Fetching all tables based on the data in columns.
Trying for something to simplify the search.
as a new developer i don't know which tables will get inserted into the database.
by this time i only know what is the data entered for example: abcd
in reverse way i would like to search this text is inserted into couple of the tables.
tried some thing like
select * from sys.tables where name like '%%' providing all the tables.
like that is there any way to search the data in the database?
Comment: Possible duplicate of http://stackoverflow.com/questions/436351/how-do-i-find-a-value-anywhere-in-a-sql-server-database
Answer: <code>CREATE PROC SearchAllTables
(
    @SearchStr nvarchar(100)
)
AS
BEGIN

-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Tested on: SQL Server 7.0 and SQL Server 2000
-- Date modified: 28th July 2002 22:50 GMT

DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630))

SET NOCOUNT ON

DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET  @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
    SET @ColumnName = ''
    SET @TableName =
    (
        SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
        FROM    INFORMATION_SCHEMA.TABLES
        WHERE       TABLE_TYPE = 'BASE TABLE'
            AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
            AND OBJECTPROPERTY(
                    OBJECT_ID(
                        QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME)
                         ), 'IsMSShipped'
                           ) = 0
    )

    WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
    BEGIN
        SET @ColumnName =
        (
            SELECT MIN(QUOTENAME(COLUMN_NAME))
            FROM    INFORMATION_SCHEMA.COLUMNS
            WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                AND TABLE_NAME  = PARSENAME(@TableName, 1)
                AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                AND QUOTENAME(COLUMN_NAME) > @ColumnName
        )

        IF @ColumnName IS NOT NULL
        BEGIN
            INSERT INTO @Results
            EXEC
            (
                'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                FROM ' + @TableName + ' (NOLOCK) ' +
                ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
            )
        END
    END
END

SELECT ColumnName, ColumnValue FROM @Results
END
</code>

Got from stack over flow , it will be so much use full. let me share to my friends also.


How can I capture traffic with tcpdump and a sliding window or sort of "logrotate"?

Question: I want to capture some traffic with tcpdump for troubleshooting. The problem is, the error is not reproducible. To not fill up the hole disks with captures, I would like to capture the traffic with some sort of sliding window.
Let's say I write the capture to a file and when the file reaches a size of 1GB it will drop the oldest packets and write the new ones. This way I would only get the traffic for some hours but hopefully enough to have the right packets when the user calls.
I couldn't find an option for tcpdump. Has someone an idea how to solve this?
Answer: The -c option can help you with this:
   -c     Exit after receiving count packets.

So this would get you a circular traffic.dmp file:
while :
do
 tcpdump -i eth0 -c 50000 -C 1 -w traffic.dmp
done

If you dropped it in a for loop you could get a series of files:
for file in 1 2 3 4 5
do
 tcpdump -i eth0 -c 50000 -C 1 -w traffic${file}.dmp
done

.  Just adjust the numbers after you figure out some number that is not to big for your disk to capture a few hours worth of packets.
-C also looks interesting:
   -C     Before writing a raw packet to a  savefile,  check  whether  the
          file  is  currently  larger than file_size and, if so, close the
          current savefile and open a new one.  Savefiles after the  first
          savefile  will  have the name specified with the -w flag, with a
          number after it, starting at 1 and continuing upward.  The units
          of  file_size  are  millions  of  bytes  (1,000,000  bytes,  not
          1,048,576 bytes).

Comment: Thanks davey. With a larger number of small files, I should get very close to a sliding window. I hope the merge will work when I have to cancel recording while writing file x from x+20.
The option '-W filecount' sounds very promising. This should get me to the sliding window. I should have read more of the man page before asking.
Answer: If you insist on using tcpdump, davey's answer is the right one. However, there are other capture packets, producing pcap files, with more options for this sort of work. Let's mention:

tshark, part of the Wireshark program. Its -a ("Stop writing to a capture file after it reaches a size of value kilobytes") and -b ("When the first capture file fills up, TShark will switch writing to the next file
       and so on") options seem particularily interesting
pcapdump, part of the pcaputils package. See the configuration options interval= (move to the next file after N seconds of capture) and filefmt= (pattern to generate the name of the capture files).


Number of products a * b giving a chosen value n in a finite field Fp

Question: Given a finite field $F_p$ for a prime number $p$, and a value $n \in F_p$, I was wondering about the number of pairs $(a,b)$ which product equals $n$.
As an example, in $F_7$, and for $n = 4$, there are (to my knowledge) 4 different (distinct) pairs of integers satisfying the relation :
$$2 \times 2 \\
1 \times 4\\
5 \times 5\\
6 \times 3$$
where the two last solutions are the pairs $(-a,-b)$ of the previous solutions. It is quite easily verifiable for small values of $p$, but what about the general case? Is there a result about the number of such pairs? Or at least some (interesting) bounds?
Comment: wouldn't $n=(a)(na^{-1})$ for all $ a \neq 0$ in the field?
Comment: Sorry if I was not specific. I am asking about distinct pairs (I don't want to count (b,a) if (a,b) already appeared previously).
Answer: For $n=0$ the pairs are clearly
$$\{ (0,a): a \in \Bbb F_p\}$$
i.e. you have $p$ pairs.
If $n$ is not a square $\pmod p$ (and $n \neq 0$) you have
$$\{ (a,b) : ab=n\} = \{ (a, a^{-1}n): a \in \Bbb F_p^{\times} \}$$
has $p-1$ elements. Since you are considering $(a,b)=(b,a)$, simply divide by $2$ and you get that your pairs are $\frac{p-1}{2}$.
In a similar way you can show that, if $n$ is a (nonzero) square $\pmod p$ you have $\frac{p+1}{2}$ pairs.
Comment: Thanks! do you have any link to an explanation for the square consideration? :)
Comment: You write $n=m^2$ and consider $\{ (a,n^{-1}a) : a \neq \pm m , a \neq 0 \}$. This set has $p-3$ pairs, made of distinct elements (i.e. $(a,b)$ with $a \neq b$). Divide by 2, and then add the two pairs $(m,m)$ and $(-m,-m)$. The total is $$\frac{p-3}{2}+2= \frac{p+1}{2}$$


change css link and wait till new css is loaded

Question: I wonder whether it's possible to change stylesheet link of the loaded document, then wait till the new css is loaded, and then run appropriate js code
thanks for any suggestions
Comment: http://www.w3.org/community/webed/wiki/Dynamic_style_-_manipulating_CSS_with_JavaScript#Accessing_style_sheets
Answer: html:
<link id="mystylesheet" href="/path/to/css.css" />

code:
$("#mystylesheet").load(function(){
  //Your javascript
}).attr("href", "/new/path/to/css.css");

This will replace your current CSS, and execute any code within the .load() handler after the new CSS file has been fetched.
Comment: @ahren does this solution wait until the CSS is applied? If not, is there a way to do that?
Comment: FYI this doesn't work for mobile devices .. see my revised answer below that works for a wider browser range
Answer: @ahren had it almost correct.  However using a callback when the css file is finished loading via dynamically changing the href on a link element DOES NOT seem to work on most mobile devices.
Instead try directly injecting the style into a style element using load .. ends up being supported by most modern browsers including mobile ones
UPDATED to include support for IE 8- ; NOTE this requires you to inject a dummy rule into your css to verify when the css is loaded (in this case use body {ready:true;})
css
body {ready:true;}
...

html

javascript
if (document.createStyleSheet) {

    //Wait for style to be loaded
    var wait = setInterval(function(){
      //Check for the style to be applied to the body
      if($('body').css('ready') === 'true') {
        clearInterval(wait);

        //CSS ready
      }
    }, 300);

    document.createStyleSheet(url);
} else {
    //Dynamically load the css for this doc
    $("#your-style-element").load(url,function(){

       //CSS ready
    });
}

Comment: does `.load()` fire after the CSS rules are applied? If not, is there a feasible way to do so?
Comment: FYI ... just make sure to note that any urls referenced within the css will be relative to the page NOT the location of the css file
Comment: @Kragalon I bet you could check a specific style attribute (that you know exists in a remote stylesheet) once per frame (using `requestAnimationFrame` in a loop) until the expected value is active. :)
Answer: Try this man: http://forum.jquery.com/topic/loading-stylesheets-on-the-fly
or : http://www.rickardnilsson.net/post/2008/08/02/Applying-stylesheets-dynamically-with-jQuery.aspx or Changing a stylesheet using jQuery
Hope it fits the cause :)
Code
var link = $("<link>");
link.attr({
        type: 'text/css',
        rel: 'stylesheet',
        href: <your CSS file url>
});
$("head").append( link );

Answer: You could try a plug-in I wrote specifically for this case.
Not sure about the .load() method of jQuery, it doesn't seem to be cross-browser. Only IE supports onload="" event on the link elements, afaik.
Answer: Here's a gist I wrote that works perfect in just 47 LOC:
https://gist.github.com/aleclarson/ac6456c75edae9fe9d9b6938142a065b
It uses requestAnimationFrame to check document.styleSheets on every frame until every given URL fragment has been loaded.
Example:
const styles = require('./styles')
const promise = styles.onLoad('foo.css', 'bar.css')
promise.then(() => console.log('Styles loaded!'))

Pure javascript, too!
Answer: TeaCoder has a good answer to this question over at https://stackoverflow.com/a/35644406/20774.
Basically use the elements onload method and put the logic you want to happen after the style loads there.
It's a nice way to use built in DOM capabilities to do it, but the callback syntax is a little awkward. Here is how I did it with Promises:
const createOnLoadPromise = (htmlElement) =>
  new Promise((resolve) => {
    htmlElement.onload = resolve;
  });
const link1 = document.head.appendChild(createStyleLink(href1));
const link2 = document.head.appendChild(createStyleLink(href2));
await Promise.all([
  createOnLoadPromise(link1),
  createOnLoadPromise(link2),
]);
// do whatever you need to do after the await


Integral Form of the Remainder of the Taylor Series

Question: If $g$ has 1 derivative on an open interval $I$ that contains the point $a$, then for each $x\in I$ the taylor polynomial gives $g(x)=g(a)+R(x)$ with $R(x)=\int_a^x g'(t)(a-t)^0\,dt$. My question is when $x=a$ is it we follow the convention that $(a-a)^0=1$ in $R(x)$, so that $R(a)=\int_a^a g'(t)(a-t)^0\,dt=0$?
Answer: The convention throughout when working with power series is that when $(x-a)^k$ appears and it so happens that $x=a$ and $k=0$, the term is interpreted as $1$, yes. (Rationale: Certainly $(x-a)^0=1$ for all $x\ne a$, and power series certainly should be continuous on the interval of convergence.)
Comment: When $x=a$, is it we are not able to use the lagrange form of the remainder, $R(x)=\frac{g'(c)}{(n+1)!}(x-a)^{n+1}$, where c is a point between x and a?
Comment: Well, at $a$ itself, there is no error, so remainder formulas would be silly :)


How to change variables in a surface integral without parametrizing

Question: This is a doubt that I carry since my PDE classes.
Some background (skippable):
In the multivariable calculus course at my university we made all sorts of standard calculations involving surface and volume integrals in $R^3$, jacobians and the generalizations of the fundamental theorem of calculus. In order to make those calculations we had to parametrize domains and calculate differentials.
A couple of years later I took a PDE course. We worked with Evans' Partial differential equations book. This was my first experience with calculus in $\mathbb R^n$ and manipulations like
$$\text{average}\int_{B(x,r)}f(y)\,dy= \text{average}\int_{B(0,1)}f(x+rz)\,dz.$$
This was an ordinary change of variables. $y=x+rz,\,\,dy=r^n\,dz$ and the mystery was solved. Like in that case, I was able to justify most of these formal manipulations after disentangling definitions.
That aside, I found these quick formal calculations to be very powerful.
However,
I realized that I wasn't able to justify this:
$$\text{average} \int_{\partial B(x,r)}f(y)dS(y)= \text{average}\int_{\partial B(0,1)}f(x+rz)\,dS(z).$$
I have some vague idea of what's happening: the same substitution as before, but this time the jacobian is $r^{n-1}$ because the transformation is actually happening between regions which "lack one dimension". Also, I see some kind of pattern: a piece of arc-length in the plane is $r\,d\theta$, a piece of sphere-area is $r^2 \sin\theta \, d\phi \,d\theta$, "and so on". Maybe some measure-theoretic argument can help me: I know, roughly speaking, that for any measure $\mu$, $$\int_\Omega f\circ \phi \,d\mu=\int_{\phi(\Omega)} f \, d(\mu\circ\phi^{-1}).$$ I'd say $\phi(z)=(z-x)/r$ and $\phi^{-1}(y)=ry+x$, but I actually don't know how $dS(y)$ looks like "as a measure" (It's not a product measure or a restriction of one, but it somehow relates to Lebesgue's in $\mathbb R^n$...). Why would I conclude that $dS(y)\circ \phi^{-1}=r^{n-1}dS(z)$? I have an intuition, but either I lack the mathematical concepts and definitions to express it or I'm just too confused. Is there some theory that I could learn in order to understand? Maybe something about the measure $dS$. Is it expressible in terms of the Lebesgue measure in some way? Or set-theoretically, maybe, without having to resort to $n-1$ parameters and complicated relations?
Maybe all of this would not have been a problem if I had ever mastered n-dimensional spherical coordinates. But even so, more generally, is there a way of changing variables when I'm integrating over a subregion of "dimension$<n$" without necessarily parametrizing?
Sorry for the vagueness, but I don't really know what to ask for exactly.
Note: I saw some of the answers to this post, but none of them were deep enough in the direction I intend.
Note II: If there are no general methods or theories, maybe restricting to linear transformations, to Lebesgue measure exclusively, or to subregions defined by simple expressions like $g(x)=C$ or $g(|x|)=C$ could get me somewhere.

Edit: I have not yet studied differential geometry, which has been mentioned in a comment. I added it to the tags.
Comment: There is a unifying framework for the question that's bothering you, [tag:differential-geometry]. In this case, we think of $dS$ as an "$(n-1)$-differential form" in $\Bbb R^n$, and integrate it along the "$(n-1)$-chain" which is your sphere. What you require is called a "pull-back" of $dS$ via the differentiable mapping $y\mapsto x+ry$. Hopefully, this might point you in the right direction.
Comment: @dafinguzman myself, I like Spivak's "calculus on manifolds" or "comprehensive introduction to differential geometry". You're looking for integration on chains/manifolds and the (proper instance of the) change of variable theorem.
Comment: @JonathanY. Do you know any good books on the subject? Rigorous, with good prose, motivations, nice examples, maybe even illustrations (not a requirement, though). Also, is this some specific subtopic? The [Wikipedia article](http://en.wikipedia.org/wiki/Differential_geometry) mentions "Riemannian manifolds", "tensors", the *Theorema Egregium*, and "symplectic geometry". I wouldn't know exactly where to put my attention.
Comment: While I haven't formally studied differential geometry in its broadest setting, I have used parts of it and in this aspect the books [Introduction to Smooth Manifolds](http://www.amazon.com/Introduction-Smooth-Manifolds-Graduate-Mathematics/dp/1441999817/ref=pd_bxgy_b_text_z) and [Riemannian Manifolds](http://www.amazon.com/Riemannian-Manifolds-Introduction-Curvature-Mathematics/dp/0387983228/ref=sr_1_1?ie=UTF8&qid=1392279234&sr=8-1&keywords=john+lee+riemannian+manifolds) by John Lee were very...smooth. =)
Comment: seeing as this just got bumped to the home page, I thought I should just mention: the $dS$ you see can be interpreted in two ways, the first is as a differential form (of appropriate dimension assuming the submanifold is orientable... which the spheres are) or you can view this as a measure induced on the submanifold via the natural metric tensor. This is just a special case of a more general phenomenon: over any (pseudo-Riemannian) manifold, one can use the metric tensor to define a "Lebesgue"measure. Using the Radon-Nikodym derivative one can then formulate a change of variables theorem.
Comment: Thank you @peek-a-boo. Could you point to a source for checking out these perspectives?
Comment: I don't really have a specific source because my understanding is derived from several sources on multivariable calculus, differential geometry and real analysis (eg Loomis and Sternberg's advanced calculus, Spivak's Calculus on Manifolds, Amann and Escher's Analysis Vol III chapter 12, Dieudonne's vol III, Folland's real analysis, Lee's smooth manifolds etc). You might want to start from [this answer](https://math.stackexchange.com/a/4059532/568204) and mayble followup with [this one](https://math.stackexchange.com/a/4059532/568204). If you have a more specific qn I'd be happy to answer.
Comment: I guess the closest of these would be Loomis and Sternberg's chapter 10 where they talk about densities and Riemannian volume densities (they don't really talk about measures, but if you have some measure theory background you can easily fill in the detals). Also, Amann and Escher's book is very measure-theory oriented so you can learn a lot of the basic definitions there. Unfortunately none of these sources talk about the change-of variables theorem in the language of measure theory and Radon-Nikodym derivatives (presumably because measure-theory itself is a huge prerequisite).
Comment: I just realized I put the same link twice, my bad, the second link should be [this](https://math.stackexchange.com/a/4138970/568204). (it's about a slightly different and more difficult form of change of variables/Fubini, but some of the ideas are still there).
Comment: That's interesting @peek-a-boo. Those answers are far more advanced than what I had in mind when I asked the question, but thanks for sharing! I appreciate.
Answer: I know this is an old question, but I thought this explanation might be helpful to some.

By definition (in $\mathbb R^3$):
$$\int_{\partial B(\boldsymbol x,r)}f(\boldsymbol y)dS(\boldsymbol y)=
\int_U f(\boldsymbol y(s,t))\left\|\frac{\partial\boldsymbol y}{\partial s}\times\frac{\partial\boldsymbol y}{\partial t}\right\|dsdt$$
Now, observe that $f(\boldsymbol y)=f(\boldsymbol x+r(\frac{\boldsymbol y-\boldsymbol x}{r}))$, and that if $\boldsymbol y(s,t)$ is a parametrization of $\partial B(\boldsymbol x,r)$ for $(s,t)\in U$, then $\frac{\boldsymbol y(s,t)-\boldsymbol x}{r}$ is a parametrization of $\partial B(\boldsymbol 0,1)$ for $(s,t)\in U$. Finally we observe that
$$\left\|\frac{\partial\boldsymbol y}{\partial s}\times\frac{\partial\boldsymbol y}{\partial t}\right\|=
r^2\left\|\frac{\partial}{\partial s} \left (\frac{\boldsymbol y-\boldsymbol x}{r} \right )\times\frac{\partial }{\partial t} \left (\frac{\boldsymbol y-\boldsymbol x}{r} \right )\right\|$$
So if we let $\boldsymbol z(s,t)=\frac{\boldsymbol y(s,t)-\boldsymbol x}{r}$, then we have
$$\int_U f(\boldsymbol y(s,t))\left\|\frac{\partial\boldsymbol y}{\partial s}\times\frac{\partial\boldsymbol y}{\partial t}\right\|dsdt=
r^2\int_U f(\boldsymbol x +r\boldsymbol z(s,t))\left\|\frac{\partial\boldsymbol z}{\partial s}\times\frac{\partial\boldsymbol z}{\partial t}\right\|dsdt\\=
r^2\int_{\partial B(\boldsymbol 0,1)}f(\boldsymbol x+r\boldsymbol z)dS(\boldsymbol z)$$

Edit by OP
As @user5753974 commented, you can generalize this if you use the fact that in $\mathbb R^n$ $$∫_{∂B(\boldsymbol x,r)}f(\boldsymbol y)dS(\boldsymbol y)=∫_{U}f(\boldsymbol y(\boldsymbol z)) \left \|\det\left (\frac{∂\boldsymbol y}{∂z_1},…,\frac{∂\boldsymbol y}{∂z_{n−1}},\boldsymbol n\right) \right \| d^{n−1}\boldsymbol z,$$ where $\boldsymbol n$ is the normal vector to the surface, and that $\boldsymbol n$ does not change when the surface is scaled and translated.
Comment: @dafinguzman I think you can generalize if you use the fact that in $\mathbb R^n$
$\int_{\partial B(\pmb x,r)}f(\pmb y)dS(\pmb y)=
\int_U f(\pmb y(\pmb z))\left|\det\left(\frac{\partial\pmb y}{\partial z_1},
\dots,\frac{\partial\pmb y}{\partial z_{n-1}},\pmb n\right)\right|d^{n-1}\pmb z$, where $\pmb n$ is the normal vector to the surface, and that $\pmb n$ does not change when the surface is scaled and translated.
Comment: This is great! I see that the cross product gets in the way of immediately generalising this reasoning to $\mathbb R^n$. I'm guessing this is more or less the role of the wedge products in Gil Bor's answer.
Comment: @user5753974 Hi, is $\pmb z$ a $(n-1)$-tuple? And does $d^{n-1}\pmb z$ mean $dz_1 dz_2 ... dz_{n-1}$? Thanks!
Comment: Yes @SamWong, to both. Also, after adding user5753974 's comment I'm going to accept this answer, as it is the closest to what I had in mind when I originally asked the question. The definition of $dS$ in $\mathbb R^n$ with the determinant was probably the most important element I was missing in those days.
Answer: No parametrization is needed, just some careful uncovering of definitions. Maybe the following can help:
Let $S^n(r)=\{x\in\mathbb R^{n+1}|\|x\|=r\}\subset\mathbb R^{n+1}$ (the sphere of radius $r>0$ centered at the origin).
There is a natural volume form $\mu_{r}$ on  $S^n(r)$,  i.e. a nowhere-vanishing $n$-form, induced by the volume form $\mu=dx_1\wedge\ldots \wedge dx_{n+1}$ on  $\mathbb R^{n+1}$ and the  "outward" unit normal $N:S^n(r)\to\mathbb R^{n+1}$,  $N(x)=x/r$, and is defined as follows:
$$\mu_r(x)(v_1,\ldots,v_n):=\mu(x)(N(x), v_1, \ldots, v_n)$$ for all $v_1, \ldots, v_n\in T_x S^n(r).$
(More informally, we write $\mu_r=\mu/dr$. Note that $dr(N)=1$).
Next let  $\Phi:S^n(1)\to S^n(r)$ be defined by $\Phi(x)=rx$. Then $$\Phi^*\mu_r=r^n\mu_1. $$ This you can prove without any parametrization, just from the definitions above and generalities like  the chain rule, pull back, etc.
It then follows, by the change of variables formula, that for any continuous function $f:S^n(r)\to\mathbb R$, $$\int_{S^n(r)}f\mu_r=\int_{S^n(1)} \Phi^*(f\mu_r)=r^n\int_{S^n(1)} (f\circ\Phi) \mu_1.$$
Makes sense?
Comment: @dafinguzman: sorry, cannot elaborate, it's too long. I am using standard language taught in most  differential geometry courses. You need to take such a course or pick a textbook  (popular ones are  Spivak, Lee, Guillemin+Pollack. My personal favorite is Arnold's mathematical methods of classical mechanics, intuitive and rigorous at the same time; but it's not easy as a first textbook). Now I am sure it is possible to translate my answer to a more elementary language (although less rigorous). Perhaps another user of the site will try to do it (or even myself if I find the time and energy).
Comment: OK, after a long time I read through some chapters of Spivak's Calculus with Manifolds and now I get what you are trying to say. Trying to adapt to the definitions in Spivak, though, I find that $(\Phi ^ * \mu_r)(x)((v_1)_x,..., (v_n)_x) = r^n \mu (rx) (x, (v_1)_{rx}, ..., (v_n)_{rx})$. Then I'm tempted to say that equals $r^n \mu (x) (x, (v_1)_{x}, ..., (v_n)_{x})$ by "invariance of $\mu$ under translations", which is known for Lebesgue measure in $R^n$. Is that correct? Thanks for your answer: once the definition of "$dS$" is made explicit everything becomes clearer.
Comment: Could you maybe elaborate some definitions? I don't know what $n$-forms, $T_x$ or "pull back" are. As you present it, it seems that $\mu$ is a product measure, somehow. Also, I don't know what $dr(N)$ is supposed to mean. I can guess it means (by the notation) that "surface infinitesimal elements" get amplified by $1$ near the points which are on the sphere.
Answer: I think the measure theoretic approach works fine, note that the surface measure is n-1 dimensional Hausdorff measure, in general for the s-dimensional Hausdorff measure we have $H^{s} (rA)=r^{s} H^{s}(A)$ and this measure is translation invariant. Now use the measure theoretic change of variable formula.
Comment: Does this mean that the measure $dS$ in the integral over $\partial B$ is the $n-1$ dimensional Hausdorff measure? I hadn't thought of it that way.
Comment: Yes, the surface measure $dS$ which is used on the boundary of n-dimensional objects  is exactly the $n-1$ Hausdorff measure on the boundary.


Correlation Between Locations

Question: I have two data sets both matrices of latitudes and longitudes.

$A = [(X,Y),(X_2,Y_2)]$

$B = [(X_3,Y_3),(X_4,Y_4),(X_5,Y_5)]$
They are of different sizes
I want to calculate by how much each of the pairs of (x,y) coordinates in A correlate with all of those in B.
So then can order A by those that correlate most closely with B.
I imagine it working a bit like B is used to create a heat map of the locations. So where there are more location clustered together in B the heat map has a higher value. Then each value of A is given a value based on what part of the heat map it is on.
Comment: Correlation is defined between two random variables. So, it is not obvious what do you mean by the correlation between a point and a set. Do you mean the distance?
Comment: It is better to add the above comments into your question.
Comment: What are you asking, exactly?  The procedure you describe at the end sounds like you will compute a density on the sphere (aka "heat map") based on the $B$ data and then assign those densities to the points in $A$--but that appears to have little to do with any of the preceding descriptions which refer to "correlate" and "order."
Answer: First of all, to compute distance between two latitude-longitude points refer to this stackoverflow question.
Here are two ideas for your question:

For each point $(X,Y)$ in $A$, find the $k$ points in $B$ that are nearest to $(X,Y)$. Then compute the distances between $(X,Y)$ and each of these points and then average these $k$ distances to find a measure of how much $(X,Y)$ is near to the points in $B$. This approach is similar to KNN algorithm in data mining. Here $k$ is a parameter which you should choose according to your application.
Cluster the points in $B$ using a density-based clustering approach such as DBScan, or a grid-based clustering such as STING, or a partitioning-based algorithm such as k-means. Then, for each point $(X,Y)$ in $A$, find the cluster which this point belongs to, and compute the distance between $(X,Y)$ and the center of that cluster. Alternatively, you can compute the average distance between $(X,Y)$ and all points in that cluster.
Comment: Given that $(X,Y)$ are latitude and longitude on a sphere (or spheroid), please explain why you recommend computing *euclidean* distances and what those might actually mean.
Comment: Just a misunderstanding. The answer is edited.

Correlation Between Locations


Allow users to set permissions for profile fields

Question: I would like users to be able to determine whether a field is displayed publicly. For example, their real name is required for the site, but I don't want to force users to display it.
Comment: What version of Drupal? Are you using the core profile module or a contrib module such as content profile?
Answer: Without information on what version of Drupal you are using or what you are using for profiles, here is a suggestion for each type of profile on Drupal 6:
Using the core profile module, check out Profile Privacy
Using Content Profile, take a look at CCK Privacy


React said: "Can not find namespace..." in creation of Context

Question: I create a Context in React.js with TypeScript but this error had occurred:
Cannot find namespace 'JobContext'.ts(2503)
import React, { createContext, useState }       from 'react';

export const JobContext = createContext<any>({});

const JobContextProvider = ({ children }) => {

    const [data, setData] = useState<any>();

    const updatingState = (newData) => setData({ ...data, ...newData });

    return (
        <JobContext.Provider value={{data, updatingState}}>
            {children}
        </JobContext.Provider>
    );

};

export default JobContextProvider;

Answer: Because as React has said, the extension of your file is .ts, which should be  .tsx.
Comment: Hours and hours again to find this solution Many thanks
Comment: OH MY GOD. this save me.. really save me


If $P(A|D) > P(A)$ and $P(B|D) > P(B)$, then is $P(A \cap B|D) > P(A \cap B)$?

Question: There are 3 events $A, B, D$ such that $D$ makes $A$ more likely and $D$ makes $B$ more likely. Does this mean that $D$ makes it more likely that both $A$ and $B$ occur? How can you prove this using mathematical formalism to prove it if it's true or what counter example makes it false?
Comment: Draw a Venn diagram and attempt to construct a counterexample from what it shows you.  Consider a case where $A\cap B \cap D=0.$
Comment: I helped you did formatting with MathJax this time.  Going forward, please make sure your math expressions are formatted properly.
Answer: If inequalities are strict, then counter examples are easy to make. For example, consider $\Omega = \{1, 2, 3, 4, 5\}$ where $P(\{1\}) = P(\{2\}) = P(\{3\}) = P(\{4\}) = P(\{5\}) = 1/5$. Let $A = \{1, 2\}, B = \{4, 5\}$, $D = \{2, 4\}$. Then
$P(A|D) = 1/2 > P(A) = 2/5$, $P(B|D) = 1/2 > P(B) = 2/5$, while $P(A \cap B|D) = 0 = P(A \cap B)$, because $A \cap B = \varnothing$.
A more interesting question is thus whether $P(A \cap B|D) \geq P(A \cap B)$ holds given $P(A|D) \geq P(A)$ and $P(B|D) \geq P(B)$. This is still false, and we can tune the first counter example by making $A \cap B \cap D = \varnothing$ but pairwise intersection events $A \cap D$ and $B \cap D$ are not.  This can be done by setting $A = \{1, 3\}$, $B = \{3, 5\}$, and $D = \{1, 5\}$, under which $P(A|D) = 1/2 \geq P(A) = 2/5$, $P(B|D) = 1/2 \geq P(B) = 2/5$, but $P(A \cap B|D) = 0 < P(A \cap B) = 1/5$.


AWS DynamoDB Encryption Unable to parse HTTP response content

Question: I'm using DirectKmsMaterialProvider of aws-dynamodb-encryption-java to encrypt my data to be stored to dynamodb but upon calling mapper.save(objectToSave) I get the error below:
 final EncryptionMaterialsProvider provider = new DirectKmsMaterialProvider(awskmsClient,
                    awsKMSAliasKey);
            mapper  = new DynamoDBMapper(dynamoDBClient, mapperConfig,
                    new AttributeEncryptor(provider));

Error:
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException: com.amazonaws.AmazonServiceException: Unable to parse HTTP response content (Service: AWSKMS; Status Code: 302; Error Code: null; Request ID: null)
    at com.amazonaws.services.dynamodbv2.datamodeling.AttributeEncryptor.transform(AttributeEncryptor.java:67)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.transformAttributes(DynamoDBMapper.java:2414)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.transformAttributeUpdates(DynamoDBMapper.java:2446)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.access$200(DynamoDBMapper.java:185)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:1080)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:795)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:974)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:824)[63:express-server:0.0.1.SNAPSHOT]
    at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:669)[63:express-server:0.0.1.SNAPSHOT]

Answer: make sure that your KMS endpoint is correct
for example:
AWSKMSClient awsKMSClient = new AWSKMSClient(new InstanceProfileCredentialsProvider());
awsKMSClient.setEndpoint("kms.ap-southeast-1.amazonaws.com");

refer to http://docs.aws.amazon.com/general/latest/gr/rande.html#kms_region


Como posso fazer um conjunto de códigos PHP serem colocados para funcionar dentro de uma modal apenas ao chamá-la?

Question: Eu estou desenvolvendo minha primeira página de pagamento para o meu e-commerce (sou um programador iniciante).
Dentro desta página uma das formas de pagamento está dentro de uma modal feita em bootstrap.
O conteúdo desta modal são códigos em PHP que fazem o pagamento ser realizado.
O que ocorre é que, independentemente de abrir a modal ou não, o código PHP é chamado e colocado em ação. Quero que esse código seja posto em prática apenas ao abrir a modal.
Alguém pode me dar o direcionamento de como fazer isso?
Vou inserir uma imagem do código mostrando o início da modal só para ajudar no entendimento de como está o código PHP dentro dela.
Código PHP na modal
Answer: Se o seu arquivo for .php  com ou sem modal, a função PHP vai retornar um arquivo HTML.
Já quem faz a função de abri a modal é JavaScript.
Em resumo crie o arquivo completo .php e ele vai gerar seu HTML dinâmico.
Agora se você quer que a cada vez que abri o modal a pagina mude (dinâmica) de valor, ai é um processo com javascript via JSON + php, seria essa a alternativa.
Pesquise no google sobre dois assuntos:
==>> HTML Form JSON PHP
==>> Ajax Php
Tanto é possível enviar como receber dados via Json, mas ai é preciso um estudo aprofundado sobre o assunto.
Fazer o que você deseja é algo complexo de explicar, ou a sua pergunta não está bem formulada. Por favor não insira imagem, ao invés disso insira o código dentro da sua pergunta, isso facilita o entendimento e testes.


If $P$ is a projection operator, is $1-P$ also a projection operator?

Question: Show that if $P$ is a (hermitian) projection operator, so are (a) $1-P$ and (b) $$ U^{+}PU $$ for any operator $U$
Answer: Definition of projection operator is $P\circ P = P$, for (a) you can simply expand $(1-P)\circ (1-P)$ and find it holds true.  You have to define the notation $U^+$ to get an  answer for (b).
Comment: As per my understanding (1-P) (1-P) should be equal to 1-P for 1-P to be Projection.
(1-P) (1-P) = $$1^2-IP-PI+P^2$$
= 1+P
Correct me If i am wrong
Comment: @priyanka: Why would two minuses and a plus make one plus?
Comment: $(1-P)^2=1-2P+P^2=1-2P+P=1-P$
Comment: okay I may be wrong but I interpreted in this way:
1-IP+IP+P = 1+P
Comment: @priyanka: $I$ would hardly be an identity matrix if $P I = -I P = - P$ was valid.
Comment: I wonder I asked such a dumb question... I figured it out.... thanks guys :)
Answer: $$\begin{align}
(1-P)^2(x) &=(1-P) \circ ((1-P)(x)) \\
\implies (1-P)^2(x) &=(1-P) \circ (x-P(x)) \\
\implies (1-P)^2(x) &=(x-P(x))-(P(x)-P^2(x)) \\
\end{align}$$
Now using the fact that P is a projection operator, i.e. $P^2=P$, we get:
$$ \begin{align}
\implies (1-P)^2(x)&=(1-P)(x)-(P(x)-P(x)) \\
\implies (1-P)^2(x)&=(1-P)(x)\\
\end{align} $$
Hence we get $(1-P)^2=(1-P)$, which implies $(1-P)$ is a projection operator.


Altering the breadcrumb contents

Question: I'm trying to use this hook in order to alter a breadcrumb link :
hook_menu_breadcrumb_alter(&$active_trail, $item)

The hook don't seem to be called.
I've tried :

Using the hook on a theme
Using the hook on a custom module (breadcrumb_finder_fix)
Clearing all caches using Drush

I have the Devel module installed and activated, and the following doesn't produce any output.
function breadcrumb_finder_fix_menu_breadcrumb_alter(&$active_trail, $item) {
    drupal_set_message(krumo($active_trail));
}

Any ideas ? Directions ? Please advise.
OBS : I've read this answer : https://drupal.stackexchange.com/a/7659/12647
Comment: I'm having the same problem.  I've created the MYMODULE_menu_breadcrumb_alter() hook function, enabled the module, cleared the cache, and the hook never seems to be called on user pages.  Ironically, it does seem to be called on admin pages (I get the krumo output on admin pages).

The theme's _breadcrumb() level seems to be the wrong place to do this.
Answer: Probably a little late to respond, but I came across this thread this morning whilst looking for a way to override the breadcrumb in Drupal 7, it helped a little so I thought I would add my solution.
This creates extra crumbs based on content types and adds the current page to the crumb. I'm using this to add a crumb to a filtering view seen before the given node.
function MYMODULE_menu_breadcrumb_alter(&$active_trail, $item) {

    //STORE THE LAST ITEM
    $end = end($active_trail);

    foreach ($active_trail as $key => $crumb){

        //CHECK AGAINST NODE TYPE
        if($crumb['map'][1]->type == 'NODE_MACHINE_NAME'){

            //INSERT THE REPLACEMENT CRUMB
            $active_trail[$key] = array(
                'title' => t("Title"),
                'href' => 'PATH',
                'link_path' => 'PATH',
                'localized_options' => array(),
                'type' => 0
            );
            //RECREATE ITEM
            $active_trail[] = $crumb;
        }

    }

    //SHOW CURRENT PAGE IN BREADCRUMB BY DUPLICATING THE LAST ARRAY ITEM IN ACTIVE_TRAIL

    if (!drupal_is_front_page()) {
        if ($item['href'] == $end['href']) {
            $active_trail[] = $end;
        }
    }

}

Comment: This seems to be the right way, but it isn't working for me.  Ironically, this does work on admin pages, but it doesn't work on general user content.  Suggestions on how to debug?
Comment: I have the same problem as @PeterMurray. I haven't solved it fully yet but from what I can tell right now, this is caused by the custom_breadcrumbs module somehow overriding the links. My 2 cents, anyway.
Answer: hook_menu_breadcrumb_alter() does not work on pages where drupal_set_breadcrumb() has been called before.
hook_menu_breadcrumb_alter() is invoked from menu_get_active_breadcrumb(). This is called from drupal_get_breadcrumb(), but only if no breadcrumb has been previously set with drupal_set_breadcrumb().
It does not look like drupal_set_breadcrumb() is called from the user page. But maybe there is a contrib module which does that. You could put a dpm() or ddebug_backtrace() in drupal_set_breadcrumb() to see if this is the case (needs the devel module to be enabled, and you having permission to see devel information).
You can use hook_preprocess_breadcrumb() instead, but this requires to parse the breadcrumb link you want to alter. Because in this hook the breadcrumb links are already rendered as html, so you need regular expressions (preg_match()) or similar to determine e.g. the url.
A much better solution is to use one of the various breadcrumb-customizing modules that are available for Drupal.
Answer: Here is a snippet to show how you can alter breadcrumbs.
Keep in mind the following:

This method changes breadcrumbs at theme level, which is the last place to change any thing before it reaches to template files, so changing here will not allow other module to change the breadcrumbs later.
Consider this way as the last option to alter your breadcrumbs.
Add this snippet to template.php file of your theme.
function THEME_NAME_breadcrumb($variables) {
  $breadcrumb = $variables['breadcrumb'];

  // check to ensure this is the one you want to alter
  // Custom rebuild process of breadcrumb with custom links.
  if ($breadcrumb[1] == 'your_breadcrumb_id') {
    // linking to home page
    $links[0] = l(t('Home'), '<front>');

    // Keeping the trail/current page as non linked
    $links[1] = ('your desired breadcrumb');
    drupal_set_breadcrumb($links);
  }
}

Comment: @jean I have done few changes, have a look at it(not in the snippet), but in the disclaimer
Answer: this may not be the most efficient way, but try:
function THEME_breadcrumb($variables)
and then read the variables.
... also my god I hate breadcrumbs. so much.
Comment: I saw this. But it doesn't seems the "Drupal way". This is a theme hook and therefore shouldn't be use to modify the input
Comment: I'm going for this because the other way isn't working. I'm upvoting your question, but not accepting. Hoping that someone find the "right way".
Answer: If you only need to alter the breadcrumb on a specific page maybe the following solution can help you. The example updates the breadcrumb for a edit form.
$breadcrumb = array();
$breadcrumb[] = l(t('Home'), '<front>');
$breadcrumb[] = l(t('Nodes listing'), 'nodes/listing');
# Update breadcrumb on the edit form
if (isset($form['nid']) && (is_numeric($form['nid']['#value']))) {
    $breadcrumb[] = l($form['#node']->title, 'node/' . $node->nid);
}

drupal_set_breadcrumb($breadcrumb);

Another Drupal way is to user hook_menu_breadcrumb_alter but make sure to name it YOUR_MODULE_menu_breadcrumb_alter and clear the cache after adding the function.
Or also theme_breadcrumb is a Drupal way to update the breadcrumb but in this hook you should only change the breadcrumb's markup, not links.
Answer: the THEME_NAME_breadcrumb did not work for me.
However, I did manage to override breadcrumb with this function:
function MODULE_node_view_alter(&$build) {
  $node = $build['#node'];
  if ($build['#view_mode'] == 'full' && $node->type == 'CONTENT_TYPE') {
    $breadcrumb = array();
    $breadcrumb[] = l('Home', '<front>');
    $breadcrumb[] = l('People', 'group/node/' . arg(2) . '/people');
    $breadcrumb[] = l('Attendance', 'group/node/' . arg(2) . '/people/attendance');
    drupal_set_breadcrumb($breadcrumb);
  }
}

credit goes to: https://stackoverflow.com/questions/10087168/how-to-add-breadcrumb
Answer: function MODULE_menu_breadcrumb_alter(&$active_trail, $item) {
  // Store the last item
  $end = end($active_trail);
  foreach ($active_trail as $key => $crumb){
    // Check against the node type
    if ($crumb['map'][1]->type == 'CONTENT_TYPE' && $crumb['link_path'] == 'node/%') {
      // Replace the breadcrumb
      $active_trail[$key] = array(
        'title' => t("Title"),
        'href' => 'PATH',
        'link_path' => 'PATH',
        'localized_options' => array(),
        'type' => 0
      );
    }
  }
}

this much code is sufficient to modify breadcrumb url.

Altering the breadcrumb contents


how to improve for loop in python

Question: I have this code:
    for row in range(len(df[col])):
        df[col][row] = int(df[col][row].replace(',',''))
    df[col] = df[col].astype(int)
    df[col] = np.round(df[col]/500)*500  #rounds the numbers to the closest 500 multiple.
    df[col] = df[col].astype(int) #round returns a float, this turns it back to int after rounding

In the for loop the: df[col][row].replace(',','') basically removes commas from numbers that are stored as objects like 1,430 and then converts it to int like 1430
Then I'm having to add the df[col] = df[col].astype(int) because otherwise, the following np.round() throws the error: 'float' object has no attribute 'rint'
The thing is that after the np.round() I'm having to add again the .astype(int) because the round as I have it is returning a float, but I want ints.
I'm seeing that the execution of this is considerably long, even thought my dataframe is only 32 x 17
is there anyway I could improve it??
Comment: hi there welcome to SO, please see [ask] and [mcve] - also you don't need the loop do - `df[col].replace(',','').astype(int)` but unsure what you're trying to entirely
Comment: Does this answer your question? [Convert Pandas Dataframe to Float with commas and negative numbers](https://stackoverflow.com/questions/42192323/convert-pandas-dataframe-to-float-with-commas-and-negative-numbers), and then just use `astype(int)`
Answer: Would a more general replace using a lambda function df[col].apply(lambda x: x.str.replace(',','')) be more suitable and time efficient?
And would a one liner like this not yield what you are after?
df['col'] = (df['col'] / 500).astype(int) * 500
Comment: it's not neccesary the usage of apply when specifying the col, you can just use `df[col].str.replace(',','')` ;)
Answer: Don't do that for row in range(len(df[col])):
do this: for row in df[col]
or instead of that for use this:
Use this for actually replacing string with another string: DataFrame.replace
or better use a lambda: DataFrame.apply (Example here)

how to improve for loop in python


Django WSGI segfaults when importing setproctitle module

Question: I want to use the python setproctitle module to update the process name of a python WSGI worker process when it starts working on a request. (This is to try to track down what URLs are using all the CPU). I have written a simple Django middleware class that will call setproctitle.setproctitle(request.path). This works fine in the django debug server (i.e. python manage.py runserver), i.e. I can see the request URL in the output of top.
However when I try to run the same code using apache & mod_wsgi the wsgi process segfaults when it loads the middleware python file. It segfaults at the import setproctitle line. (print statements before that line are executed, but not after).
Is it possible to get setproctitle working with wsgi?
The server is Ubuntu Linux, using apache, mod_wsgi, and django.
Answer: Use gdb to work out why it crashes. See:
http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Debugging_Crashes_With_GDB
If that doesn't help you to work out problem yourself, then suggest you post all the details to the mod_wsgi mailing list as this site doesn't work well when needing to iteratively debug a problem.
Also try forcing use of main Python interpreter using:
WSGIApplicationGroup %{GLOBAL}

It may be the case that setproctitle module doesn't work properly in sub interpreters, although I can't see why it wouldn't as it should just be a wrapper for a single function and should be pretty simple.


Is it possible to override document.cookie in WebKit?

Question: In Firefox it's possible using the following...
HTMLDocument.prototype.__defineGetter__("cookie",function (){return "foo=bar";});
HTMLDocument.prototype.__defineSetter__("cookie",function (){});

This doesn't cause any errors in WebKit, and WebKit definitely supports __defineGetter__ and __defineSetter__, but it doesn't work. Guessing WebKit is protecting that property somehow.
So, any ideas of how to achieve the same effect in WebKit?
Answer: Have you tried do define the getter/setter pair on the document object itself, instead on the prototype?
document.__defineGetter__("cookie", function() {} );
document.__defineSetter__("cookie", function() {} );

I know it shouldn't matter, but I don't underestimate browser quirks. Even with WebKit.
Update
I've done some tests in Chrome 2 and it appears that it only allows defining a setter. Anyway, I'm not sure how valid this observation is to WebKit, as Google Chrome uses a different JavaScript interpreter than WebKit.
Comment: Nice idea, but unfortunately that also doesn't work in Safari (neither getter or setter).


Count no. of words using Regular expressions in java

Question: How to count the number of times each word appear in a String in Java using Regular Expression?
Comment: Could you post what you have tried yourself? Also, what about if you search for the word `abba` and the string is `ABBA members didn't wear abbadabbas`. What would be the count for `abba`? And why regex?
Answer: I don't think a regex can solve your problem completely.
You want to

split a string into words, a regular expression can do this for a very simple definition of word, "parts of a string seperated by whitespace or punctuation", which is not a very good definition even if you just stick to English text
Count the number of occurances of each word derived from step 1. To do that you must store some kind of Mapping, and regexes neither store nor count.

A workable approach could be to

split the inputstring (by either regex or other means) into an array of word-strings
iterate over the array, and building a Map to keep count of each word
iterate over the map to output a list of words and the number of occurances.

If your input is limited to English you still have to consider how you want your algorithm to behave in case of things like they're <->they are etc and compound words. Add other languages to the mix for additional kinds of headaches (different ways of writing the same word, words split into parts, difference in writing depending on where in a sentence the word occurs, etc)
Comment: +1 for also mentioning the linguistic issue, which is indeed a little complex.
Answer: I would split your task into a) identify words and b) count number of each unique word in text.
a) could be solved with splitting the text with a regex.
b) could be solved by building a map with the result from a).
String text = "I like good mules. Mules are good :)";
String[] words = text.split("([\\W\\s]+)");
Map<String, Integer> counts = new HashMap<String, Integer>();
for (String word: words) {
    if (counts.containsKey(word)) {
        counts.put(word, counts.get(word) + 1);
    } else {
        counts.put(word, 1);
    }
}

result: {Mules=1, are=1, good=2, mules=1, like=1, I=1}
Comment: `\W` also matches `\s`: so there's no need to include `\s` in the character set.
Answer: Pattern p = Pattern.compile("\\babba\\b");
Matcher m = p.matcher("abba is abba with abbabba and abba doing abba");
int count = 0;
while(m.find()){
    count++;
}
System.out.println(count); //4

Answer: Using Guava, this is a one-liner:
Multiset<String> countOfEachWord =
   HashMultiset.create(Splitter.on(" ").omitEmptyStrings().split(myString));
then to get the count of "dog" for example you would say:
countOfEachWord.count("dog")
Answer: Must you use a regex? If not this might help:
public static int count(final String string, final String substring)
  {
     int count = 0;
     int idx = 0;

     while ((idx = string.indexOf(substring, idx)) != -1)
     {
        idx++;
        count++;
     }

     return count;
  }

Comment: That would count two `abba`'s in the string `abbabba`, which can't be correct, IMO.
Comment: my actual requirement is
"hi hi this"
hi --->2
this --> 1
they are separate words..
Comment: Make it `idx += substring.length` to fix the abbabba issue. To match whole words: does indexOf take a regex?
Answer:     int CountWords(String t){
        return t.split("([[a-z][A-Z][0-9][\\Q-\\E]]+)",-1).length+(t.replaceAll("([[a-z][A-Z][0-9][\\W]]*)", "")).length()-1;
    }

English Words(chemical names)+Chinese words


É melhor fazer uma requisição grande ao banco de dados ou várias pequenas?

Question: O que é mais recomendável? Tenho um sistema web que no load da página ASPX ele alimenta vários controles com dados de várias tabelas do banco de dados. É melhor fazer uma pesquisa com uma requisição (post) em cada tabela do banco no servidor remoto ou em uma query só já retornar todos os dados de todas as tabelas alimentando um DataSet só? Ou seja, é melhor fazer mais requisições ao servidor e transportar menos dados na banda ou menos requisições e transportar mais dados na banda?
Comment: A resposta resolveu sua dúvida? Acha que pode aceitá-la? Veja o [tour] se não souber como faz. Isso ajudaria muito indicar que a solução foi útil para você. Também pode votar em qualquer pergunta ou resposta que achar útil no site todo.
Answer: Sempre dizemos para essas coisas que depende, mas no geral fazer uma requisição que retorne um grande volume de dados é melhor já que o custo de cada requisição em suas várias partes de transporte e processamento costuma ser bem considerável. O que é melhor sair da sala e ir na cozinha pegar uma bolacha de cada vez ou trazer o pacote todo?
Mas é claro que se você trouxer muita coisa e não precisar, não compensa. Tem caso que pra decidir o que vai trazer precisa trazer alguma coisa anterior. Pode ser que alguns casos o sistema de banco de dados pode se dar melhor com um volume menor e otimizar. E tem casos que você precisa começar mostrar alguns dados para o usuário antes de receber tudo para dar uma experiência melhor, mesmo que o todo tenha um custo maior. Percebe que há casos que é melhor trazer aos poucos? Mas isso é mais raro. Entenda que existem uma quantidade enorme de coisas para observar para definir o que compensa.
Quanto pior o transporte mais fácil é decidir por uma única requisição, em uma rede remota uma requisição tem uma vantagem enorme.
Por isso que sempre falo que aprender a receita de bolo do que deve fazer serve pra nada, o que importa é entender profundamente todo o funcionamento das tecnologias que estão envolvidas no que faz e tomar a decisão de acordo com a necessidade. É, eu sei, todos querem uma regra mágica que decide fácil tudo, mas isto não existe, e por muitos acreditarem que existe é que tem tanto software ruim.
A pergunta é ambígua, ora, transportar menos dados sempre é melhor, sempre! Mas tem que considerar a operação toda, não individual, me parece que está falando de fazer uma transação com um volume de dados ou várias outras com pouco volume mas que somando dá a mesma quantidade, então aí não faz sentido pelo custo adicional, inclusive de volume de dados de transporte porque em cada transporte tem um overhead.
Coloquei no GitHub para referência futura.
Comment: Entendi Maniero. Talvez não tenha me expressado detalhadamente, mas o que eu queria saber, você já esclareceu. No caso preciso trazer uma quantidade de dados já no carregar da página, pois ela precisa abrir com essas informações. E como esses dados vinham de várias tabelas diferentes, fiquei na dúvida em fazer uma requisição por tabela ou já buscar tudo em uma requisição só. nesta caso como estas informações fazem parte da página sem interação do usuário e não é muita coisa, é melhor em uma requisição só. Obrigado.


Insert next available integer in elastic search

Question: I am moving a table from SQL to elastic search. It has an revision_number column with value equals to previous value + 1.
I found that ES does not support autoincremental feature.
Should i create a static integer on server side code and assign it every time while inserting? what would be the best way to achieve it
Answer: Using static integer will not help as when server restarts, it will be reset.
There is a workaround for that by using _versions. Version number is the in-build concept of elastic search https://www.elastic.co/blog/elasticsearch-versioning-support.
Create a dummy index or type in elastic search with minimum fields. Insert a value in it with Id = 1. It will return object along with version Info. every time you need a incremental integer, update that dummy index. It will return the incremented version number. I got this trick from
http://blogs.perl.org/users/clinton_gormley/2011/10/elasticsearchsequence---a-blazing-fast-ticket-server.html
Answer: Yes, Elasticsearch does not have auto-increment feature for any field. See this. As you've correctly mentioned, this has to be implemented on the client side (Client of Elasticsearch cluster) by incrementing some static integer.


Software testing and regression testing

Question: My company has taken maintenance of a Drupal website where there are some modules that have been specifically developed for this site.
I have to answer to a question that most software do: how can we do "software testing" and "regression testing" with Drupal?
Answer: Drupal 7 comes with a Testing module, and for Drupal 6 you can download http://drupal.org/project/simpletest.
It doesn't do anything automatically (how could it..) but it allows you to write automated tests that test the functionality of your custom modules.
I wrote a blog post about this a while ago: Writing automated tests for Drupal 7. Even though the title says Drupal 7, most of it applies to Drupal 6 too. See Simpletest documentation on drupal.org for more information.
Answer:
Using tools like Selenium, you can automate testing of the website. This is not Drupal a specific solution and can be used with any web stack.
Drupal 6 and 7 have their own testing framework called SimpleTest which can be used to perform functional testing and unit tests (with some caveats, because Drupal itself isn't suited for unit testing). This solution is tied to Drupal and requires a good understanding if Drupal as a developpement platform.
Answer: I am sorry, but I think your question is a little too broad to answer.
It sounds like you need to maintain a site, and the site has custom modules that it uses.
It also sounds like maybe you are interested in knowing how to go about testing new changes you intend to make for the site.
If all of this is true then I think you need to learn Drupal first.
This page should get you started: http://drupal.org/documentation/develop
You may also want to look at the Devel module: http://drupal.org/project/devel
If you have a little more specific details let us know so we can help you out.
Comment: Thank you I check this as good, because it summarize what I've asked for and a solution (which may not be the best but it seems there's no automatic tool to insure that some things still behave the way we want). Thank you very much indeed!

Software testing and regression testing


What is difference between 'transfer learning' and 'domain adaptation'?

Question: Is there any difference between 'transfer learning' and 'domain adaptation'?
I don't know about context, but my understanding is that we have some dataset 1 and train on it, after which we have another dataset 2 for which we want to adapt our model without retraining from scratch, for which 'transfer learning' and 'domain adaptation' help solve this problem.
According to the field of Convolutional Neural Networks:

By 'transfer learning' I mean 'finetuning' [1]
In this case [2] it's unsupervised, but should 'domain adaptation' always be unsupervised?
Comment: [A Survey on Transfer Learning](https://www.cse.ust.hk/~qyang/Docs/2009/tkde_transfer_learning.pdf) by Pan et. al, 2009 provides some insight. They categorize domain adaptation as a type of transfer learning.
Answer: It seems that there are some disagreement between researchers on what the difference between 'transfer learning' and 'domain adaptation' is.
From {0}:

The notion of domain adaptation is closely related to transfer learning. Transfer learning is a general term that refers to a class of machine learning problems that involve different tasks or domains. In the literature, there isn't yet a standard definition of transfer learning. In some papers it's interchangeable with domain
  adaptation.

From {1}:

References:

{0} Li, Qi. "Literature survey: domain adaptation algorithms for natural language processing." Department of Computer Science The Graduate Center, The City University of New York (2012): 8-10. https://scholar.google.com/scholar?cluster=2828982016930721315&hl=en&as_sdt=0,22 ; https://pdfs.semanticscholar.org/532e/3d5b1b5807771b77cac60fe8594b506fcff9.pdf ; http://nlp.cs.rpi.edu/paper/qisurvey.pdf  (mirror)
{1} Pan, Sinno Jialin, and Qiang Yang. "A survey on transfer learning." IEEE Transactions on knowledge and data engineering 22, no. 10 (2010): 1345-1359. https://scholar.google.com/scholar?cluster=17771403852323259019&hl=en&as_sdt=0,22 ; http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.158.4126&rep=rep1&type=pdf  (mirror) (2.6k citations)
Answer: From Hal Daume's article [1]:

The standard classification setting is a input distribution p(X) and a
  label distribution p(Y|X).  Domain adaptation: when p(X) changes
  between training and test.  Transfer learning: when p(Y|X) changes
  between training and test.
In other words, in DA the input distribution changes but the labels
  remain the same; in TL, the input distributions stays the same, but
  the labels change.

https://nlpers.blogspot.com/2007/11/domain-adaptation-vs-transfer-learning.html  (mirror)
Comment: I don't believe this explanation. I don't believe HAL here. What if both $p(Y|X)$ and $p(X)$ change at the same time?
Comment: I agree with @caveman. For many transfer learning scenarios that's the case.
Comment: Welcome to [stats.se]!  Please take a moment to view our [tour].  It is preferred that answers are self-contained with proper citations.  If you were to use the information from your link to provide a reasonable answer to the question with the link for further reading, this would be a much improved answer.
Answer: Throughout the literature on transfer learning, there is a number of terminology inconsistencies. Phrases such as transfer learning and domain adaptation are used to refer to similar processes. Domain adaptation is the process of adapting one or more source domains for the means of transferring information to improve the performance of a target learner. The domain adaptation process attempts to alter a source domain in an attempt to bring the distribution of the source closer to that of the target. In the Domain Adaptation setting the source and target domains have different marginal distributions p(X). According to Pan's survey, Transfer Learning is a broader term that can also include the case when there is a difference in the conditional distributions p(Y|X) of the source and target domains. In contrast, Daume discriminates the two terms [1], referring that Domain Adaptation is when p(X) changes between source and target and Transfer learning is when p(Y|X) changes between source and target domains.

https://nlpers.blogspot.com/2007/11/domain-adaptation-vs-transfer-learning.html
Comment: Would it be possible to add a citation for "Pan's survey"? I think it would make this answer more useful to future readers.
Comment: Pan, Sinno Jialin, and Qiang Yang. "A survey on transfer learning." IEEE Transactions on knowledge and data engineering 22, no. 10 (2010): 1345-1359. https://scholar.google.com/scholar?cluster=17771403852323259019&hl=en&as_sdt=0,22 ; http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.158.4126&rep=rep1&type=pdf
Answer: I think that "Transfer Learning" is a more general term, and "Domain Adaptation" is a scenario of "Transfer Learning".
[1] Transferable Attention for Domain Adaptation. http://ise.thss.tsinghua.edu.cn/~mlong/doc/transferable-attention-aaai19.pdf
Answer: According to [1], domain adaptation is the transfer learning in NLP: "Transfer learning in the NLP domain is sometimes referred to as domain adaptation."
[1] Pan, S. J., and Q. Yang. "A Survey on Transfer Learning." IEEE Transactions on Knowledge and Data Engineering 22, no. 10 (October 2010): 1345–59. https://doi.org/10.1109/TKDE.2009.191 or https://www.cse.ust.hk/~qyang/Docs/2009/tkde_transfer_learning.pdf
Answer: It seems wikipedia has the most concise answer:

Domain adaptation is a subcategory of transfer learning. In domain
adaptation, the source and target domains all have the same feature
space (but different distributions); in contrast, transfer learning
includes cases where the target domain's feature space is different
from the source feature space or spaces.

Here is the source.
Comment: While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/321272)


Volume of a pyramid.

Question: Find the volume of the pyramid with base in the plane $z=−9$ and sides formed by the three planes $y=0$ and $y−x=3$ and $2x+y+z=3$.
Comment: If you just google "Find the volume of the pyramid with base in the plane " there are a bunch of websites that show you how to do it. Here is one http://math.berkeley.edu/~scanez/courses/math53/spring06/problems/review2_solns.pdf
Comment: Despite the tag, this can be solved just with geometry.
Comment: @RossMillikan I have readded the tag because the OP (or others who may search this question) may be looking for an answer using multivariable calculus, though it may not be the simplest path.
Answer: First find the coordinates of the corners of the base.  You are given $z=-9$ and have three lines in the plane.  If you solve each pair as a set of simultaneous equations, you get a point.  Those three points are the corners of the base.  What is its area?
To find the peak, solve all three equations as a simultaneous set.  They are designed to be easy.  The height of the pyramid is the distance from this point to the plane $z=-9$
The volume is then $\frac 13$(area of the base)(height)
Comment: Therefore the answer would be? im still having trouble. I appreciate the help
Comment: @Michael:  can you solve a pair of simultaneous equations?  One corner, coming from $y=0$ and $y-x=3$, is $(-3,0,-9)$.  Can you do the others?

Volume of a pyramid.


ostream must take exactly one argument

Question: I am getting a compile error in my output stream operator and I cannot seem to find out how to fix it as I never received this error before:
linkedList.cpp:258: error: 'std::ostream& linkedList<T>::operator<<(std::ostream&, linkedList<T>)' must take exactly one argument
make: *** [linkedList.o] Error 1

Here is the definition of my operator<<
template <class T>
ostream& linkedList<T>::operator<<(ostream &output, linkedList<T> list)
{
    node *curr;
    curr=list.head;

    while(curr!=NULL )
    {
        output << curr->data;
        curr = curr->next;
    }

    return output;
}

Here it is in my header:
//ostream operator for printing the list
template <class T>
ostream &operator<<(ostream &output, linkedList<T> list);

Any help will be appreciated!
Comment: You should pass the linked list by reference.  I don't believe you want the compiler to pass a copy of the linked list on the stack to your function.  If you don't plan on modifying the list, pass it by constant reference.
Answer: You defined it as a member function, you have to define it as a free standing (probably friend) function, either

outside your class
template <class U>
ostream& operator<<(ostream &output, linkedList list){...}

in which case you also have to declare it inside the class as
template <class U> // note the different type name
friend ostream& operator<<(ostream &output, linkedList list)

or

inside the class as
// no need for template, type is passed automatically the function is not templated anymore
friend ostream& operator<<(ostream &output, linkedList list){...}

The difference between these 2 declarations is a bit subtle, but for your purpose both work equally well. And probably you want to pass linkedList by const reference, linkedList<T>& list.

EDIT
A common mistake is to just declare the friend operator inside the class as
template<typename T>
class linkedlist
{
    //....
    friend ostream& operator<<(ostream& output, const linkList& list); // declaration only
}

then try to define it outside the class as
template<typename T>
ostream& operator<<(ostream& output, const linkList<T>& list){...}

Guess what? The code will compile, but won't link, as the declaration inside the class declares a non-template function, one for each type T you pass to linkList<T>. Then, when you declare e.g. linkList<int> lst, and try cout << lst, the compiler will see the declaration of the friend, which for it looks like
friend ostream& operator<<(ostream& output, const linkList<int>& list);

and will try searching for its definition. However there is no definition in the rest of the header, only the template operator, so the linker isn't able to find the implementation and will spit a linker error. Live example here.
Answer: It's all in the error message. This function that you declared:
template <class T>
ostream &operator<<(ostream &output, linkedList<T> list);

is a member function of linkedList<T> that takes two arguments. All the binary operators (+, *, <<, ... all except for the call operator ()), when defined as member functions, must take exactly one argument, hence the error. What you had intended to do was to declare a non-member function, external to the class:
template <typename T>
class linkedList { .. };

template <typename T>
ostream &operator<<(ostream &output, linkedList<T> list) {
    // implementation
}

You could also define it as a non-member friend inside the class definition:
template <class T>
class linkedList {
    ...
    friend ostream &operator<<(ostream &output, linkedList list){
        ...
    }
    ...
};

ostream must take exactly one argument


How does one tell a button to make sender something else?

Question: A quote from Apple docs: "The sender parameter usually identifies the control sending the action message (although it can be another object substituted by the actual sender)."
How is this accomplished? The "it can be another object" part.
In my case I have a number of buttons that all target the same method which produces a popover with a graphic of a tape measure with a pointer to the number. I have a lot of labels I want to use this on and will put a small button with an icon next to each of them so the user can see the fractional equivalent. I need a way to tell the method the number, which is held by a different label in each case. Making "sender" the label would make this a simple thing.
Comment: You might want to revise this question it's hard to tell what your even talking about...
Comment: If you know about buttons and sender it shouldn't be hard to tell what I am asking for. Are you a mod?
Comment: no i'm not a mod and i didn't down vote you i'm trying to help but I don't even know what your trying to say which is what they probably think too.
Comment: Thanks Shawna. Is it any better?
Comment: Okay, I could just use bunch of if then statements in my method, I was hoping to avoid it, but it's about the same number of lines I suppose.
Answer: You can pass any sender you want if you invoke the method from somewhere else in your code, but if your action method is being invoked from an action on the control, then the sender will be the control (i.e. UIButton) that invoked the method.  You will need to associate the sensor with the meaning in your code.  The tag property may be of use.
The quote you added from Apple is merely indicating that the actual sender can supply a different object if it wants to - but it doesn't mean that all objects have the ability to specify a different sender.  In the case of a UIButton there is no way of specifying a different sender.


Theme hook MENU_CALLBACK not found

Question: I am seeing this error in my logs:
<code>Theme hook MENU_CALLBACK not found
</code>
What are the causes? I cannot find this exact phrase in google or d.o. This is an example menu item:
<code>$items['user/%user/integration/%integration'] = array(
    'title' => 'View An Integration',
    'page callback' => 'integration_view_page',
    'page arguments' => array(3),
    'access callback' => 'is_owner',
    'access arguments' => array(1, 3),
    'type' => MENU_CALLBACK,
);
</code>
Yes, cleared caches, including menu cache. The actual page appears to load ok.
Comment: You should get a stack trace. Maybe the logs already provide that? If you look into the actual apache error.log file.
Answer: In my case, this was a mistake on my part. I recently performed a find and replace on my codebase to change all my menu hooks from MENU_LOCAL_TASKS to MENU_CALLBACK.
I clearly did this ignoring case, and also did not check properly as in my template.php, I now had...
<code>$vars['secondary_local_tasks'] = array(
    '#theme' => 'MENU_CALLBACK',
    '#secondary' => $vars['tabs']['#secondary'],
);
</code>
instead of...
<code>$vars['secondary_local_tasks'] = array(
    '#theme' => 'menu_local_tasks',
    '#secondary' => $vars['tabs']['#secondary'],
);
</code>
Because it was now called MENU_CALLBACK in caps, it confused me and I was looking in the wrong place. It is only when I went back and diff'd my entire backed up codebase did I notice it.
Lesson Learned: Find & Replace is not always a good idea :)

Theme hook MENU_CALLBACK not found