WSOD after PHP 5.3: Issue with call_user_func_array() in menu.inc

Question: EDIT Nov 10: This has been solved by Letharion's suggestion to do a md5 file compare of my file with an original package file containing the function that was throwing the error.
--
I was referred here by https://www.drupal.org/node/2336585#comment-9311707
I've spent the better part of two days on this. I have searched and tried suggestions and so far no dice. Summarizing as much as possible:
Recently my WHM/cPanel auto-updated itself and locked us out of phpMyAdmin short of upgrading to MySQL 5.5 or higher -- when I tried accessing phpMyAdmin one day I was confronted with a red box with red text stating to upgrade. We've been ignoring it but two days ago we needed to get into our database so we had cPanel perform an unassisted upgrade to SQL 5.5.
Process went perfectly smooth and things seemed normal until we went to edit a node on our Drupal 6.33 and received a WSOD. Reloading a different page gets this error:
warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_page_edit' not found or invalid function name in /home/SITENAME/public_html/includes/menu.inc on line 350.
Line 350 of my unmodified menu.inc is within the function menu_execute_active_handler() as follows:

345  if ($router_item = menu_get_item($path)) {
346    if ($router_item['access']) {
347      if ($router_item['file']) {
348        require_once($router_item['file']);
349      }
350      return call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
351    }
352    else {
353      return MENU_ACCESS_DENIED;
354    }
355  }
356  return MENU_NOT_FOUND;

After pulling out some hair I discovered that during the SQL upgrade the server automagically updated it's PHP from our longstanding 5.2-branch to now 5.3.29. I have since learned that D6 does not 'officially' support PHP 5.3.
Looking up call-user-func-array(), indeed it has changed in PHP 5.3+
Can anyone shed some light on how to patch this for now? We are still using D6 because a few modules we need are not ready for D7 yet.
Thank you very much in advance,
BigMike
--
Additional Info:
So far everything else including a good number of contrib modules are working as expected. The only error we have seen is call_user_func_array() expects parameter 1 to be a valid callback and only when trying to create (node_add) or edit (node_page_edit) nodes.
I did a dump on $router_item and call-user-func-array() is working for
node_page_view, drupal_get_form, and statistics_node_tracker page_callback's but not working for node_page_edit or node_add.
Anything that uses drupal_get_form is fine, which so far I've tested creating and editing both blocks and taxonomy and both function as expected.
So for kicks I intercepted 'node_page_edit' and changed it to 'drupal_get_form' and now my node edit pages load -- no longer white screen of death -- but have a ton of other errors and nothing useful is outputted to the screen.
We also get an error on our Clone page (Clone module v6.x-1.3),
warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'node_form' not found or invalid function name in /home/SITENAME/public_html/includes/form.inc on line 421.
which in form.inc is...
419  // If $callback was returned by a hook_forms() implementation, call it.
420  // Otherwise, call the function named after the form id.
421  $form = call_user_func_array(isset($callback) ? $callback : $form_id, $args);

Dumping $callback here and it's an ordinary string of value "node_form".
So I need to figure out how to manipulate call_user_func_array() for use under PHP 5.3.x. There are a few tips on the php.net site but so far I can't figure it out.
So far I've tried...
  return call_user_func_array($router_item['page_callback'], array(&$router_item['page_arguments']));
and

  return call_user_func_array(array($router_item['page_arguments'], $router_item['page_callback']), $router_item['page_arguments']);
...and I've tried adding ampersands and changing array orders... I'm really just spit balling as this is my first time ever working with call_user_func_array().
Any help is GREATLY appreciated! Our website is http://www.marlincrawler.com and most things are working as they should. Not being able to edit content isn't the end of the world as we can do that in the DB, but we need to be able to create content and not having this feature is a critical issue for us.
Comment: What's the md5 sum of your node.pages.inc file? Perhaps it's gotten corrupted somehow. I downloaded 6.33, and mine is "e77cc2e63d87afaa6b297a0549437590".
Comment: HOLY CRAP IN A HAND BAG. Letharion. How in the world did you guess this... I did a md5 and it was different. Then I figured that's probably because I made some core edits back in the day... Then I used a text compare utility with the stock file and they had the same contents, just wasn't a binary match. Why this? So I copied over the stock file and WA-LA! I can edit and do everything else!! Checking some things now, brb...
Comment: I'm with caleb below. Have you tried clearing the cache? Drupal 6 normally works just fine on 5.3.
Comment: Letharion & calebtr, Sorry for not specifying but yes I've done that and found where people had to do it multiple times, all to no avail. I also truncated the cache tables manually in phpMyAdmin, restarted both httpd & mysql, still getting blank white pages when trying to edit or create nodes.
Comment: Update: I also get WSOD while trying to delete a node at /node/%/edit/delete. I looked at the page_callback value and it is node_page_edit here as well.
Comment: Ok, I've tested pretty much everything I can think of and everything is functioning as it should. I can't believe it was a bad file even when the file contents were correct. Thank you SO MUCH for the help, I will share this answer with others in hopes it can help someone out in the future!
Comment: One sort of similar thing that once happened to me was that I ended up getting a [bom](https://en.wikipedia.org/wiki/Byte_order_mark) character in my file. Not sure how I did it, and not sure how you would have, but IIRC it terribly confuses PHP, and as such, the rest of us.
Comment: FWIW, using git is very useful to keep track of the exact content of files and their state. :)
Answer: Letharion's suggestion above has solved my issue. For some reason the MD5 checksum of my d6_root/modules/node/node.pages.inc file changed during the cPanel auto-update of our PHP/SQL rendering 'node_page_edit' not found or as an invalid function name. Even despite a word-for-word text compare match of my unmodified node.pages.inc file with an original/stock Drupal 6.33 file, I was getting this WSOD. My node.pages.inc file was not a binary match of the stock D6 file, and directly after overwriting my unmodified node.pages.inc file with an original file from the D6 package, my website instantly began functioning normally.
To me it seems highly unlikely that this change occurred during the PHP & SQL upgrade. I wonder if rather the file had some issue with it before and perhaps the older version of PHP simply didn't mind it....?
So if anyone else out there has a particularly pesky white screen of death, in my example here, knowing which function was causing the issue and which file contains said function, perform a MD5 file match and see if for any reason your file differs from the original Drupal install file.
Many thanks to Ashish Bairagi, calebtr, and Letharion for their help is getting this resolved.
Answer: First of all I would like to mention that the error you are referring is indeed just a warning which does not cause WSOD. So you need to dig out what exactly the fetal error there which is causing WSOD.
To do this you need to change level of error reporting in you settings.php file.
Add this code :
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//Note:  Do not include the opening and closing PHP tags when you copy this code
?>

then you would be able to see exact error, if you are able to solve that then the issue might get resolved or you can simply post that here as well so any one of us can help you.
more details here:
https://www.drupal.org/node/1056468
Comment: Could the WSOD still be caused by the warning, because the failure to call the function just means Drupal doesn't know how to proceed and you end up with no output?
Comment: Warning appear only when drupal can go ahead after notifying the user that there may be some unusual output but not a blocker. If you go through reference link you get more clarification.
Comment: Ashish, thank you very much for the help. I added this code and am now receiving the following:
.... Notice: unserialize() [function.unserialize]: Error at offset 465 of 466 bytes in /home/SITE/public_html/includes/bootstrap.inc on line 566 .... Notice: unserialize() [function.unserialize]: Error at offset 605 of 606 bytes in /home/SITE/public_html/includes/bootstrap.inc on line 566 .... and .... Notice: unserialize() [function.unserialize]: Error at offset 611 of 612 bytes in /home/SITE/public_html/includes/bootstrap.inc on line 566
Comment: Line 566 of my bootstrap.ini is in the function variable_init() and is as follows .... $variables[$variable->name] = unserialize($variable->value);
Comment: This is the only new error and I checked my /usr/local/apache/logs/error_log and it's being reported there as well but without any other errors. One thing to note however is that this error is seemingly occurring to all my site visitors. Ever time I tail the log file I get the error being generated from different referrers (random visitors on our site at the moment), yet, however, they are not getting WSOD. Browsing site works fine, just can't create or edit nodes.
Comment: Just confirmed that we get WSOD while editing nodes under my account (uid = 1) and a privileged user (uid = 4 with permissions), so it's not limited to the superuser.
Comment: Again you need not to focus on notice... look for fatal error if there any...
Comment: No fatal errors exist in error_log and none are reported by Drupal. I just went through and removed 8 modules we don't need anymore, no improvement. Going to try to start disabling contrib modules one at a time without breaking the site (as visitors are still using the site as normal without a glitch)...
Comment: I have now disabled a lot of contrib modules and still only receive a blank white screen when attempting to edit/create nodes. In menu.inc I added a simple echo statement and it appears on the blank white screen. Now, with the 3-lines of deeper error reporting added, I can get the error to output to the blank white screen but it's still only just the Notice on the function.unserialize of bootstrap.inc line 566... No fatals errors are appearing anywhere not even in my server error_log :(
Comment: Just did a permissions rebuild, did not help.
Answer: I don't have enough reputation to comment. I don't see you saying anywhere that you've tried this, but here it is:
Clear all of your caches.
(at admin/settings/performance)
call_user_func_array() is working fine, but it can't find the function 'node_page_edit', so it PHP is complaining.
But of course you have a function called node_page_edit, it is part of the node module in Drupal core, and there is no way you can disable that module. So something is wrong with the way Drupal is loading modules and most of the time clearing caches helps.


How to change background-color on click?

Question: I want to change the background color of the div tag when it is clicked, however I am unable to make it work.
.ts
goToHome() {
    this.router.navigate(['home']);
}
isHome() {
    return this.goToHome;
}

.html

    <mat-icon class="icon-container"> home</mat-icon>

.scss
.selected {
    background-color: #ff3588;
}

Answer: use [ngClass], (assuming isHome() returns a boolean value)

    <mat-icon class="icon-container"> home</mat-icon>

It applies classes conditionally.
Comment: @JonasPraem Then you should ask OP to clarify the question.
Comment: no difference in functionality from what is there in the question
Comment: @SachinGupta we can only assume what is not provided. The ts file doesn't contain any logic. We can't debug that
Comment: the only difference from OP and you code is `[class.selected]="isHome()"` replaced by `[ngClass]="{'selected': isHome()}"`. Both these things do the same work
Comment: This answer works if the provided assumption is implemented. It answers the title question.. i mean I could write `'selected': true` - but I don't think it adds anything
Answer: Seems like goToHome is a function you return inside the isHome method. Instead return a boolean value

    <mat-icon class="icon-container"> home</mat-icon>

isHomeSelected = false
goToHome() {
    this.isHomeSelected = true;
    this.router.navigate(['home']);
}

Comment: it's not a must to use `ngClass` every time. yes, it's an angular directive but you can also use `[class.]` since it also enforces the two-way binding. in here using this approach is much more simple.
Comment: @JonasPraem, ngClass is for overriding\ modifying the entire css class. But [class.selected] is more granular to choose whether 'selected' css class be added or not. Sachila Ranawaka is correct in this case.
Comment: The proper Angular way of inserting classes conditionally is by using `[ngClass]`


Diferenças entre compilar e recompilar?

Question: Alguns IDEs como o Visual Studio possuem as opções de compilar e de recompilar o projeto, qual a diferença entre as duas e o que elas executam de diferente? E quando cada uma deve ser usada?
Answer: Se estiver falando de C# e VB.Net (não posso afirmar outros): a principal diferença é que o rebuild (recompilar) faz um clean no projeto e
depois faz um build (compilar).
Enquanto o build vai verificar todos os arquivos que foram alterados e tentar compilar somente aquilo que foi modificado. Rebuild vai compilar tudo do zero.
Answer: Imagino que está falando de build e rebuild que é um pouco diferente de compilar e recompilar.
A semântica exata pode variar e nem é tanto o IDE, é o sistema de construção de projetos que o IDE reproduz em GUI.
Construir aproveita o que já tem, é chamada de construção incremental. Por  exemplo, tudo que ele detecta que não precisa para gerar um novo executável ele não gera. Em geral isso é verificado quando o horário do que foi mudado no código e que o executável está com horário anterior, precisa gerar um novo.
Reconstruir começa tudo do zero como se nada tivesse sido feito com aquilo antes, o que obviamente demora mais, mas evita pegar algo que já está defasado.

Diferenças entre compilar e recompilar?


$f$ such that $\sum a_n$ converges $\implies \sum f(a_n)$ converges

Question:
Let $f:\mathbb R\to \mathbb R$ be such that for every sequence $(a_n)$ of real numbers,
$\sum a_n$ converges $\implies \sum f(a_n)$ converges
Prove there is some open neighborhood $V$, such that $0\in V$ and $f$ restricted to $V$ is a linear function.

This was given to a friend at his oral exam this week. He told me the problem is hard. I tried it myself, but I haven't made any significant progress.
Comment: For which sequence $\sum a_n$ converges but $\sum\sin(a_n)$ doesn't?
Comment: @LeGranDODOM do you mind telling me at which university people ask these kind of questions in oral exams?- I would love to avoid this place in my life.
Comment: @wewasss this one was given at Ecole Polytechnique this week. The examiner gave my friend a few hints after he got stuck though.
Comment: @ajotatxe Consider the series $\sum a_n $ where

$$a_{3n-2} = \frac{1}{n^{1/3}}, a_{3n-1} = -\frac{1}{2n^{1/3}}, a_{3n} = -\frac{1}{2n^{1/3}}.$$

Then $\sum a_n$ converges (to $0$). Using $\sin x = x - x^3/6 + O(x^5),$ you can see $\sum \sin a_n = \infty.$
Comment: @Did no, but I prefer not to learn in exams. ;-)
Comment: f is continuous ?
Comment: @Surb continuity is not assumed, but you can prove $f$ is at least continuous at $0$
Comment: How? Can you elaborate?
Comment: @ajotatxe such a sequence must have infinitely many changes of sign. I haven't found one at the moment (but there must be, I have faith in the statement of the problem).
Comment: Now I found a very similar question: [The set of functions which map convergent series to convergent series](http://math.stackexchange.com/questions/116964/the-set-of-functions-which-map-convergent-series-to-convergent-series)
Comment: @wewasss Why? Afraid to... *learn*?
Comment: @LeGrandDODOM thanks for the info.
Answer: I have added an answer to collect various resources where this fact is proven. This answer is community-wiki - feel free to add further references you are aware of.
Papers:

Gerald Wildenberg: Convergence-Preserving Functions, The American Mathematical Monthly Vol. 95, No. 6 (Jun. - Jul., 1988), pp. 542-544, jstor link, doi: 10.2307/2322761, MR0945022, Zbl 0664.40001.
Arthur Smith: Convergence-Preserving Functions: An Alternative Discussion, The American Mathematical Monthly Vol. 98, No. 9 (Nov., 1991), pp. 831-833, jstor link, doi: 10.2307/2324271, MR1133000, Zbl 0783.40002
Rado, R. A theorem on infinite series. J. London Math. Soc. 35 1960 273–276; doi: 10.1112/jlms/s1-35.3.273, MR145321, Zbl 0098.26703

Books

Teodora-Liliana Radulescu, Vicentiu D. Radulescu and Titu Andreescu: Problems in Real Analysis: Advanced Calculus on the Real Axis, Problem 2.5.30, page 108

Online resources

The set of functions which map convergent series to convergent series
Comment: Wow, I didn't know there was some lore about the problem.
Comment: Neither did I. So I [googled](https://www.google.com/search?q=function+preserves+convergence+series), found some papers, looked at references in them.
Comment: Would it be appropriate for the site if I added some screenshots of the second article ?
Comment: If you have a link to a copy of the paper, which is (legally) freely available, then adding a link would work just as fine. If it is not freely available, then posting it here would be questionable: [To what extent should copyrighted material be made available on math.se?](http://meta.math.stackexchange.com/questions/529/to-what-extent-should-copyrighted-material-be-made-available-on-math-se).
Answer: Here comes a proof in the general case. We first start with the following
Lemma: Let $-\varepsilon<y<0<x<\varepsilon$ and $N\in\mathbb{N}$.
Then there is a some $M\in\mathbb{N}$ and $z_{1},\dots,z_{M}\in\left\{ x,y\right\} $
with
$$
\left|\left\{ i\in\left\{ 1,\dots,M\right\} \,\mid\, z_{i}=x\right\} \right|=N
$$
and
$$
\left|\sum_{i=1}^{K}z_{i}\right|<\varepsilon\qquad\forall K\in\left\{ 1,\dots,M\right\} .\qquad\qquad\left(\ast\right)
$$
Proof: We first inductively construct an infinite sequence $\left(w_{n}\right)_{n\in\mathbb{N}}\in\left\{ x,y\right\} ^{\mathbb{N}}$
with $\left|\sum_{i=1}^{n}w_{i}\right|<\varepsilon$ for all $n\in\mathbb{N}$.
It is clear that the stated condition holds for $w_{1}:=x$, since
$-\varepsilon<x<\varepsilon$. Now, let $w_{1},\dots,w_{n}$ be already
constructed. Distinguish two cases:

We have $\alpha:=\sum_{i=1}^{n}w_{i}\geq0$. Then choose $w_{n+1}:=y$.
Then
$$
\varepsilon>\alpha>\alpha+y=\sum_{i=1}^{n+1}w_{i}=\alpha+y\geq y>-\varepsilon,
$$
i.e. $\left|\sum_{i=1}^{n+1}w_{i}\right|<\varepsilon$.
We have $\alpha:=\sum_{i=1}^{n}w_{i}<0$. Then we choose $w_{n+1}:=x$.
Similar to the above, it follows
$$
-\varepsilon<\alpha<\alpha+x=\sum_{i=1}^{n+1}w_{i}=\alpha+x\leq x<\varepsilon
$$
and hence $\left|\sum_{i=1}^{n+1}w_{i}\right|<\varepsilon$.

Now assume that $\left\{ i\in\mathbb{N}\,\mid\, w_{i}=x\right\} $
is finite. This implies $w_{i}=y$ for all $i\geq N_{0}$ with $N_{0}\in\mathbb{N}$
suitable. But this implies
$$
\sum_{i=1}^{N}w_{i}=\sum_{i=1}^{N_{0}-1}w_{i}+\sum_{i=N_{0}}^{N}w_{i}=\sum_{i=1}^{N_{0}-1}w_{i}+\left(N-N_{0}\right)y\xrightarrow[N\to\infty]{}-\infty,
$$
in contradiction to $\left|\sum_{i=1}^{N}w_{i}\right|<\varepsilon$
for all $N$.
Thus, $\left\{ i\in\mathbb{N}\,\mid\, w_{i}=x\right\} $ is infinite.
It is easy to see that this implies existence of $M\in\mathbb{N}$
with $\left|\left\{ i\in\left\{ 1,\dots,M\right\} \,\mid\, w_{i}=x\right\} \right|=N$,
so that we can set $z_{i}:=w_{i}$ for $i\in\left\{ 1,\dots,M\right\} $.
$\square$
Remark:
1. A completely similar argument show that we can choose $z_{1},\dots,z_{M}\in\left\{ x,y\right\} $
with
$$
\left|\left\{ i\in\left\{ 1,\dots,M\right\} \,\mid\, z_{i}=y\right\} \right|=N
$$
and such that $\left(\ast\right)$ still holds.

For the above sequence, we also have
$$
\left|\sum_{i=K}^{M}z_{i}\right|=\left|\sum_{i=1}^{M}z_{i}-\sum_{i=1}^{K-1}z_{i}\right|\leq\left|\sum_{i=1}^{M}z_{i}\right|+\left|\sum_{i=1}^{K-1}z_{i}\right|<2\varepsilon\qquad\qquad\left(\square\right)
$$
for all $K\in\left\{ 1,\dots,M\right\} $.

By the argument given by @zhw., there is some $\delta>0$ and $C>0$
with $\left|\frac{f\left(x\right)}{x}\right|\leq C$ for all $x\in\left(-\delta,\delta\right)\setminus\left\{ 0\right\} $.
We will need this constant $C$ below.
First note that $f\left(0\right)=0$ is trivial (consider the sequence
$a_{n}=0$). Now, let us assume towards a contradiction that $f$
is not linear on any neighborhood of $0$. This implies that for every
$n\in\mathbb{N}$ there are $x_{n}\in\left(0,\frac{1}{n^{2}}\right)$
and $y_{n}\in\left(-\frac{1}{n^{2}},0\right)$ with
$$
\alpha_{n}:=\frac{f\left(x_{n}\right)}{x_{n}}\neq\frac{f\left(y_{n}\right)}{y_{n}}=:\beta_{n}.
$$
Indeed, if there where no such $x_{n},y_{n}$ for some $n\in\mathbb{N}$,
we could fix some $y_{n}\in\left(-\frac{1}{n^{2}},0\right)$ and would
get
$$
\gamma:=\frac{f\left(y_{n}\right)}{y_{n}}=\frac{f\left(x\right)}{x}
$$
for all $x\in\left(0,\frac{1}{n^{2}}\right)$. Likewise, fixing now
an arbitrary $x_{n}\in\left(0,\frac{1}{n^{2}}\right)$ and get
$$
\frac{f\left(y\right)}{y}=\frac{f\left(x_{n}\right)}{x_{n}}=\frac{f\left(y_{n}\right)}{y_{n}}=\gamma
$$
for all $y\in\left(-\frac{1}{n^{2}},0\right)$. All in all, this implies
$f\left(y\right)=\gamma\cdot y$ for all $y\in\left(-\frac{1}{n^{2}},\frac{1}{n^{2}}\right)$,
since we have $f\left(0\right)=0$. Thus, $f$ is linear on a neighborhood
of $0$ after all, a contradiction.
Note that (by choice of $C$ above), we have $\left|\alpha_{n}\right|\leq C$
and $\left|\beta_{n}\right|\leq C$. Let $\varepsilon_{n}:=\frac{1}{n^{2}}$
and choose $N_{n}\in\mathbb{N}$ with $N_{n}\geq\frac{1+C\varepsilon_{n}}{\left|\alpha_{n}-\beta_{n}\right|\left|x_{n}\right|}$.
Note that this is possible, since $\left|\alpha_{n}-\beta_{n}\right|>0$
and $\left|x_{n}\right|>0$. By the Lemma above, we find some $M_{n}\in\mathbb{N}$
and $z_{1}^{\left(n\right)},\dots,z_{M_{n}}^{\left(n\right)}\in\left\{ x_{n},y_{n}\right\} $
with
$$
N_{n}=\left|\left\{ i\in\left\{ 1,\dots,M_{n}\right\} \,\mid\, z_{i}^{\left(n\right)}=x\right\} \right|
$$
and
$$
\left|\sum_{i=1}^{K}z_{i}^{\left(n\right)}\right|<\varepsilon_{n}=\frac{1}{n^{2}}\qquad\forall K\in\left\{ 1,\dots,M_{n}\right\} .\qquad\qquad\left(\dagger\right)
$$
In particular (for $K=M_{n}$), we get
$$
\left|N_{n}x_{n}+\left(M_{n}-N_{n}\right)y_{n}\right|=\left|\sum_{i=1}^{M_{n}}z_{i}^{\left(n\right)}\right|<\frac{1}{n^{2}}.\qquad\qquad\left(\ddagger\right).
$$
Now define a sequence $\left(a_{k}\right)_{k\in\mathbb{N}}$ by
$$
a_{k}=z_{\ell}^{\left(K\right)}\qquad\text{ for }k=\sum_{i=1}^{K-1}M_{i}+\ell\text{ with }K\in\mathbb{N}\text{ and }\ell\in\left\{ 1,\dots,M_{K}\right\} .
$$
It is not too hard to see that this is well-defined. Furthermore,
the series $\sum_{k}a_{k}$ is convergent, since it is Cauchy; indeed, for $\sum_{i=1}^{T-1}M_{i}+p=t\geq k=\sum_{i=1}^{K-1}M_{i}+\ell$,
we have
\begin{eqnarray*}
\left|\sum_{n=k}^{t}a_{n}\right| & \leq & \left|\sum_{n=\ell}^{M_{K}}z_{n}^{\left(K\right)}\right|+\sum_{S=K+1}^{T-1}\left|\sum_{n=1}^{M_{S}}z_{n}^{\left(S\right)}\right|+\left|\sum_{n=p}^{M_{T}}z_{n}^{\left(T\right)}\right|\\
 & < & 2\varepsilon_{K}+\sum_{S=K+1}^{T-1}\varepsilon_{S}+\varepsilon_{T}\\
 & \leq & 2\sum_{n=K}^{T}\frac{1}{n^{2}}\leq2\sum_{n=K}^{\infty}\frac{1}{n^{2}}\xrightarrow[K\to\infty]{}0.
\end{eqnarray*}
By assumption on $f$, this implies convergence of $\sum_{n}f\left(a_{n}\right)$.
In particular, this series is Cauchy. But for $K\in\mathbb{N}$, we
have
\begin{eqnarray*}
\left|\sum_{n=1+\sum_{i=1}^{K-1}M_{i}}^{\sum_{i=1}^{K}M_{i}}f\left(a_{n}\right)\right| & = & \left|\sum_{n=1}^{M_{K}}f\left(z_{n}^{\left(K\right)}\right)\right|\\
 & = & \left|N_{n}f\left(x_{n}\right)+\left(M_{n}-N_{n}\right)f\left(y_{n}\right)\right|\\
 & = & \left|N_{n}\alpha_{n}x_{n}+\left(M_{n}-N_{n}\right)\beta_{n}y_{n}\right|\\
 & = & \left|N_{n}\left(\alpha_{n}-\beta_{n}\right)x_{n}+\beta_{n}\left(N_{n}x_{n}+\left(M_{n}-N_{n}\right)y_{n}\right)\right|\\
 & \geq & N_{n}\left|\alpha_{n}-\beta_{n}\right|\left|x_{n}\right|-\left|\beta_{n}\right|\cdot\left|N_{n}x_{n}+\left(M_{n}-N_{n}\right)y_{n}\right|\\
 & \overset{\text{see }\left(\ddagger\right)}{\geq} & N_{n}\left|\alpha_{n}-\beta_{n}\right|\left|x_{n}\right|-C\varepsilon_{n}\\
 & \geq & 1
\end{eqnarray*}
by choice of $N_{n}$, which shows that $\sum_{n}f\left(a_{n}\right)$
is not Cauchy and hence not convergent, a contradiction.
Answer: A start: There exists $\delta > 0$ such that $\frac{f(x)}{x}$ is bounded in $\{0<|x|<\delta\}.$ Proof: Otherwise there is a sequence of nonzero terms $x_n \to 0$ such that
$$\left|\frac{f(x_n)}{x_n}\right|> n$$
for all $n.$ We can pass to a subsequence $n_k$ such that $|x_{n_k}| < 1/k^2$ for all $k.$ We then have
$$(1)\,\,\,\,\left|\frac{f(x_{n_k})}{x_{n_k}}\right|> n_k \ge k.$$
Consider now the case where $x_{n_k}, f(x_{n_k})> 0$ for all $k.$ Then for each $k,$ there is a positive integer $m_k$ such that
$$(2)\,\,\,\,\frac{1}{k^2} < m_kx_{n_k} < \frac{2}{k^2}.$$
Think about the series
$$x_{n_1} + x_{n_1} + \cdots + x_{n_1} + x_{n_2} + \cdots + x_{n_2} + x_{n_3} + \cdots ,$$
where $x_{n_1}$ occurs $m_1$ times, $x_{n_2}$ occurs $m_2$ times, etc. By $(2)$ this series converges. But note $(1)$ shows the $k$th grouping in the "$f$-series" sums to
$$m_kf(x_{n_k}) > m_k\cdot k\cdot x_{n_k} > \frac{1}{k}.$$
Thus the $f$-series diverges, contradiction. So we are done in the case $x_{n_k}, f(x_{n_k})> 0.$ The other cases follow by similar arguments..
Answer: Here is a proof in the case that $f$ is differentiable at $0$.
Let $f(x) = rx + \epsilon(x)$, where $\lim_{x \to 0} {\epsilon(x)/x}=0$. I claim $\epsilon = 0$ in a a neighborhood of 0.
Suppose not. Then, up to extracting subsequences and making a few sign choices that are without loss of generality, we may assume that there exists $a_n$ decreasing monotonically to $0$ with $\epsilon(a_n)>0$, and $\epsilon(a_n)/a_n$ decreasing monotonically to $0$. Up to extracting another subsequence, we are left with two cases: either $\epsilon(-a_n) \geq 0$ for all $n$, or $\epsilon(-a_n) \leq 0$ for all $n$. I claim that neither is actually possible.
First, the easy case: assume $\epsilon(-a_n) \geq 0$ for all $n$. Let $k_n$ be the least integer greater than $1 \over \epsilon(a_n)$. Define $b_i$ to be alternatingly $a_1$ and $-a_1$ for the first $2k_1$ entries. Then define $b_i$ to be alternatingly $a_2$ and $-a_2$ for the subsequent $2k_2$ entries, and so forth. It is easy to check that $\sum b_i$ converges (not absolutely), but $\sum f(b_i) \geq \sum k_n f(a_n) = \infty$.
Now, the hard case: assume $\epsilon(-a_n) \leq 0$ for all $n$. The index manipulation here is pretty awful, but here goes. Let $l_1 = 1$, let $m_{1,1}=k_1$, and let $b_i = a_{l_1}$ for $i \in \{1,...,m_{1,1}\}$. Now, given $l_\alpha$, $m_{\alpha,1}$, and $b_i$ for $i \in \{1,...,m_{\alpha,1}\}$, choose $j_\alpha > l_\alpha$ such that $a_{j_\alpha} < 1/2^\alpha$ and $${\epsilon(-a_{j_\alpha}) \over - a_{j_\alpha}} < {1 \over 4^\alpha} \epsilon(a_{l_\alpha}).$$ Now, choose $p_\alpha > 0$ such that $0 < p_\alpha a_{j_\alpha} - k_{l_\alpha} a_{l_\alpha} < a_{j_\alpha}$. Let $m_{\alpha,2} = m_{\alpha,1} + p_\alpha$, and let $b_i = -a_{j_\alpha}$ for $i \in \{m_{\alpha,1} + 1,...,m_{\alpha,2}\}$.
Now pick $l_{\alpha + 1} > j_\alpha$, define $m_{\alpha + 1,1} = m_{\alpha,2} + k_{l_{\alpha + 1}}$, and define $b_i = a_{l_{\alpha + 1}}$ when $m_{\alpha,2} < i \leq m_{\alpha + 1,1}$.
To check that indeed $\sum b_i < \infty$ and $\sum f(b_i) = \infty$, note that $$|\sum\limits_{i=m_{\alpha - 1, 2} + 1}^{m_{\alpha,2}} b_i| = |p_\alpha a_{j_\alpha} - k_{l_\alpha} a_{l_\alpha}| < a_{j_\alpha} < {1 \over 2^\alpha},$$, whence $\sum b_i$ converges. Edit: well, we need to bound the partial sums within each $\sum\limits_{i=m_{\alpha - 1, 2} + 1}^{m_{\alpha,2}} b_i$, but this can be done by rearranging terms since the terms tend to zero as $\alpha \to \infty$. On the other hand, $$\sum\limits_{i=m_{\alpha - 1, 2} + 1}^{m_{\alpha,2}} f(b_i) \geq 1 - r a_{j_\alpha} + p_\alpha \epsilon(-a_{j_\alpha}).$$
Since $a_n \to 0$, we only need to check that $p_\alpha \epsilon(-a_{j_\alpha})$ is not too negative. By our choice of $j_\alpha$, $\epsilon(-a_{j_\alpha}) \geq {-1 \over 4^\alpha} a_{j_\alpha} \epsilon(a_{l_\alpha})$. By our choice of $p_\alpha$, $p_\alpha a_{j_\alpha} < 2 k_{l_\alpha} a_{l_\alpha}$, whence $p_\alpha \epsilon(-a_{j_\alpha}) \geq -2 a_{l_\alpha} k_{l_\alpha} \epsilon(a_{l_\alpha}) \geq -4 a_{l_\alpha}$. For $\alpha$ large, $a_{l_\alpha}$ is very small, so $$\sum\limits_{i=m_{\alpha - 1, 2} + 1}^{m_{\alpha,2}} f(b_i) \geq 1/2.$$ This proves the claim for $f$ differentiable.
By zhw.'s answer, the difference quotients near $0$ are bounded. By Heine-Borel, for each $a_n \to 0$, there is a subsequence $a_{n_k}$ such that $f(a_{n_k})/a_{n_k}$ converges. I'm sure that using similar arguments to the ones so far, you could show that all the subsequential limits are the same. This would show that, in fact, $f(x)/x$ converges as $x \to 0$, which would complete the proof.


Javascript: load with Ajax a javascript and transmit data to it as to a php script

Question: I am loading my script like this:
    var myTestString = "/modules/admin";
    $.ajax({
       type: "GET",
       url: "../../includes/test_tooltip.js",
       data: "module="+myTestString,
       dataType: "script"
     });

Is it possible to have access to module variable in my test_tooltip.js like this?
console.log("I am loaded!" + module);

My scenario is like this. I sometimes need to load that javascript and when i do, i do it in different modules, and i need this javascript to know which module because he will have to do some requests based on the module.
In php i know you can acces data with $_REQUEST["module"], if it could be done in javascript similar would be great.
Comment: what's should respond your test_tooltip.js when you launch your query ?
Comment: Does this actually have anything to do with PHP?
Comment: @Awea : test_tooltip.js will have to put some tooltips on some elements, and the text of that tooltips depends on what parameters i send to it.
Comment: @Ash : It doesn't involve PHP directly, i just need to send some data with that ajax request to the js file, as we do with PHP when making a request. I wished that your code below worked but it doesn't unfortunately.
Comment: I use `window.variable` and `delete window.variable` and case closed. Thanks guys!
Answer: var myTestString = "/modules/admin";
$.ajax({
   type: "GET",
   url: "../../includes/test_tooltip.js",
   context: { module: myTestString },
   dataType: "script"
 });

Your returned javascript should be executed within scope of the context object given to #.ajax, so you could then do:
console.log("I am loaded!" + this.module);

Comment: It doesn't work unfortunately. Any more ideas? have you tested it works for you? maybe i am doing something wrong. It says data not defined.
Comment: Okay I've modified the answer with an alternative solution


Encoding special characters within XML strings

Question: I have a config file that is XML. It looks like this:
<add key="PWD" value="adfas3312<"/>

The problem is that < at the end of the password. I thought that inside quotes it was fine. but my application croaks reading this config file. I have tried it with a CDATA type approach, tried < etc, but none of these seem to work.
What is the correct way to encode it in "" in XML?
Answer: <
< is not the same as <
See https://www.w3.org/TR/REC-xml/#syntax for more info.


Is the beta-binomial distribution a conjugate prior for some distribution?

Question: The beta distribution is conjugate prior for the binomial distribution.
Is the beta-binomial distribution a conjugate prior for some sampling distribution?
Answer: You're looking for the hypergeometric distribution. Incidentally, this link is one of the first two hits on Google for "beta binomial" "conjugate prior".
Answer: Have a look at the wikipedia page, there's a very nice conjugate prior table there.
If you are working with python, you can import the conjugate_prior package and start hacking


MYSQL - Retornar ocorrências mais próximo da REGEXP

Question: Preciso retornar o numero de ocorrências mais próximo da REGEXP, veja o exemplo abaixo:
SELECT * FROM tabela WHERE nome_produto REGEXP 'vestido|longo|manga|curta'

A ideia é que esta query me retorne assim

Vestido longo com mangas curtas
Vestido perolado com mangas curtas
Vestido Longo líndissimo ..

Mas ele retorna algo como:

Vestido lindo para usar no verão
Vestido qualquercoisa..

Enfim, ele não ordenada pelo maior número de ocorrências, têm como fazer isso?
Isso é pra um sistema de busca simples que preciso fazer..
Answer: Isto deverá ajudar a atingir aquilo que desejas.
SELECT * , MATCH (nome_produto) AGAINST ('vestido longo manga curta' IN BOOLEAN MODE) AS relevancia
FROM tabela
WHERE MATCH (nome_produto) AGAINST ('vestido longo manga curta' IN BOOLEAN MODE)
ORDER BY relevancia


How to change highcharts radius according to data

Question: i have data comprised of both positive and negative values which are to be displayed in a chart. i
am trying to display data in such a way that data point of positive values is greater than that of negative values.
the following is my code

        <button id="update"> Update</button>

When i click the update button, the size of data point value radius has to be changed.
Can this scenario will work ?
Answer: You can simply use the update method for points that meet your condition and change marker options. For performance reasons, it is better to set redraw parameter to false and redraw the chart after loop to avoid redrawing on every iteration.
Highcharts.chart('container', {
    ...
}, function(chart) {
    $('#update').click(function() {
        var points = chart.series[0].points;

        points.forEach(function(point) {
            if (point.y > 0) {
                point.update({
                    marker: {
                        radius: 10
                    }
                }, false);
            }
        });

        chart.redraw();
    })
});

Live demo: http://jsfiddle.net/BlackLabel/jznums3L/
API Reference:
https://api.highcharts.com/class-reference/Highcharts.Point#update
https://api.highcharts.com/class-reference/Highcharts.Chart#redraw


javascript equivalent change() in c#

Question: I would like to trigger the onchange with c# because i can't use js
<code>        (Master.FindControl("ComboBox") as CustomComboBox).SelectedValue = foo;
        (Master.FindControl("ComboBox") as CustomComboBox).change();
</code>
the ".change()" won't work. Is there a way in c# to make it work ?
Thank you for your help.
Comment: `change` is an event, you can't use standard method call to trigger other events in C# like JS does. You need to use `protected void ComboBox_Change(object sender, EventArgs e)` event handler in case of ASP.NET webforms code-behind.
Answer: Nope, there is no generic way to trigger another object's events in C#.
However, there is a simple workaround: Extract the code you execute in your ComboBox's onchange event into a separate method and call this method.

javascript equivalent change() in c#


A proper subspace of a normed vector space has empty interior.

Question: In a vector normed space $E$, prove that all vectorial subspace $F\neq E$ has a interior empty.
My approach:We consider, the open ball $B\subset F$, with $F$ proper subspace of $E$. If $x\notin F$, then we can increase the radius of the open ball $B$, such that $x\in B$, then the open ball $B$ came out of the subspace $F$, therefore there can be no such open ball. This is my intuition, but I don't know how write this "mathematically".
Comment: Your approach works well. Assume that $B\subset F$ with center at $0$ (can always translate it there), then $nB\subset F$ by linearity of $F$, but $nB$ for large enough $n$ can "swallow" any $x\in X$, so $F=X$ (contradiction).
Comment: Thanks, A.G. that's what I thought, but I want to write this more mathematically.
Answer: Setup and a hint:
Let $x \in F$. Let $y \in E \setminus F$, $\| y \|=1$. Then $\| x - (x+\varepsilon y/2) \|=\varepsilon/2<\varepsilon$. So if $x+\varepsilon y/2 \not \in F$, then $B_\varepsilon(x) \not \subset F$.
Now show that for every $\varepsilon > 0$, $x+\varepsilon y/2 \not \in F$. My hint: suppose it is in $F$, and conclude that $y \in F$, which is a contradiction.
So we have shown that $F$ does not contain any open balls around any of its points. Why does this imply it does not contain any open balls at all?
Your approach also works. Suppose $F$ contains some ball. Then it also contains a ball of the same radius centered at zero (subtract the center from each vector in the original ball). Hence it also contains any dilation of this new ball centered at zero (multiply by whatever scalar you like). But any vector can be in some such dilation; thus $F=E$ which is a contradiction.
I like my approach better, because we do similar tricks in loosely related problems. (For instance, we can use a very similar technique to prove that $L^2[0,1]$ is a meager subset of $L^1[0,1]$.)


Simple closed curve in $\mathbb C$

Question: A simple closed curve is a continuous function from [a b] to $\mathbb C$. Does a pair of concentric circles represent a simple closed curve? What about 3 concentric circles?
My thinking is that a pair of concentric circles is not the continuous image of a closed and bounded interval in $\mathbb R$. Since continuity fails it can not be a simple closed curve. Similarly any collection of n concentric circles. Can someone throw light on the concept.
Answer: If $f:[a,b] \to \mathbb C$ is continuous, then $f([a,b])$ is  connected, since $[a,b]$ is connected.
Any  collection of $n$ concentric circles is  not connected !
Conclusion ?
Comment: Conclusion is " not a simple closed curve. "

Simple closed curve in $\mathbb C$


Combine reinforces and unsupervised learning?

Question: I have an existing set of data and plan to generate more data that follows the same pattern. To do this, I plan to use unsupervised learning. How can I provide feedback on the generated data and reinforce "good" and discourage "bad" results?
In other words: how can I combine reinforced and unsupervised learning? Or am I approaching this problem the wrong way?
edit: I am interested in using machine learning to generate music. It would be comparatively easy to use an unsupervised network to generate new music, but how would human graders come into play? Let's say I generate 10 samples and have a human answer good or bad, how can I improve the network? I thought of simply feeding back the "good" pieces back in, but there must be a better way.
Comment: @gung I have edited the question to be more specific
Comment: Are you thinking of human input that says "no, these samples are no good," or some kind of automated mechanism?
Comment: @Dougal It would be human input
Comment: This is awfully broad. Why don't you just generate data from a fitted distribution w/ the same parameters, & correlation matrix?
Answer: Something that reminds me of this is the framework of generative adversarial networks. These models have two parts:

a generator, which is usually implemented as a neural network mapping uniformly distributed inputs to the data you generate, e.g. images, and
a discriminator, which tries to classify between generated samples and true data.

The generator is updated to try to trick the discriminator (by gradient descent to minimize its accuracy), which is then updated again to deal with the new samples.
This framework has been very popular in the past few years, but is very tricky to use in practice, and there's a lot of ongoing research (e.g. this paper from earlier this year and this one just published two days ago) in getting them to work more reliably.
I'm not aware of anyone having put humans into the loop yet. You could imagine, maybe, having human annotators do some kind of label smoothing for the discriminator: true data set samples get the label 1, terrible samples get label -1, okay ones get -.75, great ones get 0, maybe the best ones get labeled as .5 or even 1. I haven't thought through the consequences of this too much, but it might help.
As an aside, incorporating human feedback into machine learning is often termed active learning.


I'm getting error of .html extension not recognized using node command

Question: I got project from my client to update that project with some points. But I'm facing problem to run this project.
I install npm and all required node modules downloaded based on package.json information.

    {
  "name": "acelle-builder",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "type" : "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/ace": "0.0.42",
    "copy-webpack-plugin": "^5.1.1",
    "css-loader": "^3.6.0",
    "file-loader": "^4.1.0",
    "html-loader": "^0.5.5",
    "mini-css-extract-plugin": "^0.8.0",
    "node-sass": "^4.14.1",
    "raw-loader": "^3.1.0",
    "sass-loader": "^7.1.0",
    "style-loader": "^0.23.1",
    "svg-url-loader": "^3.0.0",
    "to-string-loader": "^1.1.5",
    "url-loader": "^2.1.0",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  },
  "dependencies": {
    "ace-builds": "^1.4.12",
    "bootstrap": "^4.5.2",
    "jquery": "^3.5.1",
    "js-beautify": "^1.13.0",
    "popper.js": "^1.16.1"
  }
}

there are some codes of importing html files like

    import controls from './controls.html';
import widgets from './widgets.html';

but when I run this project using node command I'm getting error with unknown file .html extension.
How can I solve this?
Answer: Node.js can only import JS modules.
If you want to use syntax which involves importing other kinds of things then you need to use an appropriate tool. The dependencies in the package.json file include WebPack. Use that.
There is even a script (named build) listed that will run it.
npm run build

Comment: yes. I know build command which gives bundle minified files using webpack . using bundled minified files I'm getting output . but I wanted to run this application with unminified source files so that I can add some extra features and check output instantly .
Comment: You can't. It isn't written in plain JS, you *need* the bundler to run.
Answer: You can't import from an html file. You are trying to import from ./controls.html and ./widgets.html. You have to import from js files. Maybe you meant "./controls.html" and "./widgets.js".


Include type-overs in Code Snippets

Question: When using XCode, I find the Code Snippets window to be very useful for dragging common code snippets into the editor. It's easy enough to add snippets, but I don't know how to make my custom snippets include type-overs (placeholder informative text that you type over). For example here is an included snippet for switch

Suppose I am adding a custom snippet for notifications. I can leave the parameter types empty like this, but I'd love to be able to include the type-overs.

If you double click on a snippet, you can select edit which lists a few actions. I'm not going to lie, some of them are vague. It's possible that the ability to do this lies on that screen but I'm not seeing.
Answer: You specify a type-over parameter like so:
<#type-over-text#>
So for my notifications example it would be:
<code>[[NSNotificationCenter defaultCenter] addObserverForName:<#notificationString#>
                                                  object:<#object#>
                                                   queue:[NSOperationQueue mainQueue]
                                              usingBlock:^(NSNotification *note) {
                                                  NSDictionary *dictionary = note.userInfo;
                                              }];
</code>
You can type this in your code, then highlight your code and drag it into the library or you can double click a code snippet then enter edit mode and type it in there.
Comment: As of this date, I've found snippet edit mode to be very buggy. For non-trival changes, I usually opt to copy-paste the text out. When finished, I either copy it back in, or just recreate the snippet.

Include type-overs in Code Snippets


Products containing the same digits

Question: I am looking for $d_1$ and $d_2$, where $d_1$ is a two digit integer and $d_2$ is a three digit integer, such that $d_1\cdot d_2$ is a product that contains the exact same digits as $d_1$ and $d_2$.
For example when $d_1$ is a single digit integer ($6$) and $d_2$ is a two digit integer ($21$) their product is $126$ (same digits as $6$ and $21$).
Many years ago wrote a program in BASIC and found a two digit number and and a three digit number whose product contained the same five digits as $d_1$ and $d_2$, but I have forgotten the numbers.
Comment: Thanks.  Excellent work.  I forgot to ask for unique answers.  For example, 15 × 705 = 10575 contains the zero and the five two times. I was looking for answers like 21 × 915 = 19215 and 14 × 926 = 12964.
Answer: This simple Mathematica code
Do[If[Sort[Join[IntegerDigits[m], IntegerDigits[n]]] ==
   Sort[IntegerDigits[m*n]],
  Print[m, " x ", n, " = ", m*n]], {m, 10, 99}, {n, 100, 999}]

gives the desired output:
14 × 926 = 12964

15 × 705 = 10575

15 × 930 = 13950

21 × 501 = 10521

21 × 600 = 12600

21 × 870 = 18270

21 × 906 = 19026

21 × 915 = 19215

24 × 651 = 15624

26 × 401 = 10426

27 × 810 = 21870

30 × 501 = 15030

30 × 510 = 15300

32 × 926 = 29632

35 × 401 = 14035

35 × 410 = 14350

35 × 725 = 25375

36 × 936 = 33696

41 × 323 = 13243

41 × 350 = 14350

42 × 678 = 28476

47 × 371 = 17437

47 × 542 = 25474

50 × 251 = 12550

51 × 201 = 10251

51 × 246 = 12546

51 × 300 = 15300

53 × 635 = 33655

54 × 846 = 45684

57 × 834 = 47538

59 × 845 = 49855

60 × 201 = 12060

60 × 210 = 12600

63 × 585 = 36855

63 × 855 = 53865

65 × 281 = 18265

65 × 641 = 41665

65 × 704 = 45760

65 × 875 = 56875

65 × 983 = 63895

68 × 926 = 62968

72 × 936 = 67392

75 × 231 = 17325

75 × 906 = 67950

78 × 624 = 48672

80 × 473 = 37840

80 × 860 = 68800

81 × 225 = 18225

81 × 270 = 21870

84 × 141 = 11844

84 × 546 = 45864

86 × 251 = 21586

86 × 800 = 68800

87 × 210 = 18270

87 × 435 = 37845

89 × 482 = 42898

90 × 351 = 31590

93 × 150 = 13950

Comment: Thank you very much.  I forgot to mention that I wanted only unique

Products containing the same digits


How to prove that continuous function do not necessarily preserve cauchy sequences

Question:
I am trying to construct a proof that continuous function do not
preserve Cauchy sequences
Every proof I can find is disprove by counter example, which is great
but these counter examples cannot be extend to how we can fix the
failure of Cauchy preservation through uniform continuity.

Prove: Let $(x_n)$ be a Cauchy sequence on a metric space $(M,d)$, let
  $f: (M,d_M) \mapsto (N,d_N)$ be a continuous function, then $(f(x_n))$
  may not be Cauchy.

(Note: I worded the problem myself which maybe a little bit awkward, feel free to point out a good fix)

(Use definition + by contradiction)
Let $(x_n)$ be a Cauchy sequence on $(M,d_N)$. Then $(x_n)$ is Cauchy if $\forall \epsilon > 0, \exists N \in \mathbb{N}$, such that $\forall n, m \geq N, d_M(x_n, x_m) < \epsilon$
Let $f$ be a continuous function such that  $f: (M,d_M) \mapsto (N,d_N)$. Then given $x_o \in M, \forall \epsilon>0, \exists \delta(\epsilon,x_o) > 0 \text{ s. t. } \forall x \in M, d_M(x,x_o) < \epsilon \implies d_N(f(x), f(x_o)) < \delta $
Suppose $(f(x_n))$ is Cauchy on $(N,d_N)$, then $\forall \epsilon > 0, \exists N' \in \mathbb{N}$, such that $\forall n', m' \geq N', d_N(f(x_{n'}), f(x_{m'})) < \epsilon$
At this point I thought I would be notice some inconsistencies between the definition thus revealing a problem but I am not confident with my conclusions...

Can we say that we reach a contradiction because $f$ cannot be
continuous since it isn't true for $\forall x$ since $(x_n)$ is only
Cauchy for $n \geq N$?
Can we say that since $M$ is not complete, therefore $(x_n)$ may fail
to convergence, thus $f(x_n)$ is not defined as $n \to \infty$?

What is the problem here exactly?
Comment: A conter-example is of course great to disprove the statement. There is no "generalization" of what you ask, because some cauchy sequence are preserved, and some other are not, and we can't do better. By the way, in a complete metric space, your statement is true !
Comment: How can there be a "proof" since sometimes continuous functions preserve cauchy sequences and sime others not? Unless you are trying to find the exact point in the proof where continuity doesn' get you any further (which may be done of course).
Answer: If $d$ is a complete metric on $X$ and $f:X\to X$ is continuous then any Cauchy sequence $(p_n)_{n\in N}$ has a limit point $p$,  and the continuity of $f$ requires that $(f(p_n))_{n\in N}$ converges to $f(p).$
So to find an exception we must use  an incomplete metric.
Example. Let $X$ be the positive reals with the usual metric $d(x,y)=|x-y|$. Let $f(x)=1/x.$ The image of the Cauchy sequence $(1/n)_{n\in N}$ is the sequence $(n)_{n \in N}.$
It is not necessary that the metric be unbounded. In the above example, replace the metric $d$ with the equivalent metric $e(x,y)=\min (1, |x-y|).$
Comment: Hi thanks for the counter example, but I can't help but think of if $X = \mathbb{R}$ instead, wouldn't the image of the sequence $(1/n)$ under $f(x) = 1/x$ also be...non-cauchy? It would still be $n$ wouldn't it
Comment: But in R the function f(x)=1/x  for x>0 is not continuous no matter what value you choose for f(0). The usual metric on R is complete so a continuous f on R will preserve the Cauchy property.
Answer: The statement says that $(f(x_n))$ may not be Cauchy.
The keyword here is "may not", hence trying to prove by contradiction (in the manner you described) is not possible, as the negation of "may not" is still "may not".


fgets doesn't stop reading user input

Question: I found some challenge on reddit to make a program which will sum up all DnD dice rolls. Number of throws is unlimited therefore I created this while loop.
I used fgets to input the string,  (I can't input only integers because the input is for example 1d3, where 1 is number of dice thrown, and 3 is number of sides of the dice thrown.)
When the user is prompted to input dice, fgets never stops reading user input.
For example:
To end inputting dice type 0
1d3
1d4
1d5
0
0
^C

Main function:
int main(void)
{
    char input[MAXSIZE];
    int sum = 0;
    printf("To end inputting dice type 0\n");
    while(*(input) != 0);
    {
        fgets(input, sizeof(input), stdin);
        printf("Debug: input = ");
        puts(input);
        printf("\n");
        sum += dice(input);
        printf("Debug: sum = %d\n", sum);
    }
    printf("Sum of dice rolls is %d.", sum);
    return 0;
}

Comment: @DevSolar `input[ strlen( input ) -1 ] == '\n'` sets up a hacker exploit when the first character read  is a _null character_.
Comment: You have found the culprit (also notice Sourav's correct mention of `0` not being the same as `'0'` in your `while` condition); but there is more that can be improved. You should check that `input[ strlen( input ) -1 ] == '\n'`. If it isn't, the line you read was incomplete. Also: 1) `#include ` missing. 2) `MAXSIZE` undeclared. 3) function `dice` undeclared. Please use [mcve]s.
Comment: @chux: Sheesh... good point. I'll let my comment stand though, as the general gist still holds. (Good thing I never wrote C in places where this would have mattered...)
Answer: Firstly, the literal value of the character input 0 is not 0. In ASCII, it is 48 (decimal).
Try
 while(*(input) != '0')  // (1) - use the character literal form
                         // (2) remove the ;

That said, the standard output is usually line buffered. You need to force a flush if you want to see the outputs in the terminal. You can do that by either

add a newline
 printf("Debug: input = \n");

use fflush(stdout).
Comment: Detail: C calls `'0'` a _character constant_, not a literal.
Comment: @ThomasJager Yes, I added that part, too.
Comment: It is a good point that it would make it so that hitting enter without entering a die type would cause it to end if the rest was working, but it's doesn't seem to be the real issue.
Comment: @user3121023 Right you are, missed that. Need to read more carefully. One bug is not enough. :(
Comment: The code should initialize `input` before testing whether `input[0]` is `'0'`.
Answer: Try this:-
while(fgets(input, sizeof input, stdin) != NULL)

or
while(fgets(input, sizeof input, stdin))

Comment: @LovreGusar Did you also delete the `;` at the end of the `while()`?
Comment: It doesn't fix the bug.
Answer: The issue was really simple and such a beginner mistake I feel shameful for even asking the question.
The semicolon after the while loop.
Thanks all for helping me out.
Answer: char input[MAXSIZE] = { 0 }; // initialise input!
// otherwise you get to here and access an uninitialised variable:
while(*(input) != 0); // <--- and a semicolon right there!!! Remove that!

In fact I think the loop you want is while (fgets(input, sizeof input, stdin) && strcmp(input, "0\n"))... note that I've hoisted the fgets into the loops control expression.
You should probably do a check after calling fgets to ensure a newline is read, for example
while (fgets(input, sizeof input, stdin) && strcmp(input, "0\n")) {
    size_t n = strcspn(input, "\n");
    if (input[n] == '\n') input[n] = '\0';
    else assert(input[n] == '\0'), // #include <assert.h>
         fscanf(stdin, "%*[^\n]"),
         fgetc(stdin);

There's no undefined behaviour associated with reading unsigned integers when using fscanf, so if you only plan on using positive values you can use that instead of fgets if you wish, i.e.
unsigned dice_count, dice_sides;
while (fscanf(stdin, "%ud%u", &dice_count, &dice_sides) == 2) {
    printf("You chose to roll %u times with dice that contain %u sides\n", dice_count, dice_sides);
}

fgets doesn't stop reading user input


An Euclidean geometry problem

Question: Consider two sets of three unit, coplanar vectors $(\mathbf{T}_1,\mathbf{N}_1,\mathbf{S}_1)$ and $(\mathbf{T}_2,\mathbf{N}_2,\mathbf{S}_2)$. Such that $\mathbf{T}_1\cdot\mathbf{N}_1=\mathbf{T}_2\cdot\mathbf{N}_2=0$, and $\mathbf{S}_1$ makes an angle $0<\sigma<\pi$ with $\mathbf{N}_1$, and similarly $\mathbf{S}_2$ makes an angle $0<\rho<\pi$ with $\mathbf{N}_2$. We align $\mathbf{S}_1$ and $\mathbf{S}_2$ such that $\mathbf{S}_1=-\mathbf{S}_2$, and impose some $\gamma\neq 0$ or $\pi$ such that $\mathbf{T}_1\cdot\mathbf{T}_2=\cos\gamma$.
The question is, what is $\mathbf{N}_1\cdot\left(\mathbf{T}_1\times\mathbf{T}_2 \right)$ in terms of $\sigma$, $\rho$ and $\gamma$ ?
I approached the problem by writing
\begin{align}
0=\mathbf{S}_1+\mathbf{S}_2=\sin\sigma\: \mathbf{T}_1+\cos\sigma\: \mathbf{N}_1+\sin\rho\: \mathbf{T}_2+\cos\rho\: \mathbf{N}_2
\end{align}
Then crossing with, say, $\mathbf{T}_2$ and dotting with, say, $\mathbf{N}_1$ we get an equation involving $\mathbf{N}_1\cdot\left(\mathbf{T}_1\times\mathbf{T}_2 \right)$ and $\mathbf{N}_1\cdot\left(\mathbf{N}_2\times\mathbf{T}_2 \right)$. Crossing with, say, $\mathbf{T}_2$ and dotting with, say, $\mathbf{N}_2$ we get another equation and so on, until we have a homogeneous system of 6 equations involving the 6 mixed products. On top of that we can write $\mathbf{T}_1$ in terms of the basis $(\mathbf{T}_2,\mathbf{N}_2,\mathbf{T}_2\times\mathbf{N}_2)$ and get another equation from which we can extract a non-trivial solution. The answer is
\begin{align}
\left(\mathbf{N}_1\cdot\left(\mathbf{T}_1\times\mathbf{T}_2 \right)\right)^2=1-\sec^2\sigma\left(\cos^2\gamma+\sin^2\rho+2\cos\gamma\sin\rho\sin\sigma \right)
\end{align}
I'm looking for a more direct, geometrical way to the answer.
Answer: We can chose a coordinate system such that:
$$
\mathbf{S}_1=(0,0,1),\quad
\mathbf{N}_1=(\sin\sigma, 0,\cos\sigma),\quad
\mathbf{T}_1=(\cos\sigma, 0,-\sin\sigma),\quad
\mathbf{S}_2=(0,0,-1).
$$
Vectors $\mathbf{N}_2$ and $\mathbf{T}_2$
lie then on a plane through $z$-axis,
making an angle $\alpha$ with $x$-axis. Hence:
$$
\mathbf{N}_2=(\sin\rho\cos\alpha, \sin\rho\sin\alpha,-\cos\rho),\quad
\mathbf{T}_2=(\cos\rho\cos\alpha, \cos\rho\sin\alpha,\sin\rho).
$$
The condition $\mathbf{T}_1\cdot\mathbf{T}_2=\cos\gamma$ gives:
$$
\cos\alpha={\cos\gamma+\sin\rho\sin\sigma
\over\cos\rho\cos\sigma}.
$$
We can then compute:
$$
\mathbf{N}_1\cdot(\mathbf{T}_1\times\mathbf{T}_2)=\cos\rho\sin\alpha
$$
and finally:
$$
\big(\mathbf{N}_1\cdot(\mathbf{T}_1\times\mathbf{T}_2)\big)^2
=\cos^2\rho-{(\cos\gamma+\sin\rho\sin\sigma)^2
\over\cos^2\sigma}.
$$
Answer: Since $S_1 = - S_2$, we can initially take
$ S_1 = j $
where $j$ the unit vector along the $Y$ axis
and
$S_2 = - j $
Now the angle between $N_1$ and $S_1$ is $\sigma$, therefore
$N_1 = - \sin \sigma \ i + \cos \sigma \ j $
($i$ is the unit vector along the $X$ axis)
and
$ T_1 = \cos \sigma \ i + \sin \sigma \ j $
In a similar fashion, we have
$ N_2 = \sin \rho \ i - cos \rho \ j $
and
$ T_2 = - \cos \rho \ i - \sin \rho \ j $
Now we'll rotate $T_2$ about the $ Y $ axis (to preserve the relation $S_1 = - S_2$).  The rotate $T_2$ is given by
$ T'_2 = R_Y( \phi ) T_2 = R_Y(\phi) ( - \cos \rho \ i - \sin \rho \ j ) $
And this equals
$ T'_2 = - \cos \rho ( \cos \phi , 0, - \sin \phi ) - \sin \rho (0, 1, 0) $
which can be written as
$ T'_2 = ( - \cos \rho \cos \phi, - \sin \rho, \cos \rho \sin \phi ) $
Since $ T'_2 \cdot T_1 = \cos \gamma $
Therefore,
$\cos \gamma = -\cos \sigma \cos \rho \cos \phi - \sin \sigma \sin \rho $
It follows that
$ \cos \phi = - \dfrac{ \cos \gamma + \sin \sigma \sin \rho }{\cos \sigma \cos \rho } $
Now, from the triple product identity,
$ N_1 \cdot (T_1 \times T'_2 ) = T'_2 \cdot (N_1 \times T_1)$
and
$N_1 \times T_1 = - k $
where $k$ is the unit vector along the $Z$ direction.
Hence
$ N_1 \cdot (T_1 \times T'_2) = - \cos \rho \sin \phi $
From which it follows that
$ \bigg( N_1 \cdot (T_1 \times T'_2) \bigg)^2 = \cos^2 \rho \left( 1 -  \left( \dfrac{\cos \gamma + \sin \sigma \sin \rho }{ \cos \sigma \cos \rho } \right)^2 \right)$
And this equals
$ \bigg( N_1 \cdot (T_1 \times T'_2) \bigg)^2 = \sec^2 \sigma \left( \cos^2 \sigma \cos^2 \rho - \cos^2 \gamma - \sin^2 \sigma \sin^2 \rho - 2 \cos \gamma \sin \sigma \sin \rho \right) $
Replacing $\sin^2 \sigma $ with $1 - \cos^2 \sigma $ gives
$\bigg( N_1 \cdot (T_1 \times T'_2) \bigg)^2 = \sec^2 \sigma \left( \cos^2 \sigma  - \cos^2 \gamma - \sin^2 \rho - 2 \cos \gamma \sin \sigma \sin \rho \right) $
And this equals
$\bigg( N_1 \cdot (T_1 \times T'_2) \bigg)^2 = 1 - \sec^2 \sigma \left(  \cos^2 \gamma + \sin^2 \rho + 2 \cos \gamma \sin \sigma \sin \rho \right) $

An Euclidean geometry problem


How can I install Drush without Composer?

Question: I've been trying to install Drush for a while but have failed. I have no experience in command line applications.
I've seen quite a few tutorials:

https://www.drupal.org/node/594744
https://www.drupal.org/node/2405811
https://drupalize.me/videos/wonderful-world-composer
https://getcomposer.org/doc/00-intro.md#installation-windows

but each one says that Composer is required. The catch, I can't seem to get Composer to work either.
Would I ever be able to install Drush, but still work around installing Composer?
Specifications:

Windows 10
Drupal 8.1.8
Cpanel 56.0.33
Php 5.59 (or higher according to this)
Composer Manager 8x-10-rc
Answer: This is the simplest solution I have found.
If you don't want to use composer, follow the instructions here...
https://sharpi.sh/blog/web-development/install-drush-on-ubuntu-quickly-without-composer/

Download a Drush release from Github to user folder

wget https://github.com/drush-ops/drush/releases/download/8.1.17/drush.phar

Rename drush.phar to drush

mv drush.phar drush

Find the bin directory

echo $PATH
which shows something like.... /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
I'll go with /usr/local/bin

Move drush to the bin

mv drush /usr/local/bin/drush

Change permissions to

chmod +x /usr/local/bin/drush

Test with

drush version
Comment: OP is on Windows...
Comment: Isn't it advised to install Drush to the project level now and optionally install Drush Wrapper? Anyway if user is on Windows, `wget` isn't going to work without additional steps. Better off with composer.
Comment: Sorry, stuck this here for my own sanity more than anything. Some people don't want to use composer https://www.ostraining.com/blog/coding/composer-cms/
Answer: Just follow the installation instructions on http://docs.drush.org/en/8.x/install/ No need for Composer to use Drush 8.
PS! Drush 9 is meant to be installed site local - as part of your Drupal installation - using Composer.


Having trouble using my usual method of partial fraction decomposition for $\frac{9 + 3s}{s^3 + 2s^2 - s - 2}$.

Question: I'm having trouble using my usual method of partial fraction decomposition for $\dfrac{9 + 3s}{s^3 + 2s^2 - s - 2}$.
We can factor such that $$\dfrac{9 + 3s}{s^3 + 2s^2 - s - 2} = \dfrac{A}{s - 1} + \dfrac{B}{s + 1} + \dfrac{C}{s + 2}$$
Therefore, $$ 9 + 3s = A(s + 1)(s + 2) + B(s - 1)(s + 2) + C(s + 1)(s - 1)$$
And we have that $s \not = 1, -1, -2$.
From here I usually plug in values to find $A$, $B$, and $C$.
$s = 0:$
$$9 = 2A - 2B - C \implies C = 2A - 2B - 9$$
$s = 2:$
$$15 = 12A + 4B + 3C \implies A = \dfrac{15 - 4B - 3C}{12}$$
$s = 3:$
$$18 = 20A + 10B + 8C \implies 10B = 18 - 20A - 8C \implies B = \dfrac{9}{5} - 2A - \dfrac{4C}{5}$$
We now have equations for $A$, $B$, and $C$. But if I try to substitute them into each other, this will result in an infinite loop of substitution.
This method for partial fraction decomposition have always worked for me in the past, so I don't understand why it isn't working in this situation.
I would greatly appreciate it if people could please take the time to explain why my method for partial fraction decomposition is not working in this case and what I should do.
Comment: @Moo I think I found my mistake. For some reason, I've confused myself by convincing myself that $s \not = 1, -1, -2$; but $s = 1, -1, -2$ is actually necessary to use this method of partial fraction decomposition. Sorry, I feel very stupid right now.
Comment: We all do stuff like that at least ten times a day! If we aren't making mistakes, we are not learning!
Comment: Try expanding the RHS, collecting like terms and then equating terms on LHS/RHS side of $$3 s + 9 = A(s + 1)(s + 2) + B(s - 1)(s + 2) + C(s + 1)(s - 1)$$ You get 3-equations and 3 unknowns and arrive at $$A = 2, B = -3, C = 1$$
Answer: You've written:
$$9+3s = A(s+1)(s+2)+B(s-1)(s+2)+C(s+1)(s-1).$$
This equation has to be true for any $s$, so choose clever values.  For instance, $s=-1$ gives us
$$ 6 = B(-2)(1) \implies B=-3$$
Next $s=1$:
$$12 = A(2)(3)  \implies A=2.  $$
Next, $s=-2$:
$$3 = C(-1)(-3) \implies C=1.$$
One can also plug in complex values for $s$ and equate real and imaginary parts.
Comment: When we clear the fractions, we create new functions with removable singularities.  The graph of the new function looks exactly like the polynomial, except there are holes at the three singular points.  But that just means the polynomials themselves have to be equal, so we work with them instead of the rational functions.
Comment: Thanks for the response. Why is it that we are allowed to select $s = 1, -1, -2$ when we have $\dfrac{9 + 3s}{s^3 + 2s^2 - s - 2} \forall s \not = 1, -1, -2$? What confused me was that, initially, it would seem that we cannot select these values for $s$ (because they would result in division by $0$).
Answer: You've got the right expression
$$
9 + 3s = A(s + 1)(s + 2) + B(s - 1)(s + 2) + C(s + 1)(s - 1).
$$
Now you can think like this: it is a polynomial equation of the kind $p(s)=0$. A nonzero polynomial cannot have more than the finite number of zeros. Since this equation has infinitely many solutions (all $s$ except a finite number) then the polynomial must be identical zero, and the equation holds true for those exceptional values as well. Setting $s=\pm 1, -2$ we get $A=2$, $B=-3$, $C=1$.
It is also possible - as you did - to set other values of $s$ and get the linear system. In your case you have obtained
$$
\begin{cases}
2A-2B-C=9,\\
12A+4B+3C=15,\\
20A+10B+8C=18.
\end{cases}
$$
Using the linear algebra technique such systems are usually solved by Gauss elimination, but it is also possible to solve it by substitution as you tried, but got infinite loops. You have to do a systematic substitution: express one variable e.g. $C$ from one equation and substitute it into all other equations. Here how it goes: the first equation gives $C=2A-2B-9$. Substitute it into the second and the third ones
$$
\begin{cases}
C=2A-2B-9,\\
12A+4B+3(2A-2B-9)=15,\\
20A+10B+8(2A-2B-9)=18.
\end{cases}\quad\Leftrightarrow\quad
\begin{cases}
C=2A-2B-9,\\
9A-B=21,\\
18A-3B=45.
\end{cases}
$$
Now we do the same: express $B$ from the second equation $B=9A-21$ and set into the third one
$$
\begin{cases}
C=2A-2B-9,\\
B=9A-21,\\
18A-3(9A-21)=45.
\end{cases}\quad\Leftrightarrow\quad
\begin{cases}
C=2A-2B-9,\\
B=9A-21,\\
A=2.
\end{cases}
$$
It works without infinite loops.
Answer: I would prefer a simpler method for this problem, known as Heaviside cover-up method:
$$\dfrac{9+3s}{s^3+2s^2-s-2}=\dfrac{9+3s}{s^2(s+2)-(s+2)}
=\dfrac{9+3s}{(s-1)(s+1)(s+2)}$$
Now,$$\dfrac{9+3s}{(s-1)(s+1)(s+2)}\\=\left.\dfrac{9+3s}{(s+1)(s+2)}\right|_{s=1}\cdot\dfrac{1}{s-1}+\left.\dfrac{9+3s}{(s-1)(s+2)}\right|_{s=-1}\cdot\dfrac{1}{s+1}+\left.\dfrac{9+3s}{(s-1)(s+1)}\right|_{s=-2}\cdot\dfrac{1}{s+2}\\
=\dfrac{2}{s-1}-\dfrac{3}{s+1}+\dfrac{1}{s+2}
$$
Comment: This is very neat.
Answer: The method you are using is: if the equality holds for all values of s, then it will hold for the special ones, but that isn't enough.
In the equation $$ 3s+9=A(s+1)(s+2)+B(s-1)(s+2) +C(s+1)(s-1)$$ multiply everything on the right side and write it in a form $$ \alpha_1 s^2+\alpha_2 s +\alpha_3$$ . $\alpha_1$ is 0 because it's 0 on the left side, $\alpha_2=3, \alpha_3=9$.
I would like to mention that the reason your method usually works is that there is a theorem that says this equation always has the solution for A,B,C, otherwise you would have to check that it holds for the A,B,C you've calculated. But to get them, you need to choose "good" values for s.


How to override default caching of node_modules while building Node.js application in Bluemix?

Question: Is it possible to override the default behavior of Bluemix to cache the node_modules installed by NPM during builds ?
Answer: Bluemix maintains a cache directory per node application, that is persisted between builds. The cache stores resolved dependencies so they are not downloaded and installed every time the app is deployed. Use the NODE_MODULES_CACHE variable to determine whether or not the Node buildpack uses or ignores the cache from previous builds. The default value is true.
<code>    $ cf set-env myapp NODE_MODULES_CACHE false
</code>
Note that node_modules that are included in your application are not cached.
You can use a cacheDirectories array in your top-level package.json to achieve fine grained control over what modules are cached. When the cacheDirectories element is present in the package.json only those modules which are in the cacheDirectories array will be cached. In the following example only node_modules and bower_components are cached:
<code>{
  "cacheDirectories": ["node_modules","bower_components"],
  ...
}
</code>
More information here.
Answer: The default behavior in Bluemix is to cache all node_modules installed by NPM.
However, we can use the NODE_MODULES_CACHE variable to determine whether or not the Node buildpack uses or ignores the cache from previous builds.
To disable caching set NODE_MODULES_CACHE to false by executing the below CF command.
$ cf set-env myapp NODE_MODULES_CACHE false


How to implement .psd to .jpg conversion using ImageMagick for a batch of files using Java

Question: I need to view .psd images in swing so I decided to convert that into .jpg and try to show it.
<code> My terminal command for single .psd to .jpg

 convert image.psd image.jpg (this is creating three images image-0.jpg,image-1.jpg,image-2.jpg)
</code>
but if I used
<code> convert image.psd[0] image.jpg (this gives me correct output)
</code>
But i need to convert .psd images using java. i tried this but it is not working
<code>if (new File(_imageicon[i].toString()).getName().endsWith(".psd") ||
        new File(_imageicon[i].toString()).getName().endsWith(".PSD")) {
    File psdFile = new File(_imageicon[i].toString());
    if(psdFile.exists()) {
        System.out.println("_imageicon[i].toString()"+_imageicon[i].toString());
        System.out.println("_imageicon[i].toString().replace"+_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
        ProcessBuilder pb = new ProcessBuilder("convert", _imageicon[i].toString() , _imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
        pb.redirectErrorStream(true);
        try {
            Process p = pb.start();
        } catch (IOException ex) {
            Logger.getLogger(GridEditor.class.getName()).log(Level.SEVERE, null, ex);
        }

        ImageIcon ii = new ImageIcon(_imageicon[i].toString().replace(".psd", ".jpg").replace(".PSD", ".jpg"));
        Image imagepdf1 = ii.getImage();
        Image newimg = imagepdf1.getScaledInstance(100, 60, java.awt.Image.SCALE_SMOOTH);
        ii = new ImageIcon(newimg);
        _lbl[i].setIcon(ii);
    }
}
</code>
Any idea please suggest.
Comment: Where does the code consume the error and output streams?  See also [The Perils of Image.getScaledInstance()](https://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html).
Comment: http://im4java.sourceforge.net/
Answer: For batch convert use this
<code>    ProcessBuilder pb = new ProcessBuilder("mogrify", "-format ", "jpg ", psdafterconvpath, psdpath + "\\" + "*.psd");
    pb.redirectErrorStream(true);
    try {
        Process p = pb.start();
    } catch (IOException ex) {
        Logger.getLogger(DefineTask.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
</code>
Comment: This code does not throw error but it is not converting but this works from command line as like "mogrify -format jpg psdafterconvpath psdpath/*psd"
Answer: There is a space after format and jpg. Also add [0] to get the single image
<code> ProcessBuilder pb = new ProcessBuilder("mogrify", "-format", "jpg", psdafterconvpath, psdpath + "\\" + "*.psd[0]");
pb.redirectErrorStream(true);
try {
    Process p = pb.start();
} catch (IOException ex) {
    Logger.getLogger(DefineTask.class.getName()).log(Level.SEVERE, null, ex);
}
}
</code>
This works for me. Check and confirm.


Is this a correct interpretation of Python code?

Question: Here'a snippet of Python code:
 while i > 1:
    i = i - 1
    j = randrange(i)  # 0 <= j <= i-1
    items[j], items[i] = items[i], items[j]
 return

I want to use this algorithm in my Pascal project. The first 3 lines are absolutely clear to me, but what does this program do in the fourth line of code? Does it assign the random value kept on the j to the ith slot in the array, and then moves to the left (keeping the "used" values on the right)?
Comment: If this is supposed to be Fisher-Yates shuffle, then it's wrong. It should be `j = randrange(i+1)` (so 0 <= j <= i).
Comment: It's Sattolo's algorithm, a variation of F-Y shuffle.
Answer: Python has a neat syntax for swapping variables:
a,b = b,a

Now a has the value of b and vice-versa. The fourth line of your program does exactly this.


Frequency/harmonic analysis of accents

Question: I am looking to find out how accents could/would be detected by a programme, I haven't as of yet undergone an experiment into detecting or observing anything noticeable about recorded accents. I am not sure a frequency/harmonic analyses will reveal anything. Trying to find any literature review on the subject is sadly lacking, so I was hoping to find out from the community where one might start or what would you look for in any given accent. Something quantifiable could or should surely be observed dependant on an accent?
For instance say I have 10 people from town A and 10 people from town B, all males with roughly the same age Town A and Town B both speak English but have different accents. If I ask each of them to repeat the same word, we should notice a difference in the frequency/harmonic analysis of Town B folk from Town A folk.
What is your best guess at where this could be found? Is frequency or harmonic analysis going to reveal anything between the two groups?
For instance if we take specific vowels we could possibly see a certain threshold reached in amplitude level and frequency (pitch) and could then work out the resonance frequencies of the vocal tract for certain accents based on key vowels? In speech science and phonetics the use of formant is used to mean an acoustic resonance of the human vocal tract. It is often measured as an amplitude peak in the frequency spectrum of the sound, using a spectrogram or a spectrum analyzer, though in vowels spoken with a high fundamental frequency, as in a female or child voice, the frequency of the resonance may lie between the widely-spread harmonics and hence no peak is visible.
If you notice that using a formant table you can construct vowels with a vocal formant filter, could this be reverse engineered to essentially "detect"?
My worst fear however is that any given vowel is going to have either a lack of accent specific information, or the analysis done will have too much sporadic information between individuals.
Could anyone point me in the right direction here im quite stuck?
Comment: It seems that for pitch or some other feature of sound the sound of a word could represent a short time series for the individuals.  If the sample is not too short you could perhaps fit harmonic regression models for individuals and look to see if amplitude and frequency vary more between members from different towns than for comparing members from different towns.
Answer: I would suggest creating a dataset of voice recordings, labelled by accent. This will allow you (eventually), to create a model that can distinguish between accents. Obviously the more speech samples you have per subject and per accent, the more likely  you will be able to perform this task reliably.
After appropriate filtering, you could then break each recording into (domain relevant) chunks or epochs (e.g. 10s epochs) and then calculate a number of standard speech signal processing or standard signal processing features for each epoch.
In terms of the signal properties I think accent would manifest itself in terms of both amplitude and frequency characteristics. Some features to try per epoch:

Mean amplitude per epoch
RMS amplitude per epoch
Amplitude range per epoch
Mel-frequency cepstral coefficients (MFCCs)
Spectral edge frequency (calculated from windowed power spectral density per epoch)
Harmonic frequency ratios (literature search may be necessary here to determine frequency ranges)
Power in relevant frequency ranges (again, application specific)

Plotting the features for each accent group might be a good first pass for determining which features can discriminate. If you have more than one subject you could take the mean and coefficient of variability of each feature across all epochs to allow comparison between subjects.
An ANOVA could then serve as a good starting point to test for significance difference between different accent groups for a given feature.
Hope this helps.

Frequency/harmonic analysis of accents


Find number of sub-directories in each folder separately

Question: I have a folder that holds a certain number of folders and they all contain a folder within a folder, I want to check the number of subdirectories in each of these folders. I tried using os.walk and adding +1 each time it comes across a folder. But this returns the sub-directory count of all the directories, I want them separately for each folder.
for eg, lets say I have folder A1 and A2.
A1: subfolder1 -(contains)-> subfolder2
A2: subfolder1 -(contains)-> subfolder2 -(contains)-> subfolder3 -(contains)-> subfolder4

Right now my code returns 6 instead of 2 and 4.
def count_folders(path):
    count=0
    for dir in os.listdir(path):
        nDir = os.path.join(path,dir)
        if os.path.isdir(nDir):
           for dirs in os.walk(nDir):
               if os.path.isdir(dirs[0]):
                  count+=1
    print count

Comment: The result you want could be, perharps, a dictionary like this: {"A1": 2, "A2": 4} ?
Comment: @igordsm I made a mistake in my question, I've clarified that now.
Answer: This works fine when I try it here:
def count_folders(path):
    count = 0
    for root, dirs, files in os.walk(pth):
        count += len(dirs)
    return count

To understand how this works try to print "root", "dirs" and "files" one by one.
Documentation
A short tutorial
Answer: Maybe you can comment out these three lines, that can prevent the count variable to count the number of 'subfolders of subfolder'.
import os
def count_folders(path):
    count=0
    for dir in os.listdir(path):
        nDir = os.path.join(path,dir)
        if os.path.isdir(nDir):
            count+=1
#            for dirs in os.walk(nDir):
#                if os.path.isdir(dirs[0]):
#                   count+=1
    print count

Answer: If you are looking for the count of subdirs inside each subdir in path you can try this function:
def count_folders(path):
    count={}
    for dir in os.listdir(path):
        nDir = os.path.join(path,dir)
        if os.path.isdir(nDir):
           c = 0
           for d in os.listdir(nDir):
               if os.path.isdir(os.path.join(nDir, d)):
                  c+=1
           count[nDir] = c
    print count

It returns a dictionary with the count of subdirs inside each subdir of path.
Comment: I made a small mistake in the question, essentially what I'm trying to get is the length of the directory tree. Please see the edited question


Variance Ratio Formula

Question: I've been trying to minimize/maximize the ratio of quadratic forms given by
$$Q(c)=\frac{c^\top \Sigma c}{c^\top \text{diag}(\Sigma) c}$$
where $\Sigma$ denotes a covariance matrix of some $n$-dimensional vector, $X$.
I've been able to show that in the $n=2$ case, $Q(c)$ takes values between $1 \pm R$, where $R$ is the correlation coefficient between $X_1$ and $X_2$. But I'm getting stuck trying to optimize this function in the general case. Is there an analytic solution to this optimization problem?
Answer: You're right: indeed, there is an algebraic solution.
The optimization must occur over the set of $c$ for which the denominator is nonzero.  I will leave to interested readers the special case where there exist nonzero $c$ for which the denominator nevertheless is zero: this is equivalent to at least one of the components of $X$ being constant.
This leaves us to deal with the generic case where all diagonal elements $\sigma_{ii}^2$ of $\Sigma$ are (strictly) positive.  Writing
$$\Delta = \pmatrix{\sigma_{11} & 0 & \cdots & 0 \\ \vdots & \ddots & \cdots & 0 \\ 0 & 0 & \cdots & \sigma_{nn}}$$
we obtain the usual relationship between the covariance matrix and the correlation matrix $R,$
$$\Sigma = \Delta R\Delta.$$
Given $c\in\mathbb{R}^n\setminus\{0\},$ rescaling $$x = c\Delta \ne 0$$ gives
$$\frac{c^\prime\Sigma c}{c^\prime \operatorname{diag}(\Sigma) c} = \frac{x^\prime R x}{x^\prime x}.$$
Those familiar with PCA will already see the answer, but for the record let's obtain it using more fundamental results of linear algebra.
Because $\Sigma$ represents a positive-definite quadratic form, so does $R$ and therefore (by the Spectral Theorem) $R$ has an orthonormal eigenbasis $e_1, \ldots, e_n$ of eigenvectors with associated eigenvalues $\lambda_i\ge 0.$  Use this basis to express $x\ne 0$ as a linear combination
$$x = x_1 e_1 + \cdots + x_n e_n.$$
Then
$$\frac{x^\prime R x}{x^\prime x} = \frac{x_1^2\lambda_1 + \cdots +x_n^2\lambda_n}{x_1^2 + \cdots + x_n^2}$$
is a linear combination of the eigenvalues with coefficients $x_i^2 / (x_1^2 + \cdots + x_n^2)$ that are not all zero.
This set is (by definition) the convex hull of the eigenvalues, which will be the smallest closest interval containing them all.  Clearly this is maximized by the largest eigenvalue of $R$ and minimized by the smallest one.
This generalizes the $n=2$ case because the eigenvalues of the correlation matrix with correlation coefficient $r$ are $1\pm r.$
Incidentally, because the eigenvalues are the roots of the characteristic polynomial of $R,$ we may consider this  an algebraic solution, even though it's somewhat indirect (you still have to find the roots if you need explicit values).
Comment: @Hasse Thank you--that's correct.  I have made the change.

Variance Ratio Formula


After adding additional features, same accuracy on test data, but higher accuracy on training data, how should I interpret ?

Question: I've done 5-fold cross-validation and the model is SVM.
300 features: 0.53 on test, 0.55 on training;
700 featuers: 0.53 on test, 0.67 on training.
Does this mean that the additional 400 features is useless ?
Comment: It depends on the size of the dataset you are using to train the model. If you added new features and performance increased on the training set but nothing or lower for testing, my guess is that you are starting to overfit.
Comment: SVMs are not guaranteed to be overfit-proof. They have nice properties of generalization but not guarantees that you will always learn from data. The power of SVMs lies in custom kernels, which if used properly, can map your data in a new space where separation is much easier than in the original feature space.
Comment: Let me kindly disagree. You showed that after addition of 400 new features the performance improved *only* on the training set and stayed the same on the test set. You are interested of the performance on out-of-sample dataset, not on the training set since the error on training set is not a good indicator how well you learned.
Comment: @xeon, SVM is a max-margin classifier. Does it mean that it can avoid overfitting to some extent ?
Comment: @xeon, I think my results just shows the SVM's power. Even though it "overfits" on training data, but it still maintains a not-worse result on testing data. In my opinion, the overfitting problem is that the model overfits the noise in the training data, and lost the real underlying trends in the data, which will lead to a much worse results on testing.
Comment: Can you provide the sizes of training and testing sets you are using in your experiment?
Comment: @xeon I have 4000 data points. I do 5-fold cross-validation. I agree that it's overfitting on the training data, but the overfitting in SVM seems doesn't hurt the performance on testing data. My question is, we I do prediction on some other dataset, should I use my 700 features of just 300 features ?
Answer: I think you have overfitting on training data.you can go to this link for solving this matter :
http://www.researchgate.net/post/How_can_we_solve_an_overfitting_problem
Answer: Usually you pick the smallest possible set of features with the highest accuracy on the testing set. If your dataset is not balanced however check the acquired confusion matrices or use a metric that is not affected by skewed classes.


A tricky integral (flux of a point charge through a disk)

Question: The integrals:
$$
\oint \frac{r\,dr\,d\phi}{\left(L^2+r^2+h^2+2Lr\cos\phi\right)^{3/2}}\\
\oint \frac{dx\,dy}{\left((L+x)^2+y^2+h^2\right)^{3/2}}
$$
If we have a point charge at the origin and we want to find the flux through a disk of radius $R$ which is located at $(x,0,z)$ and lies parallel to the $x-y$ plane we will have to do a tricky integral. We can write down the exact $E.dA$ or we can try and find the solid angle (turns out it is like finding the flux through an ellipse at $(0,0,z)$).
What I'm looking for is the answer to that integral or the solid angle. I thought the integral wasn't doable. But recently I came across a physical way of finding it using greens reciprocity theorem. If you can find it from that, then the integral should be doable as well!
To be clear: this is entirely a math problem. We have an inverse square vector field. We want its flux through a disk.
for example take the (x=0) situation.we can simply use gauss law and just find the solid angle to obtain the flux.ot write out the integral by using r and theta as variables.but even at this situation doing it with dxdy integral is tough.
Comment: 1) the whiff of desperation will not help you much here, 2) you are getting no response because your description of the problem is poor,  I suggest you link to a picture of the geometry and the equation.
Comment: @iman: for future reference, use MathJax (see explanation here: http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference ) in order to typeset mathematics as I did.
Comment: I dont have access to LaTeX to write down the integral but its simple.the hard part is evaluating it.c'mon people please help me in this!!
Comment: you are right Mr.Gordon but I couldnt write the integral itself in LaTeX so I had to go with this crappy description.I added a picture.hope it helps.and to be clear:I know how to write the integral.trick is how to do this? I get an elliptic in cartesian.sadly!
Answer: The solid angle can be expressed in terms of complete elliptic integrals of first and third kind.
I believe this is first derived by F. Paxton in 1959.

THE REVIEW OF SCIENTIFIC INSTRUMENTS. VOLUME 30, NUMBER 4 APRIL, 1959.
  Solid Angle Calculation for a Circular Disk. F. PAXTON

A copy of the article can be found
here.
Below is my attempt to derive the same result in an alternate manner.
The integral is indeed trickier than I thought.
To avoid confusion with the usage of $x,y,z$ as coordinates, let us change the problem and assume the circular disk $C$ we are dealing with lies in the plane $z = b$, centered at $(a,0,b)$ with radius $s$. We will assume $a, b > 0$ and $a \ne s$.
In terms of ordinary spherical polar coordinates $(r,\theta,\phi)$, points on the plane $z = b$ can be parametrized as:
$$(x,y,z) = (b\tan\theta \cos\phi,\,b\tan\theta\sin\phi,\, b)$$
Let $\rho = \sqrt{x^2+y^2} = b\tan\theta$, the "element" for integrating the solid angle is given by:
$$d\Omega
= \sin\theta d\theta \wedge d\phi
=\frac{\tan\theta d\tan\theta}{\sqrt{1 + \tan\theta^2}^3} \wedge d\phi
= \frac{b \rho d\rho \wedge d\phi}{\sqrt{\rho^2+b^2}^3}
= \frac{b\;dx \wedge dy}{\sqrt{\rho^2+b^2}^3}
$$
Introduce complex coorindates $\eta = x + iy$ and $\bar{\eta} = x - iy$, the solid angle
extended by $C$ can be rewritten as:
$$\begin{align}
\Omega_{C}
= & \int_{C} d\Omega
= \frac{b}{2i}\int_{C} \frac{d\bar{\eta} \wedge d\eta}{\sqrt{\eta\bar{\eta}+b^2}^3}
=\color{blue}{^{[1]}} \frac{b}{i} \int_C d\left(\frac{1}{\eta}\left( \frac{1}{b} - \frac{1}{\sqrt{\eta\bar{\eta}+b^2}}\right)\right) \wedge d\eta\\
= & \frac{b}{i} \int_{\partial C} \left(\frac{1}{b} - \frac{1}{\sqrt{\eta\bar{\eta} + b^2}}\right) \frac{d\eta}{\eta}
= 2\pi \delta_{C} + ib \int_{\partial C} \frac{d\eta}{\eta \sqrt{\eta\bar{\eta} + b^2}}
\end{align}$$
where $\delta_{C} = 1 \text{ or } 0$ depends on whether $s > a$ or $< a$. In other words, whether $\partial C$ contains $0$ or not.
On $\partial C$, we can parametrize $\eta$ as $s e^{it} + a$ and $\bar{\eta}$ as $s e^{-it} + a$. Substitute this into above expression, we obtain:
$$\begin{align}
&\Omega_C - 2\pi \delta_{C}\\
= &ib \int_{-\pi}^{\pi} \frac{ dt }{\sqrt{ s^2 + a^2 + b^2 + 2sa\cos t}}\frac{ is e^{it}}{s e^{it} + a }\\
= & -b
\int_{0}^{\pi} \frac{ dt }{\sqrt{ s^2 + a^2 + b^2 + 2sa\cos t}}
\left( \frac{s e^{it}}{s e^{it} + a } + \frac{s e^{-it}}{s e^{-it} + a } \right)\\
= & -b
\int_{0}^{\pi} \frac{ dt }{\sqrt{ s^2 + a^2 + b^2 + 2sa\cos t}}
\frac{2s(s + a\cos t)}{s^2 + a^2 + 2sa\cos t}\\
= & -b
\int_{0}^{\pi} \frac{ dt }{\sqrt{ s^2 + a^2 + b^2 + 2sa\cos t}}
\left( 1 + \frac{s^2 - a^2}{s^2 + a^2 + 2sa\cos t} \right)\\
= & -2b
\int_{0}^{\pi/2} \frac{ dt }{\sqrt{ s^2 + a^2 + b^2 + 2sa\cos(2t)}}
\left( 1 + \frac{s^2 - a^2}{s^2 + a^2 + 2sa\cos(2t)} \right)\\
= & -2b
\int_{0}^{\pi/2} \frac{ dt }{\sqrt{ (s+a)^2 + b^2 - 4sa\sin^2(t)}}
\left( 1 + \frac{s^2 - a^2}{(s+a)^2 - 4sa\sin^2(t)} \right)
\end{align}$$
The last integral can be expressed in terms of the
complete elliptic integral
of first and third kind:
$$
K(k) = \int_{0}^{\frac{\pi}{2}} \frac{dt}{\sqrt{1-k^2\sin^{2}t}}
\quad\text{ and }\quad
\Pi(n,k) = \int_{0}^{\frac{\pi}{2}} \frac{dt}{(1-n\sin^{2}t)\sqrt{1-k^2\sin^{2}t}}
$$
The final results are:
$$\Omega_{C} = 2\pi\delta_C -\frac{2b}{\sqrt{(s+a)^2+b^2}}
\left(\;K(k) + \left(\frac{s-a}{s+a}\right) \Pi(n,k)\;\right)
$$
where $\displaystyle \;\;k = \sqrt{\frac{4sa}{(s+a)^2+b^2}}
\quad\text{ and }\quad
n = \frac{4sa}{(s+a)^2}
$.
Notes
$\color{blue}{[1]}$ When $C$ contains $(0,0,b)$, we need the $\frac{1}{b}$ term. It regularize the 1-form at $\eta = 0$ and make Stroke's theorem continue to work.
Comment: thank you sir!It was so nice of you to work it out.and a great refrence also.but im a bit uneasy about the wedge thing..it is cross product right?also using complex coordinates..is it just a convention to make things simpler ?
Comment: @iman the wedge is the wedge product. The standard tool for dealing with differential forms. I use complex coordinates to make the conversion from surface to line integral easier. Sometimes it will be easier to guess what the line integral looks like when complex coordinates are used. One should be able to derive same result using pure vector analysis and [Green's theorem](http://en.wikipedia.org/wiki/Green%27s_theorem).


simple python oAuth 1.0 example with consumer key and secret

Question: I am new in python and oAuth world.
I want to connect to my server with consumer key and secret and all the examples I found is where the server  has access_token,authorize,request_token_ready etc api but my server does the oAuth authentication for me.
So my question is how to connect with python to my server using oAuth (My server use oAuth 1.0)
elaboration:
My server does not request token and access token. He use just the key and secret.
How do I implement oAuth connection to this server in python
Comment: As I said in all examples the server support access_token,authorize,request_token_ready etc APis while my server don't.
Am I missing something?
Answer: This is a working example using requests_oauthlib
from requests_oauthlib import OAuth1Session
test = OAuth1Session('consumer_key',
                    client_secret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
url = 'https://one-legged-ouath.example.com/username/test'
r = test.get(url)
print r.content

I know this is an old question, but the accepted answer really doesn't address his question, since as the OP notes, none of the examples pertain to just using the key and secret, sans token.
It sounds as if you're using what I understand is referred to as OAuth 1.0a (One Leg), although some refer to it as OAuth 1.0a Two-legged.
I haven't tested this but there appears to be a pretty good example here:
https://github.com/CarmaSys/CarmaLinkAPI/wiki/Authentication-&-Permissions
There is another good example here:
https://stackoverflow.com/a/12710408/2599534
Comment: @weaming Not sure that pertains to the question, which wasn't about SO's use of OAuth.
Comment: it shows how to use OAuth in the aspect of service user, the developer
Comment: See the [requests-oauthlib docs](https://requests-oauthlib.readthedocs.io/en/latest/oauth1_workflow.html) for more workflow examples (incl. OAuth 2).
Answer: As roman already said, this is an old question, but there still are some APIs out there which are OAuth 1.0a (One Leg) - protected and today I spent a couple of hours finding a working solution for accessing such an  API.
I hope, the solution might come handy for next one to face similar task.
My solution is based on roman's answer. Many thanks @roman!!
The default-response of the API that I wanted to access was in XML, therefore I needed a way to set request headers. It's pretty simple to do actually, if you know how.
from requests_oauthlib import OAuth1Session

CONSUMER_KEY = ""
CONSUMER_SECRET = ""

host = "rest.host.de"
uri = "/restapi/api/search/v1.0/statistic?geocode=1276001039"

oauthRequest = OAuth1Session(CONSUMER_KEY,
                    client_secret=CONSUMER_SECRET)

url = 'https://' + host + uri

headers = {
        'Accept': "application/json",
        'Accept-Encoding': "gzip, deflate",
    }

response = oauthRequest.get(url, headers=headers)

print(response.status_code)
print(response.content)

Answer: If you're looking for a client with which to connect to your server with I can recommend rauth. There's a number of examples demonstrating both OAuth 1.0/a and 2.0.
Answer: I'm adding this OAuth 1.0a (one-legged) example with a POX post body. This is a simple example using a request/post/response with a "Plain Old XML" (POX) body:
from requests_oauthlib import OAuth1Session

CONSUMER_KEY = "xxxxxxx"
CONSUMER_SECRET = "xxxxxxx"

ourSession = OAuth1Session(CONSUMER_KEY, client_secret=CONSUMER_SECRET, force_include_body=True)

body= '<?xml version="1.0" encoding="UTF-8"?>' \
   '<POXEnvelopeRequest xmlns="http://whateve">' \
   '<POXHeader>' \
   ' <RequestHeaderInfo>' \
      .   .   .   .
   ' </RequestHeaderInfo>' \
   '</POXHeader>'   \
   '</POXEnvelopeRequest>'

clen = str(len(body))

headers = {
 'Accept': '*/*',
 'Accept-Encoding': 'gzip, deflate, br',
 'Host': 'X.Y.com',
 'Content-Type': 'application/xml',
 'Connection': 'keep-alive',
 'Content-Length': clen
}

r = ourSession.post(url, headers=headers, data=body, verify=False)

# DEBUG: Comment out in and out as needed...
print("===================== B E G I N    R E S P O N S E =======================\n")
print(r)
print(r.text)
print("===================== E N D    of  R E S P O N S E =======================\n")

[python][oAuth1.0a][one-legged][two-legged]


Create URL field

Question: I want to create a field that is automatically filled with the current page URL, and displayed as a link. The user should not be able to change that field. How can I do this?
If coding is required, please describe exactly what, and where to code.
Answer: Have a look at the Link module, it defines a link/url field. If you have the Token module, you might be able to use [site:current-page:url] as a default value for the field.
Answer: The link module accepts tokens.
I used it many time to build url in some of my content type to pass on the value of the [node:id].
If you want to have the current url you have to use [current-page:url].
In the default value of the link module write this http://example.com/[current-page:url:path], and you will have the good result. I just test on my website (so don't forget to write your domain).
[]]1
Comment: I just edit my post now it's work fine
Comment: Thank you very much Epok, this works. I created such a field in the private message form so that I can send to the recipient a link to the node. But now the problem is that once the user got the message, the link points to the message and not to the original node. Any idea? Thank you very much for your help!

Create URL field