Implicit JsonWriter for trait not working

Question: I have class as below
trait RiskCheckStatusCode {
  def code: String
  def isSuccess: Boolean
}

object RiskCheckStatusCode {

  val SUCCESS = SuccessRiskCheckStatusCode("1.1.1")
  val FAIL = FailRiskCheckStatusCode("2.2.2")

  case class SuccessRiskCheckStatusCode(code: String) extends RiskCheckStatusCode {
    override def isSuccess = true
  }

  object SuccessRiskCheckStatusCode {
    import spray.json.DefaultJsonProtocol._
    implicit val formatter = jsonFormat1(SuccessRiskCheckStatusCode.apply)
  }

  case class FailRiskCheckStatusCode(code: String) extends RiskCheckStatusCode {
    override def isSuccess = false
  }

  object FailRiskCheckStatusCode {
    import spray.json.DefaultJsonProtocol._
    implicit val formatter = jsonFormat1(FailRiskCheckStatusCode.apply)
  }
}

and now I would like to convert the list of RiskCheckStatusCode to json
object Main extends App{

import spray.json._
import spray.json.DefaultJsonProtocol._

  val l = List(RiskCheckStatusCode.SUCCESS, RiskCheckStatusCode.FAIL)

  implicit object RiskCheckStatusCodeJsonFormat extends JsonWriter[RiskCheckStatusCode] {
    override def write(obj: RiskCheckStatusCode): JsValue = obj match {
      case obj: SuccessRiskCheckStatusCode => obj.toJson
      case obj: FailRiskCheckStatusCode => obj.toJson
    }
  }

  def json[T](list: T)(implicit formatter: JsonWriter[T]) = {
    print(list.toJson)
  }

  json(l)
}

but the json method can not find jsonWriter[RiskCheckStatusCode].
Can you explain why? Maybe should I do it differently for trait type?
Edit:
It works for
 val l: RiskCheckStatusCode = RiskCheckStatusCode.SUCCESS

so the problem is with List[RiskCheckStatusCode] because I have a formatter for RiskCheckStatusCode, not for List[RiskCheckStatusCode]. I tried import DefaultJsonProtocol but it still does not work.
import spray.json.DefaultJsonProtocol._

I have to change the definitions? From
implicit object RiskCheckStatusCodeJsonFormat extends JsonWriter[RiskCheckStatusCode]

to
implicit object RiskCheckStatusCodeJsonFormat extends JsonWriter[List[RiskCheckStatusCode]]

error:
Error:(28, 7) Cannot find JsonWriter or JsonFormat type class for List[com.example.status.RiskCheckStatusCode]
  json(l)

Error:(28, 7) not enough arguments for method json: (implicit formatter: spray.json.JsonWriter[List[com.example.status.RiskCheckStatusCode]])Unit.
Unspecified value parameter formatter.
  json(l)

Comment: Thanks for updating your question. I added more details to my answer.
Answer: Your code is fine you are just not having toJson in your scope (it is located in the package object of spray.json).
Add it and your code should compile:
object Main extends App with DefaultJsonProtocol {

  import spray.json._

  // ...

}

Furthermore spray has some issues to lift JsonWriter through derived formats (see this for details).
You can switch to JsonFormat instead:
implicit object RiskCheckStatusCodeJsonFormat extends JsonFormat[RiskCheckStatusCode] {
  override def write(obj: RiskCheckStatusCode): JsValue = obj match {
    case obj: SuccessRiskCheckStatusCode => obj.toJson
    case obj: FailRiskCheckStatusCode => obj.toJson
  }

  override def read(json: JsValue): RiskCheckStatusCode = ???
}

In addition, to cleanup the type of your List change the definition of RiskCheckStatusCode to (this explains more details):
sealed trait RiskCheckStatusCode extends Serializable with Product


Providing phantom power to 3.5mm mic

Question: I need to provide power to a mic that has 3.5mm jack. All of the external phantom power supplies are for XLR. Does anyone know of a good solution.
Answer: I'd be extremely surprised if your mic needed phantom power with only a mini jack. Phantom power is 48V and it would likely fry your mic.
See this thread for some more details about what power you might need;
http://www.dvinfo.net/forum/all-things-audio/514394-xlr-mini-jack-adapter-phantom-power.html
Comment: Phantom Power is completely different than plug-in power! New lesson learned. Thanks!!
Answer: Usually mics that need phantom power come with an XLR plug, as phantom power does not usually get fed through jack plugs/sockets. Especially 3.5mm jacks. Having said that, some of my minidisc recorders provide some sort of power to some mics, but I doubt it's the sort of phantom power(48v) that's available on mixers, etc.
Answer: You want to use a USB power injector, like this:  https://www.amazon.com/gp/product/B00I6ILPPC/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1
Comment: Matt - if you read Jamie's question and the comment underneath it, you'll see the OP was mistaken!

Providing phantom power to 3.5mm mic


How to get TX/RX bytes without ifconfig?

Question: Since ifconfig is apparently being deprecated in major Linux distributions, I thought I'd learn something about the ip tool that's supposed to be used instead of ifconfig.
And here I ran into a problem: when run on its own, ifconfig shows the number of bytes received/transmitted on each interface besides other info. I couldn't find a way to get this from ip. Is there no such function in this tool? What other built-in tools could I use for getting those stats?
Comment: You can also check out `netstat`. http://linux.die.net/man/8/netstat
Answer: The ip command which is part of the the iproute2 package is the new tool.  The link subcommand is for managing the devices/interfaces.
If you can get the stats of an interface using ip -s link
root:~# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    RX: bytes  packets  errors  dropped overrun mcast
    50679705   529967   0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    50679705   529967   0       0       0       0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:1d:7d:aa:e3:4e brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    187663757  308710386 0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    4051284587 532435117 0       0       0       0

Comment: While the `proc` answer is clean and lightweight, this answer is probably the closest to a "replacement" for the `ifconfig` tool because it was explicitly designed with replacement of `ifconfig` in mind.
Comment: To get this in human readable form (reporting in mb/gb/tb rather than bytes), use the `-h` flag. For instance, `ip -h -s link`.
Comment: `ip -s link show dev eth0` to show only traffic on eth0
Answer: Another option is to use the /proc filesystem. The /proc/net/dev file contains statistics about the configured network interfaces. Each line is dedicated to one network  interface and it contains statistics for receive and transmit. The statistics include metrics such total number of received/transmittted bytes, packets, drops, errors and so on.
cat /proc/net/dev

    Inter-|   Receive                                                |  Transmit
     face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed

    lo:    29846937   129576     0    0    0     0          0       0 29846937   129576     0    0    0     0       0          0
 wlan0:    9467393340 8027251    0    0    0     0          0       0 2559312961 5896509    0    0    0     0       0          0

Or you can try the netstat command which can display all network interfaces and related statistics:
netstat -i

Iface   MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
lo         65536   0   130435      0      0      0   130435      0      0      0 LRU
wlan0       1492   0  8028018      0      0      0  5897361      0      0      0 BMRU

Comment: Stats showed by `cat /proc/net/dev` are for how long time ?
Comment: Try to parse 3. and 11. field of the output, something like awk '/:/ { print($1,$3, $11) }' < /proc/net/dev
Comment: `/proc/net/dev` has the cleanest format of all of the solutions IMO, accepting.
Comment: How do you get tx/rx from `/proc/net/dev` ?
Comment: netstat is deprecated along with ifconfig. On Linux, not sure about other *IX varietals.
Comment: `netstat -i` cuts off interface names after the 8th char, not very usable if your system has longer interface names (which mine does). Recommend using `ss -i` instead. `ss` is the replacement to netstat. Unrelated, many flags that were used in `netstat` are supported in `ss`
Answer: You can get all necessary info via proc
# cat /sys/class/net/eth0/statistics/rx_bytes
# cat /sys/class/net/eth0/statistics/rx_packets

# cat /sys/class/net/eth0/statistics/tx_packets
# cat /sys/class/net/eth0/statistics/tx_bytes

Also you can use iptables and parse output.
For received packets
# iptables -L INPUT -n -v

for transmitted packets
# iptables -L OUTPUT -n -v

If server is a gateway, then you should also parse FORWARD chain
Comment: This answer is the most simple, I was able to build a script with this fairly easily. Also I use `mmwatch` (https://github.com/cloudflare/cloudflare-blog/blob/master/2017-06-29-ssdp/mmwatch) to turn the values in to rates. However, do not use `iptables` now, it is deprecated.
Comment: to have a single command to use when checking on servers I use
 `grep . /sys/class/net/$(ip route show|awk '/default/{print $5}'|head -1)/statistics/*|grep -v ':0$'`
or - if you know the name of the nic - `grep . /sys/class/net/wlp0s20f3/statistics/*|grep -v ':0$'`
Answer: You can read the file /sys/class/net/wlp3s0/statistics/rx_bytes and get the rx_byes directly without calling another command, vnstat is also good.
Linux stores all information in files as I know, so better to find those files and get information. Finding the relevant file is the challenge.
Comment: Welcome to the community! Well done, that's correct, but note that some old kernels don't provide these files. Wish you luck, and success! ;)
Answer: You can also use ethtool:
ethtool -S eth0

The benefit to ethtool, is you can see each rx / tx queue and how they are balanced.
I found watch is a great tool to update the screen using all these tools. However most of these tools display traffic as bytes or packets per second. I find it difficult to convert bytes to gigs or pps to millions of packets persecond on the fly.
Just a tip, check out Cloudflare's mmwatch tool. It does the same as watch, but will do the calculations automatically and display the output to the screen like watch. (Example: So you will see 1.2m/s for 1.2 million packets per-second)
https://github.com/cloudflare/cloudflare-blog/blob/master/2017-06-29-ssdp/mmwatch
Also, ethtool -S eth0 gives A lot of output, I grep the following way to show receive queues and discards also with mmwatch:
mmwatch "ethtool -S eth0 | grep 'rx-\|discard'"


Continuous and differentiable bell-shaped distribution on $[a, b]$

Question: Is there a distribution with these three properties?

Supported on $[a, b]$ for any $a, b\in\mathbb{R}$ and $a < b$
Continuous and Differentiable (that is $\nabla_x p(x)$ can be computed)
Bell-curved (or at least not as flat as the Uniform(a, b))
Comment: General answer: let $f:[0,1]\to\mathbb{R}\cup\{\infty\}$ be any nonnegative integrable function that increases on the interval $[0,c)$ and decreases on $(c,1].$ On the interval $[a,b]$ define $$F_0(x) = \int_a^x f((t-a)/b)\,\mathrm{d}t.$$ Extend the function $F(x) = F_0(x)/F_0(b)$ to be $0$ on $(-\infty, a)$ and $1$ on $(b,\infty).$ By construction this has all the features you seek and every solution can be expressed in this form. The extreme generality of these solutions shows that you should be more narrowly focused on a solution that is meaningful for whatever application you have in mind.
Comment: https://stats.stackexchange.com/questions/500862/random-number-between-0-1-5-decimal-places-from-binomial-beta-like-distri
Comment: @whuber +1. That indeed should be left as an answer; after all, it's a general construction.
Comment: @whuber great answer! Do you mind posting that as an answer?
Answer: One option is to transform a beta distribution.
$Beta(3,3)$ has your desired properties on $[0,1]$.
Now subtract $1/2$ to center the distribution.
Next, multiply to stretch or compress the distribution.
Finally, add your desired mean.
Comment: This will be differentiate. @Euler_Salter
Comment: Usually when people say 'bell shaped' they'd expect a point of inflection either side of the mode; the Beta(2,2) doesn't have one, I'd suggest having each parameter being 3 or more; it will also make the density differentiable across the support boundary.
Comment: I just added a detail that I forgot about. I need it to be differentiable
Answer: The Truncated normal distribution obeys all prerequisites:

It's bell shaped
It's continuous
Its support is $x \in [a,b]$
It's differentiable, i.e. $\nabla_x p(x)$ exists for all $x \in [a,b]$
Comment: I just added a detail that I forgot about. I need it to be differentiable
Comment: @Euler_Salter no problem, the truncated normal distribution is also differentiable.
Answer: Let's construct all possible solutions.
By "distribution" you appear to refer to a density function (PDF) $f.$  The properties you require are

Supported on $[a,b].$  That is, $f(x)=0$ for any $x\le a$ or $x \ge b.$

$f$ should be (continuously) differentiable on $(a,b)$ with derivative $f^\prime.$

"Bell-curved," which can be taken as

(Strictly) increasing from value of $0$ at $a$ to some intermediate point $c;$ that is, $f^\prime(x) \gt 0$ for $a\lt x \lt c;$ and
(Strictly) decreasing from $c$ to a value of $0$ at $b;$ that is, $f^\prime(x) \lt 0$ for $c \lt x \lt b.$

To standardize this description, translate and scale the left-hand arm of $f^\prime$ to the interval $[0,1]$ and do the same for the right-hand arm, reversing and negating it.  That is, let
$$g_{-}(x) = f^\prime\left((c-a)x\right)$$
and
$$g_{+}(x) = -f^\prime\left(1 - (b-c)x\right).$$
Both are increasing positive integrable functions defined on $[0,1]$ for which
$$\int_0^1 g_{-}(x)\,\mathrm{d}x = \int_0^1 f^\prime((c-a)x)\,\mathrm{d}x = \frac{1}{c-a}\int_a^c f^\prime(y)\,\mathrm{d}y = \frac{f(c^-)}{c-a}$$
and
$$\int_0^1 g_{+}(x)\,\mathrm{d}x = \int_0^1 -f^\prime(1 - (b-c)x)\,\mathrm{d}x = \frac{1}{b-c}\int_b^c f^\prime(y)\,\mathrm{d}y = \frac{f(c^+)}{b-c}.$$
Conversely, given any two positive increasing integrable functions $g_{-}$ and $g_{+}$ defined on $[0,1]$ (the "left side" and "right side" models), these steps can be reversed to construct $f^\prime,$ which in turn can be integrated (and normalized) to yield a valid distribution function.
Here is this reverse process in pictures.  It begins with the two model functions.

(Notice that these functions need not even be continuous and can be unbounded, as illustrated by $g_{+}$ at the right.)
They are then integrated and assembled to produce $f^\prime,$ which in turn is integrated and normalized to unit area to yield a density $f$ with every required characteristic.

You may further control the appearance of the density in many ways.  For instance, by taking the two models to be the same function and placing the peak $c = (a+b)/2$ at the midpoint, you will obtain a symmetric density.  Here I have used the original $g_{-}$ for the right hand model $g_{+}.$

You can enforce many other properties of $f$ by going through the original analysis to deduce the corresponding properties of the model functions and restricting your construction to functions of that type.
Finally, if you choose to limit the two model functions to a finitely parameterized subset of the possibilities, you will have constructed a parametric family of distributions meeting all your criteria.


Need help with Views and Glossary

Question: Note: as a neophyte user, I'm not allowed multiple links or images. It has been suggested that I edit my original content in order to add updates. Also it's been suggested to edit the hyperlinks so they're not quite right. Hopefully you can sort out what's going on.
I've been following this post by Kristin Brinner "Drupal Tutorial: Use Views to Create an Alphabetical List of Taxonomy Terms" (at h ttp://getlevelten.com/blog/kristin-brinner/drupal-tutorial-use-views-create-alphabetical-list-taxonomy-terms) but my sample does not produce the results illustrated and by now I'm very confused.
Part 1: said to create new view showing taxonomy terms, display in grid format and create menu link. Done.
Part 2: grouped terms alphabetically (add Taxonomy term: Name, label it "Grouping", exclude from display, rewrite to max length = 1 and uncheck 'trim on word boundary' and 'add ellipsis'). Under Grid-Settings use "Grouping" apply to all displays. My view looks like the sample. Done.
Part 3, Create a Views page for each letter of the alphabet: said to add a Contextual Filter: Taxonomy term: Name. When the filter value is NOT in the url, display all results for specified field. Under More, click Glossary mode, character limit = 1. Note that I now have a Taxonomy term: Name in the Contextual Filter section. I don't know how to test these results.
Part 4, Create A-Z list (create a block that will display the list of first letters in a cute list above the grouping grids) says to add a new Contextual Filter for this block (override). When the filter value is not available, 'display a summary', sort by alphabetical, unformatted, display record count and display items inline. This isn't working as predicted, here is what the tutorial says should be the result: Image 1 in the diagram (h ttp://imgur.com/l9TbLyv). My content continues to look the same as it did previously in the exercise, i.e. like this: Image 2 in the diagram. However when I put "S" into the Preview with contextual filters, I get: Image 3 in the diagram. I was asked for screenshots, so without contextual filters is h ttp://imgur.com/zXCnsvA and with "s" in contextual filters is h ttp://imgur.com/7DF6UUD .
When I created the new contextual filter in Part 4, I got a copy of what was in the Page, so I have two contextual filters, both with Taxonomy term: Name. If I delete the first contextual filter from the block, then my preview shows the same information as Image 1 in the diagram. I think I'm missing something &/or the blog post is unclear. Should I have started "this block override" with 0 contextual filters? I.e. Should I have started by deleting elements from the page which were copied into the block?
Part 5 instructs to "Add the alphabetical list on our page with the grouped terms and Go back to our Page display".
I've got the view working correctly now. The thing which stumped me was that adding a block created an entire copy of the original page which (philosophically) I don't understand. When there's a page and a block override which give instructions about the view, how does drupal know which instructions to pay attention to?
Thanks to all the folks who have helped.
Comment: This is Kristin Brinner's blog post http://getlevelten.com/blog/kristin-brinner/drupal-tutorial-use-views-create-alphabetical-list-taxonomy-terms
Comment: Hey @TdeV, could you add/post a screenshot of your View/Block configuration for Part 4? When editing that view-block, you should be able to see the "cute" list, do you?
Comment: @StefanosPetrakis I can't figure out how to add a view to the comment field or how to add another-question/more-discussion to the original question. Do you have any idea how to find Q&A on this site's behaviour?
Comment: That is http://meta.drupal.stackexchange.com/ you would be looking for. I had the feeling you could update/edit your original question though, would expect that would be directly available to the original poster.
Comment: @StefanosPetrakis, thanks. Because of my "neophyte" status I am limited to two images on the first post, so I'm looking for a new way to add a comment which connects to images.
Answer: I am posting here in return, my block configuration, you will see that your contextual filters differ from mine, and for that matter, from what the tutorial describes.

Whatmore, the tutorial from Kristin Brinner describes in "Part 4. Create A-Z list" how to set up this block, which is what I did and got the expected result.
I would suggest you go through that part in the Tutorial again, the block you have at the moment is not configured according to the instructions of the tutorial.
And a useful quote from the Views 3 Handbook (accessible via Advanced Help):

Each display can have its own settings, but when created, a display
  will take all of its basic settings from the default display which all
  Views must have. For most settings, there is an override button that
  will override that single setting for the current display. Overridden
  settings will have a mark in the summary for that display. All
  'default display settings' are shown in the other displays in
  'italic'. When you override a setting, then it is shown 'normal'.

Will keep an eye on this post! Best of luck!
Comment: Hey @TdeV, took some time to get back to you about this. It's a good question, and is luckily also documented in the Views documentation. I quoted the specific excerpt from that docu in my answer. I think you should also inform the tutorial author to extend the tutorial with a similar word-of-caution, since it caused you such trouble. And finally, in case my answer helped you solve your problem, you should accept it.
Comment: I don't see how this is true. The first and second contextual filters are both "Taxonomy term: name" but renamed per Johann Falk's advice. This is the third post I've made for this View. Earlier I asked if the items in the Page were duplicated in the Block, or should I delete the contextual filter which was part of the Page?
Comment: @Clive. I added the screen views because StefanosPetrakis asked for them and as a neophyte user of Drupal Answers, I can't post the views in the first question. I have to complain about the number of hours I've spent trying to get this data posted!
Comment: Hello @TdeV, I was just trying to figure out what is the status of your question, but it seems your comment where you said you managed to solve the issue by removing the duplicate Taxonomy Term: Name contextual filter is gone. So, I am curious, did you manage to solve this in the end?
Comment: Hi @StefanosPetrakis, I have completely edited my original question, per someone's suggestion, so it includes my up-to-date status. I have got the view working *exactly* like the tutorial but I'm a bit mystified about how that came about; I guess the original tutorial glossed over this. I created a block and it copied all of the elements of the original page. Why? Why does Drupal have the instructions in the Page and duplicated again in the Block?
Comment: Very very welcome! See you around!

Need help with Views and Glossary


(Frechet) Differentiability of Implicit function in Banach spaces

Question: I'm looking at the classical implicit function theorem in Banach spaces. So $X,Y,Z$ are Banach spaces and $F: U_{x_0}\times V_{y_0} \to Z$ continuous and continuously differentiable with respect to y. And the inverse linear operator of the Frechet partial derivative is bounded linear operator. Also $F(x_0,y_0)=O.$
Then locally there is unique implicit function $T$ which $F(x,Tx)=O.$ This $T$ is continuous.
However if we assume additional smoothness  condition for $F,$ then $T$ also has it.
Ofcouse formal differentiation of $F(x,Tx) = O$ gets us that if $T$ is Frechet differentiable, then $T'x = - F'_y(x,Tx)^{-1} F'_{x}(x,Tx)$ possibly on smaller ball.
So If I assume additionally that $F$ is continuously differentiable, then im trying to prove that indeed $T$ is differentiable by trying to see that $||\omega(x,h)||:=||T(x+h)-Tx+F'_y(x,Tx)^{-1} F'_{x}(x,Tx)h|| = o(||h||)$ as $h \to O.$ And so trying to get to $||\omega(x,h)||\leqq c \varepsilon ||h||.$
But the bound I'm currently getting is something along those lines: ($\overline{x}:=x+h, y:=Tx, \overline{y}:=T(x+h))$
\begin{align*}
||\omega(x,h)||&= ||-F'_y (x,y)^{-1}||_{L(Z,Y)}.||-F'_y(x,y)(\overline{y}-y)-F'_x(x,y)h|| \\
&\leq c_1 ||F(x,y)-F(x,\overline{y})+\nu(x,\overline{y}-y)+F(x,y)-F(\overline{x},y)+\mu(h,x)|| \\
&\leq c_1 ( \varepsilon ||\overline{y}-y|| + \varepsilon ||h|| + ||F(x,\overline{y})-F(x,y)+F(\overline{x},y)-F(x,y)||),
\end{align*}
provided that $||h|| < \delta(\varepsilon), ||\overline{y}-\overline{y}|| < \delta(\varepsilon).$
Where $c_1:=||-F'_y (x,y)^{-1}||_{L(Z,Y)}.$
Now the last term in the norm I evaluate the same way with the partial Frechet derivatives
\begin{align*}
||F(x,\overline{y})-F(x,y)+F(\overline{x},y)-F(x,y)|| \leqq ||F'_y(x,y)||. ||\overline{y} - y|| +\varepsilon ||\overline{y}-y|| +||F'_x(x,y)||.||h||+\varepsilon .||h||.
\end{align*}
Denoting $c_2:=||F'_y(x,y)||_{L(Y,Z)}$ and $c_3:=||F'_x(x,y)||_{L(X,Z)}.$ This then reads
$||F(x,\overline{y})-F(x,y)+F(\overline{x},y)-F(x,y)|| \leqq (c_2 + \varepsilon)||\overline{y}-y|| + (c_3 +\varepsilon)||h||$ and in substituing in the inequality for $||\omega(x,h)||$ we get
$$
|| \omega(x,h)|| \leqq c_1 (2\varepsilon+c_2)||\overline{y}-y||+(2\varepsilon+c_3)||h||.
$$
Bound for $||\overline{y}-y||$ will get with this inequality and combined with reversed triangle inequality for the definition of omega :
$$
| ||\overline{y}-y|| - ||-F'_y(x,y)^{-1}F'_x(x,y)||.||h|| | \leq ||\omega(x,h)||\leqq c_1 [(2\varepsilon+c_2)||\overline{y}-y||+(2\varepsilon+c_3)||h||].
$$
Therefore denoting $c_4:=||-F'_y(x,y)^{-1}F'_x(x,y)||=c_1.c_3$ we get $(1-c_1(2\varepsilon+c_2))||\overline{y}-y|| \leq (c_1 c_3 +c_1 (2\varepsilon +c_2))||h||.$
Thus getting the following absurd (useless)bound
$$
||\omega(x,h)|| \leqq \left[ (2\varepsilon+c_3) + \frac{c_1(2\varepsilon+c_2)}{1-c_1(2\varepsilon+c_2)} [c_1 c_3 + c_1(2\varepsilon + c_2)] \right] ||h||.
$$
The problem with this bound is that it must be multiple of $\varepsilon$  and $||h||$ in order to get $o(||h||).$
Any suggestions on how to get a better bound will be much appreciated.
For reference: I tried to escape the argument in Deimling's book, where implicit function theorem was proven (without the assertion for differentiability of the implicit function) and then inverse function theorem was proven, and differentiability of the inverse function was established quoite easy.
After that Mr. Deimling proves differentiability of the implicit function using the inverse function theorem;
There he assumes $F is C^m$ and considers the following map: $G(x,y):=(x, F'_y(x_0,y_0)^{-1}F(x,y)).$ And claims that since
$$
G'(x_0,y_0)(h,k) = (h, k+ F'_y(x_0,y_0)^{-1}F'_x(x_0,y_0)h),
$$
$G'(x_0,y_0)$ must be a homeomorphism (which i dont see how its automatically true)
And then $G^{-1}(x,O)=(x,Tx)$ with $T$ exactly the implicit function we are discussing. And  now its clear how differentiability (and $C^m$) in inverse function theorem establishes it in the implicit function theorem.
So additional question: Is it obvious that $G'(x_0,y_0) = (Id_X, Id_Y +F'_y(x_0,y_0)^{-1}F'_x(x_0,y_0))$ is homeomorphism?
Update It is obvious... since the right coordinate is translation with linear bounded operator the inverse will be sign-conjugated one:
$$G'(x_0,y_0)^{-1}=(Id_X, Id_Y - F'_y(x_0,y_0)^{-1}F'_x(x_0,y_0)).$$
Now it's clear how the rest follows.
Comment: The proof of the implicit (or inverse) function theorem gives us that the implicit (resp inverse) function is in fact differentiable, and thus by the formula for the derivative, you can deduce that if $F$ is $C^k$, then so is $T$. I suggest looking over the proof of the theorem, where differentiability is established. From what I remember (in the case of inverse function theorem), the local inverse is shown to first be Lipschitz continuous, and then by a relatively straightforward estimate (using facts previously established in the proof), differentiable.
Comment: I understand you're trying to prove it, but I'm saying if you're stuck, then look up a standard reference, because differentiability is established directly (but slightly painfully) in the proof itself (while extra regularity like $C^k$ can easily be deduced from differentiating and looking at the explicit formula for derivatives and induction). For example, [Loomis Sternberg](https://people.math.harvard.edu/~shlomo/docs/Advanced_Calculus.pdf) chapter 4.9, theorems 9.3, 9.4 proves implicit function theorem. Abraham Marsden Ratiu prove the inverse, and prove the equivalence of the two IFTs.
Comment: Lang must also have a proof, though I forget which way he proceeds. See also Dieudonne, Henri Cartan etc. But, I should remark that proving the equivalence of the two IFTs is something you should get comfortable with (not just the statement, but the proof of the equivalence). The proof of equivalence is I'd say a very natural idea from linear algebra for converting back and forth between rectangular and square systems of equations.
Comment: I'm trying to prove differentiability of the implicit function. Im trying to prove the theorem not use it :).  For reference, in Deimling's Nonlinear Functional Analysis its proven indirectly via the Inverse function theorem. But it looks extremely not natural and so my attempts to just get it from trivial (tho long) bounds.
Comment: Thank you for the book references. :)
Answer: Most of the treatments of the inverse function theorem or the implicit function theorem are based on finding fixed points of a contraction in Banach spaces. Smoothness of the implicit solution $y\mapsto g(y)$ to the equation $F(g(y),y)=0$ follows from the smoothness of the inverse map $A\mapsto A^{-1}$ (defined on the set of invertible bounded operators on a Banach space $X$) and the smoothness of $F$. The main trick resides in finding good uniform bounds (via the mean value theorem), or by constructing uniform contractions.  Here is a sketch of how one may proceed:

Definition Let $U$ and $V$ be  open subsets of Banach spaces $X$ and $Y$ respectively. A function $F:\overline{U}\times V\longrightarrow \overline{U}$ is a uniform contraction if  there exists $0\leq\theta<1$ such that
\begin{align}
|F(x,y)-F(x',y)|\leq \theta|x-x'| \qquad x,\,x'\in \overline{U},\, y\in V.\tag{0}\label{unif_contrac}
\end{align}

The following theorem shows that fixed point of a uniform contraction $F$ is as smooth as the function $F$.

Theorem (Uniform contraction principle): Suppose $W$ and $V$
are closed and  open subsets of Banach spaces $X$ and $Y$ respectively. Let
$F:W\times V\longrightarrow  W$ be a uniform contraction
and let $x_*(y)$ be the unique fixed point of $F(\cdot,y):W\longrightarrow W$.

If
$F\in\mathcal{C}(W\times V,X)$,  then $x_*\in \mathcal{C}(V,X)$.

Suppose $W=\overline{U}$ where $U$ is an open subset of $X$ and that $F(\overline{U}\times V)\subset U$.

If $F\in\mathcal{C}(\overline{U}\times V,X)$ and
$ F\in\mathcal{C}^r(U\times V,X)$ ($r\geq1$), then $x_*\in \mathcal{C}^r(V,X)$,  for each $y\in V$ the linear functional $I-\partial_x F(x_*(y),y)\in L(X)$ has a bounded inverse,  and
\begin{align}
x_*'(y)=\Big(I-\partial_xF(x_*(y),y)\Big)^{-1}\partial_yF(x_*(y),y),\quad y\in V\tag{1}\label{smooth-fixedpoint}
\end{align}

A proof of this result is at the end of this posting. Having the uniform contraction principle at our disposal we can prove establish the following result:

Theorem (Implicit function theorem):  Let $X$, $Y$ and $Z$ be
Banach spaces,  $\Omega\subset X\times Y$ open and
$F\in \mathcal{C}^r(\Omega,Z)$ for some $r\geq0$.
When  $r=0$ assume that $\partial_xF\in\mathcal{C}(\Omega)$.
If $\partial_xF(x_0,y_0)\in\mathcal{L}(X,Z)$
has a bounded inverse for some $(x_0,y_0)\in\Omega$, then there is an open neighborhood $U\times  V\subset\Omega$ of $(x_0,y_0)$ and a unique function   $g:V\longrightarrow U$ such that
\begin{align}
 g(y_0)=x_0,\qquad F(g(y),y)=F(x_0,y_0).
\end{align}
Moreover,    $g\in\mathcal{C}^r(V,X)$ and if $r\geq1$, then for every $y\in V$ the linear operator $\partial_xF(g(y),y)\in L(X,Z)$ has a bounded inverse, and
\begin{align}
g'(y)=-\big(\partial_xF(g(y),y)\big)^{-1}\partial_yF(g(y),y),\qquad
y\in V.\tag{2}\label{imp_f_deriv}
\end{align}

Proof of the implicit function theorem:
Define $G:\Omega\longrightarrow X$ by
\begin{align}
G(x,y)=x-\big(\partial_xF(x_0,y_0)\big)^{-1} (F(x,y)-F(x_0,y_0))
\end{align}
Observe that $G$ has the same smoothness as $F$; moreover,
$x-G(x,y)=0$ iff $F(x,y)=F(x_0,y_0)$. Since $\partial_xG(x_0,y_0)=0$, for any $0<\theta<1$
there exists open balls $U$ and $V_1$ around $x_0$ and $y_0$
respectively,   such that $\overline{U}\times \overline{V_1}\subset\Omega$
and $\sup_{(x,y)\in \overline{U}\times V_1}\|\partial_xG(x,y)\|\leq \theta<1$. The mean value theorem implies that
\begin{align}
\|G(x,y)-G(x',y)\|\leq\theta\|x-x'\|,\qquad x,\, x'\in \overline{U},\quad y\in V_1
\end{align}
Let $\delta=\text{rad}(U)$. Since $F$ in continuous on $U\times V_1$ and
\begin{align}
\|G(x_0,y)-x_0\|\leq\|\big(\partial_xF(x_0,y_0)\big)^{-1}\| \|F(x_0,y)-F(x_0,y_0)\|,
\end{align}
there is an open ball $V\subset V_1$ around $y_0$ such that  $\|G(x_0,y)-x_0\|<(1-\theta)\delta$. Hence,
\begin{align}
\|G(x,y)-x_0\|\leq \|G(x,y)-G(x_0,y)\|+\|G(x_0,y)-y_0\|<\delta
\end{align}
for all $x\in \overline{U}$ and $y\in V$.  This shows that $G:\overline{U}\times V\longrightarrow U$  is a uniform contraction with $G\in\mathcal{C}^r(U\times V,X)$. By the uniform contraction principle, for each  $y\in V$ there is a unique  $g(y)\in U$ such that $F(g(y),y)=F(x_0,y_0)$; moreover,  $g\in\mathcal{C}^r(V,X)$ and, if $r\geq 1$,
\begin{align}
g'(y)=\big(I-\partial_xG(g(y),y)\big)^{-1}\partial_yG(g(y),y)=
-\big(\partial_xF(g(y),y)\big)^{-1}\partial_yF(g(y),y)
\end{align}
for all $y\in V\qquad \Box.$
The inverse function theorem can be obtained as an application of the implicit function theorem.

Theorem(Inverse Function Theorem) Let $X$, $Y$ be Banach
spaces, $W\subset X$ open, and  let  $f\in\mathcal{C}^r(W,Y)$, $r\geq1$. If $f'(x_0)$ has a bounded inverse for some $x_0\in W$, then there exists an open set  $U\subset W$ containing $x_0$ such that $f(U)$ is open, $f:U\longrightarrow f(U)$ is bijective,  the inverse function $g=f^{-1}\in \mathcal{C}^r(f(U),X)$, and
\begin{align}
g'(y)=\big(f'(g(y)\big)^{-1}, \qquad y\in f(U)\tag{3}\label{inv_f_deriv}.
\end{align}

Proof inverse function theorem:
Applying the implicit function theorem to $F(x,y)=y-f(x)$ yields
neighborhoods $U'\subset W$ and $V\subset Y$ around $x_0$ and $y_0=f(x_0)$ respectively, such that for each $y\in V$, there exists a unique $g(y)\in U'$ satisfying $y=f(g(y))$. Moreover,  the relation $g:y\mapsto g(y)$ is necessarily in $\mathcal{C}^r(V,X)$. This uniqueness shows that $f$ is injective in $U'$.
The set  $U=U'\cap f^{-1}(V)$ is an open neighborhood of $x_0$ with $V=f(U)$, and thus,  $f:U\longrightarrow V$ is a bijective function whose inverse $f^{-1}=g$. Finally, the identity \ref{inv_f_deriv} follows directly
from \eqref{imp_f_deriv} $\Box$.

For completeness, I add a proof of the uniform contraction principle that I have used in the past. I don't remember whether I prove it myself as an exercise or whether it came from a set of notes in a summer school, so I owe you a source, but I am sure is of common knowledge.
First, here is a useful version of the mean value theorem:

Theorem (Mean value theorem): Suppose
$F\in\mathcal{C}^1(U,Y)$ where $U\subset X$ is convex. For any
$\boldsymbol{x},\,\boldsymbol{y}\in U$,
\begin{align}
\|F(\boldsymbol{x})-F(\boldsymbol{y})\|\leq M(\boldsymbol{x},\boldsymbol{y})\,\|\boldsymbol{x}-\boldsymbol{y}\|
\end{align}
where  $M(\boldsymbol{x},\boldsymbol{y})=\sup_{0\leq t\leq 1}\|F'(\boldsymbol{x}+t(\boldsymbol{y-x}))\|$.
Conversely, if there is  $M\geq0$ such that
\begin{align}
\|F(\boldsymbol{x})-F(\boldsymbol{y})\|\leq M\|\boldsymbol{x-y}\|,\qquad \boldsymbol{x},\,\boldsymbol{y}\in U,
\end{align}
then $\sup_{\boldsymbol{x}\in U}\|F'(\boldsymbol{x})\|\leq M$.

The last part of the mean value theorem will be particularly useful in what follows.
(1) Notice that
\begin{align}
\|x_*(y&+h)-x_*(y)\|=\|F(x_*(y+h),y+h)-F(x_*(y),y)\|\\
&\leq
\|F(x_*(y+h),y+h)-F(x_*(y),y+h))\|+\|F(x_*(y),y+h)-F(x_*(y),y)\|\\
&< \theta\|x_*(y+h)-x_*(y)\|+\|F(x_*(y),y+h)-F(x_*(y),y)\|.
\end{align}
The continuity of $F$ on $W\times V$ implies that
\begin{align}
\|x_*(y+h)-x_*(y)\|\leq
\frac{1}{1-\theta}\|F(x_*(y),y+h)-F(x_*(y),y)\|\xrightarrow{h\rightarrow0}0
\end{align}
Hence,  $x_*\in\mathcal{C}(V,X)$.
(2) The assumption $F(\overline{U}\times V)\subset U$ implies that $x_*$ maps $V$ into $U$ since $x_*(y)=F(x_*(y),y)$. A formal application of the chain rule yields
\begin{align}
x'_*(y)=\partial_xF(x_*(y),y)x'_*(y)+\partial_yF(x_*(y),y)\tag{4}\label{formal_der}
\end{align}
at every $y\in V$ where $x_*$ is differentiable. Consider \eqref{formal_der} as a fixed point equation $T(z,y)=z$ where $T:\mathcal{L}(Y,X)\times V\rightarrow \mathcal{L}(Y,X)$ is  given by
\begin{align}
T(z,y)=\partial_xF(x_*(y),y)z+\partial_yF(x_*(y),y)\tag{5}\label{fix_point_eqn}
\end{align}
The mean value theorem along with \eqref{unif_contrac} implies that
\begin{align}
\sup_{(x,y)\in U\times V}\|\partial_xF(x,y)\|\leq\theta\tag{6}\label{unif_bnd_der}
\end{align}
Hence $T$ is a uniform contraction and, by the first part of the
proof, $T$ has a continuous fixed point $z:V\rightarrow\mathcal{L}(Y,X)$.
We will now show that $z$ is in fact the derivative of $x_*$.
We fix $y\in V$, and set $B(y)=\partial_xF(x_*(y),y)$, $A(y)=\partial_yF(x_*(y),y)$. Let  $h(k):=x_*(y+k)-x_*(y)$ for all $k$
small enough. The fixed point property of $x_*$ and $z$ together with the  differentiability of $F$ implies that for all $k$ small enough
\begin{align*}
(I-B(y))(h(k)-z(y)k)&=F(x_*(y+k),y+k)-F(x_*(y),y)-B(y)h(k)-A(y)k\\
&=F(x_*(y)+h(k),y+k)-F(x_*(y),y)-B(y)h(k)-A(y)k\\
&:=P(h(k),k),
\end{align*}
where $\frac{\|P(h,k)\|}{\|h\|+\|k\|}\rightarrow0$ as
$(h,k)\rightarrow(0,0)$. From \eqref{unif_bnd_der},  we have that $(I-B(y))\in\mathcal{L}(X)$ is an invertible operator with $(I-B(y))^{-1}\in\mathcal{L}(X)$. This shows that
\begin{align}
x_*(y+k)=x_*(y)+z(y)k+r(k)
\end{align}
where $r(k)=o(k)$ as $k\rightarrow0$
For $r>1$, the result follows by induction. Suppose the result holds for $r-1$. Then, at least $x\in\mathcal{C}^{r-1}(V,X)$. The fact that $x_*$ satisfies \eqref{formal_der} implies that
\begin{align}
x_*'(y)=\big(I-\partial_xF(x_*(y),y)\big)^{-1}\partial_yF(x_*(y),y)
\tag{7}\label{deriv_implicit}
\end{align}
Since the map $T\mapsto T^{-1}$ from $GL(X)$ to $GL(X)$ is differentiable, it follows that $x_*\in\mathcal{C}^r(V)$ whenever $F\in\mathcal{C}^r(U\times V,Y)\quad\Box.$


Padrão de documentação de código Javascript e geração automática de documentação em IDEs e exportável

Question: Java tem o Javadoc, PHP tem PHPDoc e outras linguagens, tem padrões de documentação. Qual padrão mais usado para documentar javascript, já integrado a IDEs, de modo que ao usar funções, ele auto-complete o código e haja um meio de gerar documentação automática tendo como base unicamente documentação do código?
Como exibir documentação de bibliotecas de terceiros, como jQuery?
Answer: Para documentar Javascript, recomendo o uso do padão descrito em JSDoc, cuja página com documentação explicativa é http://usejsdoc.org/. Além de dizer em detalhes um padrão que IDEs como Netbeans e Eclipse entendem, o JSDoc também tem uma ferramenta que funciona por linha de comando que lê seu código e converte ele em um manual em HTML pronto para uso.
Como exemplo rápido, olhe o código abaixo
/**
 * Esta é uma função de exemplo de uso de JSDoc
 *
 * @example
 *   exemplo(3, 5); // 8
 *
 * @param   {Number} obrigatorio   Parametro obrigatório
 * @param   {Number} [opcional]    Parametro ocional. Note os '[ ]'
 * @returns {Number}
 */
function exemplo (obrigatorio, opcional) {
    var resultado = 0;
    resultado = obrigatorio + (opcional || 0);
    return resultado;
}

Para IDE Netbeans 7.4, ao usar a função, irá gerar o seguinte

No caso do Netbeans e outras IDEs, veja como adicionar sua biblioteca favorita, por exemplo jQuery, a um caminho aonde há o arquivo documentado dele de modo que sua IDE exiba as documentações de contexto. Desse modo vai precisar ver muito menos vezes o Google para algo que já está explicado durante o uso.


Missing HDD space - says 65GB used, selecting all folders shows 40GB used

Question: Running Windows Server 2008, 74GB raptor drive and noticed we only had about 500MB left - yikes!
So deleted some old backups we don't need, but can't track down where about 25GB seems to be taken up. If I go to C: and select all folders and go to properties, this comes to around 40GB but in My Computer I can see 65GB is used.
How can I find out whats eating the space?
Just IIS + MSSQL Express + Smartermail on the server
EDIT Checked to show hidden folders plus protected operating system files - 41.8GB usage, so 24.6GB is missing somewhere. Theres no system restore even installed on the server
Comment: Off topic, but saving backups to the drive that you're backing up is a waste of space and very dangerous.
Comment: We take offsite backups to a separate continent - its useful to store daily backups on the server too to get quick changes in the DB.
Comment: Check the size of your pagefile, 10+ gigs reserved is not uncommon.
Answer: Are you looking at hidden folders too?
I'm willing to bet you've got something like shadow copies or system restore points enabled on that volume which is taking up stupid amounts of disk space and putting it in a hidden folder, which your Select All, Properties method isn't picking up.
Comment: I'll double check the hidden folders, will check restore points, thanks
Comment: Ok, this time I checked to include hidden folders AND protected operating system files - total usage (on disk) 41.8GB. So there is a black hole of about 24.6GB.
Comment: Does that include a folder called **C:/System Volume Information**? That's a critical system folder which by default Windows goes to great lengths to hide (I've just checked on my laptop - Windows says it's empty) but I guarantee that it's got stuff inside.
Comment: It says 0 bytes but clicking on it shows Access Denied. I wonder if its UAC - how can I open explorer with Admin privileges?
Comment: Got access to it by adding the user account to the Security tab, only 20KB in there!
Answer: Try this free program and see if it can help you. Should show you amount of space used per directory.
Also check how much your hard drive is fragmented, this surely didn't take your 35GB but could loose you couple of megs.
Comment: I don't think a fragmented drive takes up any more space than an unfragmented drive, even with extreme fragmentation. A block is a block.
Comment: Can't possibly lose that much space because its de fragmented, plus Microsoft says de fragmenting isn't good for MSSQL.
Comment: Well check the program I've showed you. It should show you what takes all the megs.
Comment: Unfortunately, didnt work. Says the complete C drive is 39.4GB, but windows says 66.4GB is used.
Comment: Re-running this with admin privileges
Comment: Thank you, found the Culprit - Plesk's own backups which don't seem to be executing properly...
Answer: Just as a thought could MSSQL be reserving disk space for itself that it hasn't physically used so looking at actual disk space shows space remaining but SQL has "told" Windows that the space is allocated.
Worth disabling VSS too to see if that has an impact.
Answer: Just to help anyone else - i had this problem too where there was a missing 30gb of space.
Turns out that the SQL DB folder itself was the problem, opening it up and clicking 'Continue' to allow access via UAC did the trick. Navigating back to select all root folders then shows the correctly used space.
So i would say if there is any protected folders on the drive this would likely be the issue if you already checked for hidden and system files (system page file and the like).


how do I loop through a certain date range using SQL

Question: I have a sql query
select * from tableA A where (A.Date>='2019-01-01') and (A.Date<'2019-02-01')
select * from tableA A where (A.Date>='2019-02-01') and (A.Date<'2019-03-01')
...
select * from tableA A where (A.Date>='2020-12-01') and (A.Date<'2021-01-01')

Each run will return a different set of results. How do I write one line query to append all results together?
I need to have output as
return of line 1
return of line 1
return of line 2
return of line 1
return of line 2
return of line 3
..
return of line 1
return of line 2
return of line 3
..
return of line n

Comment: Please provide a few rows of the expected result.
Comment: Do you really want to skip the 1st of each month?
Comment: Use a recursive cte to create all these dates.
Answer: For your specific query you can use:
select t.*
from table
where t.Date >= '2018-01-01' and t.Date < '2018-10-01';

Note:  This assumes that you actually do want the dates on the first of the month.  If you don't, then:
select t.*
from table
where t.Date >= '2018-01-01' and t.Date < '2018-10-01' and
      extract(day from date) <> 1;


ipython installed but not running on OSX mavericks

Question: I'm running Mavericks with conda and pip as python package managers. I'm trying to run ipython from the terminal (bash) but the system just isn't having it. Whenever I try to run it, I get the following error thrown at me:

<code>Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 5, in <module>
    from pkg_resources import load_entry_point
  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2716, in <module>

  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 685, in require
    def __getstate__(self):
  File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 588, in resolve
    The `plugin_env` should be an ``Environment`` instance that contains
pkg_resources.DistributionNotFound: ipython==2.0.0-dev
</code>

I've tried uninstalling and reinstalling the software several times, but it doesn't seem to work.
If you have any suggestions, please let me know. I'm trying to get iJulia up and running.
Answer: I also experienced the similar problem. Here is the solution that I found and works for me.
<code># refresh the ipython installation
rm -f /usr/local/bin/ipython && pip uninstall ipython -y && pip install ipython

# remove the warning startup
rm -rf ~/.ipython
</code>
Hope it may help you.
Cheers,
RL


When using getSymbols/BatchGetSymbols sometimes I receive download errors. Is there a way I can add a re-try function to my script?

Question: When using 'getSymbols'/'BatchGetSymbols' sometimes I receive "Error in download" when downloading a ticker's price data. I am aware of why these errors occur, normally due to max limits with yahoo's API etc which is fine.
> TSLA | yahoo (161|206) | Found cache file - Got 100% of valid prices |Feels good!
AAPL | yahoo (162|206) | Found cache file - Got 100% of valid prices | Got it!
FB | yahoo (163|206) | Found cache file - Got 100% of valid prices | Boa!
AAL | yahoo (164|206) | Not Cached - Error in download..
GOOG | yahoo (165|206) | Not Cached - Error in download..
SPY | yahoo (166|206) | Not Cached - Error in download..
QQQ | yahoo (163|206) | Found cache file - Got 100% of valid prices |Boa!

Whenever I receive these errors I just need to manually re-run my script a few times and all the ticker price data normally downloads correctly.
Once the price data download is 100% complete I then use 'googlesheets4' to send price data to a spreadsheet via 'sheet_write'. Currently, I have my script setup with 'cronR' which is great when all price data downloads correctly but terrible when download errors occur and the missing data is sent to a spreadsheet.
Is there a way I can add a re-try function to my script?
Ideally, if download errors occur I would like it to re-run the script and only send the price data to a spreadsheet (via googlesheets4's 'sheet_write' function) when approximately >75% of the tickers have been downloaded successfully.
Here's my current script:
library(rvest)
library(xml2)
library(dplyr)
library(BatchGetSymbols
library(shiny)
library(miniUI)
library(shinyFiles)

setwd("/Users/Desktop/..")

ax.data29 <- BatchGetSymbols(tickers = c("TSLA","AAPL","FB","AAL","GOOG","SPY","QQQ","IWM","XLE","XLF","XLK","XLV","XLU","BA","MRNA","GM","QCOM","TWTR","PTON"),
                            first.date = Sys.Date()-20,
                            last.date = Sys.Date(),
                            freq.data = 'daily',
                            how.to.aggregate = "last",
                            do.complete.data = FALSE,
                            thresh.bad.data = 0.75,
                            cache.folder = file.path(tempdir(),
                                                     'BGS_Cache') ) # cache in tempdir()

Sys.sleep(2)

ax.data.out29 <- as_tibble(ax.data29$df.tickers)

library(googledrive)
library(googlesheets4)
gs4_auth(email = "...@gmail.com")
Sys.sleep(2)

sheet_write(ax.data.out29, "https://docs.google.com/spreadsheets....", sheet = "dailypricedata")

Any help would be much appreciated.
Thank you,
Ron
Comment: I was using this library every day for the past year pulling daily ticker data for the entire 500. Something changed recently with the api.
Answer: the creator of the package has made a new package called yfR.
The code is almost similar, with a minor change to the function call and the names of the variables:
library(yfR)

l_out <- yf_get(
  tickers = c("TSLA","AAPL","FB"),
  first_date = first.date,
  last_date = last.date,
  thresh_bad_data = 0.75,
  bench_ticker = "^GSPC",
  type_return = "arit",
  freq_data = freq.data,
  how_to_aggregate = "last",
  do_complete_data = FALSE,
  do_cache = TRUE,
  cache_folder = yf_cachefolder_get(),
  do_parallel = FALSE,
  be_quiet = FALSE)

Best, P


MySQL authentication plugin set to mysql_native_password but server requests caching_sha2_password

Question: I have an old PHP script that is using mysql_connect("localhost:3306", "root", "password"); to connect to a MySQL server running locally. (Yes, I know this is a security concern; it's not staying that way.)
When I run the script (using PHP5) it says
mysql_connect(): The server requested authentication method unknown to the client [caching_sha2_password]

So, in order to fix this, I went into the database and ran
ALTER USER 'root'@'localhost' identified with mysql_native_password by 'password';
FLUSH privileges;

After restarting the MySQL server, I checked the mysql.user table to confirm that the authentication plugin was now set to mysql_native_password. It is.
I ran the PHP script again, and got the same error.
Then, not knowing what else to do, I opened up etc/mysql/conf.d/mysql.cnf and added the line
default-authentication-plugin=mysql_native_password

I restarted the MySQL server. I ran the PHP script again, and got the same error.
At this point, I don't know what to do? The user (and the server) are both configured to use mysql_native_password; why is it requesting caching_sha2_password?
Comment: don't use the default authentification
Answer: I changed the default method in /etc/mysql/mysql.conf.d/mysqld.cnf, underneath the [mysqld] section:
default_authentication_plugin = mysql_native_password

Comment: Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer).


Namespaces and projects

Question: I am trying to introduce namespaces to a solution.
I have three projects in one solution:
Business Logic Layer
Data Access Layer
User Interface Layer

The namespaces of the classes in the business logic layer and data access layer are as follows:
companyname.applicationname.layername

If I want to access a class in the Data Logic Layer then I have to include the following statement:
Imports DataAccessLayer.companyname.applicationname.layername

I don't want to have DataAccessLayer as the first node.  Is there a way around this or am I misunderstanding something fundamental about namespaces?
Answer: For Namespace Naming Guidelines Check this:
Namespace Naming Guidelines
Try setting: Assembly Name & Default Namespace
Comment: Thanks +1.  This is what I was looking for.  Is it advisable to add Namespaces to the UI layer?, which is a Windows Forms.  Windows Forms are already part of a Namespace.
Answer: I'm not entirely sure of exactly what you're after, but here's a few options:
Import DataAccessLayer, then referring to the sub-namespaces directly:
Imports DataAccessLayer
...
companyname.applicationname.layername.mymethod(abc)

Make your assembly namespace in the project properties "DataAccessLayer".  Then you won't need to import DataAccessLayer, just import companyname... or refer to companyname... directly.
Answer: First you need to define that class inside the desired namespace like,
Namespace companyname.applicationname
  Public Class layername

  End  Class
End Namespace

Or can make default namespace by changing property,

Namespaces and projects


Update Style/Remove Attribute

Question: I need remove style attribute of a div
Line 85
https://github.com/PolymerElements/app-layout/blob/master/app-toolbar/app-toolbar.html
::content > [condensed-title] {
        pointer-events: none;
        @apply(--layout-flex)*;
      }

*(I don't wanna apply flexbox to [condensed-title] in a espefic head component I had made)
Line 133 https://github.com/PolymerElements/iron-flex-layout/blob/master/iron-flex-layout.html
    --layout-flex: {
  -ms-flex: 1 1 0.000000001px;
  -webkit-flex: 1;
  flex: 1;
  -webkit-flex-basis: 0.000000001px;
  flex-basis: 0.000000001px;
};

My code
<app-toolbar>

          <iron-icon icon="custom-icons:casinha"></iron-icon>

          <paper-icon-button icon="card-membership"></paper-icon-button>

Sublogo

      </app-toolbar>

Answer: You can achieve this in 3 three ways

You can style #outAlert in your element and set flex: 0. This will overwrite app-layout's styling.
#outerAlert {
    flex: 0;
}

Use inline style to overwrite flex and set it to 0

And lastly overwrite the --layout-flex mixin for the app-layout where you don't want flex to be there.
app-layout {
   --layout-flex: {
      flex: 0; /* You can have any other value also. Not sure if empty mixin will work or not */
   };
}

Comment: Thanks, your ideias were very helpful.
Answer: I solved problem using following code:
      #outAlert{
        @apply(--layout-flex-none);
      }

Update Style/Remove Attribute


Does Isolation Forest need an anomaly sample during training?

Question: I am using Isolation Forest for anomaly detection (scikit implementation in python).
My data have 1000 dimensions. My normal data, which I use for training Isolation Forest model, has only to features non zero. All samples are unique but differ only in two components.
My anomaly samples on the other hand differ from normal data in all other components, but not those two.
When I train Isolation Forest model on my train data only, the model does not detect any anomaly.
If I add one anomaly to the training set and train another model, this model detects almost everything correctly including low false positive count.
I think it's not ok that the model needs an anomaly sample.
Am I doing it correctly?
How to fix it?
Thank you
Comment: Did you see this [answer](https://stackoverflow.com/a/60204239/10452700) and how involving anomaly examples can effect on IF?
Answer: First, some notation: let $x=(x_1, x_2)$ be the features that vary within the normal data, and $z$ be all the other features (that equal zero in the normal data).
Your model did not use $z$, because $z$ was useless for the training data, because it contained no variation. If you want to force $z$ into the model, you can add small random noize to it: $\tilde{z}:=z+\varepsilon$. The variance of $\varepsilon$ may be on the same scale with your measurement error, or just represent your notion of how large $z$ is still "normal". A quick illustration:
<code>import numpy as np
from sklearn.datasets import load_iris
from sklearn.ensemble import IsolationForest
from sklearn.metrics import roc_auc_score
X, _ = load_iris(return_X_y=True)
target = np.array([0]*140+[1]*10) # 140 normal observations, 10 anomalies
X = np.c_[X, target] # a column that marks anomalies is included into X!
X_train = X[:140, :] # include only normal observations into train set
np.random.seed(1)

# a forest with raw data
forest1 = IsolationForest(contamination=0.0001).fit(X_train)
print(roc_auc_score(target, -forest1.decision_function(X)))
# this ROC AUC is only 0.6475, not a good model

# a forest with jittered data
forest2 = IsolationForest(contamination=0.0001).fit(X_train + np.random.normal(size=X_train.shape, scale=0.0001))
print(roc_auc_score(target, -forest2.decision_function(X)))
# this ROC AUC is 0.9521, much better
</code>
However, if you know that $z=0$ for normal data and $z\neq0$ for anomalies, you do not need any isolation forest - you already have a very simple and sound decision rule!
Comment: Thank you. I will try to add noise. 'z' is not always 0 in general case.
Comment: But if 'z' can be zero only for normal observations, you still know that they are normal and don't need to use your model for them.
Comment: The anomaly could differ in 'x' as well in some cases. Or 'z' could be present in normal data, but different amount


Call a bash script in perl

Question: I am trying to call a bash script in perl, by doing this -
my $which_mpi = "/sw/tools/tacc/builds/carter/site/salt_which_mpi";
$mpi_stack = system("$which_mpi",-n);

the problem is that I want the script to execute when it is called by system command in line
$mpi_stack = system("$which_mpi",-n);

but the problem with this is while assigning the path in $which_mpi it automatically executes the script. So instead of me getting this value
WHICH_MPI : /sw/tools/salt/builds/carter/altd/bin/site/salt_which_mpi

I am getting the path with the output of the bash script like
WHICH_MPI : /sw/tools/salt/builds/carter/altd/bin/site/salt_which_mpiopenmpi 1.6.1

where openmpi 1.6.1 is the output of my salt_which_mpi bash script.
Answer: You can use perl's backtick operator
`bash -c "$WHICH_MPI"`

take a look at this question:
another stackoverflow question
Comment: No worries I used this and it worked $mpi_stack = "`$which_mpi --name`; "thanks! which is close to you suggested.

Call a bash script in perl


jqgrid columns not sorting when clicked

Question: I have the following block of code:
$("#searchlist").jqGrid({
                url:'./searchlibrary',
                datatype: 'json',
                mtype: 'POST',
                postData: {type: function(){return $('select[name="searchtype"]').val();},
                    criteria: function(){return getSearchData();}
                },
                colNames:['Resource Name','Unit', 'Topic','Document Type','Content Type','Select'],
                colModel :[
                  {name:'resourceName', index:'resourceName', width:380, align:'left'},
                  {name:'unit', index:'unitID', width:40, align:'center',sortable:true},
                  {name:'topic', index:'topicID', width:220, align:'center',sortable:true},
                  {name:'docType', index:'docTypeID', width:97, align:'center',sortable:true},
                  {name:'contentType', index:'contentTypeID', width:97, align:'center',sortable:true},
                  {name: 'select', index:'resourceID', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", editoptions: { value:"Yes:No", defaultValue:"No" }, formatter:"checkbox",formatoptions: {disabled : false}}
                ],
                rowNum:20,
                sortname: 'resourceName',
                sortorder: 'asc',
                viewrecords: true,
                gridview: true,
                width:878,
                height:251,
                loadComplete: function(data){
                    initCheckboxes();
                    $('input[type="checkbox"]').click(function(ev){
                        initCheckboxes();
                    });
                }
             });

The data loads just fine, however when I click the various column headers they don't sort. The loading box shows up briefly over the data, but the columns never actually re-sort. The only column that the sort works on is the very first column. Any help would be greatly appreciated.
Comment: The `index` property you set for other columns are different compared to the column name. When you sort a particular column jQGrid passes the value you set at the index as the sort parameter (sidx).
Comment: That was it! Thanks. If you post that as an answer I'll mark it as the accepted answer.
Answer: The index property you set for other columns are different compared to the column name. When you sort a particular column jQGrid passes the value you set at the index as the sort parameter (sidx).
$("#searchlist").jqGrid({
    ...
    colModel :[
        {name:'resourceName', index:'resourceName', width:380, align:'left'},
        {name:'unit', index:'unit', width:40, align:'center',sortable:true},
        {name:'topic', index:'topic', width:220, align:'center',sortable:true},
        {name:'docType', index:'docType', width:97, align:'center',sortable:true},
        {name:'contentType', index:'contentType', width:97, align:'center',sortable:true},
        {name: 'select', index:'select', width:55, align: "center", sortable: false, editable: true, edittype: "checkbox", editoptions: { value:"Yes:No", defaultValue:"No" }, formatter:"checkbox",formatoptions: {disabled : false}}
    ],
    ...
});

jqgrid columns not sorting when clicked


Why do I get IllegalMonitorException in a synchronized block?

Question: public static void main(String[] args) {
        String resource1 = "ratan jaiswal";
        Thread t1 = new Thread() {
            public void run() {
                synchronized (resource1) {
                    System.out.println("Thread 1: locked resource 1");
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                    }
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        };

        Thread t2 = new Thread() {
            public void run() {
                synchronized (resource1) {
                    System.out.println("Thread 2: locked resource 2");
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                    }
                }
            }
        };

        t1.start();
        t2.start();
    }

After I run this code I get
line 16 is the line with the wait() call
Exception in thread "Thread-0" java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Unknown Source)
    at ThreadSyncFromMark.deadlock.dead$1.run(dead.java:16)

Why I get this exception as I see everything is OK here because t1 owns the monitor of resource1 when it call wait
Comment: From the doc : _Thrown to indicate that a thread has attempted to wait on an object's monitor or to notify other threads waiting on an object's monitor without owning the specified monitor_
Answer:
Why I get this exception as I see everything is OK here because t1 owns the monitor of resource1 when it call wait

Yes, t1 owns the monitor of resource1. But you're not calling resource1.wait(), you're calling this.wait().
You need to synchronize, wait() and notify() all on the same object (monitor) to make things work the way they should.


IIS Express 502 error in vs 2017

Question: When I create new .NET Core 2.0 project in Visual Studio 2017, I am getting an error when I try to run IIS Express:

"Unable to start process C:\Program Files\dotnet\dotnet.exe. The web server request failed with status code 502, Bad Gateway"

I try:

Visual Studio restart
Machine restart
.Net SDK reinstall
Run Visual Studio as admin
Clean project (delete .vs, bin and obj folders)
Comment: I have exactly the same problem. Did you solve yours?
Answer: Same after upgrading to VS 15.6.4. Workaround in the meantime to keep working: click on IIS Express and change to project name, that will start the server in a console.
Answer: Can you elaborate the issue, are you able to run dotnet core application with default template.
Add Current logged in user in IIS_Users Group and try to run the application.

IIS Express 502 error in vs 2017


Is each mixed partial derivatives at one point independent of the order of differentiation ?

Question:
$\left(\textit{A.C.CLAIRAUT}\right)$
Suppose that $U$ is an open connected set in $\mathbf{R}^n,$ that $x_0\in U,$ and that $f:U\rightarrow \mathbf{R}.$Its mixed second partial derivatives $f_{ji},f_{ij} (1\leq i<j \leq n) $ exist on $U$. If $f_{ji},f_{ij}$ are continuous at  $x=x_0$, then$f_{ji}(x_0)=f_{ij}(x_0).$

By the Clairaut's theorem,the following proposition can be easily proved applying the induction method.

$\textbf{Proposition}$
$U$ is an open connected set in $\mathbf{R}^n.$ If $f:U\rightarrow \mathbf{R}$ all of whose partial derivatives up to $k$ are$\underline{\text{ defined and continuous in } U }$$(i.e.f\in C^{k}(U))$, then for any fixed $r (2\leq r\leq k),$the value $\partial_{i_1\cdots i_r}f(x)$ of the partial derivative remains the same for any permutation of the  indices $i_1\cdots i_r (1\leq i_{1},\cdots,i_{r}\leq n).$

$\textbf{My Question:}$
Now we consider an elementary question,slightly modify the proposition'condition:replacing by " If $f:U\rightarrow \mathbf{R}$ all of whose partial derivatives up to order $k$ are$\underline{\text{defined in } U\text{ and continuous at } x_{0}\in U.}$ " Whether we also get that the value of $\partial_{i_1\cdots i_r}f(x)$ at $x=x_{0}$ is independent of the order $i_1\cdots i_r  (1\leq i_{1},\cdots,i_{r}\leq n)$, for any fixed $r (2\leq r\leq k)$?When $k>2$,the conclusion will not holds (I think so).But I need some counterexamples to verify!
Comment: Please, avoid making several edits.
Comment: Suggestion: Elementary algebra, the definition of partial derivatives and the mean-value theorem applied twice will give you two points P' and P" arbitrarily close to your point P such that one mixed partial at P' equals the other mixed partial at P".You should have no trouble taking it from there.
Comment: @P.Lawrence: I am sorry to say that are you sure you have understand my question?
Comment: Sorry for the delay in replying. My understanding is that you are asking if existence of the mixed partials everywhere in U and continuity of the mixed partials at P is enough to guarantee equality of the mixed partials at P.
Comment: @P.Lawrence :Don't mention it ^__^ I considered whether the argument fails or not,when $ k\geq r>2$.Actually,you said is based on $k=r=2$,which holds according to Clairaut's theorem(the method of proof as you suggested).
Answer: The modified proposition is true.
To reduce the subscripts, fix vectors $v_1,\dots,v_k\in\mathbb R^n$ and let $\partial_i$ denote the partial derivative operator in the direction of $v_i,$ so $\partial_ig(x)=\lim_{t\to 0}\frac{g(x+tv_i)-g(x)}t.$

Theorem. Fix an open set $U,$ a point $x_0\in U,$ a function $f:U\to \mathbb R,$ and a permutation $\pi$ of $\{1,\dots,k\}.$ Assume:

$(\partial_m \partial_{m+1}\dots\partial_kf)(x)$ exists for all $1\leq m\leq k$ and all $x\in U$
$\partial_1 \partial_{2}\dots\partial_kf$ is continuous at $x_0$
$(\partial_{\pi(m)}\partial_{\pi(m+1)}\dots\partial_{\pi(k)}f)(x)$ exists for all $2\leq m\leq k$ and all $x\in U$

Then $(\partial_{\pi(1)}\partial_{\pi(2)}\dots\partial_{\pi(k)}f)(x_0)$ exists and equals $(\partial_1 \partial_{2}\dots\partial_kf)(x_0).$

Define the forward quotient operators $$(D_i^tg)(x)=(g(x+tv_i)-g(x))/t.$$
I'll use the following weak form of the mean value theorem: if a function $g$ satisfies $C_1\leq\partial_i g(x+tv_i)\leq C_2$ for all $0<|t|<\delta,$ then it satisfies $C_1\leq(D_i^tg)(x)\leq C_2$ for all $0<|t|<\delta.$
Fix $\epsilon>0.$ Let $c=(\partial_1 \partial_{2}\dots\partial_kf)(x_0)$ and pick $\delta>0$ small enough that $$c-\epsilon\leq (\partial_1 \partial_{2}\dots\partial_kf)(x_0+\sum_{i=1}^kt_iv_i)\leq c+\epsilon\tag{1}$$ whenever $0<|t_1|,\dots,|t_k|< \delta.$ To prove the theorem we need to show that
$$c-\epsilon\leq (D_{\pi(1)}^{t} \partial_{\pi(2)}\dots\partial_{\pi(k)}f)(x_0)\leq c+\epsilon\tag{2}$$
whenever $0<|t|<\delta$ - this is just applying the definition of the derivative.
Applying the mean value theorem to (1) gives
$$c-\epsilon\leq (D^{t_1}_1 \partial_{2}\dots\partial_kf)(x_0+\sum_{i=2}^kt_iv_i)\leq c+\epsilon$$
whenever $0<|t_1|,\dots,|t_k|<\delta.$
Derivative operators commute with translations (as long as everything is properly defined), so we can commute the $D^{t_1}_1$ operator with the $\partial_i$ operators to give
$$c-\epsilon\leq (\partial_{2}\dots\partial_kD^{t_1}_1 f)(x_0+\sum_{i=2}^kt_iv_i)\leq c+\epsilon.$$
Applying the mean value theorem again, and continuing in this way, we eventually get
$$c-\epsilon\leq (D^{t_k}_kD^{t_{k-1}}_{k-1}\dots D^{t_1}_1 f)(x_0)\leq c+\epsilon.$$
Translations commute, so this is the the same as saying
$$c-\epsilon\leq (D^{t_{\pi(1)}}_{\pi(1)}\dots D^{t_{\pi(k)}}_{\pi(k)} f)(x_0)\leq c+\epsilon.$$
Taking the limit $t_{\pi(k)}\to 0$ gives
$$c-\epsilon\leq (D^{t_{\pi(1)}}_{\pi(1)}\dots D^{t_{\pi(k-1)}}_{\pi(k-1)}\partial_{\pi(k)} f)(x_0)\leq c+\epsilon$$
whenever $0<|t_{\pi(1)}|,\dots,|t_{\pi(k-1)}|<\delta.$
Continuing in this way, taking the limit as $t_{\pi(k-1)}\to 0$ and so on up to $t_{\pi(2)}\to 0,$ gives
$$c-\epsilon\leq (D^{t_{\pi(1)}}_{\pi(1)}\partial_{\pi(2)}\dots \partial_{\pi(k)} f)(x_0)\leq c+\epsilon$$
which gives (2) by setting $t_{\pi(1)}=t.$
Comment: I really appreciate your help!But I want to confirm whether those partial derivatives $\partial_{1},\cdots,\partial_{k}$(or those fixed vectors $v_{1},\cdots,v_{k}$) are distinctive from each other in the theorem that you referred to?If we need not such requirement , my modified proposition will be true.
Comment: @Nemo: they aren't required to be distinct, so you can use it for things like $f_{xxy}=f_{xyx}.$
Comment: I see.This theorem can be used on more generalized scope than the condition which the modified propostion gives.Thanks for your elegant proof!

Is each mixed partial derivatives at one point independent of the order of differentiation ？


Range and domain of functions and composite functions

Question: I really getting stuck at finding range of function . For example suppose there is this function
$ f: {R}^+ \to R $ where $ f(x) = |x-1| $  and $ g:[-1 , \infty) \to R $ where $g(x) =e^{x} $ . Then the domain and range of  $fog(x) is $
I'm being taught to fit the $ x $ in some inequality and then recreate the $ fog(x) $  to get the range where the function lies. I know how to recreate the $ fog(x) $ but I get confused between the conditions for which $fog(x)$ exists and where to recreate the $fog(x)$ so that it yields an inequality giving the range of $fog(x)$.I'll be thankful if someone explains that to me.
Answer: Given the domain $D_1$ of $f$ and $D_2$ of $g$, to find the domain $D$ of $f\circ g$ we can solve these relations:
\begin{cases}
x\in D_2,\\g(x)\in D_1.
\end{cases}
In this problem, these relastions become
\begin{cases}
x\geq -1,\\e^x>0
\end{cases}
implying that the domain of $f\circ g$ is $[-1,\infty)$.
To find the range of $f\circ g$, we note that $y\in Range(f\circ g)\iff y=f(g(x))\text{ for some }x\in D\iff y\in Range(f|_{Range(g|_D)})$.
So $$Range(f\circ g)=Range(f|_{Range(g|_D)}).$$
In this problem, $Range(g|_D)=[e^{-1},\infty)$ and $Range(f|_{[e^{-1},\infty)})=[0,+\infty)$ so $Range(f\circ g)=[0,+\infty)$.
Answer: $(f\circ g)(x)=f(g(x)).$
Let $D(h)$ be a domain of the function $h$.
Thus, $$D(f\circ g)=D(g)\cap\{x|g(x)\in D(f)\}=[-1,+\infty)\cap\mathbb R=[-1,+\infty).$$
The range of $f\circ g$ it's $[0,+\infty)$ because $f\circ g$ is a continuous function, $(f\circ g)(x)\geq0,$
$(f\circ g)(0)=0$ and $\lim\limits_{x\rightarrow+\infty}(f\circ g)(x)=+\infty.$


Integral $\int \frac{\cos(x)+\sin(2x)}{\sin(x)}\text{ d}x$

Question: I would like to evaluate
$$\int \dfrac{\cos(x)+\sin(2x)}{\sin(x)}\text{ d}x\text{.}$$
This is from Stewart's Calculus text, section 7.2., #19. Please note that I don't have a solutions manual and I am not interested in a complete solution.
I would merely like some guidance on a first step on approaching this one, since I've gotten 9 similar problems correct, and I hit a brick wall on this one. My first thought was perhaps splitting the fraction like so:
$$\int\cot(x)\text{ d}x + \int\dfrac{\sin(2x)}{\sin(x)}\text{ d}x$$
but this does not look helpful.
Comment: hint : $\sin (2x) = 2\sin( x) \cos (x)$
Comment: A tip for solving integrals that have sin or cosine or some trigonometric function is use a bunch of identities
Answer: Substituting using the double-angle identity
$$\sin (2x) = 2 \sin x \cos x$$
will transform the integrand into an expression that involves only $\sin x$ and $\cos x$, which suggests a particular substitution.
Comment: @Lubin I think it *is* well-known to everyone who has learned calculus, but it may not be obvious to people who are only just learning about trig integrals.
Comment: You don't even need a substitution: after using the double-angle formula, separate the integrand into two fractions, each easily integrated.
Comment: @Lubin Well, the integral of $\cot x$ is not that easy to remember. I usually recognise the integrand as of the form $\frac{(\sin x)'}{\sin x}$, but that's basically equivalent to substituting $u = \sin x$.
Comment: @Lubin You're quite right, of course, but when a student first encounters this type of integral they may well have only seen integrands involving $\sin$ and $\cos$ and in particular may not yet have seen how to handle $\int \cot x \,dx$.
Comment: @Travis - Thank you for your suggestion. I'm a recent math graduate who's studying for the Math GRE Subject Test, and I want to keep memorization to a minimum, so I appreciate yor answer.
Comment: Oh, sorry, I'm too old. I thought that the integral of tangent was well known, so cotangent (sort of) follows.


Are there fundamental problem how I'm fingering this fugue?

Question: Part of my question about how I'm fingering this fugue is based on what I call "contraction" fingering. For example, with this passage...

...where I normally can finger it 1543 2432 1321 2. But I could also play it by "contracting" the fingering where the idea is in five-finger position a third would normally be played every other finger like 2 4, but I reposition the hand for the continuous descending line, 5 "contracts" closer to 2, taking the place where 4 would normally be.
That example may not be the best to use, because 1543 2432 1321 2 is the obvious fingering, but it just illustrates the point about "contracted" fingering. I use contraction in real scores usually when there is a fairly long ascending/descending line and a thumb cross under won't work, or to avoid the thumb on a black key.
I've been trying to train myself for sight reading to see overall descending or ascending passages and use this kind of "contraction" or "expansion" fingering to execute the passages without running out of fingers or just getting my finger tied up in knots. So far it seems to help. Even if I don't execute the best fingering in a sight reading, if I get the general choice of contraction or expansion to match the line with whatever fingers I can manage in the moment, the performance goes smoother.
Below is a little fugue where I tried to apply this contraction fingering, I wrote out the fingering only for the short final half...

...especially in the last three measures, in the right hand, there are several stepwise ascents that I play contracting 3 5 to accommodate the overall long descent of the line. Toward the final cadence I do not absolutely need to do all of those contractions. The final three notes of the top line could be played 4 3 4. But I tried practicing the contraction 4 3 5 for the sake of making the contraction motion a natural habit.
Does it seem like a bad idea to apply contraction fingering literally through to the very end?
Are there other fingerings that seem bad? Both hands play a lot of two notes at once, and my small hand can comfortably reach only an octave, so some of the turns and scale runs while holding a long note in the same hand are tricky for me to play.
Comment: An important thing to keep in mind about fingering (similarly to "hand management" - sorry, I don't know the English term) is that there's no *absolute* best. Each one of us has different hands: bone length, finger position, proportions between finger bones, tendon elasticity, etc. While it's true that some level of adapting can be achieved through practice, it's mostly about your physical "limits", experience, body awareness, and, last but not east, effectiveness based on purpose. Does it work for you? Have you tried alternatives long enough to understand if they have limits based on the »
Comment: @KelvinSherlock, it's just something I came up with off the top of my head. Turns out it wasn't the best example regarding the fingering question.
Comment: What strikes me most is how much I avoid using 5 and would usually prefer 4 3 2 1 instead of 5 4 3 2.
Comment: In your initial example of "contraction fingering", I wouldn't use that fingering to begin with. I'd use `1-5-4-3  2-4-3-2  1-3-2-1  2`, which requires fewer hand shifts, and makes for a more comfortable arrival on the final F#. For my sight-reading, the less often I have to move my hand, the better.
Comment: @aaron. I would use that fingering too for the initial example. Maybe it was not the best example, because it only really requires the position change for the final `F#`. But there are times when playing real scores where I need to do something like that when the line keeps descending.
Comment: » physical possibilities of your hands and fingers, or they just need further practice? Also consider mental practice: some finger patterns just require some habit, so that you don't need to think too much about what fingers you're using. Finally, as said, it's all about effectiveness. When dealing with sight reading, what's important is how effective is what and how you finally play, no matter if you use some "wrong" (according to whom?) fingering.
Comment: Here I was, thinking it was the lower staff's fingering that was wrong.
Comment: @Dekkadeci, the lower staff of the fugue?
Comment: @MichaelCurtis - Correct.
Comment: Can you post an answer, how would you do it?
Comment: Slightly OT but what is that first passage?
Answer: No, there is no fundamental problem with doing this. It might not be the best fingering in any situation, but it allows for fast uncomplicated playing of sequenced runs. Not employing the thumb means you have less problem with landing on black keys.
But you should keep in mind that this will most likely also lead to an accent shift: If you played the top example with 1-5-4-3-2-4-3-2-1-3-2-1-(2) you'd probably accent the beat: (1>-5-4-3)-(2>-4-3-2)-(1>-3-2-1)-(2->). With your fingering your are grouping this in runs, which means you are most likely going to play 1-(5>-4-3-2)-(5>-4-3-2)-(5>-4-3-2). So instead of emphasizing the line G-A-G-F♯ you are going to emphasize with an accent shifted by one 16th D-C-B.
Of course one can then practice against this, but still the point remains that certain types of fingerings will work better for certain type of phrasings and articulations.
I think you should use your fingering when it feels good, but not force yourself to use a fingering that might not work so well.
Comment: But what about the fingering for the fugue? That is my main concern.
Answer: First, the idea to keep the hand, by expansion or contraction, as close to "neutral" as possible (i.e., five-finger position) is a very solid principle to go by. One wants to be as comfortable and relaxed as possible (allowing for exceptions when necessary), and this usually means the hand's natural, relaxed position, which in turn usually means five-finger position or something close to it.
My definition of "fundamental fingering problem": likely to cause injury. So, at that level, your fingering is just fine.
The next level would be allows for musical execution. This is more individual, but again everything seems okay.
Then we get to allows for efficient execution. This is even more individual, but there's nothing that, "as your teacher", I would object to.
My one suggestion, then, is that, four measures before the end, I would take some of the lower right-hand notes with my left hand. I find it makes the surrounding fingering easier and more straightforward.
In general, I am very, very liberal with finger switches, especially when sight-reading, and especially with counterpoint. This is not something that is planned out, and I try to minimize them when creating my "real" fingering for the piece.
Comment: This is really helpful. I appreciate the level break down. Also, your comment about counterpoint really resonates as I work on this set of fugues (Muffat's 72 Versets.) I'm finding the scale and chord patterns so common in Haydn, Mozart, etc. don't help much for these fugues. Every little fugue presents me fingering dilemmas!


How do I fix this error caused by migrating from drupal-composer/drupal-scaffold to drupal/core-composer-scaffold?

Question: I have to develop features for an old project stuck on drupal 8.5, so I figured out it would be great to update the core version to at least 8.8 for a start.
The project is setup using composer and drush, so I started following the steps listed in https://www.drupal.org/docs/updating-drupal/migrating-the-composer-project-for-drupal-earlier-than-880
But I'm stucked with an error in "Migrating from drupal-composer/drupal-scaffold to drupal/core-composer-scaffold"
This is the initial composer.json
{
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^1.2",
        "cweagans/composer-patches": "^1.6",
        "drupal-composer/drupal-scaffold": "^2.2",
        "drupal/admin_toolbar": "^1.23",
        "drupal/ajax_comments": "^1.0@beta",
        "drupal/allowed_formats": "^1.1",
        "drupal/better_exposed_filters": "^3.0@alpha",
        "drupal/colorbutton": "^1.1",
        "drupal/console": "^1.0.2",
        "drupal/core": "~8.5.3",
        "drupal/devel": "^1.2",
        "drupal/eu_cookie_compliance": "^1.0",
        "drupal/filefield_paths": "^1.0@beta",
        "drupal/google_analytics": "^3.0",
        "drupal/metatag": "^1.5",
        "drupal/paragraphs": "^1.3",
        "drupal/pathauto": "^1.2",
        "drupal/quick_node_clone": "^1.10",
        "drupal/simple_sitemap": "^2.12",
        "drupal/smtp": "^1.0@beta",
        "drupal/video_embed_field": "^2.4",
        "drupal/views_infinite_scroll": "^1.5",
        "drupal/viewsreference": "^1.2",
        "drupal/webform": "^5.0@RC",
        "drupal/yoast_seo": "2.0-alpha3",
        "drush/drush": "^9.0.0",
        "vlucas/phpdotenv": "^2.4",
        "webflo/drupal-finder": "^1.0.0",
        "webmozart/path-util": "^2.3"
    },
    "require-dev": {
        "webflo/drupal-core-require-dev": "~8.5.3"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    },
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ],
        "files": ["load.environment.php"]
    },
    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/Commands/{$name}": ["type:drupal-drush"]
        }
    }
}

Running the first step (Migrating from webflo/drupal-core-require-dev to drupal/core-dev) was pretty strait forward but from the second I'm stuck with an error as I run composer require drupal/core-composer-scaffold:^8.8
This is the full error message
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.11
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.10
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.9
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.8
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.7
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.6
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.5
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.4
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.3
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.2
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.1
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.0
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.12
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.11
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.10
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.9
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.8
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.7
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.6
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.5
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.4
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.3
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.2
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.1
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.0
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.0-rc1
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.0-rc1
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.0-beta3
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.0-beta2
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.0-beta1
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.0-beta1
    - Conclusion: don't install drupal/core-composer-scaffold 8.8.0-alpha1
    - Conclusion: don't install drupal/core-composer-scaffold 8.9.x-dev
    - drupal/core-composer-scaffold 8.8.x-dev conflicts with drupal-composer/drupal-scaffold[2.5.4].
    - drupal/core-composer-scaffold 8.8.x-dev conflicts with drupal-composer/drupal-scaffold[2.5.4].
    - drupal/core-composer-scaffold 8.8.x-dev conflicts with drupal-composer/drupal-scaffold[2.5.4].
    - Installation request for drupal/core-composer-scaffold ^8.8 -> satisfiable by drupal/core-composer-scaffold[8.8.0, 8.8.0-alpha1, 8.8.0-beta1, 8.8.0-rc1, 8.8.1, 8.8.10, 8.8.11, 8.8.12, 8.8.2, 8.8.3, 8.8.4, 8.8.5, 8.8.6, 8.8.7, 8.8.8, 8.8.9, 8.8.x-dev, 8.9.0, 8.9.0-beta1, 8.9.0-beta2, 8.9.0-beta3, 8.9.0-rc1, 8.9.1, 8.9.10, 8.9.11, 8.9.2, 8.9.3, 8.9.4, 8.9.5, 8.9.6, 8.9.7, 8.9.8, 8.9.9, 8.9.x-dev].
    - Installation request for drupal-composer/drupal-scaffold (locked at 2.5.4) -> satisfiable by drupal-composer/drupal-scaffold[2.5.4].

I'm considering giving up on the upgrade since this is only the beginning and it should be the easy part since I don't have to handle the database yet.
How do I fix these errors?
Comment: Looks like you didn't follow the instructions in the link - specifically it says you need to remove `drupal-composer/drupal-scaffold` first
Comment: Well, I did run composer remove drupal-composer/drupal-scaffold --no-update and still got this message, hence my post. My current composer.json no longer has "drupal-composer/drupal-scaffold": "^2.2" but there is still a line mentionning drupal-scaffold in the scripts, maybe the problem come from this line ?
Comment: I would look at the content of composer.lock, as _drupal-composer/drupal-scaffold (locked at 2.5.4)_ seems to suggest that file still has a reference to drupal-composer/drupal-scaffold.
Comment: Hi, please create a **new** post if you have a new question. Thanks
Answer: The Installation request for drupal-composer/drupal-scaffold (locked at 2.5.4) -> satisfiable by drupal-composer/drupal-scaffold[2.5.4] part means the composer.lock file contains a reference to that version of the drupal-composer/drupal-scaffold package.
Since you already ran composer remove drupal-composer/drupal-scaffold, remove the line referring to the drupal-composer/drupal-scaffold package from the composer.lock file, and run again composer require drupal/core-composer-scaffold:^8.8.
Answer: In the end running composer remove drupal-composer/drupal-scaffold instead of composer remove drupal-composer/drupal-scaffold --no-update solved the issue. No idea why the line specified in the doc has this --no-update.
Comment: Please don't ask questions in answers - you can always create a new post if you have a new question. Thanks


How to add nested functions javascript in custom commands for Nightwatch testing- forEach -loop through elements

Question: Hi I am new to javascript and Nightwatch, I am a manual tester who started doing automation about 6 months ago.
I am writing test cases for checking the details of a product, with collapsible menus. Pressing + button will open and display a list of elements, when closing with the same button, it closes the list, and shows a counter with the number of items on the list.
I have a function that is correctly doing this procedure, but I have it written on the test. I would like to use it in the Page where I have all elements and functions related to that page. And I would like to call that function from the test. I have been able to do this, but not with cases with nested functions, because I do not know how to write it.
These are my pages:
   loginPage.js;
   productPage.js;
   productFuntionalityListPage.js;

This is my test:
module.exports = {
    'Buy a Product with Bank Account': function (browser) {
        const login = browser.page.loginPage();
        const productList = browser.page.productPage();
        const productFunctionalityList = browser.page.productFuntionalityListPage();

        login
            .navigate()
            .checkLoginPage();

        productList
            .getAProduct()

        //------------------------------------------Features--------------------------------------

        //function to click on each button for functionalities and wait for list to appear
        function displayFunctionsList(elems) {
            elems.value.forEach(function (element) {
                browser.elementIdClick(element.ELEMENT)
                    //wait for list to appear
                    .waitForElementVisible('.list_of_items')
                    .pause(2000)
            })
        }

        // click on each function and wait for list to appear
        browser.elements('css selector', '.expand_collapse_btn', displayFunctionsList, 5000)

        browser.useCss()

        // close each function
        function closeFunctionsList(elems) {
            elems.value.forEach(function (element) {
                browser.elementIdClick(element.ELEMENT)
                    //after click close wait for count to appear
                    .waitForElementVisible("input[data-id='counter']")
                    .pause(2000)
            })
        }

 browser.elements('css selector', '.expand_collapse_btn', closeFunctionsList, 2000)

browser.end()

}
}

This is working correctly.
Below it's what I have tried and does not work:
Page:
productFuntionalityListPage.js
module.exports = {

    elements: {

        counterOfItemsInList: {
            locatorStrategy: 'css selector'
            selector: "input[data-id='counter']",
        },

        expandCollapseBtn: {
            locateStrategy: 'css selector',
            selector: '.expand_collapse_btn',
        },
       listOfItems: {
            locateStrategy: 'css selector',
            selector: '.list_of_items',
        }
  },

commands: [{
        displayFunctionsList: function () {
            function displayFunctionsList(elems) {
                elems.value.forEach(function (element) {
                    this.elementIdClick(element.ELEMENT)
                        //wait for list to appear
                        .waitForElementVisible('@listOfItems')
                        .pause(2000)
                })
            }

            this.elements('css selector', '@expandCollapseBtn', displayFunctionsList, 5000)

        },

 closeFunctionsList: function () {
            function closeFunctionsList(elems) {
                elems.value.forEach(function (element) {
                    this.elementIdClick(element.ELEMENT)
                        //wait for list to appear
                        .waitForElementVisible('@counterOfItemsInList')
                        .pause(2000)
                })
            }

            this.elements('css selector', '@expandCollapseBtn', closeFunctionsList, 5000)

        }

    }]
}

Test calling function from page:
module.exports = {
    'Buy a Product with Bank Account': function (browser) {
        const login = browser.page.loginPage();
        const productList = browser.page.productPage();
        const productFunctionalityList = browser.page.productFuntionalityListPage();

        login
            .navigate()
            .checkLoginPage();

        productList
            .getAProduct()

        //------------------------------------------Features--------------------------------------

         //calling displayFunctionsList from productFuntionalityListPage.js
         productFunctionalityList.displayFunctionsList()

         //calling closeFunctionsList from productFuntionalityListPage.js
         productFunctionalityList.closeFunctionsList()

browser.end()

}
}

Result after running the test above:

Error:
TypeError: this.elements is not a function
   - writing an ES6 async test case? - keep in mind that commands return a Promise;
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.

Could anyone please help me adding these functions as custom commands in the productFuntionalityListPage.js and call these functions from the test itself? Not sure what's wrong, because of my lack of javascript and nightwatch knowledge.
Answer: Try passing browser as a variable when calling the function like this -
##Test page##
//Example call

gmail.selectEmail(browser, 'browser authentication')

And then the method in the pageObject -
##Page Object##
//Example Method
selectEmail(browser, searchValue){
     browser.blah(searchValue);
     browser.blah
     browser.blah
};

Its slightly messy way of getting it to work but this has saved my bacon a few times
Comment: Alternatively this might be a better explanation of the cleaner route - https://stackoverflow.com/questions/50651476/how-to-nest-nightwatch-js-commands-in-page-sections/50707725#50707725
Comment: Thanks a lot for the help!!!! I will try it out and I check the explanation to make it better. Have a great weekend! Stefi


Code property in javascript functions

Question: function hello(){
  console.log('Goodbye');
}

is an object. Almost everything in js is object. We have name property on it and its hello, but what about code property? How can I access that? Also, do I have the code inside {} or the whole whats above?
Comment: where is your `name ` and `code` property?
Comment: @AnkitAgarwal hello.name
Answer:
Also, do I have the code inside {} or the whole whats above?

For your method, use toString
hello.toString()

Demo

function hello(){
  console.log('Goodbye');
}
console.log(hello.toString());

And if you only want to access code between { and }, then (assuming it is not an arrow function)
var code = hello.toString();
code = code.substring( code.indexOf( "{" ) + 1 ); //remove code before first {
code = code.substring( 0, code.lastIndexOf( "}" ) - 1 ); //remove code from last }

If it is an arrow function, then
var hello = () => console.log('Goodbye');
var code = hello.toString();
code = code.substring( code.indexOf( "=>" ) + 2 ); //get the string after =>

Comment: Is that the same thing as when I just do `hello` without `()` ?
Comment: @Learnonhardway Sorry I didn't get *do hello without ()*.
Comment: @Learnonhardway `console.log()` calls `toString()` internally to get the string to display.
Comment: @gurvinder372 Means, getting the code without invoking it.
Comment: @Learnonhardway you are not invoking the function, just getting its body by doing `toString`.
Comment: Well ok. I thought it had some special property, like `hello.code` that will get me the string version of function. That is why I made parallel with `hello.name` property.
Comment: You should use `lastIndexOf("}")` instead of `indexOf("}")` if there is eg. an if-clause inside the function.
Comment: @MEE Thanks, for some reason that is what I thought I had used :)
Answer: The code of a function is not in a publicly accessible property. It's stored in an internal [[Code]] property, as specified in Creating Function Objects.
The toString() method of a function will return the entire function definition as a string.
Comment: That is what I need. Thanks. Did not knew about [[Code]]. Not very occasional on the surface of the js code.

Code property in javascript functions