How to communicate or send data from one ionic application to another ionic application?

Question: I want to communicate my ionic application(Subscriber Application) with another ionic application(Merchant Application).
Here the requirement is I want to send the transaction success message to the another application once the payment is done by hand.
I have tried few work grounds like using PUSH service but not make it worked.
Is there any idea around to make it possible?
Comment: yes thry this one http://docs.ionic.io/v1.0/docs/push-from-scratch
Answer: Share a database between both merchant and subscriber apps. Like Parse Server or something that will allow server side code execution.
1/ Make payment (handle securely on server)
2/ Backend server confirms to client side payment made successfully returning payment successful to subscriber and sending a push to the merchant to alert them.
3/ On opening the merchant app, request data from database to show details of transaction etc.
Parse server: https://github.com/ParsePlatform/parse-server
Answer: I think as suggested by Ant I'm using Baasbox for my application and it has built in push server where I can send the push notification to the logged in users.
I'm also sending a notification when the transaction is sent to database and Merchant can get the list with the swipe down feature.
One problem I'm facing in IONIC is the push notification won't work when the application is in the foreground. so I'm unable to catch the events when a push notification arrives.
Comment: If you are using $cordovaPush then you should be able to monitor the device state on notification receipt like so: `$scope.$on('$cordovaPush:notificationReceived', function (event, notification) { if (notification.foreground == "1") { Do stuff here as received in the foreground } else { do stuff here as received in background } }`. Post a new question if you can't get it going and I'll help out if I can.


What pitches for singing "Movable Do"?

Question: Considering that everybody has their own most comfortable singing range: when using the 'movable do'-system for solfège, which pitches does one choose to sing the various syllables?
Can 'do' be any pitch one wishes? i.e. does this mean everybody chooses their own key to sing in, transposing the music while singing? And, if so: isn't this confusing when singing with others and/or an instrument?
Or is 'do' always the C from the C-major scale, and does one choose the most comfortable octave?
Comment: One could even choose a pitch, say, between B and C, and decide that was doh. Especially if it was only voices. Of course, one chooses the most comfortable octave to sing in. But whatever note name is chosen, that note name, in all octaves, will be 'doh'
Answer:
Can 'do' be any pitch one wishes?, i.e. does this mean everybody chooses their own key to sing in, transposing the music while singing?

A movable 'do' can indeed be any pitch, however, in a group setting, the entire group must use the same any pitch. Otherwise, you get unintended multitonality, and chaos! If needed, the group's leader could pick a pitch as 'do', based on the range of the piece, and the ranges of the individuals in the group.
But usually pieces are already written in a specific key, which defines what 'do' is for that piece -- movable 'do' always refers to the tonic, or first scale degree (the key note).
This is opposed to the fixed 'do' system (as is used by some European countries), where 'do' always refers to the pitch 'C'.
Example: Consider singing the syllables 'do', 're', 'mi'. In a fixed-do system, this will always mean to sing C, D, E, regardless of what key you are in. In a movable-do system, it will always mean to sing the first three scale degrees of whatever key you are in. So in the key of C, it is identical to fixed-do (C, D, E). However, in the key of A major, you would be singing A, B, C#. In the key of Eb, you would be singing Eb, F, G. And so on...
Also, as you note, solfege syllables do not specify the octave. Thus, they are not enough to completely specify a melody by themselves. That is not their intent -- they are meant as an aid to highlight the interval relations within an octave.
Frequency vs Pitch Fixed vs. Movable 'do' says nothing about what frequency (in Hz) a given pitch (such as A) will be. To determine that, there are different pitch standards, the most widely-adopted (and the official standard for the US and Europe) being A=440Hz. For playing in early music ensembles, other standards will sometimes be adopted; e.g. A=415 is frequently used for Baroque music, and A=432 seems to be a popular alternative as well (especially in youtube videos, which apparently claim that that frequency is somehow more relaxing than others). But using something other than A=440 is still pretty rare.
Comment: In A major, movable 'doh' is always A.  A might be 440Hz, but isn't always -- see http://music.stackexchange.com/a/23303/1252
Comment: "But usually pieces are already written in a specific key, which defines what 'do' is for that piece -- movable 'do' always refers to the tonic, or first scale degree (the key note)." Now I'm confused again. Are you saying that for a piece in an obvious key, one should always sing "do" at the pitch of this first scale degree? This means that for a piece in C major, movable 'do' and fixed 'do' are always exactly the same?
Comment: So, in A-major "do" is always sung at 440Hz?
Comment: @Tim H - In the Western world, A is generally regarded as being pitched at 440Hz, for convenience.Whatever the note designated to be 'doh' actually is, A will usually be 440 - or darned close to that.
Comment: @Tim H - regarding your first comment - Fixed doh = C. Movable doh = whatever note the players designate. If they decide C, then yes, the fixed and movable are one and the same.
Comment: @Tim H - You may be confused as to which particular C may be doh. If one elects that C actually will be doh, then EVERY C in that tune will be called doh, regardless of which octave it is in, or which pitch called C is considered.
Comment: @TimH I added an example. Hopefully that will clear things up for you. Let me know if you still have questions.
Comment: Thank you for the clarification. I was a bit thrown off by your first paragraph because it implied to me that the frequency of 'do' could be anything. But in practice using the 'movable do'-system only really makes sense in tonal music for pieces in a specific key or keys. So in practice there nearly always is a tonic to refer to. One then sings at the frequency that is culturally linked to the pitch of this tonic, while having the freedom to choose the most comfortable octave.
Comment: I can see how that could be misleading. I was thinking of a warmup exercise I sing in a vocal ensemble, where we sing solfege symbols in a round. I have no idea *what* starting pitch the director gives us (and therefore what key we are in) or if its even the same one each time. But we sing the piece by knowing where the syllables fall in the scale. There's one spot where it reaches the do an octave above the starting do, so the choice of octave isn't completely arbitrary, just not encoded in the syllables.
Answer: Movable Do is called such because it is just that: movable.
Movable Do focuses on intervallic relationships. When you change keys, "Do" becomes the new tonal center for that key and all of the other solfege syllables are transposed accordingly.  For example, in the key of D, "D" would be "Do".  If we changed keys to "F", "F" would now be "Do."
Fixed Do focuses on pitch classes. In fixed do pitch classes retain their solfege regardless of context. For example, "C" is always "Do" regardless if it is the root of the chord / scale or not.
Comment: Technically, I did answer your question as you asked about *pitch*.  However, you *meant* to ask about *frequency*. In all tuning systems, pitch classes are always consistent within themselves (due to how the overtone series functions). The actual frequency of F differs depending on the tuning system, but whatever system you're singing in will determine the frequencies of the notes you sing. FYI we use the Equal Temperament system in the Western European tradition. Voice ranges and groups only effect what key you choose, not the frequencies of those keys. Find a key that works for everyone.
Comment: Ok, thank you for making explicit the difference between movable do and fixed do. But this doesn't answer my question. In practice at what pitch (Hz) do you choose to sing this "Do" (= the tonic) in the key of F?, considering voice range. And what to do in a group setting?
Answer: The fixed doh system as used in France, as one example, can quickly become more of a hindrance than a help. If a tune is in , say, Eb, then doh automatically isn't the root key note (tonic); that will be called Me flat. One of the helpful bits to a movable doh is the lack of sharps and flats - usually, in simpler tunes at least. Thus, the whole ensemble regards the key note as 'doh' and all the others follow it as if the tune was actually written in C.(C sort of being construed as a datum point doh). I suppose it's somewhat like an alto sax player playing a 'C' note from music, but actually, that 'doh' for him turns out to be an Eb doh in reality.From that point of view, in an orchestral score, there would be several different dohs to compensate for the different transposing instruments, i.e. in a piece in concert D, the trumpet doh would be E.
Comment: Are you saying that for a piece in F-major the note F, sung with the syllable "do", is always sung at the pitch of C? This is not the same answer as the answer of Caleb Hines, where it would be the pitch of F.
Comment: In the fixed doh, doh is always C. So in that format, F would always be Fah. I'm saying the same as Caleb - that for the movable system, when in the key of F, F is regarded as doh. In the latter system, doh will only be sung (or played) as C when it's decided that the tune IS in C.Maybe I need to re-phrase my answer ?

What pitches for singing "Movable Do"?


Homeomorphism via map between topologies

Question: Background

Theorem. Let $(X,\tau_X)$ and $(Y,\tau_Y)$ be two topological spaces and $f:(X,\tau_X)\to(Y,\tau_Y)$ be a homeomorphism between them. Then there exists a bijection $\varphi:\tau_X\to\tau_Y$.
Sketch of the Proof. Define $\varphi:\tau_X\to\tau_Y$ by $\varphi(U)=f(U)$. Then the map is well-defined because $f(U)\in\tau_Y$ for all $U\in\tau_X$. To show that $\varphi$ is injective observe that for all $U,V\in\tau_X$,\begin{align}\varphi(U)=\varphi(V)\implies f(U)=f(V)\tag{1}\end{align}If possible, let $U\not\subseteq V$ or $V\not\subseteq U$. Without loss of generality let us assume that $U\not\subseteq V$. Then there exists $x\in U$ such that $x\notin V$. Then $f(x)\in f(U)$ and $f(x)\notin f(V)$ (since $f$ is injective). Consequently $f(U)\ne f(V)$ contrary to $(1)$. Similarly we can prove that it is impossible to have $V\not\subseteq U$. Consequently $U=V$.
To prove the surjectivity of $\varphi$, let $V\in \tau_Y$. Then observe that since $f$ is continuous $f^{-1}(V)\in\tau_X$ and since $f$ is surjective we have, $$\varphi(f^{-1}(V))=f(f^{-1}(V))=V$$
Consequently $\varphi$ is bijective.

Questions

Is the converse of the above theorem true? More specifically, if there exist bijections between $\tau_X,\tau_Y$ and $X,Y$ respectively then are $(X,\tau_X)$ and $(Y,\tau_Y)$ homeomorphic?

Let $\phi:\tau_X\to\tau_Y$ be any function. Then does $\phi$ always "induces" an open map from $(X,\tau_X)$ to $(Y,\tau_Y)$?

Let $\phi:\tau_Y\to\tau_X$ be any function. Then does $\phi$ always "induces" a continuous function from $(X,\tau_X)$ to $(Y,\tau_Y)$?

My Conjecture
I think that the answer to my first question is most probably affirmative. However, I couldn't construct such a map till now. Regarding the other two I have no idea. Can anyone help (especially regarding the first question by constructing explicitly such map)?
Comment: If there is a bijection $f:X\to Y$ and a bijection $g:\tau_X\to \tau_Y,$ all we have is that $X, Y$ have the same cardinal and that $\tau_X,\tau_Y$ have the same cardinal.  With $X=Y=\Bbb N,$ there are, for example, many non-homeomorphic countable topologies on $X$.
Answer: The sets $\tau_X$ and $\tau_Y$ have more structure on them than just bare sets: they are partially ordered sets, where the partial ordering on $\tau_X$ is the inclusion relation on subsets of $X$, and similarly for $\tau_Y$. The bijection $\phi : \tau_X \to \tau_Y$ that is induced by a homeomorphism $f : (X,\tau_X) \to (Y,\tau_Y)$ preserves that partial ordering.
So the answer to all of your questions is no. Assuming $X$ and $Y$ are not empty, and using that $\tau_X$ and $\tau_Y$ have the same cardinality (which is implied by your statement that there exists some bijection between them), it is easy to define a bijection $\phi : \tau_X \to \tau_Y$ that not preserve inclusion. Simply define $\phi(\emptyset)=Y$ and $\phi(X)=\emptyset$, and extend this arbitrarily to a bijection. The same $\phi$ gives a "no" answer to all of your questions.
Comment: I gave you a $\phi$. Using that $\phi$, it is impossible to construct the continuous function with the properties that you ask. The reason it is impossible is because there *does not exist* a function $f : X \to Y$ such that $f(X) = \emptyset$ and $f(\emptyset) = Y$.
Comment: I don't understand your second paragraph. My first question asks that if there is a bijection $\Phi: \tau_X\to \tau_Y$ and a bijection $\Psi:X\to Y$ then is it always true that there exists a homeomorphism  between $(X,\tau_X)$ and $(Y,\tau_Y)$? Why do I need to construct another $\phi$?
Comment: The same thing holds for the other questions. We are given $\phi$ and **using that** we need to construct (if we can) a continuous function or an open map. Can you explain in a more detail how the answer to all my question is "no"?


Why are there parentheses and dots after an array's name instead of brackets?

Question: When accessing an element in an array the square brackets are used like so:
{'X is an int and Numbers is an int array'}
X := Numbers[8];

However, While reading others' code I sometimes find the following syntax:
{'PBox , SBox1 , SBox2 are arrays of int , And X,Y are ints'}
Result := Result or PBox(.SBox1[X] or SBox2[Y].);

What does it mean to have parentheses after the array's name, as in PBox(someNumber)? Is this another way to access an array element?
What does the "." before SBox1 and after SBox2 mean? Both SBox1 and SBox2 are arrays. The code compiles without error but I don't know what those dots are for.
Comment: It took me almost a minute to see what is going on here! The `(.` way of writing `[` is very uncommon! And it is also very uncommon to use a bitwise `or` to compute an index of an array! As a "noob", you **really** should begin with studying far simpler things than this! In addition, `PBox` is a very bad name of an integer array, since the `P` prefix usually denotes pointer types, such as `PInteger` (`=^Integer`).
Comment: @Andreas: Have you seen it before? I work with Delphi since '98 and never saw an array indexed with `(.`. The bitwise part I never saw too, but if the code use some API the bitwise `OR` would be need to set flags.
Comment: @Fabrico: I have never seen `(.` in an actual piece of code, but I knew about it (although, at first, I mistook it for `(*`, the alternative way of writing `{`). Bitwise `or` is something every programmer knows about. As you say, it is perhaps most often used to combine flags in "bitmaps", but there are far more applications than that if you work with low-level stuff. I have never seen a bitwise `or` as an array index, though...
Comment: @Andreas : I saw this in an implementation of the DES algorithm , pbox stands for permutation box.
Comment: The bitwise `OR` is quite common on Win API programming (it's common on some low level methods of VCL) - but indexing an array on a bitwise expression is something you don't see every day... ;-)
Comment: I prefer to use // comments as they don't confuse the C++ programmers as much. Also you don't need to put quote marks around your comments.
Comment: The (. and .) for [ and ] is a leftover from the early Turbo Pascal days, before all keyboards had the [] keys, IIRC. I haven't seen it for decades (dating myself here ). Same for the (* for { and *) for }.
Comment: @Ken White: That is how I understand it, too.
Answer: Yes, now I see what you do.
In fact, (. and .) are merely alternative ways (but very uncommon!) of writing [ and ] in Delphi.
If PBox is an array, then PBox[a] (or, equivalently, PBox(.a.)) would require a to be an integer, right? And if SBox1[x] and SBox2[Y] are integers, so is the bitwise or of them. (Bitwise or is an operation that takes two integers and returns a new integer.) Hence, PBox(.SBox1[X] or SBox2[Y].) is the (SBox1[X] or SBox2[Y])th element in the array PBox, that is, an integer. So it makes sense to compute the bitwise or between Result and this integer, which is what is done:
Result := Result or PBox(.SBox1[X] or SBox2[Y].);

Comment: Now the `WeirdLookingArray: array(.1..10.) of string;` from the [The Future of the Delphi Compiler](http://edn.embarcadero.com/article/39174) finally makes sense!
Comment: Thanks a lot Andreas .. Now I get it:)


How to analysis the repeated measured study where combine with matched pairs?

Question: I am doing a study to evaluate the effect of treatment on eyes.
The purpose was to explore whether the level of X protein is different between treatment group (sick eye) and normal control group (normal eye).
Twenty patients were selected in our study and accepted the treatment for the sick eye.
After the treatment, for each patient, we tested the level of X protein in the treatment group (sick eye) and normal control group (normal eye) at 5 time point, respectively (1 month, 3 month, 6month, 9 month, 12 month).
Therefore, here's the form of my data (attached figure).
How to describe the design in the present study?
1、Two repeated measured factors design?
We think the time factor is a repeated measured factor, and the treatment factor is the other repeated measured factor.
However, could the treatment factor be considered as a repeated measured factor?
Because it only has two levels (Treatment group vs. control group).
2、The sick eye is selected in treatment group, the normal eye is control group.
Did it is a matched pairs design?
And it is a matched pairs combine two repeated measured factor design?
So, which design it is?
How to conduct the analysis?
Linear Mixed model or GLMM or Multilevel model?
Thanks a lot!
Answer: The problem with trying to come up with a precise, technical name for your design is that not everyone understands it, or agrees with the name, so it might not help (see, for example 'mixed anova', 'structural equation' or 'hierarchical regression').
In your design, how will you treat time? Is that categorical or continuous?
"Two repeated measured factors design" is not wrong, but you probably want to add some more description, because that doesn't provide enough information. There are many ways to analyze it - I'd use a linear mixed model (probably).
Comment: Thank you very much for your solution and your suggestion! In the study, the time was treated as a categorical variable. Does the study include the matched pairs design or not?  " the sick eye is selected in treatment group, the normal eye is control group. " Should we consider it (treatment factor)as a self-matching factor ? If it is, how to manipulation the self-matching factor in  repeated measured analysis? : 1. only consider the self-matching factor(treatment factor)as fixed factor in LMM ?  2. Should we analysis it by special method? Thanks! @Jeremy Miles
Comment: I would call eye status (sick or not) a predictor in the model.
Comment: Thanks!  Actually,  It's not similar with Paired-Samples T Test .  The matched pairs factor is not considered as a special factor when we conduct a repeated measured design ?
Comment: Not sure what you're asking. What's a special factor?
Comment: Forgive me the imprecise description. But, I always confused that if a factor was considered as the matched pairs factor in the design, whether we should treat it as the the matched pairs  when we conduct the statistic analysis.                                                             The question is:   Is there a statistic method for  special treating  self-matching factor  similar with the paired t test (sorry, the statement may not appropriate ) when we  analysis the repeated measured data by LMM method  or GLMM or GEE ?  Thanks a lot!
 @Jeremy Miles


Continuity of the derivative of a continuous function

Question: Is it true, that if $f(x)$ is continuous and differentiable on an interval $[a;b]$, then  $f'(x)$ is continuous? Thanks in advance!
Comment: Do you mean: if f is continuous and differentiable on [a,b]?
Comment: What if $x=|x-c|$   Check differentiability at $x=c$
Comment: A continuous function doesn't necessarily **have** a derivative at all - thus, as Jonas says, did you intend to require that $f$ be differentiable?
Comment: Yes, I'm going to edit that, thanks.
Answer: Consider the function
$$
f(x) =\begin{cases} x^2\sin\frac 1x &\text{ if } x\neq 0\\
0 &\text{ otherwise}
\end{cases}
$$

It is smooth everywhere, because
$$
|f(x)|\le x^2 \implies \text{ continuous in }0\\
\left|\frac{f(x) - f(0)}{x-0}\right|\le |x| \implies \text{ has a derivative in }0\ \ \  (f'(0) = 0)
$$

Now its derivative is, around $0$ (and for $x\neq 0$):
$$
f'(x) = 2x\sin\frac 1x - \sin\frac 1x = O(x) - \sin\frac 1x
$$

and is not continuous: it takes all values of $[-1,1]$ in any neighborhood of $0$.


How to prove sin(sin(sin...(sin(1))) converges to 0 without using continuity?

Question: Using continuity I was able to show the sequence $x_0 = 1$, $x_{n+1} = sin(x_n)$ converges to 0, but I was wondering if there was a way to prove it using only properties and theorems related to sequences and series, without using continuity.
So far, I know the sequence is monotonically decreasing and bounded below by 0, so it must converge to its infimum. From here I'm not exactly sure how to show 0 is the infimum of this set of numbers.
Alternatively, I could check convergence to $0$ by comparison, but no sequences come to mind that are greater than the given sequence for all $n \geq N$ and converge to $0$.
I've already seen the answers at the following:
Compute $ \lim\limits_{n \to \infty }\sin \sin \dots\sin n$
Prove that $\sin(\sin...(\sin(x))..)$ converges asymptotically to zero
Answer: We know that for all $x \in (0,1]$, we have
$$
0 < \sin x < x
$$
From there, you can show that $x_0,x_1,\dots$ is a strictly monotonically decreasing sequence.  Is this enough? That is, can we forgo continuity? No. As a counterexample, consider the seuqence $x_k = f(x_{k-1}); x_0 =1$ with
$$
f(x) =
\begin{cases}
\sin(x) + 0.1 & x^*<0\leq 1\\
\sin(x) & 0 < x \leq x^*
\end{cases}
$$
Where $x^*$ is the positive solution to $= x^* = \sin(x^*) + 0.1$.
We note that $x_k$ is a strictly monotonically decreasing sequence converging to $x^*$ (and therefore bounded below by $0$), and we even have $f(x)<x$ for every point in $(0,1]$.  However, because of the lack of continuity, this is not enough to "force" $\{x_k\}$ to converge to $0$.
Comment: So, is this saying that continuity is a necessary condition for the iterated sines to converge?
Comment: At the very least, this is saying that the properties I've listed besides continuity are not enough. I don't think you can show that this set has an infimum of $0$ without invoking continuity in some respect.
Answer: $$\sin(\sin...sin(1)))....)) =L$$
$$ \sin(\sin...sin(1)))....)) =arcsin(L)$$
$$L=arcsin(L)$$
$$\sin(L) =L$$
$$L=0$$
Comment: That kind of implicitly uses continuity.


Rendering elements around a central point

Question: I've got a bit of a tricky question I couldn't find the answer to. Basically, This is what I have:

In the center is a search box (fixed to the center of the page), and around it are dynamically loaded search results of differing sizes (although, if need be these can be restricted). Thing is, they need to "wrap" around the search box after the results have been loaded. My normal go-to is floating, but this isn't really going to work, as the box isn't aligned to a particular direction.
I've looked at jQuery Masonry for a solution, but it isn't going to work for me (doesn't detect fixed elements, doesn't work from a point).
Any pointers in terms of solutions or Google-Fu would be much appreciated.
Comment: start here http://en.wikipedia.org/wiki/Bin_packing_problem
Comment: Thanks a bundle. One of the hardest things about this problem was trying to describe it in words
Answer: This is similar to packing textures of different sizes on a square. Have a look at this algorithm: http://www.blackpawn.com/texts/lightmaps/default.html
Since you have a central fixed box, maybe you can divide your available space in 4 rectangles and then pack the boxes into them.
Comment: You know, I was thinking of using the quadrant approach (populating them in turn) but I wasn't sure if I was on the right track. Thanks for the tip!


Services (such as Twilo, Plivo, Nexmo) to verify phone numbers in Rails app

Question: I'd like to verify phone numbers of user accounts in my Rails 4 app (by simply sending them a four digit pin number which they'll need to enter back into the app) - which services are available and which ones are the least hassle to implement into a Rails app?
I'd like to verify both mobile and landline numbers internationally, though my main areas will be Europe, the US & Canada, Australia and New Zealand (I am based in the UK).
Answer: Your title lists three main SMS APIs, so for services available you already have a good understanding. But there are also APIs that focus exclusively on 2FA / Verification. Here is a list of some, worth noting that it tends to be focused on the user side of the equation (things like Google Authenticator).
Since you ask about ease of integration, a 2FA API (instead of an SMS API) may be far easier (you don't need to be concerned about generating a truly random OTP, or using voice fallback if the user does not respond to SMS, etc).
Nexmo (Disclaimer: I work there.) actually offers both SMS / Voice APIs, and a Verify API built on top of those lower level APIs.
With our Verify API (it's going to be similar regardless of the 2FA API) you'd make a call to https://api.nexmo.com/verify/json and pass along number and brand (to identify your app) parameters. The response will contain a request_id, and once the user provides your app with the code, you'll pass both the request_id and code to https://api.nexmo.com/verify/check/json.
So it's 2 simple API calls, and in the interim you associate the request_id with the user's session. Here's a quickstart on that process.
With Nexmo specifically, if enough time passes without the second API call, the code is sent again, this time with a voice call (or, if the number is a fixed line, just starts with voice).
With our SMS API (again, will be similar regardless of the API) first you'll generate a code - which may sound deceptively simple, if security is a concern you'll need to ensure that the generation is truly random.
Then you'll store the code and send an SMS. With Nexmo, that'd be a call to https://rest.nexmo.com/sms/json with the text of your message, the to and the from*. There's also security concern there because you're storing the code on the same server as it validating it. If that's compromised, the verification flow is as well.
Finally, you'll compare the user provided code to the code you stored.
So the least hassle really depends on you. Is it easier to  make two API calls and avoid secure code generation / storage (and potentially get voice fallback for free)? Or DIY the code generation and reduce your integration to a single call to an SMS API?
Comment: @A4J On the SMS API you're charged for each SMS (generally true for all SMS APIs). If the number itself is invalid, then you wouldn't be charged anything. For Verify, you're only charged for a successful verification (user provides the correct code).
Comment: Thanks Tim. I think for me the SMS API is fine. My only concern is bots - what if they sign up and put invalid numbers in and the system requests verification - do services like Nexmo only charge for valid/delivered SMS messages?
Comment: Thanks Tim - do you know of any guides or gems to help integrate Nexmo with a Rails app?
Comment: @A4J Not a guide, but this ruby client library should be helpful: https://github.com/timcraft/nexmo
Answer: Twilio developer evangelist here.
You absolutely can use Twilio (or any of those other services) to verify phone numbers. There is a good blog post here that explains the steps you can go through to perform a phone verification via SMS.
As you are looking to verify landline numbers too, you might need to add voice confirmation too, where you call a user up and read out the 4 digit passcode instead. That can be accomplished in a similar way, but by making an outgoing call to the phone number which reads out the individual code using Twilio's text to speech <Say> verb.
Let me know if this helps at all. I'm in the UK too, so do reach out if I can help further.
Comment: Thanks for the info Phil - I'll check out the link. Do you still have a startup offer ($133.70 in Twilio credit) that Danielle mentions in the Quora thread? Twilio seems more expensive than the others :/


How to determine likely cause of a failure in a cloud system?

Question: I'm analyzing failures in a large cloud system, and would like to triage likely causes for a specific type of error (category, not a single incident) based on the location or other properties of the failure.
To simplify, let's say I have just one feature to consider - the data center where the type of failure that I'm analyzing happened. There are hundreds of types of errors, and millions of errors logged per day.
My data set consists of the most recent 24 hour track of failures.
From this I can extract a table that looks like this:
<code>| Error type | # cases in location 1 | # cases in location 2 | # cases in location 3 | # cases in location 4 |
|--------------|-----------------------|-----------------------|-----------------------|-----------------------|
| Error type 1 | 100 | 2 | 15 | 0 |
| Error type 2 | 20 | 500 | 10 | 10 |
| Error type 3 | 90 | 10 | 10 | 10 |
| Error type 4 | 92 | 9 | 11 | 5 |
| Error type 5 | 80 | 13 | 8 | 6 |
</code>
(etc)
If I'm interested in determining whether the cause of error type 2 is likely to be somehow connected to conditions related to location 2, it's intuitively clear that's the case due to the disproportional number of cases happening there.
What's the best way(s) to automatically detect this, preferably with a confidence score attached to it? I guess I could ask what the probability of any other error happening in location 2 vs. the same calculation for error type 2 somehow?
Answer: So I ended up calculating the standard deviation and mean in percent + essentially normalizing it. Do this for the total population, and use as a baseline. Then for each error calculate the same, and use a cutoff based on general mean and stddev.
I went with a factor being significant if it was represented more than general mean + 1.5 * general stddev


Is this pseudoCode for composing a medieval song accurate/adequate?

Question: I've created some pseudocode for some software that is supposed to compose music independently, given a specific musical time period. This particular algorithm is supposed to create a medieval song, help regarding how to make it more accurate to the medieval time period (circa. 500 to 1400).
I'm also going to put this on code review but I figured that this site would be better regarding the musical side of things ^_^
Set Time signature to 6:8
Set tempo to a random number between 60 and 75 bpm
Set dynamics interval (the amount of bars to wait until changing dynamics) to a random multiple of 2 between 4 and 12.
Set Dynamics to forte
Set number of bars to a random multiple of 4 between 16 and 32.
For each dynamic interval
Set the dynamics either one step louder (e.g. from forte to fortissimo) or one step quieter (e.g. from forte to mezzo forte).
Set key signature to any key signature whose sharps and flats are less than 4 (e.g. A major).
Create random chord sequence based on key signature (e.g. A, D,
For the first bar:
Add a dotted minim with a random note of the chord (e.g. either A, C#, or E from A major).

Create a random pattern for half the bar (mostly either three quavers or a crotchet and a quaver) using random notes from the key signature.

Create another random pattern for the second half of the bar (preferably different from the first half)

For the rest of the bars except for the last:
Add a dotted minim with a random note of the chord (e.g. either A, C#, or E from A major).

Create random notes using the same rhythm pattern for both halves of the first bar.

For the last bar:
Add a dotted minim for each note of the final chord.

Comment: Why don't you try and listen for yourself?
Comment: There is a name for this field of study: *algorithmic composition*. Look it up.
Answer: I'm not a programmer so I cannot say anything about the validity of the program but what I can say is that all of these parameters will not give you medieval music.
I usually just completely abstain from interacting with these types of questions because I do not want to build an atmosphere of opposition in my post on this site but I think I can make a meaningful contribution to this question.
What I will say is that I think you grossly underestimate the complexity of writing music. Ju8st to get to the level of writing a good 8 bar melody can take upwards of 5 - 6 years of quality instruction to achieve.
If a computer would be able to do this then it would almost have to posses some sort of artificial intelligence but let me leave it there and further delve into your question.
As I have mentioned before on this site modern Major and minor tonalities where not part of the Medieval music. It was an invention of the Baroque era. So unless your program does music in the church modes it is not really going to be medieval music.

Create random chord sequence based on key signature (e.g. A, D, For
  the first bar:...

Chords are definitely not chosen at random this is a poor way to choose chords.

Set Time signature to 6:8

Could you explain to me why exactly you think 6/8 would have to be chosen for Medieval music? This seems rather arbitrary.

Set number of bars to a random multiple of 4 between 16 and 32.

You would rather want multiple phrases of 8 bars. You would definitely not want 4 bar or 12 bar phrases.
Questions you would have to ask yourself is how are you going to teach the machine to write melodies? How are you going to teach the machine how to do rhythmical sequences? How are you going to get the machine to choose which part of the rhythm to make a sequence out of? How are you going to teach the machine to handle the issue of inversions? There exist a plethora of rules on how chordal inversions work.
In conclusion I think that all these problems I see on this sites in regards to reducing the making of music to some form of formula or program is that the people who do this have a fundamental lack of knowledge in regards to how music is created.
There is definite logical approach to good music creation. Nothing about this is random. The rules regarding melody can often be complicated. Chordal choosing has its own amount of rules that can also get complicated. You need a thorough understanding of the instrument you are writing for to know how the phrasing works and to know what notes the instrument can play.
And through it all even if you are able to teach all the nuances of all these rules to the machine how are you going to get the computer to feel emotions? How are you going to get the express emotions? How are you going to get the machine to write and tell stories trough the making of the music? Sterile, emotionless music is meaningless.
I do not think you would be able. You may get it to spout out a collection of notes but it would probably be far from music.
Comment: Check out Philip K. Dick,  "The Preserving Machine"
Comment: I'll bet you could have a computer randomly create some convincing 12-tone compositions. That's mainly because those seem to be a bit random sounding when they are composed by humans.
Answer: I fear that you do not have sufficient musical background to achieve much with this.
Any such computer code would depend on your having listened to a great deal of music from the style period, and thoroughly understanding the rules that composers used to write music then. This means having studied all the relevant music theory and the relevant historical textbooks, and then trying to express those principles into code. This would be something that somebody with a master's degree or a Ph.D. in music composition might attempt after many years of study. It would be way beyond the skills of a musician such as myself.
As mentioned by Neil Meyer in his excellent answer, a lot of modern concepts in music did not exist in the Medieval period. They did not use the major or minor scales; they used the church modes. Key signatures had not been invented. They did not use chords or chord progressions per se. The concept of the time signature, and measures and bars, had not been invented. When you see medieval music written in modern notation, modern editors superimpose those elements onto the music to make it easier for modern musicians to read it, but the fact is that the composers in the medieval style period were not thinking in those terms and those ideas did not influence the music they wrote.
Polyphony and counterpoint were being invented and developed during this style period (leading to the Renaissance), and that is a difficult subject to learn. You would need an understanding of certain concepts including church modes, organum, discant, melisma, polyphony, clausulae, and rhythmic modes, and how they were used in that style period.
Historically, for medieval music, you would look to the work of Guido of Arezzo (992-1033) and Franco of Cologne (mid-1200s).
Finally, in any style period, there are many different kinds of music written for different purposes. Are you talking about church music, to be sung? Instrumental music for dancing? Sacred or secular motets? Music for strings, winds, brass, percussion and drums? Different styles of music popular in different nations and locations? There is no way to generalize and write one short piece of computer code that can cover the music made in many different nations across many hundreds of years.


p-adic integers, isomorphism, proof explanation

Question: I am studying the following proof and need some help at some points.
While going through the proof, I numerate my questions, to refer to them at the end.
For the notation note, that $U_n=1+p^n\mathbb{Z}_p$ and $U=\mathbb{Z}_p^\times$ (the group of p-adic units).
Theorem:
If $p\neq 2$, $U_1$ is isomorphic to $\mathbb{Z}_p$.
If $p=2, U_1=\{\pm 1\}\times U_2$ and $U_2$ is isomorphic to $\mathbb{Z}_2$.
Proof:
Consider first the case $p\neq 2$.
Choose an element $\alpha\in U_1- U_2$, for example $\alpha=1+p$. (1)
By the lemma:

Let $x\in U_n- U_{n+1}$ with $n\geq 1$ if $p\neq 2$ and $n\geq 2$ if $p=2$. Then $x^p\in U_{n+1}- U_{n+2}$

we have $\alpha^{p^i}\in U_{i+1}- U_{i+2}$.
Let $\alpha_n$ be the image of $\alpha$ in $U_1/ U_n$.
We have $\alpha_n^{p^{n-2}}\neq 1$ and $\alpha_n^{p^{n-1}}=1$. (2)
But $U_1/ U_n$ is of order $p-1$, hence it is a cyclic group generated by $\alpha_n$.
Now denote by $\theta_{n,\alpha}:\mathbb{Z}/p^{n-1}\mathbb{Z}\to U_1/U_n$ the isomorphism $z\mapsto \alpha_n^z$.
The diagram:
$\require{AMScd}$
\begin{CD}
\mathbb{Z}/p^n\mathbb{Z} @>{\theta_{n+1,\alpha}}>> U_1/U_{n+1}\\
@VVV @VVV\\
\mathbb{Z}/p^{n-1}\mathbb{Z} @>{\theta_{n,\alpha}}>> U_1/U_n
\end{CD}
is commutative.
From this one sees that the $\theta_{n,\alpha}$ define an isomorphism (3)
$\theta:\mathbb{Z}_p\to U_1$ hence the proposition for $p\neq 2$.
Suppose now that $p=2$.
Choose $\alpha\in U_2- U_3$, that is $\alpha\equiv 5\mod 8$. (4)
Define as above isomorphism $\theta_\alpha:\mathbb{Z}_2\to U_2$.
On the other hand, the homomorphism $U_1\to U_1\setminus U_2\cong\mathbb{Z}/2\mathbb{Z}$ induces an isomorphism of $\{\pm 1\}$ onto $\mathbb{Z}/2\mathbb{Z}$ (5)
From this we get $U_1=\{\pm 1\}\times U_2$
Questions:
(1)
It appears that the choice of $\alpha\in U_1-U_2$ is free, since the given lemma we get always a generator of the cyclic group for every $x\in U_1-U_2$ as long as $x\neq 1$.
(2)
The image of $\alpha$ in $U_1/U_n$ is given by $\alpha_n\mod (1+p^n\mathbb{Z}_p)$.
What can we say about $\alpha_n$? Holds $\alpha_n\equiv 1\mod p^n$?
How can we see, that $\alpha_n^{p^{n-2}}\neq 1$ and $\alpha_n^{p^{n-1}}=1$?
Why is this enough to see, that $U_1/U_n$ is cyclic.
I guess, that $\alpha_n^{p^{n-1}}=1$ and $\alpha_n^{p^{n-2}}=\alpha_n\neq 1$ ensues from Fermat's little theorem. Am I right?
(3)
How exactly do we get the isomorphism $\theta:\mathbb{Z}_p\to U_1$
It is $\mathbb{Z}_p=\displaystyle{\lim_{\leftarrow}}~ \mathbb{Z}/p^{n-1}\mathbb{Z}$ and $U_1=\displaystyle{\lim_{\leftarrow}}~ U_1/U_n$
I see that we can extend the diagram and reduce $p^{n}$ any further until $n=0$.
But how do we get the projective limit? We get finite isomorphisms, but is that enough for the projective limit?
(4)
Why is for $\alpha\in U_2-U_3$ that $\alpha\equiv 5\mod 8$.
$\alpha\in 1+4\mathbb{Z}_2$ that means $\alpha\equiv 1\mod 4$. Since $\alpha\notin (1+8\mathbb{Z}_2)$ it is $\alpha\not\equiv 1\mod 8$ which means, that $\alpha\equiv 5\mod 8$.
(5)
We define an isomorphism $\theta_\alpha: \mathbb{Z}_2\to U_1$ as above. That is clear.
How do we see from the homomorphism $U_1\to U_1/U_2\cong \mathbb{Z}/2\mathbb{Z}$
That we get an isomorphism from $\{\pm 1\}\to \mathbb{Z}/2\mathbb{Z}$
How do we see that $U_1/U_2\cong \mathbb{Z}/2\mathbb{Z}$?
I want to give a function $f: U_1\to\mathbb{Z}/2\mathbb{Z}$ which is surjective and has kernel $U_2$.
Can this be done by $\alpha\mapsto \alpha\mod 4$? I am struggeling with the elements of the form $1+2\mathbb{Z}_2=U_1$. We can not say, that $U_1\cong 1+\mathbb{Z}/2\mathbb{Z}$, can we?
Thanks in advance for your help and comments.
Comment: You may refer to Neukirch's "Algebraic Number Theory". And I remember the proof is also contained in Iwasawa's "local class field theory" .
Comment: Not really an answer to your questions, but I think there is a "standard" proof  based on the exp and log function on the $p$-adic fields.
Comment: Do you have a source for that?
Comment: Thank you. Maybe I find these books at my university.
Comment: Thank you for transcribing the argument into MathJax so that the question is self-contained for posterity.  However, it would be good to also cite the source of your material, which appears to be Serre's *Course in Arithmetic* (a favourite of mine).
Comment: Yes, the source is Serre's Course in Arithmetic, which can be found here: https://www.math.purdue.edu/~lipman/MA598/Serre-Course%20in%20Arithmetic.pdf. I tried to give everything which is needed for the proof.
Comment: Neukirch's book is freely available here- http://www.cimat.mx/~luis/seminarios/Teoria-de-Numeros/Neukirch_Algebraic_number_theory.pdf
Comment: Do you know why this question does not have any answer yet? Are the questions unclear, or to many? You can also just answer a few, if you consider to answer the question but do not want to answer them all.
Answer: I see that you managed to confuse yourself quite a bit over it, so let's start with simple things. Forget about $p=2$ altogether (it just there to complicate every step by a special case; you can return to it later once you figured the rest out).
1) Yes, you can take anything in $U_1\setminus U_2$ though the condition $x\in U_1\setminus U_2$ is much stronger than $x\ne 1$. It means $x=1+yp+\dots$ for some "$p$-adic digit" $y\ne 0$.
2) $\alpha_n$ is the full remainder of $\alpha$ modulo $p^n$, so it is just the first $n$ digits of $\alpha$ (compare with the standard decimal representation; if you go modulo $10^n$, you just operate on the last $n$ digits ignoring all transfers to higher positions; $p$-adic integers are the same, just infinite and written low to high powers instead of high to low in the decimal notation. Obviously $\alpha_n\ne 1\mod p^n$. Note that $U_1/U_n$ is the multiplicative group (compare to the multiplicative group of last $n$ decimal digits of numbers ending in $1$).
$\alpha_n^{p^{n-2}}$ is the equivalence class of $\alpha^{p^{n-2}}\in U_{n-1}\setminus U_n$, so it is definitely not $1$ in $U_1/U_n$ (the $n$-th digit is still not $0$) but the next raising to the power $p$ will kill it.
$U_1/U_n$ has exactly $p^{n-1}$ elements (the first digit is $1$ and you have $p$ choices for each of the remaining $n-1$ digits. So, you have a finite group of order $p^{n-1}$ and an element $\alpha_n$ in it that has exactly the same order (recall that the order of any group element is a divisor of the group order and we have just excluded any divisor of $p^{n-1}$ strictly less than $p^{n-1}$. Thus, all powers of $\alpha^n$ from $0$ to $p^{n-1}-1$ are different and thus cover the whole group once.
(3) We can use this isomorphism $(Z_p/p^{n-1}Z_p,+)\ni z\mapsto \alpha_n^z\in (U_1/U_n,\times)$ to define the $n$ digits of $\theta(z)$ from the $n-1$ digits of $z$ and vice versa. The diagram shows that this process is consistent in the sense that getting more digits with larger $n$ doesn't change the digits we obtained with smaller $n$. So, in order to obtain the $n$-th digit we can just use any $\theta_m$ with $m>n$ with the same result.
This is indeed called something I don't remember what in algebra but the story is merely that you try to define a function that maps infinite sequences to infinite sequences from functions that tell you how to get the first $n$ elements of the output sequence from the first $n$ elements in the input sequence in a consistent way.
I'll stop here for now. Hope it helps a bit. :-)
Comment: @Cornman Not too much: in order to figure out just the $n$-th digit of the output, you need to know all the $n-1$ digits in the input. The formal story is that to know $\theta(z)$ in $\mathbb Z_p$ is equivalent to knowing it in all $\mathbb Z/p^n\mathbb Z$ and you are told how to find it there if you know $z$ in $\mathbb Z/ p^{n-1}\mathbb Z$ for each $n$. That information is always enough to determine $\theta(z)$ uniquely and allows to conclude that it exists if it is consistent. On the other hand, if you think of real analysis, can you give me some insight on what $x\mapsto e^x$ looks like?
Comment: Thanks for your answer. I quite do not understand what you write in (3). The diagram is reducing the $n$. Should it not go up to get an infinite series, therefore a p-adic integer?
Comment: @Cornman Yes you should, but who prevents you from reading the diagram from the bottom to the top instead of from the top to the bottom? (meaning that the next diagram that you should think of is not the one in which $n+1$ is replaced by $n$ but the one in which $n$ is replaced by $n+1$ and you should stack them up, not down)
Comment: Ah, ok. That makes sense. Could you give a little bit more insight on how the "final" isomorphism looks like? Or to be more specific how we conclude that we get $\theta: \mathbb{Z}_p\to U_1$
Comment: Thank you. If you now go over the questions (4) and (5). You can have the 100 reputations. :) I already showed that $U_1/U_2\cong \mathbb{Z}/2\mathbb{Z}$
Comment: @Cornman As to (4),your explanation there is perfectly correct. As to (5), I'm not quite sure what exactly is your problem. You have one misprint: the isomorphism is from $\mathbb Z_2$ to $U_2$, not to $U_1$. After that you just have to show that $U_1$ isomorphic to $U_2\times\{-1,1\}$. Is it this last step that gives you trouble or is it something else? If it is, all that happens there is that $-1=(1,1,1,1,\dots)\in U_1\setminus U_2$ and $(-1)^2=1$, so each element $z\in U_1$ is either in $U_2$ or in $(-1)U_2$ (depending on the second digit) and the multiplication behaves as it should.
Comment: Thank you very much. Sorry for the misprint.


Backing up server and multiple clients

Question: I'm running a Amahi server. It's basically a Fedora14 x64 installation.
I'm looking for a good solution to backup my 200GB system drive on the server to an external USB/eSATA drive every night. I looked into using dd but since other things might be running on the server at the same time it didn't feel quite safe.
I would like the backups to be incremental so the following backups after the initial one would be quite fast. The backup should also be bootable or prehaps be able to produce a bootable disk after booting from a CD or something.
I would also like the server to be able to do similar backups of my clients running Ubuntu, Windows 7 x64, Windows 7 Starter, OSX Lion, Windows XP and so on. So no applications backing up only shared folders or something like that. My guess is a client daemon would have to exist that would lock the system to allow backup of a Windows system drive that can otherwise be quite cranky.
Booting up a CD in a crashed client and connecting to the server restoring the latest backup and being up running is my ideal goal.
Is there anything out there that would fit these needs?
Answer: I would say you need a different backup solution for each operation system.
For restoring linux you usually do not need an image (though it can be faster). Saving all files with permission is enough to restore a bootable Linux.
Thus I suggest using BackupPC or a client initiated backup using rsync/tar/dar. You can create consistent Linux backups using LVM. If you did not use LVM already you need to reinstall. See BackupPC+LVM.
I do not know much about Macs but TimeMachine seems to be good enough for your purposes. You can through some hackery use Linux as a TimeMachine target. If you want the plug'n'play(TM) Apple experience you should buy a real time maschine box ;)
For Windows you can either use the integrated image backup (in Win 7) to a network share on your home server; Go for Windows Home Server (which has such a client you mention). Or you go with UrBackup, that has that CD restore over network.
Comment: seconding backuppc. I've used it before as a third party and recently set it up myself on my own network. It's very very good imho. Highly recommended. It'll also backup linux, windows, and mac (and its own localhost) easy enough.
Answer: Getting a perfect snapshot while the unix systems are live is hard. You could reboot/change to a runlevel where not much is running, to get everything into a safe state. Otherwise, you're going to always have some risk of backups not quite matching - as you say yourself.
For backing up unix (linux and os x) incrementally, you might look at rsync. There are various higher level wrappers around it, but basically:
rsync / destsrv:/mnt/backup/snap-20110905 --link-dest=/mnt/backup/snap-20110904
will create a new tree under /mnt/backup/snap-20110905 containing all the files, but where they have not changed from the previous backup (specificed in link-dest) then they will be hard-linked to that directory rather than copied. So you'll keep yesterday's snapshop and today's snapshot, with them sharing as much as can be shared. So it matches your incremental requirement.
This won't give you a bootable snapshot - though you'll be able to easily copy the files onto a new drive and make it bootable. That is your secondary bootable requirement.
rsync will run over ssh, so as long as you can ssh from your client to your backup server you can back up a number of unix based systems onto the same backup server.
I have no idea how that would work under Windows (cygwin, for example). My assumption without further investigation is that it wouldn't work well at all. I think it would be fine for 'data-like' files (eg word docs) that don't have complicated file system permissions/extended attributes but probably not OK for system files.

Backing up server and multiple clients


Distance between triangle's centroid and incenter, given coordinates of vertices

Question:
If $G$ is the centroid and $I$ is the in-center of the triangle, with vertices $A(-36,7)$, $B(20,7)$, and $C(0,-8)$, then find the length of $GI$.

Well the obvious way to approach this problem would be to centroid of the triangle and then the incenter of the triangle, and then find the distance. Is there an easier method to do this problem? Doing it that way would get a bit lengthy.
Comment: The sides of the triangle can be immediately calculated. After that, the coordinates of $G$ are just the averages of the coordinates of the vertices. For the incenter the formula is simple: you can find it here http://mathworld.wolfram.com/Incenter.html In my opinion there's no simpler way.
Comment: I removed the `graph-theory` tag, since graph theory is an entirely different field of mathematics. :)
Comment: As @BeniBogosel notes, the centroid and incenter have straightforward coordinate formulas (average and weighted-average, respectively). It occurs to me that these imply that the vector from centroid to incenter has its own interesting form:
$$\overrightarrow{GI} =\frac{(b-a)(B-A)+(c-b)(C-B)+(a-c)(A-C)}{3(a+b+c)}$$ (where, of course, $a$, $b$, $c$ are the lengths of the sides opposite respective vertices $A$, $B$, $C$).
Comment: @Blue How exactly can you subtract coordinate points?
Comment: @Gummybears: You'll see this all the time when you learn about vectors. Until then, think of it as shorthand: we add (subtract) points by adding (subtracting) their corresponding coordinates; we multiply (divide) a point by a number by multiplying (dividing) each coordinate by that number. So, for instance, with $A(x,y)$ and $B(u,v)$, we have $$A+B = (x+u, y+v)\quad\text{and}\quad 2 A = (2 x, 2 y )$$ and even $$2 A + 5 B = ( 2 x + 5 u, 2 y + 5 v )$$ This lets us write things like $$G = \frac{1}{3}(A+B+C)$$ more compactly than as $$G = \left(\frac{A_x+B_x+C_x}{3}, \frac{A_y+B_y+C_y}{3}\right)$$
Answer: The side lengths are $a=25,b=39,c=56$ by the pythagorean theorem and the area is $\Delta=420$ by the Heron's formula or the shoelace formula, hence $r=7$. Since $h_c=\frac{2\Delta}{c}$, the length of the height relative to $C$ is $15$, hence the distance of $G$ from $AB$ is just $5$.
It is well known that $I=\frac{aA+bB+cC}{a+b+c}$ and $AI^2=bc-4rR=bc-\frac{2abc}{a+b+c}$, hence $IG^2$ can also be computed through the parallel axis theorem. Let we assume that $A$ has mass $a$, $B$ has mass $b$ and $C$ has mass $c$. With such assumptions, $I$ is the center of mass of $S=\{A,B,C\}$ and the moment of inertia of $S$ around $I$ is given by:
$$ M_I = a AI^2 + b BI^2 + c CI^2 = 3abc - 4(a+b+c) rR = abc $$
while the moment of inertia of $S$ around $G$ is given by:
$$ M_G = a AG^2 + b BG^2 + c CG^2 = \frac{1}{9}\sum_{cyc}a(2b^2+2c^2-a^2) $$
and by the parallel axis theorem $ M_G = (a+b+c) IG^2 + M_I$, hence:

$$ IG^2 = \frac{M_G-M_I}{a+b+c} = \boxed{\frac{\frac{2}{3}(a+b+c)^3-\frac{5}{3}(a^3+b^3+c^3)-13abc}{9(a+b+c)}}.$$

A difficult problem has just born:
 Prove that if $a,b,c$ are the side lengths of a triangle,
 $$ 2(a+b+c)^3 \geq 5 (a^3+b^3+c^3) + 39abc. $$
Tricky solution: $IG^2\geq 0$, and equality is achieved only when $I\equiv G$, i.e. when $a=b=c$.


AbsoluteLayout width and height 0px in a Panel. Vaadin

Question: First here is the code :
  mainLayout = new AbsoluteLayout();
mainLayout.setImmediate(false);

// body
HorizontalSplitPanel panel = new HorizontalSplitPanel();

panel.setFirstComponent(getFirstPanel());
panel.setSplitPosition(10, Unit.PERCENTAGE);
panel.setSecondComponent(getSecondPanel());

// absoluteLayout_2
body = new AbsoluteLayout();
body.addComponent(panel);
body.setImmediate(false);
body.setSizeUndefined();
body.setStyleName("Mybody");
mainLayout.addComponent(body, "top:160.0px;right:1.0px;bottom:45.0px;left:0.0px;");
mainLayout.setSizeUndefined();

Panel mainPanel = new Panel();
mainPanel.setContent(mainLayout);
mainPanel.setSizeFull();
// mainPanel.getContent().setSizeUndefined();

when I open the page nothing is displayed. It seems that all my layout that are inside my Panel have size : width:0px;height:0px;.
When I change the size as setSizefull() for all the layout it works but the panel does not scroll.
Any idea what I forgot in the code above ?
Answer: setSizeFull() usually disables scrollbars, use setSizeUndefined() and scrollbars will appear if the component is big enough
Comment: When I use setSizeUndefined() all my components have 0 width and Height. I don't want to give them a fixed size because the content change dynamically.


Machine Learning for Time Series: Train and test set overlap due to lagged target as feature – problem of data leakage?

Question: Situation:
My objective is to apply Machine Learning (for regression problems). Therefore, I have a panel dataset of time series with daily fund data from 2018-01-01 to 2020-12-31. My target is fund flow. To apply ML models, I wanted to split my dataset into train and test set, using 2018-01-01 to 2019-12-31 for training and 2020-01-01 to 2020-12-31 for testing.
Among others, I also use the lagged target as features (as well as other lagged variables of my time series) up to a lag of 1 year before the actual Date (t-365)
Question:
To predict the fund flow at 2020-01-01 (first date of test data) I use lagged time series features such as lagged fund flow (t-365). Therefore, this flow data used as feature here actually is from 2019-01-01. This data is appears as target (and features) also in the training set. I'm wondering whether this is an issue similar to data leakage. As I understand, my test dataset uses the exact data as features, my train data has already seen. Therefore the model knows large parts of this data (the closer the target date to the train set the more of the data the train set has already seen).
I'm wondering if this is an issue in predicting time series? If I use feature with a lag of 365 days, do I need to keep a gap of 365 days between train and test set?
Haven't found much in the literature so far, so your help is appreciated! Thanks for your support!
Answer: Yes, of course this is an issue. The most obvious case where this pops up is in autoregressive models, where we use lagged values of the time series itself as a predictor. It is the exact same problem as for any other predictor we don't know with certainty in the future, e.g., if we use weather data as a predictor.
This is commonly addressed by forecasting the predictor itself and feeding this forecast into the model. If there are interrelationships between the predictor and the target, one typically runs the forecasting system step by step into the future. In this method, it makes most sense to use an expectation forecast for the predictor (which is not necessarily what we are aiming for for the focal variable, depending on our accuracy measure, Kolassa, 2020).
A more sophisticated approach would be not to account for the uncertainty in the forecast of the predictor. For instance, one could re-run the prediction multiple times, each time feeding in a sample from the predictive distribution of the predictor. This will do a better job at capturing the uncertainty in the focal variable.


How to filter views output base on custom field

Question: I've created a view listing a content type named foo, it has a custom field 'start_date' which can be left blank.
When a node's start_date field is left blank, it should always show in the listing. When it's populated, and the date is less than the current date - then the node should also be listed.
I've tried to use hook_views_query_alter to do this, but it didn't do what I wanted as it's for changing the query itself.
Which hook should I use?
Answer: You can use the Views UI to accomplish this.
Add two date filters: one of them should filter date fields for "is empty" and the other should filter date fields for "is less than" and choose "Enter relative date" and type "now".
Then create an "OR" group and drag the two date filters to it. It should look like this:
Comment: Hi, @argiepiano.
Thans for your kindly comment. It's a great answer! But i have a another question complementary.Is it possible only worked for a special user role.
Example if current user's role is 'trainee', then the filter is efficient and if role is admin the filter was bypassed.
Comment: I don't think it's possible to do that with Views UI. You could try creating a custom filter programmatically that returns true for admin and false for everyone else, and include that in two OR groups. A tutorial on creating a custom filter: http://www.metaltoad.com/blog/drupal-7-tutorial-creating-custom-filters-views. Otherwise, Views PHP is a module that is despised by many Drupal programmers, but it *may* work for something like (keeping in mind that it poses many serious security risks.)
Comment: One more thing, since you are new to Drupal Answers - if you find answers useful you can vote them up or mark them as correct. That encourages people to provide other answers.
Comment: The tutorial above may not be that helpful in your case.
Comment: Take a look at this post. This may have what you need: http://drupal.stackexchange.com/questions/98551/d7-filter-a-view-based-on-current-users-roles (look at the answer marked as correct)


what is service mesh in container Load Balancing?

Question: When i read about Load Balancers & containers.Looking for clear understanding of service mesh in Load balancer and how it is useful in containers.
Answer: Thinking of service meshes, there is istio coming onto my mind, as well as envoy proxy.
https://istio.io/docs/concepts/what-is-istio/
https://www.envoyproxy.io/
What is that all about? To many things to squeeze into an answer over here, but this is a good article with several practical examples what features istio can provide:
https://developers.redhat.com/blog/2018/03/06/introduction-istio-makes-mesh-things/
Answer: Istio is coming to be well known for this. It operates as a 'sidecar' container, which just means it is another container in the same pod, so will co-locate with another container and can influence network traffic for that container.
Put simply, a service mesh is effectively a collection of agents (typically for a micro-service architecture), but somewhat inverted to traditional HA approaches with load-balancing virtual servers.
So for example: say an container app A wants to talk to service S; instead of S being an load-balancer (eg haproxy), you might have multiple instances of Ss. A will have a sidecar that has the property of when A wants to connect to S, the sidecar will route traffic to one of the Ss.
Imagine the difference in traffic throughout a microservice architecture; you've reduced the number of choke points because you've effectively got a load balancer for every client.
Now consider what else you could do with this sort of thing; want to authenticate services in a standard way without having to implement that in your container app? Perhaps a sidecar container could do that for you.
Want to have some nice circuit-breaker logic to help prevent timeouts and provide for graceful failure? Sidecar!
What about feature-flag support, so you can do things like dark-launch or fail-out features gracefully to cope with load. Sidecar!
How about helping to monitor, visualise and analyse traffic within your architecture? Monorail! Monorail! .... Sidecar!
What I'm trying to say is that you can make your application as simple as a green unicorn speaking http, and have something else care about the infrastructure and things that Developers typically hate thinking about (ssl, load-balancing, etc)
Or at least I hope that's what the service mesh promise is about.


Expectation of continuous rv X^2

Question: I ran the following algorithm to find the expected value of X^2 for a random variable X with pdf:
exp(-abs(x)^3/3)

This is what I did and my results:
reject_env <- function(){
  f <- function(x){exp(-abs(x)^3/3)}
  g <- function(x){1.1*exp(-abs(x)^2/4)}
  reject <- TRUE
  while (reject) {
    x <- rnorm(1)
    y <- runif(1, 0, g(x))
    if (y < f(x)) reject <- FALSE
  }
  return(x)
}

x <- c()
for (i in 1:1000000) {
  x[i] <- reject_env()
}

y = x^2
ybar <- mean(y)
mcse <- sd(y)/sqrt(length(y))
UB <- ybar + mcse*1.96
LB <- ybar - mcse*1.96
cat("The expected value is between [", LB, ",", UB, "]")

I end up with: The expected value is between [ 0.6018746 , 0.6048092 ]
This looks correct when you graph f:
xgrid <- seq(-10, 10, length.out = 100)
plot(xgrid, f(xgrid), type = "l")

My question is, how would I just use R's built in numerical integration function to solve this problem?
Comment: The expectation is elementary to evaluate (in the integrals use the substitution $3u=|x|^3,$ integrate from $0$ to $\infty,$ and double that); it equals $3^{2/3} / \Gamma(1/3) \approx 0.776458211378\ldots.$
Answer: Beware that the function $g = 1.1e^{-\frac{x^2}{4}}$ is proportional to the density of a $\mathcal{N}(0,2)$ but in your rejection algorithm you are sampling from a $\mathcal{N}(0,1)$ instead of a $\mathcal{N}(0,2)$.
If I just replace the $\mathcal{N}(0,1)$ by a $\mathcal{N}(0,2)$ in your code I find the interval $[ 0.7751043 , 0.7787279 ]$.
I you want you can use the R function integrate to compute approximations of integrals (here approximations on the interval $[-20,20]$).
f<-function(x) exp(-abs(x)^3/3)
c=integrate(f=f,-20,20)$value
f2<-function(x) (x*x)*f(x)/c
integrate(f2,-10,10)

$c$ is the normalizing constant of $e^{-\frac{\vert x \vert ^3}{3}}$.
The last line gives the message

0.7764582 with absolute error < 8.6e-10

which is indeed in the previously computed interval.
Maybe there are better functions to compute integrals in R (like area is the MASS library).
Comment: In what sense does it matter that the function g is proportional to N(0,2) rather than N(0,1)? g is an envelope function for the creation of an acceptance/rejection region, so isn't it the case that all I care about is that it is >= f at every point x? Except then when I change it to rnorm(1,0,2) I get a different answer from mine and yours... I'm also confused about the constant. Why is the constant the integral of the pdf? We don't know the constant for f(x) = c *pdf. Wouldn't we have to figure that out some other way?
Comment: The purpose is to draw random points under the curve of this envelope function and keep only those which are under the targeted curve. If $X \sim g$ then $(g(X), U)$ where $U \sim \mathcal{U}(0,g(X))$ is uniformly distributed under the curve of $g$. However if you draw $X$ which is not distributed as $g$ then the uniformity doesn't hold anymore. In R the third argument in rnorm(1,0,2) is the standard deviation not the variance, thus you should use rnorm(1,0,sqrt(2)) instead.
Comment: Okay, that all makes perfect sense. Thank you very much.

Expectation of continuous rv X^2


Notation for violin harmonics in "La Création du Monde"

Question: At the end of Darius Milhaud's La Création du Monde, the violins have some harmonics notated that I can't quite figure out.  I'm not a string player, and I'm wondering if the notation given here would be sufficiently clear for a modern violinist, or whether a different notation would be better.  Here are the chords in question:

For the Violin I (upper) part, I think I've convinced myself that the notes are straight octave harmonics.  So the first note involves lightly touching the G string at its midpoint and the second involves lightly touching the D string at its midpoint.  Both notes would sound as written.
The Violin II (lower) part is what confuses me.  Are the Ds supposed to be fingered as D4s on the G string (i.e., string IV), sounding at D5?  Or is there some way to produce a D4 as a harmonic on the G string?  I thought that the sounding pitch is what's shown when harmonics are called for, rather than the fingering position.  The fingering note and the sounding note are the same for the Violin I notes, but not for these.
Answer: This suffers from the confusing fact that the "small perfect circle" symbol is being used in two ways simultaneously. You're right that the 1st violins have plain old harmonics (midpoint of G and D strings). However, many publications, especially from French turn-of-the-century printers, used the circle as a "0" to indicate open strings as well. The final notes of the second violins have open D strings, with the E and F# fingered on G string (so the "IV" applies to the E and F#).
Comment: It seems obvious now that you point it out.  Many thanks.
Comment: For reference,  use of a small "o" to indicate open string is standard use in all the 20th-century printings (not composition date) I've seen
Answer: Judging by recordings, these violin chords definitely sound as if they're supposed to contain e, g and d. Therefore I assume that the second violins are supposed to touch the G string at the d and simultaneously play an e on the D string normally. (You can generate the second harmonic either by touching the string at 2/3 or at 1/3 of its length; presumably Milhaud chose the less common 1/3 solution here so that you can reach it while also playing the regular e.)


A connection between primes, right triangles and $\pi$.

Question: This question is motivated by the question A mysterious connection between primes and $\pi$ in MO hence a similar title. Is the following claim true?

Conjecture: The ratio of the sum of the squares of the hypotenuse to the
  sum of the area of all Pythagorean triangles in which the hypotenuse
  is a prime $\le n$ tends to $2\pi$ as $n \to \infty$.

Source code:
<code>p = 5
sn = sd = 0
target = step = 10^3

while True:
    if p%4 == 1:
        x = 1
        while x < p:
            y = (p^2 - x^2)^0.5
            if y%1 == 0:
                sn = sn + x^2 + y^2
                sd = sd + x*y
                i = i + 1
                break
            else:
                x = x + 1
    p = next_prime(p)
    if p > target:
        target = target + step
        print p, sn/sd.n()
</code>
Comment: I would replace "is a prime number is $2\pi$" with "is a prime number less than $n$ tends to $2\pi$ as $n$ tends to infinity". Normally I wouldn't bother to spell it out like this, but the statement is unusual enough that I think it should be stated precisely.
Comment: @TonyK Sure. Done.
Answer: This follows from certain results about equidistribution of Gaussian primes in sectors, references for which you can find e.g. here. I will not perform the detailed calculations, but rather outline the ideas involved.
For a prime $p\equiv 1\pmod 4$, the nontrivial solutions $(x,y)\in\mathbb N^2$ of $x^2+y^2=p^2$ arise as $x+yi=(a+bi)^2$ for a Gaussian prime $a+bi$ in the sector $\{re^{i\theta}:0<\theta<\pi/4\}$ (or the same with $x,y$ swapped, but for the sums you are interested in it won't make a difference). For every $p$ there will be precisely one such prime, let us write $a+bi=\sqrt{p}e^{i\theta_p},0<\theta_p<\pi/4$. Then $x+yi=pe^{2i\theta_p}$. We have $x^2+y^2=p^2$ and
$$xy=p^2\sin 2\theta_p\cos 2\theta_p=\frac{p^2}{2}\sin 4\theta_p.$$
Now by the result cited above, the angles $\theta_p$ are equidistributed in $[0,\pi/4]$, and so the angles $\psi_p:=4\theta_p$ are equidistributed in $[0,\pi]$. Since the average value of $\sin x$ on $[0,\pi]$ is $2/\pi$, we that the sum of $xy$ over all primes $p\leq N$ for some $N$ will be approximately
$\frac{2}{\pi}\sum_{p\leq N}\frac{p^2}{2}=\frac{1}{\pi}\sum_{p\leq N}p^2$,
so the sum of the areas of the triangles will be approximately half that, $\frac{1}{2\pi}\sum_{p\leq N}p^2$.
On the other hand, the sum of the squares of hypotenuses is clearly $\sum_{p\leq N}p^2$. Taking the quotient of the latter with the former we get the desired $2\pi$.


How can I communicate with a REV robot control hub through wifi?

Question: I have a REV robot kit from the First Global Challenge competition. It has a control hub which runs Android and creates an own network. I can connect that wifi with my phone and I can upload a program. But if I am connected to that network, I am offline and I can't send web requests to communicate with my server. Is there any way to solve this? I have a router, maybe it can help.
Comment: If you are participating in FIRST isn't [WiFi against the rules](https://frc-qa.firstinspires.org/eventrules/rule/E/12)?
Comment: I was participating in FIRST, but I want to use the robot for a home project.
Answer: Unfortunately, the only way to do this currently is to connect a USB WiFi adapter to your computer, which will allow you to connect to a second network.
Answer: I solved this by connecting to the REV Controller's WIFI with my laptop, and then I plugged the ethernet cable in my computer.


What permissions should SQL Server User be granted for LinqToSql?

Question: I am using LinqToSQL and a trusted connection to handle database selects/updates/inserts/deletes.  In the past I have always used stored procedures and only granted execute permission to the Application Pool identity for the particular sproc in the database.  This is my first LinqToSql project (and I really love how much it helps).  I would prefer not to grant dbo access to the application pool identity to get LinqToSql to work (but if that is recommended then I don't mind).  What type of permissions can I grant to the Application Pool identity so that LinqToSql will have the minimum permissions?  Or should I just go with dbo permissions and be done with it?
As per KristoferA's answer this is the permissions I granted the application pool identity in the database:
EXEC sp_addrolemember 'db_datareader', 'app_pool_identity'
EXEC sp_addrolemember 'db_datawriter', 'app_pool_identity'
Not exactly the same level of security as only granting execute permissions to the necessary sprocs but I am very good with it considering the huge development gains I have achieved just by using Linq2SQL.  And it is better than granting the full dbo access.
Answer: db_datareader and db_datawriter is enough if you just want to read and write data without messing around with schema changes and stuff...
Answer: LinqToSQL creates dynamically generated SQL. As such, it needs full access to the data manipulation language commands (insert, update, delete). Your application account should not need access to data definition language commands (create, drop, alter, etc.).


Analogue GitHub for XCode

Question: I'm new at iOS developing.
I want to develope for iOS with my friend, but GitHub provides private project for money.
Does anyone know analogue of GitHub, which provides free private project and supports XCode 4.2?
Comment: git doesn't care about your language or data -- hence it does support xcode. You could always set up a remote on a server of yours
Comment: Is your question, "how to run something like GitHub for private repositories"? (http://stackoverflow.com/questions/8390828/how-can-i-have-github-on-my-own-server/8390894)
Comment: Is your question, "How to share code with your friend"?  As mentioned you could set up a repo that is accessible to both of you.  Alternatively, since git is distributed, you technically don't even need a central repo.  You could just add remotes for each other's machines, and pull/push from each other's repos as needed.
Comment: thx to all for reply. BitBucket is pretty usefull to me.
Answer: You can use BitBucket. Sadly, no more details are available since the site has been down for the past several hours (which I suppose isn't a glowing advertisement for the service).
Answer: You can just setup a private server of your own, easily.  You can use git for source control and Redmine for issue tracking, for instance.
Or as others have mentioned, BitBucket should work when the service is working again.

Analogue GitHub for XCode


python libraries for programatic email access: mime, smtp, pop3

Question: Does python have built in libraries for accessing email including: smtp, pop3, mime parsers etc?
Answer: Absolutely:

smtplib — SMTP protocol client
poplib — POP3 protocol client
imaplib — IMAP4 protocol client
email — An email and MIME handling package

They are all included in the Python standard library.
Comment: Python also has excellent documentation at http://docs.python.org including the Library Reference which includes all the above and much more.


CSS changes to .menu .leaf affect main-menu AND admin shortcut menu in Drupal 7

Question: I'm using drupal 7 and have created the subtheme of omega using drush omega-wizard. I'm using compass to watch for changes to the scss files and it's +/- behaving as I'd expect. My problem occurs when I try to style the main-menu with something like:
<code>.menu .leaf {
    width: 30px;
}
</code>
The restyling works but it also affects the admin's shortcut menu which uses .menu .leaf. Is there a setting in the config that I've missed, should I be targeting the menu in another way. How do I not affect the shortcut menu when styling the main-menu?
Any help would be greatly appreciated.
Thanks, Steve
Comment: This is not a solution but you have one extra dot after leaf.
Answer: You need to make your CSS more specific so that it only applies to menu items on your main menu. You can do this by prefixing the CSS rule with the class of its container e.g.
<code>.block--system-main-menu .menu .leaf. {
    width: 30px;
}
</code>


How do I use RPM to install GCC from my CentOS distribution media?

Question: I have a few package installation related questions concerning RPM, YUM and CentOS and getting GCC installed:

I've mounted my distribution media on my CentOS 5.2 machine but I can't seem to work out how to point RPM at the media and use that instead of looking to the internet. All the examples I've googled for appear to assume downloading the RPM's from the internet.
What does the -ivh switch combo do (I'm guessing -i is for install)? I did man rpm but the switch count and combinations blew my mind.
Should I be using YUM instead of RPM?
Answer: I'd recommend using yum localinstall rather than using the rpm command directly; that way you'll have the gcc package in your yum database so that it can keep track of updates.  The command would just be:
yum localinstall /mnt/cdrom/CentOS/gcc-(whatever).rpm

Comment: Good answer, I didn't know about that.
Comment: These were all great answers and they all got a +1 from me earlier, but this was the one got me going.
Answer: You want to use something like rpm -ivh /mnt/cdrom/CentOS/gcc-(whatever).rpm.  The command line options there are:

-i -- install (you can use -U to install or upgrade, many just always use that)
-v -- verbose output
-h -- show hashmarks, a simplistic progress bar

Yum will figure out which package you mean if you type yum install gcc.  That'll use your chosen repository, or the CD if you've got the correct repository installed (which you probably do).  In general, yum is easier to use if you're not doing anything strange.
Answer: There is probably already a repo defined in yum for the centos media that you can use that just needs to be enabled.  The documentation included in the file shows you how you could disable all your remote repos, enable just the local media repo and install your software package from cd.
$ cat /etc/yum.repos.d/CentOS-Media.repo
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
#  CentOS-5.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c5-media [command]
#
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c5-media [command]

[c5-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Comment: If you are going to go with a yum localinstall keep in mind that it usually works best when the package being installed has no dependencies. That's why setting up the local DVD repo as mtinberg/Rajat explained is not overkill, because it won't be the last time you install something from the DVD. I can't believe that yum did not go out on the internet to resolve the dependencies on binutils, cpp, and glibc-devel. Am I missing something?
Answer: 1 step rpm -ivh vsftpd.x86_64 0:2.2.2-7.rpm
2 step rpm -ivh createrepo-0.9.8-4.rpm
3 step copy every thing from DVD or .iso to /var/ftp/pub  (cp -av /var/ftp/pub)
4 step createrepo -v /var/ftp/pub/
5 step vi /etc/yum.repos.d/base.repo
6 step
[base]
name=Server Software
baseurl=ftp://192.168.0.254/pub/
enabled=1
gpgcheck=0
7 step yum install gcc -y
Comment: "Set up a local package repository" seems like overkill for "hey, how do I install a package?", doesn't it?
Comment: yum install    -y


Question about how to solve an inseperable differential equation

Question: In my differential equations class we are discussing how to find the amount of salt at a specific time given the rate of change equation $$\frac{dS}{dT} = 2-\frac{S}{(15+T)}$$ where $T$ is time and $S$ is the amount of salt.  I had the idea to attempt to rewrite the equation so that we can take the integral of each part of the equation.  I encountered a problem where $T$ didn't always align with the $dT$ and similar for $S$. I decided to partially integrate, similar to taking a partial derivative and got an answer that seemed right.  I want to know if it is viable to use this method to solve an inseparable equation or if I would need to use other methods in order to arrive at the correct answer.
Comment: Please be sure to edit your questions for grammar and spelling, and in the future to use MathJaX formatting. I have done the edits for you, and they will be visible after moderator approval.
Answer: Just separation of variables will not suffice, but you will use it at one point.
When i encounter a new differential equation, the first thing i think about is its type (like linear, nonlinear, autonomous, homogeneous, etc). So think about what type your equation is and what methods apply.
Answer: You cannot directly apply separation of variables.
This is a first-order linear ordinary differential equation:
$$\frac{dS}{dT}+f(T)S=g(T)$$
Put your equation in the form above:
$$\frac{dS}{dT}+\frac{1}{15+T}S=2 \tag{1}$$
You can solve this using an Integrating factor or by using Variation of parameters.
For this example, I will use the integrating factor method.
The integrating factor will be given by: $\mu(T)=e^{\int \frac{1}{T+15}~dT}=T+15$. No need to consider the arbitrary constant of integration.
Therefore, we multiply this by $\mu(T)$ (Our integrating factor) on both sides of $(1)$:
$$(T+15)\frac{dS}{dT}+S=2(T+15)\tag{2}$$
Now, substitute $1=\frac{d}{dT}(T+15)$:
$$(T+15)\frac{dS}{dT}+\frac{d(T+15)}{dT}S=2(T+15)\tag{3}$$
And use the reverse chain rule on the LHS of equation $(3)$: $uv'+v'u=(uv)'$. Then integrate both sides with respect to $T$.
Feel free to ask questions if you cannot continue from here.


The 32-bit program cannot be executed with RISC-V Spike. Can't Execute 32-Bit Program on RV64 Hot

Question: The following software has been built, installed, and passes. RISCV-GNU-TOOLS (both 64, 32bit), Spike, Riscv-PK (32bit).
If you try to execute the C language program with RISCV32 and execute it in Spike, you will get an error as follows. What should I do? The environment is ubuntu-20.04, 64 bit.
$ riscv32-unknown-linux-gnu-gcc -static fib.c -o fib
$spike $riscvpk/bin/pk fib
Error: cannot execute 32-bit program on RV64 hart

What I did to make 32bit support.
sudo dpkg --add-arrhitecture i386
sudo apt-get update
sudo apt-get install libc6: i386 libncurses5: i386 libstdc ++ 6: i386
sudo apt-get Install gcc-multilib

#~/.bashrc
# RISC-V gnu-tools 64bit
export PATH=${PATH}:/opt/riscv/bin
# RISC-V gnu-tools 32bit
export PATH=${PATH}:/opt/riscv32/bin
# RISC-V spike
export RISCV=/opt/riscv32-tools/toolchain
export PATH=$PATH:$RISCV/bin
# RISC-V pk
export riscvpk=/opt/riscv32/bin/riscv32-unknown-linux-gnu
export PATH=$PATH:$riscvpk/bin

Comment: It is not clear what you are trying to ask. Do you want to execute risc32 binary on Ubuntu amd64 ie. Ubuntu PC?
Comment: Yes. Ubuntu PC.
Comment: I think you need https://www.qemu.org/docs/master/system/target-riscv.html
Comment: I installed ```apt-get install qemu-system-misc```, but it can't work with the same error.
Answer: For running 32 bit riscv binaries, you need to add --isa=RV32IMAFDC flag while running spike command. (Depending on your used extensions, e.g. also it can be --isa=RV32IM)
spike --isa=RV32IMAFDC $riscvpk/bin/pk fib


MariaDB C++ Connector compile

Question: I'm trying to compile a simple c++ file that is suppose to use the mariadbc++ connector. For some reason I ran into alot of trouble with that. I get strange error messages. I neither understand them, nor do I know how to fix them.
   I did a lot of research, but either nobody else ran into these problems or I just cant find them.
I installed following packages:
mariadb-client
mariadb-client-5.5
mariadb-server
libmariadbclient18
libmysqlclient18
libmysqlcppconn7
libmysqlcppconn-dev
libmariadbclient-dev
libmariadb-dev

I'm on a x64 Ubuntu 14.04 System (well Pinguy OS, but I guess, that doesn't matter)
I tried to build following programm:
#include <my_global.h>
#include <mysql.h>
#include "mysql_driver.h"

int main(int argc, char **argv)
{
  sql::mysql::MySQL_Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance();
  con = driver->connect("tcp://localhost:3306","root", "herein");
  if (!con->isValid()) exit(1);

  stmt = con->createStatement();
  stmt->execute("use testtb");

  stmt->execute("INSERT INTO Testtable(id, label) VALUES (1, 1)");
  delete stmt;
  delete con;
  return 1;
}

And I tried this command:
g++ -lmysqlcppconn -g src/test_mariadb.cpp -o bin/test_mariadb $(mysql_config --cflags) $(mysql_config --libs)

where under in src/ my source files are and in bin/ my binaries.
And finally the Compile Errors I get:
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from /usr/include/boost/assert.hpp:82,
                 from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
                 from /usr/include/boost/scoped_ptr.hpp:14,
                 from /usr/include/mysql_driver.h:30,
                 from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:56: error: macro "min" passed 3 arguments, but takes just 2
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:56: error: macro "max" passed 3 arguments, but takes just 2
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
                                                        ^
In file included from /usr/include/boost/mpl/aux_/begin_end_impl.hpp:21:0,
                 from /usr/include/boost/mpl/begin_end.hpp:18,
                 from /usr/include/boost/mpl/iter_fold.hpp:18,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_begin.hpp:20:57: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_begin, begin, true)
                                                         ^
In file included from /usr/include/boost/mpl/sequence_tag.hpp:18:0,
                 from /usr/include/boost/mpl/begin_end.hpp:19,
                 from /usr/include/boost/mpl/iter_fold.hpp:18,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_tag.hpp:20:54: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_tag, tag, false)
                                                      ^
In file included from /usr/include/boost/mpl/aux_/O1_size_impl.hpp:20:0,
                 from /usr/include/boost/mpl/O1_size.hpp:19,
                 from /usr/include/boost/mpl/iter_fold.hpp:19,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_size.hpp:20:1: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_DEF(size)
 ^
In file included from /usr/include/boost/mpl/apply_wrap.hpp:23:0,
                 from /usr/include/boost/mpl/bind.hpp:27,
                 from /usr/include/boost/mpl/lambda.hpp:18,
                 from /usr/include/boost/mpl/iter_fold.hpp:20,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_apply.hpp:22:58: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_apply, apply, false)
                                                          ^
In file included from /usr/include/boost/mpl/quote.hpp:23:0,
                 from /usr/include/boost/mpl/aux_/full_lambda.hpp:25,
                 from /usr/include/boost/mpl/lambda.hpp:22,
                 from /usr/include/boost/mpl/iter_fold.hpp:20,
                 from /usr/include/boost/variant/detail/initializer.hpp:28,
                 from /usr/include/boost/variant/variant.hpp:31,
                 from /usr/include/boost/variant.hpp:17,
                 from /usr/include/cppconn/connection.h:31,
                 from /usr/include/cppconn/driver.h:30,
                 from /usr/include/mysql_driver.h:32,
                 from src/test_mariadb.cpp:3:
/usr/include/boost/mpl/aux_/has_type.hpp:20:55: error: macro "test" passed 2 arguments, but takes just 1
 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_type, type, true)
                                                       ^
In file included from src/test_mariadb.cpp:1:0:
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected unqualified-id before 'const'
     min(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected ')' before 'const'
/usr/include/c++/4.8/bits/stl_algobase.h:193:5: error: expected initializer before 'const'
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected unqualified-id before 'const'
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected ')' before 'const'
/usr/include/c++/4.8/bits/stl_algobase.h:216:5: error: expected initializer before 'const'
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from /usr/include/boost/assert.hpp:82,
                 from /usr/include/boost/smart_ptr/scoped_ptr.hpp:15,
                 from /usr/include/boost/scoped_ptr.hpp:14,
                 from /usr/include/mysql_driver.h:30,
                 from src/test_mariadb.cpp:3:
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: 'std::min' declared as an 'inline' variable
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:239:5: error: template declaration of 'const _Tp& std::min'
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected primary-expression before 'if'
       if (__comp(__b, __a))
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:242:7: error: expected '}' before 'if'
/usr/include/c++/4.8/bits/stl_algobase.h:244:7: error: expected unqualified-id before 'return'
       return __a;
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: 'max' declared as an 'inline' variable
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/4.8/bits/stl_algobase.h:260:5: error: template declaration of 'const _Tp& max'
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected primary-expression before 'if'
       if (__comp(__a, __b))
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:263:7: error: expected '}' before 'if'
/usr/include/c++/4.8/bits/stl_algobase.h:265:7: error: expected unqualified-id before 'return'
       return __a;
       ^
/usr/include/c++/4.8/bits/stl_algobase.h:266:5: error: expected declaration before '}' token
     }

Answer: A header you have included has defined preprocessor macros named min, max and test. These have then conflicted with identifiers used (e.g. for method names) in other header files you have included.
Assuming that those macros have been defined in one of these headers:
#include <my_global.h>
#include <mysql.h>

you could add #undefs before you include mysql_driver.h, e.g.:
#include <my_global.h>
#include <mysql.h>
#undef min
#undef max
#undef test
#include "mysql_driver.h"

You could also consider re-arranging the order in which you include the files, or look into what headers are defining these and see whether the definition of these macros can be disabled.
Comment: Thanks alot, it was actually a problem with including the headers my_global.h, mysql.h. They messed up the cppconnector. I just removed them and everything copiled just fine!

MariaDB C++ Connector compile


Apache Client-cache jar

Question: I' trying to use Jira Rest Java Client's jar and have ran into a few bumps.
I'm getting this error for a while now:
<code>java.lang.NoSuchMethodError: org.apache.http.impl.client.cache.CacheConfig.setNeverCache1_0ResponsesWithQueryString(Z)V
    at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:155)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)
    at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:41)
    at com.backend.server.HomeController.commitIssue(HomeController.java:1517)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
</code>
Now, I have a jar of httpclient-cache-4.3-beta2.jar, but that only has the desired method inside a Builder object in the CacheConfig class, as far as I can see..
Can anyone point me to the right dependency for his?
Thanks
Answer: I know my reply is late. But still I gave a great fight on my own and found the correct jar file for this
Download httpclient-cache-4.2.1-atlassian-2.jar

Apache Client-cache jar